コード例 #1
0
        private void DoChangeMode(Window mainWindow, Instance instance)
        {
            var title   = "Change App Pool Mode";
            var header  = title;
            var message = "Change {0} instance's Application Pool mode".FormatWith(instance.Name);
            var options = new[]
            {
                this.GetLabel(instance, 2, false),
                this.GetLabel(instance, 2, true),
                this.GetLabel(instance, 4, false),
                this.GetLabel(instance, 4, true)
            };

            var result = WindowHelper.AskForSelection(title, header, message, options, mainWindow);

            if (result == null)
            {
                return;
            }

            if (result.Contains(LabelCurrent))
            {
                return;
            }

            instance.SetAppPoolMode(result.Contains("4.0"), result.Contains(Label32Bit));
        }
コード例 #2
0
        public string Select([NotNull] string message, [NotNull] IEnumerable <string> options, bool allowMultipleSelection = false, string defaultValue = null)
        {
            Assert.ArgumentNotNull(message, "message");
            Assert.ArgumentNotNull(options, "options");

            return((string)this.Dispatcher.Invoke(new Func <string>(() => WindowHelper.AskForSelection("Select an option", "Select an option", message, options, this, defaultValue, allowMultipleSelection))));
        }
コード例 #3
0
        private bool EnsureFramework4(Window mainWindow, Instance instance)
        {
            // verify that .NET framework v4 is used
            if (!instance.IsNetFramework4)
            {
                // suggest to install them
                const string yesEnableSitecoreMvc = "Yes, switch to .NET 4.X";
                const string noCancel             = "No, cancel";
                var          options2             = new[]
                {
                    noCancel, yesEnableSitecoreMvc
                };
                var result2 = WindowHelper.AskForSelection(".NET Framework 4.X is not set", null,
                                                           "You decided to enable Sitecore MVC, but it requiuires using .NET Framework 4.X in Sitecore instance's application pool for correct work. \n\nWould you like to change .NET Framework version?",
                                                           options2, mainWindow);

                if (result2 == noCancel)
                {
                    return(false);
                }

                instance.SetAppPoolMode(true);
            }

            return(true);
        }
コード例 #4
0
        private string GetMode(Window mainWindow)
        {
            if (string.IsNullOrEmpty(_Mode))
            {
                var options = new[]
                {
                    CancelOption,
                    IncrementalOption,
                    SmartOption,
                    RepublishOption
                };

                return(WindowHelper.AskForSelection("Publish", "Publish", "Choose publish mode", options, mainWindow, IncrementalOption));
            }

            return(_Mode);
        }
コード例 #5
0
        public void OnClick(Window mainWindow, Instance instance)
        {
            if (instance == null)
            {
                return;
            }

            var paths = instance.GetVisualStudioSolutionFiles().ToArray();

            if (paths.Length > 0)
            {
                CoreApp.OpenFile(paths.First());
                return;
            }

            const string NoThanks     = "No, thanks";
            const string YesAspNetMvc = "Yes, create new";

            var options = new[] { NoThanks, YesAspNetMvc };
            var result  = WindowHelper.AskForSelection("Choose Visual Studio Project Type", null, "There isn't any Visual Studio project in the instance's folder. \n\nWould you like us to create a new one?", options, mainWindow);

            if (result == null || result == NoThanks)
            {
                return;
            }

            var packageName = "Visual Studio 2015 Website Project.zip";
            var product     = GetProduct(packageName);

            if (product == null)
            {
                WindowHelper.HandleError("The " + packageName + " package cannot be found in either the .\\Packages folder", false);
                return;
            }

            PipelineManager.StartPipeline("installmodules", new InstallModulesArgs(instance, new[] { product }), isAsync: false);
            var path = instance.GetVisualStudioSolutionFiles().FirstOrDefault();

            Assert.IsTrue(!string.IsNullOrEmpty(path) && FileSystem.FileSystem.Local.File.Exists(path), "The Visual Studio files are missing");

            CoreApp.OpenFile(path);
        }
コード例 #6
0
        private bool EnsureMvcEnabled(Window mainWindow, Instance instance, string version)
        {
            // verify if assemblies and configuration exists
            if ((!FileSystem.FileSystem.Local.File.Exists(Path.Combine(instance.WebRootPath, "bin\\Sitecore.Mvc.dll")) || !FileSystem.FileSystem.Local.File.Exists(Path.Combine(instance.WebRootPath, "App_Config\\Include\\Sitecore.Mvc.config"))) && (version == "6.6" || version == "7.0"))
            {
                // suggest to install them
                const string yesEnableSitecoreMvc = "Yes, enable Sitecore MVC";
                const string noCancel             = "No, cancel";
                var          options2             = new[]
                {
                    noCancel, yesEnableSitecoreMvc
                };
                var result2 = WindowHelper.AskForSelection("Sitecore MVC is not enabled", null,
                                                           "It seems that Sitecore MVC features is not enabled in your Sitecore " +
                                                           version + " instance. \n\nWould you like to enable it?",
                                                           options2, mainWindow);

                if (result2 == noCancel)
                {
                    return(false);
                }

                if (!this.EnsureFramework4(mainWindow, instance))
                {
                    return(false);
                }

                if (!this.EnsureMvcConfigured(instance, version))
                {
                    return(false);
                }

                return(true);
            }

            if (!this.EnsureFramework4(mainWindow, instance))
            {
                return(false);
            }

            return(true);
        }
