Exemple #1
0
        public bool Execute()
        {
            try
            {
                if (Keys.ControlKey.IsPressed())
                {
                    if (MessageBox.Show("Debug?", "Debug CleanHydraInstaller", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Debugger.Launch();
                    }
                }

                if (this.Configuration == "PreRelease")
                {
                    var      solutionPath     = Path.GetFullPath(Environment.ExpandEnvironmentVariables("%HYDRASOLUTIONPATH%"));
                    var      productFilePath  = Path.Combine(solutionPath, @"Hydra.InstallerStandalone\Product.wxs");
                    var      document         = XDocument.Load(productFilePath);
                    var      namespaceManager = new XmlNamespaceManager(new NameTable());
                    XElement elementFeature;
                    XElement elementDirectory;

                    namespaceManager.AddNamespace("wi", "http://schemas.microsoft.com/wix/2006/wi");

                    elementFeature   = document.XPathSelectElement("/wi:Wix/wi:Product/wi:Feature", namespaceManager);
                    elementDirectory = document.XPathSelectElement("/wi:Wix/wi:Fragment/wi:Directory", namespaceManager);

                    elementFeature.Elements().Remove();
                    elementDirectory.Elements().Remove();

                    document.Save(productFilePath, SaveOptions.DisableFormatting);
                }
            }
            catch (Exception ex)
            {
                var error = string.Format("Error installing Hydra Visual Studio templates. \r\nError: {0}", ex.ToString());

                var message = new BuildErrorEventArgs(string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, error, "", "", DateTime.Now);
                this.BuildEngine.LogErrorEvent(message);

                Console.WriteLine(error);

                return(false);
            }

            return(true);
        }
        public bool Execute()
        {
            try
            {
                if (Keys.ControlKey.IsPressed())
                {
                    if (MessageBox.Show("Debug?", "Debug UpdateHydraInstaller", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Debugger.Launch();
                    }
                }

                var      solutionPath    = Path.GetFullPath(Environment.ExpandEnvironmentVariables("%HYDRASOLUTIONPATH%"));
                var      productFilePath = Path.Combine(solutionPath, @"Hydra.InstallerStandalone\Product.wxs");
                var      applicationGeneratorBinaries = Path.Combine(solutionPath, @"ApplicationGenerator\bin", this.Configuration);
                var      applicationGeneratorProject  = Path.Combine(solutionPath, @"ApplicationGenerator\ApplicationGenerator.csproj");
                var      components       = ComponentFinder.GetComponents(applicationGeneratorBinaries, applicationGeneratorProject, this.TargetFramework, this.TargetAssembly, productFilePath);
                var      directories      = ComponentFinder.GetDirectories(applicationGeneratorBinaries, applicationGeneratorProject, this.TargetFramework, this.TargetAssembly, productFilePath);
                var      document         = XDocument.Load(productFilePath);
                var      namespaceManager = new XmlNamespaceManager(new NameTable());
                var      programMenuXml   = typeof(UpdateHydraInstaller).ReadResource <string>("ApplicationGeneratorBuildTasks.ProgramMenu.xml");
                XElement elementFeature;
                XElement elementDirectory;
                ApplicationGeneratorBuildTasks.Directory groupDirectory;
                ApplicationGeneratorBuildTasks.Directory topLeveDirectory;
                ComponentGroupRef componentGroupRef;
                XElement          elementGroupDirectory;
                XElement          elementComponentGroupRef;
                XElement          elementProgramMenu;
                XElement          elementProgramMenuDirectory;
                XElement          elementApplicationShortcutComponentRef;
                XElement          elementFragmentComponentGroup;
                ApplicationGeneratorBuildTasks.Directory programMenuDirectory;

                namespaceManager.AddNamespace("wi", "http://schemas.microsoft.com/wix/2006/wi");

                elementFeature   = document.XPathSelectElement("/wi:Wix/wi:Product/wi:Feature", namespaceManager);
                elementDirectory = document.XPathSelectElement("/wi:Wix/wi:Fragment/wi:Directory", namespaceManager);

                elementFeature.Elements().Remove();
                elementDirectory.Elements().Remove();

                foreach (var component in components)
                {
                    var elementComponent    = component.ToXElement <Component>();
                    var elementFile         = component.File.ToXElement <ApplicationGeneratorBuildTasks.File>();
                    var elementComponentRef = component.CreateComponentRef().ToXElement <ComponentRef>();

                    elementComponent.Add(elementFile);

                    elementDirectory.Add(elementComponent);
                    elementFeature.Add(elementComponentRef);
                }

                groupDirectory           = new ApplicationGeneratorBuildTasks.Directory(this.TargetAssembly + ".Binaries");
                componentGroupRef        = groupDirectory.CreateComponentGroupRef();
                elementGroupDirectory    = groupDirectory.ToXElement <ApplicationGeneratorBuildTasks.Directory>();
                elementComponentGroupRef = componentGroupRef.ToXElement <ComponentGroupRef>();

                elementDirectory.Add(elementGroupDirectory);
                elementFeature.Add(elementComponentGroupRef);

                topLeveDirectory = new ApplicationGeneratorBuildTasks.Directory();
                topLeveDirectory.Directories.AddRange(directories);

                AddDirectories(elementFeature, elementDirectory, topLeveDirectory);

                // add start menu elements

                elementProgramMenuDirectory = elementDirectory.XPathSelectElement("wi:Directory[@Id='ProgramMenuFolder']", namespaceManager);

                if (elementProgramMenuDirectory != null)
                {
                    elementProgramMenuDirectory.Remove();
                }

                programMenuDirectory = new ApplicationGeneratorBuildTasks.Directory("ProgramMenuFolder")
                {
                    Directories = new List <ApplicationGeneratorBuildTasks.Directory> {
                        new ApplicationGeneratorBuildTasks.Directory("HydraShortcuts", "CloudIDEaaS Hydra")
                    }
                };
                elementProgramMenuDirectory = programMenuDirectory.ToXElement <ApplicationGeneratorBuildTasks.Directory>();

                foreach (var shortcutDirectory in programMenuDirectory.Directories)
                {
                    elementProgramMenuDirectory.Add(shortcutDirectory.ToXElement <ApplicationGeneratorBuildTasks.Directory>());
                }

                elementDirectory.Add(elementProgramMenuDirectory);

                elementApplicationShortcutComponentRef = elementFeature.XPathSelectElement("wi:ComponentRef[@Id='ApplicationShortcut']", namespaceManager);

                if (elementApplicationShortcutComponentRef != null)
                {
                    elementApplicationShortcutComponentRef.Remove();
                }

                elementApplicationShortcutComponentRef = new ComponentRef("ApplicationShortcut").ToXElement <ComponentRef>();

                elementFeature.Add(new ComponentRef("ApplicationShortcut").ToXElement <ComponentRef>());

                elementFragmentComponentGroup = document.Root.XPathSelectElement("wi:Fragment/wi:ComponentGroup[@Id='ProductComponents']", namespaceManager);

                if (elementFragmentComponentGroup != null)
                {
                    elementFragmentComponentGroup.Remove();
                }

                elementProgramMenu = XElement.Parse(programMenuXml);
                document.Root.Add(elementProgramMenu);

                document.Save(productFilePath, SaveOptions.DisableFormatting);
            }
            catch (Exception ex)
            {
                var error = string.Format("Error installing Hydra Visual Studio templates. \r\nError: {0}", ex.ToString());

                var message = new BuildErrorEventArgs(string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, error, "", "", DateTime.Now);
                this.BuildEngine.LogErrorEvent(message);

                Console.WriteLine(error);

                return(false);
            }

            return(true);
        }
Exemple #3
0
        public bool Execute()
        {
            try
            {
                if (Keys.ControlKey.IsPressed())
                {
                    if (MessageBox.Show("Debug?", "Debug InstallTemplates", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Debugger.Launch();
                    }
                }

                var solutionPath               = Path.GetFullPath(Environment.ExpandEnvironmentVariables("%HYDRASOLUTIONPATH%"));
                var itemTemplatesOutputPath    = Path.Combine(solutionPath, @"ApplicationGenerator\ExportedItemTemplates");
                var projectTemplatesOutputPath = Path.Combine(solutionPath, @"ApplicationGenerator\ExportedProjectTemplates");
                var vsTemplatesPath            = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @"Visual Studio 2019\Templates\ItemTemplates\Hydra");
                var projectDirectory           = Path.GetDirectoryName(this.BuildEngine.ProjectFileOfTaskNode);
                var localTemplatesPath         = Path.Combine(projectDirectory, @"bin\" + this.Configuration + @"\Templates");
                var directory     = new DirectoryInfo(itemTemplatesOutputPath);
                var parentProcess = Process.GetCurrentProcess().GetParent();

                if (!parentProcess.ProcessName.IsOneOf("devenv", "msvsmon"))
                {
                    return(true);
                }

                if (!Directory.Exists(vsTemplatesPath))
                {
                    Directory.CreateDirectory(vsTemplatesPath);
                }

                // Visual Studio templates

                foreach (var folder in directory.GetDirectories())
                {
                    using (var package = ZipPackage.Open(Path.Combine(vsTemplatesPath, folder.Name + ".zip"), FileMode.Create))
                    {
                        foreach (var file in folder.GetFiles())
                        {
                            var part = package.CreatePart(new Uri("/" + file.Name, UriKind.Relative), "");

                            using (var stream = new MemoryStream(File.ReadAllBytes(file.FullName)))
                            {
                                part.GetStream().WriteAll(stream);
                            }
                        }
                    }
                }

                // Locally distributed templates

                directory = new DirectoryInfo(projectTemplatesOutputPath);

                if (!Directory.Exists(localTemplatesPath))
                {
                    Directory.CreateDirectory(localTemplatesPath);
                }

                foreach (var folder in directory.GetDirectories())
                {
                    using (var package = ZipPackage.Open(Path.Combine(localTemplatesPath, folder.Name + ".zip"), FileMode.Create))
                    {
                        var subFolders = folder.GetDirectories("*", SearchOption.AllDirectories);

                        foreach (var file in folder.GetFiles())
                        {
                            var part = package.CreatePart(new Uri("/" + file.Name, UriKind.Relative), "");

                            using (var stream = new MemoryStream(File.ReadAllBytes(file.FullName)))
                            {
                                part.GetStream().WriteAll(stream);
                            }
                        }

                        foreach (var subFolder in subFolders)
                        {
                            foreach (var file in subFolder.GetFiles())
                            {
                                var relativePath = file.FullName.RemoveStart(folder.FullName).ReverseSlashes();
                                var part         = package.CreatePart(new Uri(relativePath, UriKind.Relative), "");

                                using (var stream = new MemoryStream(File.ReadAllBytes(file.FullName)))
                                {
                                    part.GetStream().WriteAll(stream);
                                }
                            }
                        }
                    }
                }

                foreach (var file in directory.GetFiles())
                {
                    File.Copy(file.FullName, Path.Combine(localTemplatesPath, file.Name), true);
                }
            }
            catch (Exception ex)
            {
                var error = string.Format("Error installing Hydra Visual Studio templates. \r\nError: {0}", ex.ToString());

                var message = new BuildErrorEventArgs(string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, error, "", "", DateTime.Now);
                this.BuildEngine.LogErrorEvent(message);

                Console.WriteLine(error);

                return(false);
            }

            return(true);
        }