Welcome Guest, you are in: Login

FDOT Wiki

RSS RSS

GisFramework



Search the wiki
»
Startup Action Running

Startup Action Running

Startup Actions are classes that can be configured and are executed on startup of the framework. They will be only run once per a user's session. These actions are executed after all of the map services have been initialized. One example use would be performing a query on bridges and displaying them as a client side graphics before the app starts up for the user. Startup actions are Configured in Virtual Applications.

Table of Contents [Hide/Show]


IStartupAction
         Properties
         Methods
         Events
MEF Exporting
Example
See Also


IStartupAction

The interface that is implemented for Startup Actions is FDOT.GIS.Client.Domain.IStartupAction.

Properties

NameTypeDescription
IsInitializedboolIndicates if the startup action is initialized
StartupActionTextstringThis is the text that is displayed during the loading screen while the startup action is executing.

Methods

NameReturn TypeDescription
Initialize(IDictionary customSettings)voidIndicates if the startup action is initialized.
ExecuteStartupAction()voidThis is the method where the code that is to be executed for the startup action is placed.

Events

NameDescription
CompleteThis event is raised to signal the startup action is complete.

Important: The event Complete must be raised once the Startup Action is completed. If this event is not raised then the application will be stuck on the loading screen indefinetly.

MEF Exporting

Startup Actions require the MEF attribute [Export(typeof(IStartupAction))] located at the class level to exportable.

Example


[Export(typeof(IStartupAction))]
    public class BmsciStartupAction : IStartupAction
    {
        private GraphicsManager _bridgeGraphicsManager;
        private GraphicsManager _militaryGraphicsManager;
        private GraphicsManager _roadsGraphicsManager;
        private static int _count = 3;
        private static object _lockObj = new object();

        #region IStartupAction Members

        public void Initialize(IDictionary<string, string> customSettings)
        {
            _militaryGraphicsManager = GraphicManagerFactory.CreateGraphicsManager();
            _roadsGraphicsManager = GraphicManagerFactory.CreateGraphicsManager();
            _bridgeGraphicsManager = GraphicManagerFactory.CreateGraphicsManager();
        }

        public void ExecuteStartupAction()
        {
            MapHandler.DynamicLayers.First().Visible = false;
            GetMilitary();
            GetRoads();
            BridgeManager.BridgesLoaded += BridgeManager_BridgesLoaded;
            BridgeManager.LoadBridges();
        }

        public bool IsInitialized { get; set; }

        public string StartupActionText
        {
            get { return "Loading Bridges, Military Facilities, and Strahnet"; }
        }

        public event EventHandler Complete;

        #endregion
        private void CallbackComplete()
        {
            lock (_lockObj)
            {
                _count--;
                if (_count == 0)
                    Complete(this, new EventArgs());
            }
        }
        private void BridgeManager_BridgesLoaded(object sender, EventArgs e)
        {
            List<SolidColorBrush> colors = new List<string>
                                               {
                                                   "#FFFF00",
                                                   "#FF00FF",
                                                   "#808080"
                                               }.Select(c => new SolidColorBrush(ColorConverter.HexColor(c)
)).ToList();
            _bridgeGraphicsManager.AddFilteredGeometry(BridgeManager.AllBridges, colors.Select(b => b.Color).ToList(),
                                                       "VCLRCD");
            CallbackComplete();
        }

        private void GetMilitary()
        {
            QueryServiceClient querySvs = ServiceClients.GetQueryServiceClient();
            querySvs.QueryCompleted += MilitaryComplete;

            var parameters = new SpatialQueryOptions
                                 {
                                     Layer = new Layer {Id = 6},
                                     ReturnAllFields = true,
                                     ReturnGeometry = true,
                                     OutputSpatialReference = MapHandler.MapSpatialReference,
                                     InputSpatialReference = MapHandler.MapSpatialReference,
                                     Criteria = new Criteria
                                                    {
                                                        ComparisonType = ComparisonType.NotEqual,
                                                        Field = new LayerField {Name = "OBJECTID"},
                                                        Value = "-1"
                                                    }
                                 };

            querySvs.QueryAsync(parameters, MapHandler.DynamicLayers.First().Url);
        }

        private void MilitaryComplete(object sender, QueryCompletedEventArgs e)
        {
            foreach (Feature f in e.Result.ConvertToFeatures())
            {
                _militaryGraphicsManager.AddGraphic(f, new SimpleFillSymbol
                                                           {
                                                               Fill =
                                                                   new SolidColorBrush(
                                                                   ColorConverter.
                                                                       HexColor("#336633"))
                                                           }, null);
            }
            CallbackComplete();
        }

        private void GetRoads()
        {
            QueryServiceClient querySvs = ServiceClients.GetQueryServiceClient();
            querySvs.QueryCompleted += RoadsComplete;

            var parameters = new SpatialQueryOptions
                                 {
                                     Layer = new Layer {Id = 1},
                                     ReturnAllFields = true,
                                     ReturnGeometry = true,
                                     OutputSpatialReference = MapHandler.MapSpatialReference,
                                     InputSpatialReference = MapHandler.MapSpatialReference,
                                     Criteria = new Criteria
                                                    {
                                                        ComparisonType = ComparisonType.NotEqual,
                                                        Field = new LayerField {Name = "OBJECTID"},
                                                        Value = "-1"
                                                    }
                                 };

            querySvs.QueryAsync(parameters, MapHandler.DynamicLayers.First().Url);
        }

        private void RoadsComplete(object sender, QueryCompletedEventArgs e)
        {
            List<SolidColorBrush> colors = new List<string>
                                               {
                                                   "#FF0000",
                                                   "#0000FF",
                                                   "#0000FF"
                                               }.Select(c => new SolidColorBrush(ColorConverter.HexColor(c)
)).ToList();


            _roadsGraphicsManager.AddFilteredGeometry(e.Result.ConvertToFeatures(), colors.Select(b => b.Color).ToList(),
                                                      "COLOR_CODE");
            CallbackComplete();
        }
    }

See Also

  Name Size
- StartupActionLoading.PNG 28.85 KB
Any Questions or Comments? Email
Some of the icons created by FamFamFam.