コード例 #7
0
        public void OnClick(Window mainWindow, Instance instance)
        {
            if (instance == null)
            {
                var bitness = WindowHelper.AskForSelection("Managed Gc Aware Dump", null, "Choose version of the tool", new[] { "x86", "x64" }, mainWindow);
                if (bitness == null)
                {
                    return;
                }

                var options            = WindowHelper.Ask("Please specify params for Managed Gc Aware Dump", string.Empty, mainWindow);
                var executableFilePath = ApplicationManager.GetEmbeddedFile("ManagedGcAwareDump.zip", "SIM.Tool.Windows", "ManagedGcAwareDump_" + bitness + ".exe");
                Process.Start(new ProcessStartInfo(executableFilePath, options)).WaitForExit();

                return;
            }

            var ids = instance.ProcessIds.ToArray();

            if (ids.Length == 0)
            {
                WindowHelper.HandleError("No running w3wp processes for this Sitecore instance", false);
                return;
            }

            var bit = instance.Is32Bit ? "x86" : "x64";

            foreach (var id in ids)
            {
                var defaultValue = id.ToString(CultureInfo.InvariantCulture);
                var options      = WindowHelper.Ask("Please specify params for Managed Gc Aware Dump", defaultValue, mainWindow);
                if (string.IsNullOrEmpty(options))
                {
                    return;
                }

                var executableFilePath = ApplicationManager.GetEmbeddedFile("ManagedGcAwareDump.zip", "SIM.Tool.Windows", "ManagedGcAwareDump_" + bit + ".exe");
                Process.Start(executableFilePath).WaitForExit();
            }
        }
コード例 #8
0
        private static FrameworkElement GetRibbonButton(MainWindow window, Func <string, ImageSource> getImage, XmlElement button, RibbonGroupBox ribbonGroup, IMainWindowButton mainWindowButton)
        {
            var header = button.GetNonEmptyAttribute("label");

            var clickHandler = GetClickHandler(mainWindowButton);

            if (button.ChildNodes.Count == 0)
            {
                // create Ribbon Button
                var imageSource  = getImage(button.GetNonEmptyAttribute("largeImage"));
                var fluentButton = new Fluent.Button
                {
                    Icon      = imageSource,
                    LargeIcon = imageSource,
                    Header    = header
                };
                fluentButton.Click += clickHandler;
                ribbonGroup.Items.Add(fluentButton);
                return(fluentButton);
            }

            // create Ribbon Button
            var splitButton = ribbonGroup.Items.OfType <SplitButton>().SingleOrDefault(x => x.Header.ToString().Trim().EqualsIgnoreCase(header.Trim()));

            if (splitButton == null)
            {
                var imageSource = getImage(button.GetNonEmptyAttribute("largeImage"));
                splitButton = new Fluent.SplitButton
                {
                    Icon      = imageSource,
                    LargeIcon = imageSource,
                    Header    = header
                };

                if (mainWindowButton != null)
                {
                    splitButton.Click += clickHandler;
                }
                else
                {
                    var childrenButtons = new List <KeyValuePair <string, IMainWindowButton> >();
                    splitButton.Tag    = childrenButtons;
                    splitButton.Click += (sender, args) =>
                    {
                        IEnumerable <string> options = childrenButtons.Where(x => x.Value.IsEnabled(window, SelectedInstance)).Select(x => x.Key);
                        var result = WindowHelper.AskForSelection(header, header, "Choose desired action", options, window, null, null, true);
                        if (result == null)
                        {
                            return;
                        }

                        var pair = childrenButtons.Single(x => x.Key == result);
                        pair.Value.OnClick(window, SelectedInstance);
                    };
                }

                ribbonGroup.Items.Add(splitButton);
            }

            var items = splitButton.Items;

            Assert.IsNotNull(items, "items");

            foreach (var menuItem in button.ChildNodes.OfType <XmlElement>())
            {
                if (menuItem == null)
                {
                    continue;
                }

                try
                {
                    var name = menuItem.Name;
                    if (name.EqualsIgnoreCase("separator"))
                    {
                        items.Add(new Separator());
                        continue;
                    }

                    if (!name.EqualsIgnoreCase("button"))
                    {
                        Log.Error("This element is not supported as SplitButton element: {0}".FormatWith(menuItem.OuterXml), typeof(MainWindowHelper));
                        continue;
                    }

                    var menuHeader  = menuItem.GetAttribute("label");
                    var largeImage  = menuItem.GetAttribute("largeImage");
                    var menuIcon    = string.IsNullOrEmpty(largeImage) ? null : getImage(largeImage);
                    var menuHandler = (IMainWindowButton)Plugin.CreateInstance(menuItem);
                    Assert.IsNotNull(menuHandler, "model");

                    var childrenButtons = splitButton.Tag as ICollection <KeyValuePair <string, IMainWindowButton> >;
                    if (childrenButtons != null)
                    {
                        childrenButtons.Add(new KeyValuePair <string, IMainWindowButton>(menuHeader, menuHandler));
                    }

                    var menuButton = new Fluent.MenuItem()
                    {
                        Header    = menuHeader,
                        IsEnabled = menuHandler.IsEnabled(window, SelectedInstance)
                    };

                    if (menuIcon != null)
                    {
                        menuButton.Icon = menuIcon;
                    }

                    // bind IsEnabled event
                    SetIsEnabledProperty(menuButton, menuHandler);

                    menuButton.Click += delegate
                    {
                        try
                        {
                            if (menuHandler.IsEnabled(MainWindow.Instance, SelectedInstance))
                            {
                                menuHandler.OnClick(MainWindow.Instance, SelectedInstance);
                                MainWindowHelper.RefreshInstances();
                            }
                        }
                        catch (Exception ex)
                        {
                            WindowHelper.HandleError("Error during handling menu button click: " + menuHandler.GetType().FullName, true, ex);
                        }
                    };

                    items.Add(menuButton);
                }
                catch (Exception ex)
                {
                    WindowHelper.HandleError("Error during initializing ribbon button: " + menuItem.OuterXml, true, ex);
                }
            }

            return(splitButton);
        }
