private static bool EnsureAppPoolState([NotNull] Instance instance, [NotNull] Window mainWindow)
        {
            Assert.ArgumentNotNull(instance, nameof(instance));
            Assert.ArgumentNotNull(mainWindow, nameof(mainWindow));

            var state = instance.ApplicationPoolState;

            if (state == ObjectState.Stopped || state == ObjectState.Stopping)
            {
                const string cancel = "Cancel";
                const string start  = "Start";
                const string skip   = "Skip, open anyway";

                var result = WindowHelper.AskForSelection("Instance is stopped", null, "The selected Sitecore instance is stopped. Would you like to start it first?", new[]
                {
                    cancel, start, skip
                }, mainWindow, start);

                if (result == null || result == cancel)
                {
                    return(false);
                }

                if (result == start)
                {
                    instance.Start();
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static void Update(Window mainWindow, Instance instance)
        {
            if (instance != null)
            {
                const string current = "Selected instance";
                const string all     = "All instances";
                var          options = new[]
                {
                    current, all
                };

                var result = WindowHelper.AskForSelection(Title, null, "You have selected \"{0}\" Sitecore instance. \nWould you like to update the license file only there?".FormatWith(instance.Name), options, mainWindow);

                if (result == null)
                {
                    return;
                }

                if (result == all)
                {
                    instance = null;
                }
            }

            var filePath = ProfileManager.Profile.License;

            const string settings = "Definied in settings";
            const string custom   = "Another license file";
            var          options2 = new[]
            {
                settings, custom
            };
            var result2 = WindowHelper.AskForSelection(Title, null, "Which license file would you like to use?", options2, mainWindow);

            if (result2 == null)
            {
                return;
            }

            if (result2 == custom)
            {
                var openDialog = new OpenFileDialog
                {
                    Filter = @"License files|*.xml"
                };

                if (openDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                filePath = openDialog.FileName;
            }


            WindowHelper.LongRunningTask(() => DoUpdateLicense(filePath, instance), "Updating license...", mainWindow);
        }
        private static string GetLogFileTypes(Window owner, string logsFolderPath)
        {
            const string Suffix  = ".txt";
            const string Pattern = "*" + Suffix;
            var          files   = FileSystem.FileSystem.Local.Directory.GetFiles(logsFolderPath, Pattern);

            var groups = InstanceHelper.GetLogGroups(files);

            if (groups.Any())
            {
                return(WindowHelper.AskForSelection("Open current log file", "Choose log file type", "There are several types of log files in Sitecore. Please choose what type do you need?", groups, owner, groups.First(), false, true));
            }

            return(null);
        }
        public static bool PreheatInstance(Instance instance, Window mainWindow)
        {
            if (!EnsureAppPoolState(instance, mainWindow))
            {
                return(false);
            }

            if (!WinAppSettings.AppPreheatEnabled.Value)
            {
                return(true);
            }

            // Check if the instance is responsive now
            if (!InstanceHelper.IsInstanceResponsive(instance, "fast"))
            {
                // It is not responsive so we need to preheat it
                // i.e. request with larger timeout and with the
                // progress bar shown to the user to avoid UI lag
                Exception ex  = null;
                var       res = WindowHelper.LongRunningTask(() => PreheatInstance(instance, out ex), "Starting Sitecore", mainWindow,
                                                             "Sitecore is being initialized",
                                                             "It may take up to a few minutes on large solutions or slow machines.",
                                                             true, true, true);
                if (res == null)
                {
                    return(false);
                }

                // if error happened
                if (ex != null)
                {
                    const string cancel          = "Cancel";
                    const string openLog         = "Open SIM log file";
                    const string openSitecoreLog = "Open Sitecore log file";
                    const string openAnyway      = "Open in browser";
                    var          message         = "The instance returned an error. \n\n" + ex.Message;
                    Log.Error(ex, message);
                    var result = WindowHelper.AskForSelection("Running instance failed", null, message,
                                                              new[]
                    {
                        cancel, openLog, openSitecoreLog, openAnyway
                    }, mainWindow);
                    switch (result)
                    {
                    case openLog:
                        CoreApp.OpenFile(ApplicationManager.LogsFolder);
                        return(false);

                    case openSitecoreLog:
                        OpenCurrentLogFile(instance, mainWindow);
                        return(false);

                    case openAnyway:
                        return(true);

                    default:
                        return(false);
                    }
                }
            }

            return(true);
        }