예제 #1
0
        public void Start()
        {
            Debug.LogMessage("WorkManager.Start");

            // make sure events are processed before entering main loop, because the window may not be visible yet.
            CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);

            IAsyncAction    mainLoopWorker;
            WorkItemHandler workHandler = new WorkItemHandler((IAsyncAction action) =>
            {
                Debug.LogMessage("WorkManager *** thread started *** ");
                while ((action.Status == AsyncStatus.Started) && State != WorkManagerStates.Exiting)
                {
                    if (State == WorkManagerStates.Running)
                    {
                    }
                }

                // signal application quit or else ProcessUntilQuit will wait for windows close button press
                coreApp.Exit();
                Debug.LogMessage("WorkManager *** thread terminated ***");
            });

            mainLoopWorker = ThreadPool.RunAsync(workHandler, WorkItemPriority.High, WorkItemOptions.TimeSliced);

            // ProcessUntilQuit will block the UI thread and process events as they appear until the App terminates.
            CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit);
        }
예제 #2
0
        protected override void OnStartup([CanBeNull] StartupEventArgs e)
        {
            base.OnStartup(e);

            if (!App.EnsureSingleProcess(e.Args))
            {
                Environment.Exit(0);

                return;
            }

            if (CoreApp.HasBeenUpdated)
            {
                var ver = ApplicationManager.AppVersion;
                if (!string.IsNullOrEmpty(ver))
                {
                    var exists = false;
                    var wc     = new WebClient();
                    var url    = "https://github.com/Sitecore/Sitecore-Instance-Manager/releases/tag/" + ver;
                    try
                    {
                        wc.DownloadString(url);
                        exists = true;
                    }
                    catch
                    {
                        Log.Warn("Tag was not found: {0}", url);
                    }

                    if (exists)
                    {
                        WindowHelper.OpenInBrowser(url, true);
                    }
                }
            }

            if (CoreApp.IsFirstRun || CoreApp.HasBeenUpdated)
            {
                CacheManager.ClearAll();
                foreach (var dir in Directory.GetDirectories(ApplicationManager.TempFolder))
                {
                    Directory.Delete(dir, true);
                }

                var ext = ".deploy.txt";
                foreach (var filePath in Directory.GetFiles(".", "*" + ext, SearchOption.AllDirectories))
                {
                    if (filePath == null)
                    {
                        continue;
                    }

                    var newFilePath = filePath.Substring(0, filePath.Length - ext.Length);
                    if (File.Exists(newFilePath))
                    {
                        File.Delete(newFilePath);
                    }

                    File.Move(filePath, newFilePath);
                }
            }

            if (!App.CheckPermissions())
            {
                Environment.Exit(0);

                return;
            }

            CoreApp.InitializeLogging();

            CoreApp.LogMainInfo();

            if (!App.CheckIIS())
            {
                WindowHelper.ShowMessage("Cannot connect to IIS. Make sure it is installed and running.", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                Environment.Exit(0);

                return;
            }

            // Initializing pipelines from Pipelines.config and WizardPipelines.config files
            if (!App.InitializePipelines())
            {
                Environment.Exit(0);

                return;
            }

            // Application is closing when it doesn't have any window instance therefore it's
            // required to create MainWindow before creating the initial configuration dialog
            var main = App.CreateMainWindow();

            if (main == null)
            {
                Environment.Exit(0);

                return;
            }

            // Initialize Profile Manager
            if (!App.InitializeProfileManager(main))
            {
                Log.Info("Application closes due to invalid configuration");

                // Since the main window instance was already created we need to "dispose" it by showing and closing.
                main.Width  = 0;
                main.Height = 0;
                main.Show();
                main.Close();

                Environment.Exit(0);

                return;
            }

            // Check if user accepted agreement
            var agreementAcceptedFilePath = Path.Combine(ApplicationManager.TempFolder, "agreement-accepted.txt");

            if (!File.Exists(agreementAcceptedFilePath))
            {
                WizardPipelineManager.Start("agreement", main, new ProcessorArgs(), false);
                if (!File.Exists(agreementAcceptedFilePath))
                {
                    Environment.Exit(0);

                    return;
                }
            }

            // Clean up garbage
            CoreApp.DeleteTempFolders();

            Analytics.Start();

            // Show main window
            try
            {
                main.Initialize();
                WindowHelper.ShowDialog(main, null);
            }
            catch (Exception ex)
            {
                WindowHelper.HandleError("Main window caused unhandled exception", true, ex);
            }

            CoreApp.Exit();

            Analytics.Flush();

            Environment.Exit(0);
        }
예제 #3
0
        protected override void OnStartup([CanBeNull] StartupEventArgs e)
        {
            // enable TLS 1.2 by default to work around GitHub and many other websites
            // that don't accept default .NET protocol.
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;

            InitializeLogging();

            base.OnStartup(e);

            if (!CheckPermissions())
            {
                Log.Info("Shutting down due to missing permissions (it is normally okay as it will be re-run with elevated permissions)");

                Environment.Exit(0);

                return;
            }

            if (!EnsureSingleProcess(e.Args))
            {
                Log.Info("Shutting down as there is another process running");

                Environment.Exit(0);

                return;
            }

            // invoke auto-updater if not developing or debugging
            if (!ApplicationManager.IsDev && !ApplicationManager.IsDebugging)
            {
                try
                {
                    Log.Info("Running update procedure");

                    var prefix = ApplicationManager.IsQa ? "qa/" : "";
                    var suffix = ApplicationManager.IsQa ? ".QA" : "";
                    CoreApp.RunApp("rundll32.exe", $"dfshim.dll,ShOpenVerbApplication http://dl.sitecore.net/updater/{prefix}sim/SIM.Tool{suffix}.application");
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error connecting to SIM auto-updater.");
                }
            }

            if (CoreApp.HasBeenUpdated)
            {
                var ver = ApplicationManager.AppVersion;
                if (!string.IsNullOrEmpty(ver))
                {
                    var exists = false;
                    var wc     = new WebClient();
                    var url    = $"https://github.com/Sitecore/Sitecore-Instance-Manager/releases/tag/{ver}";
                    try
                    {
                        wc.DownloadString(url);
                        exists = true;
                    }
                    catch
                    {
                        Log.Warn($"Tag was not found: {url}");
                    }

                    if (exists)
                    {
                        Log.Info("Showing release notes");

                        CoreApp.OpenInBrowser(url, true);
                    }
                }
            }

            if (CoreApp.IsVeryFirstRun || CoreApp.HasBeenUpdated)
            {
                Log.Info("Cleaning up caches after update");

                CacheManager.ClearAll();
                foreach (var dir in Directory.GetDirectories(ApplicationManager.TempFolder))
                {
                    try
                    {
                        Directory.Delete(dir, true);
                    }
                    catch (Exception ex)
                    {
                        WindowHelper.HandleError($"Failed to delete directory1: {dir}", isError: true, ex: ex);
                    }
                }

                Log.Info("Unpacking resources");

                var ext = ".deploy.txt";
                foreach (var filePath in Directory.GetFiles(".", $"*{ext}", SearchOption.AllDirectories))
                {
                    if (filePath == null)
                    {
                        continue;
                    }

                    var newFilePath = filePath.Substring(0, filePath.Length - ext.Length);
                    if (File.Exists(newFilePath))
                    {
                        try
                        {
                            File.Delete(newFilePath);
                        }
                        catch (Exception ex)
                        {
                            throw new InvalidOperationException($"Failed to delete file: {newFilePath}", ex);
                        }
                    }

                    File.Move(filePath, newFilePath);
                }
            }

            // write it here as all preceding logic is finished
            CoreApp.WriteLastRunVersion();

            CoreApp.LogMainInfo();

            if (!CheckIis())
            {
                WindowHelper.ShowMessage("Cannot connect to IIS. Make sure it is installed and running.", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                Environment.Exit(0);

                return;
            }

            // Initializing pipelines from Pipelines.config and WizardPipelines.config files
            if (!InitializePipelines())
            {
                Environment.Exit(0);

                return;
            }

            // Application is closing when it doesn't have any window instance therefore it's
            // required to create MainWindow before creating the initial configuration dialog
            var main = CreateMainWindow();

            if (main == null)
            {
                Environment.Exit(0);

                return;
            }

            // Initialize Profile Manager
            if (!InitializeProfileManager(main))
            {
                Log.Info("Application closes due to invalid configuration");

                // Since the main window instance was already created we need to "dispose" it by showing and closing.
                main.Width  = 0;
                main.Height = 0;
                main.Show();
                main.Close();

                Environment.Exit(0);

                return;
            }

            // Check if user accepted agreement
            var agreementAcceptedFilePath = Path.Combine(ApplicationManager.TempFolder, "agreement-accepted.txt");

            if (!File.Exists(agreementAcceptedFilePath))
            {
                WizardPipelineManager.Start("agreement", main, new ProcessorArgs(), false, null, () => null);
                if (!File.Exists(agreementAcceptedFilePath))
                {
                    Environment.Exit(0);

                    return;
                }
            }

            // Clean up garbage
            CoreApp.DeleteTempFolders();

            LoadIocResourcesForSolr();

            InitializeTelemetry();
            Telemetry.Analytics.Track(TelemetryEvent.AppRun);

            // Show main window
            try
            {
                main.Initialize();
                WindowHelper.ShowDialog(main, null);
            }
            catch (Exception ex)
            {
                WindowHelper.HandleError("Main window caused unhandled exception", true, ex);
            }


            CoreApp.Exit();

            Environment.Exit(0);
        }