コード例 #9
0
        public void OnClick(Window mainWindow, Instance instance)
        {
            if (instance != null)
            {
                var paths = instance.GetVisualStudioSolutionFiles().ToArray();
                if (paths.Length == 1)
                {
                    WindowHelper.OpenFile(paths.First());
                }
                else if (paths.Length == 0)
                {
                    var          version           = instance.Product.Version.SubstringEx(0, 3);
                    const string noThanks          = "No, thanks";
                    const string yesAspNetWebforms = "Yes, ASP.NET WebForms";
                    const string yesAspNetMvc      = "Yes, ASP.NET MVC";

                    var packageName = "Visual Studio " + WinAppSettings.AppToolsVisualStudioVersion.Value + " Website Project.zip";

                    var is66     = version == "6.6";
                    var is70     = version == "7.0";
                    var is7x     = version[0] == '7';
                    var is71plus = is7x && !is70;
                    var is8      = version[0] == '8';
                    if (is66 || is7x || is8)
                    {
                        var options = is71plus ? new[]
                        {
                            noThanks, yesAspNetMvc
                        } : new[]
                        {
                            noThanks, yesAspNetWebforms, yesAspNetMvc
                        };
                        var result = WindowHelper.AskForSelection("Choose Visual Studio Project Type", null,
                                                                  "There isn't any Visual Studio project in the instance's folder. \n\nWould you like us to create a new one?",
                                                                  options, mainWindow);
                        if (result == null || result == noThanks)
                        {
                            return;
                        }

                        if (result == yesAspNetMvc)
                        {
                            if (!this.EnsureMvcEnabled(mainWindow, instance, version))
                            {
                                return;
                            }

                            packageName = "Visual Studio " + WinAppSettings.AppToolsVisualStudioVersion.Value + " MVC" + (is71plus ? " 4" : string.Empty) + " Website Project.zip";
                        }
                    }

                    Product product = GetProduct(packageName);

                    if (product == null)
                    {
                        WindowHelper.HandleError("The " + packageName + " package cannot be found in either the .\\Packages folder", false, null);
                        return;
                    }

                    PipelineManager.StartPipeline("installmodules", new InstallModulesArgs(instance, new[]
                    {
                        product
                    }), isAsync: false);
                    var path = instance.GetVisualStudioSolutionFiles().FirstOrDefault();
                    Assert.IsTrue(!string.IsNullOrEmpty(path) && FileSystem.FileSystem.Local.File.Exists(path), "The Visual Studio files are missing");
                    WindowHelper.OpenFile(path);
                }
                else
                {
                    var rootPath     = instance.RootPath.ToLowerInvariant();
                    var virtualPaths = paths.Select(file => file.ToLowerInvariant().Replace(rootPath, string.Empty).TrimStart('\\'));
                    var path         = WindowHelper.AskForSelection("Open Visual Studio", null, "Select the project you need", virtualPaths, mainWindow, paths.First());
                    if (string.IsNullOrEmpty(path))
                    {
                        return;
                    }

                    WindowHelper.OpenFile(Path.Combine(rootPath, path));
                }
            }
        }