Esempio n. 1
0
        public override void Initialize()
        {
            Application.Current.MainWindow.Icon = new BitmapImage(new Uri("pack://application:,,," + IconsDescription.SMAStudio32, UriKind.RelativeOrAbsolute));
            AppContext.Start();
            CertificateManager.Configure();

            // Force software rendering!
            RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;

            // Enable tracing
            TracingAdapter.SetWriter(new TracingInAppWriter());
            TracingAdapter.IsEnabled = false;

            MainWindow.Title = "Automation Studio";

            Shell.ShowFloatingWindowsInTaskbar = true;
            Shell.ToolBars.Visible             = true;
            Shell.StatusBar.AddItem("Starting Automation Studio v. " + AppContext.Version + "...", new System.Windows.GridLength(1, System.Windows.GridUnitType.Star));
            Shell.ActiveDocumentChanged += (sender, e) => RefreshInspector();

            try
            {
                if (!File.Exists(Path.Combine(AppHelper.CachePath, "ApplicationState.bin")))
                {
                    var envExplorer = Shell.Tools.FirstOrDefault(x => x.ContentId == "SMAStudio.EnvironmentExplorer");

                    if (envExplorer == null)
                    {
                        Shell.ShowTool(new EnvironmentExplorerViewModel());
                    }

                    Shell.ShowTool(_errorList);
                }
            }
            catch (Exception)
            {
            }

            // Load settings from the settings.xml file
            var settingsService = AppContext.Resolve <ISettingsService>();

            settingsService.Load();

            // Load themes after the settings has been initialized
            var themeManager = AppContext.Resolve <IThemeManager>();

            themeManager.LoadThemes();

            Shell.AttemptingDeactivation += (sender, e) =>
            {
                settingsService.Save();

                //AsyncExecution.Stop();

                foreach (var agent in _agents)
                {
                    agent.Stop();
                }
            };

            // Retrieve all agents
            var agentTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IAgent))).ToList();

            // Start all agents
            foreach (var agentType in agentTypes)
            {
                var agent = (IAgent)Activator.CreateInstance(agentType);
                agent.Start();

                _agents.Add(agent);
                AppContext.Register <IAgent>(agent, agentType.Name);
            }

            // Initialize all connections
            if (SettingsService.CurrentSettings != null)
            {
                //var contextManager = AppContext.Resolve<IBackendContextManager>();
                var contextManager = IoC.Get <IBackendContextManager>();
                contextManager.Initialize();
            }

            if (SettingsService.CurrentSettings.EnableCodeAnalysis)
            {
                AnalyzerService.Start();
            }

            _output.AppendLine("Started Automation Studio");

            Shell.StatusBar.Items[0].Message = "";
        }