Esempio n. 1
0
        private void copyInWebProjectFiles(Installation installation, WebProject webProject)
        {
            var webProjectFilesFolderPath = StandardLibraryMethods.CombinePaths(AppTools.InstallationPath, AppStatics.WebProjectFilesFolderName);
            var webProjectPath            = StandardLibraryMethods.CombinePaths(installation.GeneralLogic.Path, webProject.name);

            // Copy Ewf folder and customize namespaces in .aspx, .ascx, .master, and .cs files.
            var webProjectEwfFolderPath = StandardLibraryMethods.CombinePaths(webProjectPath, StaticFileHandler.EwfFolderName);

            IoMethods.DeleteFolder(webProjectEwfFolderPath);
            IoMethods.CopyFolder(StandardLibraryMethods.CombinePaths(webProjectFilesFolderPath, StaticFileHandler.EwfFolderName), webProjectEwfFolderPath, false);
            IoMethods.RecursivelyRemoveReadOnlyAttributeFromItem(webProjectEwfFolderPath);
            var matchingFiles = new List <string>();

            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.aspx", SearchOption.AllDirectories));
            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.ascx", SearchOption.AllDirectories));
            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.master", SearchOption.AllDirectories));
            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.cs", SearchOption.AllDirectories));
            foreach (var filePath in matchingFiles)
            {
                File.WriteAllText(filePath, customizeNamespace(File.ReadAllText(filePath), webProject));
            }

            IoMethods.CopyFile(
                StandardLibraryMethods.CombinePaths(webProjectFilesFolderPath, AppStatics.StandardLibraryFilesFileName),
                StandardLibraryMethods.CombinePaths(webProjectPath, AppStatics.StandardLibraryFilesFileName));
            IoMethods.RecursivelyRemoveReadOnlyAttributeFromItem(StandardLibraryMethods.CombinePaths(webProjectPath, AppStatics.StandardLibraryFilesFileName));
        }
        private static void packageGeneralFiles(DevelopmentInstallation installation, string folderPath, bool includeDatabaseUpdates)
        {
            // configuration files
            var configurationFolderPath = EwlStatics.CombinePaths(folderPath, InstallationConfiguration.ConfigurationFolderName);

            IoMethods.CopyFolder(installation.ExistingInstallationLogic.RuntimeConfiguration.ConfigurationFolderPath, configurationFolderPath, false);
            IoMethods.RecursivelyRemoveReadOnlyAttributeFromItem(configurationFolderPath);
            IoMethods.DeleteFolder(EwlStatics.CombinePaths(configurationFolderPath, InstallationConfiguration.InstallationConfigurationFolderName));
            IoMethods.DeleteFolder(EwlStatics.CombinePaths(configurationFolderPath, ConfigurationStatics.ProvidersFolderAndNamespaceName));
            if (!includeDatabaseUpdates)
            {
                IoMethods.DeleteFile(EwlStatics.CombinePaths(configurationFolderPath, ExistingInstallationLogic.SystemDatabaseUpdatesFileName));
            }
            IoMethods.DeleteFile(EwlStatics.CombinePaths(configurationFolderPath, InstallationConfiguration.SystemDevelopmentConfigurationFileName));
            IoMethods.DeleteFolder(EwlStatics.CombinePaths(configurationFolderPath, ".hg"));                          // EWL uses a nested repository for configuration.
            IoMethods.DeleteFile(EwlStatics.CombinePaths(configurationFolderPath, "Update All Dependent Logic.bat")); // EWL has this file.

            // other files
            var filesFolderInInstallationPath = EwlStatics.CombinePaths(
                InstallationFileStatics.GetGeneralFilesFolderPath(installation.GeneralLogic.Path, true),
                InstallationFileStatics.FilesFolderName);

            if (Directory.Exists(filesFolderInInstallationPath))
            {
                IoMethods.CopyFolder(filesFolderInInstallationPath, EwlStatics.CombinePaths(folderPath, InstallationFileStatics.FilesFolderName), false);
            }
        }
        private void copyInEwlFiles(DevelopmentInstallation installation)
        {
            if (installation is RecognizedDevelopmentInstallation recognizedInstallation)
            {
                recognizedInstallation.KnownSystemLogic.DownloadAsposeLicenses(installation.ExistingInstallationLogic.RuntimeConfiguration.ConfigurationFolderPath);
            }

            if (installation.DevelopmentInstallationLogic.SystemIsEwl)
            {
                foreach (var fileName in GlobalStatics.ConfigurationXsdFileNames)
                {
                    IoMethods.CopyFile(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, EwlStatics.CoreProjectName, "Configuration", fileName + FileExtensions.Xsd),
                        EwlStatics.CombinePaths(
                            InstallationFileStatics.GetGeneralFilesFolderPath(installation.GeneralLogic.Path, true),
                            InstallationFileStatics.FilesFolderName,
                            fileName + FileExtensions.Xsd));
                }
            }
            else
            {
                // If web projects exist for this installation, copy in web-framework static files.
                if (installation.DevelopmentInstallationLogic.DevelopmentConfiguration.webProjects != null)
                {
                    var webFrameworkStaticFilesFolderPath = EwlStatics.CombinePaths(
                        installation.GeneralLogic.Path,
                        InstallationFileStatics.WebFrameworkStaticFilesFolderName);
                    IoMethods.DeleteFolder(webFrameworkStaticFilesFolderPath);
                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(ConfigurationStatics.InstallationPath, InstallationFileStatics.WebFrameworkStaticFilesFolderName),
                        webFrameworkStaticFilesFolderPath,
                        false);
                }
            }
        }
Esempio n. 4
0
        private void copyInWebProjectFiles(Installation installation, WebProject webProject)
        {
            var webProjectFilesFolderPath = EwlStatics.CombinePaths(ConfigurationStatics.InstallationPath, AppStatics.WebProjectFilesFolderName);
            var webProjectPath            = EwlStatics.CombinePaths(installation.GeneralLogic.Path, webProject.name);

            // Copy Ewf folder and customize namespaces in .aspx, .ascx, .master, and .cs files.
            var webProjectEwfFolderPath = EwlStatics.CombinePaths(webProjectPath, StaticFileHandler.EwfFolderName);

            IoMethods.DeleteFolder(webProjectEwfFolderPath);
            IoMethods.CopyFolder(EwlStatics.CombinePaths(webProjectFilesFolderPath, StaticFileHandler.EwfFolderName), webProjectEwfFolderPath, false);
            IoMethods.RecursivelyRemoveReadOnlyAttributeFromItem(webProjectEwfFolderPath);
            var matchingFiles = new List <string>();

            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.aspx", SearchOption.AllDirectories));
            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.ascx", SearchOption.AllDirectories));
            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.master", SearchOption.AllDirectories));
            matchingFiles.AddRange(Directory.GetFiles(webProjectEwfFolderPath, "*.cs", SearchOption.AllDirectories));
            foreach (var filePath in matchingFiles)
            {
                File.WriteAllText(filePath, customizeNamespace(File.ReadAllText(filePath), webProject));
            }

            IoMethods.CopyFile(
                EwlStatics.CombinePaths(webProjectFilesFolderPath, AppStatics.StandardLibraryFilesFileName),
                EwlStatics.CombinePaths(webProjectPath, AppStatics.StandardLibraryFilesFileName));
            IoMethods.RecursivelyRemoveReadOnlyAttributeFromItem(EwlStatics.CombinePaths(webProjectPath, AppStatics.StandardLibraryFilesFileName));

            // Add the Import element to the project file if it's not already present.
            var projectDocument = new XmlDocument {
                PreserveWhitespace = true
            };
            var projectDocumentPath = EwlStatics.CombinePaths(webProjectPath, "{0}.csproj".FormatWith(webProject.name));

            projectDocument.Load(projectDocumentPath);
            var          projectElement          = projectDocument["Project"];
            const string webProjectFilesFileName = "Standard Library Files.xml";
            var          namespaceManager        = new XmlNamespaceManager(projectDocument.NameTable);
            const string ns = "http://schemas.microsoft.com/developer/msbuild/2003";

            namespaceManager.AddNamespace("p", ns);
            if (projectElement.SelectSingleNode("p:Import[ @Project = \"{0}\" ]".FormatWith(webProjectFilesFileName), namespaceManager) == null)
            {
                var importElement = projectDocument.CreateElement("Import", ns);
                importElement.SetAttribute("Project", webProjectFilesFileName);
                projectElement.AppendChild(importElement);
                projectDocument.Save(projectDocumentPath);
            }
        }
        private void packageWebApps(DevelopmentInstallation installation, string serverSideLogicFolderPath)
        {
            // NOTE: When packaging web apps, try to find a way to exclude data files. Apparently web deployment projects include these in their output even though
            // they aren't part of the source web projects. NOTE ON NOTE: We don't use WDPs anymore, so maybe we can eliminate this note.
            foreach (var webProject in installation.DevelopmentInstallationLogic.DevelopmentConfiguration.webProjects ?? new WebProject[0])
            {
                var webAppPath = EwlStatics.CombinePaths(serverSideLogicFolderPath, webProject.name);

                // Pre-compile the web project.
                try {
                    EwlStatics.RunProgram(
                        EwlStatics.CombinePaths(RuntimeEnvironment.GetRuntimeDirectory(), "aspnet_compiler"),
                        "-v \"/" + webProject.name + ".csproj\" -p \"" + EwlStatics.CombinePaths(installation.GeneralLogic.Path, webProject.name) + "\" " +
                        (webProject.IsUpdateableWhenInstalledSpecified && webProject.IsUpdateableWhenInstalled ? "-u " : "") + "-f \"" + webAppPath + "\"",
                        "",
                        true);
                }
                catch (Exception e) {
                    throw new UserCorrectableException("ASP.NET pre-compilation failed for web project " + webProject.name + ".", e);
                }
                try {
                    EwlStatics.RunProgram(
                        EwlStatics.CombinePaths(AppStatics.DotNetToolsFolderPath, "aspnet_merge"),
                        "\"" + webAppPath + "\" -o " + webProject.NamespaceAndAssemblyName + ".Package -a -copyattrs",
                        "",
                        true);
                }
                catch (Exception e) {
                    throw new UserCorrectableException("ASP.NET Merge Tool failed for web project " + webProject.name + ".", e);
                }

                // Delete files and folders that aren't necessary for installed installations.
                IoMethods.DeleteFolder(EwlStatics.CombinePaths(webAppPath, "Generated Code"));
                IoMethods.DeleteFolder(EwlStatics.CombinePaths(webAppPath, "obj"));
                IoMethods.DeleteFile(EwlStatics.CombinePaths(webAppPath, webProject.name + ".csproj"));
                IoMethods.DeleteFile(EwlStatics.CombinePaths(webAppPath, webProject.name + ".csproj.user"));
                IoMethods.DeleteFile(EwlStatics.CombinePaths(webAppPath, webProject.name + ".csproj.vspscc"));
                IoMethods.DeleteFile(EwlStatics.CombinePaths(webAppPath, AppStatics.StandardLibraryFilesFileName));

                var webConfigPath = EwlStatics.CombinePaths(webAppPath, WebApplication.WebConfigFileName);
                File.WriteAllText(
                    webConfigPath,
                    File.ReadAllText(webConfigPath)
                    .Replace("debug=\"true\"", "debug=\"false\"")
                    .Replace("<!--<add name=\"HttpCacheModule\" />-->", "<add name=\"HttpCacheModule\" />"));
            }
        }
        internal static void Test()
        {
            const string outputFolderName = "MergeOps";
            var          outputFolder     = StandardLibraryMethods.CombinePaths(TestStatics.OutputFolderPath, outputFolderName);

            IoMethods.DeleteFolder(outputFolder);
            Directory.CreateDirectory(outputFolder);

            var inputTestFiles = StandardLibraryMethods.CombinePaths(TestStatics.InputTestFilesFolderPath, outputFolderName);
            var wordDocx       = StandardLibraryMethods.CombinePaths(inputTestFiles, "word.docx");
            var pdf            = StandardLibraryMethods.CombinePaths(inputTestFiles, "pdf.pdf");

            MergeStatics.Init();
            var singleTestRow      = new PseudoTableRow(1).ToSingleElementArray();
            var testRows           = new[] { new PseudoTableRow(1), new PseudoTableRow(2), new PseudoTableRow(3) };
            var singleRowTree      = MergeStatics.CreatePseudoTableRowTree(singleTestRow);
            var pseudoTableRowTree = MergeStatics.CreatePseudoTableRowTree(testRows);

            var explanations = new List <Tuple <String, String> >();

            // Single row to merge against

            // Word files

            const string singleRowWordDoc = "SingleRowMsWordDoc" + FileExtensions.WordDocx;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, singleRowWordDoc))) {
                using (var word = File.OpenRead(wordDocx))
                    CreateMsWordDoc(singleRowTree, false, word, outputFile);
                explanations.Add(Tuple.Create(singleRowWordDoc, "Should be {0} with only one page, and FullName merged in the upper left.".FormatWith(wordDocx)));
            }

            const string singleRowWordDocAsPdf = "SingleRowMsWordDoc" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, singleRowWordDocAsPdf)))
                CreatePdfFromMsWordDoc(singleRowTree, false, wordDocx, outputFile);
            explanations.Add(
                Tuple.Create(singleRowWordDocAsPdf, "Should be {0} with only one page, FullName merged in the upper left, saved as a PDF.".FormatWith(wordDocx)));

            //Excel
            const string singleRowExcel = "SingleRowExcel" + FileExtensions.ExcelXlsx;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, singleRowExcel)))
                CreateExcelWorkbook(singleRowTree, GetExcelSupportedMergeFields(singleRowTree), outputFile);
            explanations.Add(
                Tuple.Create(
                    singleRowExcel,
                    "An Excel file with the first row frozen and bold with the merge field names. Note that only supported field types may be dispalyed. One more row with data should be present."));

            // Pdf
            const string singleRowPdf = "SingleRowPdf" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, singleRowPdf)))
                CreatePdf(singleRowTree, false, pdf, outputFile);
            explanations.Add(Tuple.Create(singleRowPdf, "Should be {0} with only one page, FullName filled in and 'Test' displayed.".FormatWith(pdf)));

            // Multiple rows to merge against

            // Word files
            const string multipleRowsWordDoc = "MultipleRowMsWordDoc" + FileExtensions.WordDocx;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, multipleRowsWordDoc))) {
                using (var word = File.OpenRead(wordDocx))
                    CreateMsWordDoc(pseudoTableRowTree, false, word, outputFile);
                explanations.Add(Tuple.Create(multipleRowsWordDoc, "Should be {0} with three pages, and FullName merged in the upper left.".FormatWith(wordDocx)));
            }

            const string multipleRowsWordDocAsPdf = "MultipleRowMsWordDoc" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, multipleRowsWordDocAsPdf)))
                CreatePdfFromMsWordDoc(pseudoTableRowTree, false, wordDocx, outputFile);
            explanations.Add(
                Tuple.Create(multipleRowsWordDocAsPdf, "Should be {0} with three pages, FullName merged in the upper left, saved as a PDF.".FormatWith(wordDocx)));

            // Excel
            const string multipleRowExcel = "MultipleRowExcel" + FileExtensions.ExcelXlsx;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, multipleRowExcel)))
                CreateExcelWorkbook(pseudoTableRowTree, GetExcelSupportedMergeFields(pseudoTableRowTree), outputFile);
            explanations.Add(
                Tuple.Create(
                    multipleRowExcel,
                    "An Excel file with the first row frozen and bold with the merge field names. Note that only supported field types may be dispalyed. Three more row with data should be present."));

            // Pdf
            const string multipleRowPdf = "MultipleRowPdf" + FileExtensions.Pdf;

            using (var outputFile = File.OpenWrite(StandardLibraryMethods.CombinePaths(outputFolder, multipleRowPdf)))
                CreatePdf(pseudoTableRowTree, false, pdf, outputFile);
            explanations.Add(Tuple.Create(multipleRowPdf, "Should be {0} with three pages, FullName filled in and 'Test' displayed.".FormatWith(pdf)));

            TestStatics.OutputReadme(outputFolder, explanations);
        }
        /// <summary>
        /// This is the code to install and start the SeleniumRC service.
        /// </summary>
        public static void InstallSeleniumServiceIfNecessary()
        {
            var          supportFilesDestinationPath = StandardLibraryMethods.CombinePaths(ConfigurationStatics.RedStaplerFolderPath, "Selenium Support");
            const string serviceName     = "SeleniumRC";
            const string seleniumJarFile = "selenium-server.jar";
            const string srvany          = "srvany.exe";

            var seleniumServerService = ServiceController.GetServices().Where(s => s.DisplayName == serviceName).SingleOrDefault();

            if (!Directory.Exists(supportFilesDestinationPath) || seleniumServerService == null)
            {
                // Wipe out any possible pre-existing configuration.
                IoMethods.DeleteFolder(supportFilesDestinationPath);
                if (seleniumServerService != null)
                {
                    // Delete the service and remove the registry values.
                    StandardLibraryMethods.RunProgram("sc", "delete " + serviceName, "", true);
                    seleniumServerService = null;
                }


                // NOTE: This will work because the only machines running tests are dev machines and integration machines, and both of those not only should have this in their Vault
                // tree, but they are guaranteed to have gotten latest on the Standard Library system before attempting to run a test (since you can't run a test until you've built).
                // Still, there may be a more robust way to do this in the future.
                // If we do keep this solution, you have to ask yourself why it makes sense to store the files here just to copy them to Red Stapler/Selenium Support. The only good reason
                // may be that the Vault tree could be prone to full deletion/re-getting, and that would fail if a service was referencing a file inside the tree.

                // NOTE: This path is probably wrong, and should not be hard-coded.
                const string supportFilesSourcePath = @"C:\Red Stapler Vault\Supporting Files\Standard Library\Solution Files\Selenium Support";

                var srvanyDestinationPath = StandardLibraryMethods.CombinePaths(supportFilesDestinationPath, srvany);
                // Create c:\Red Stapler\Selenium Support
                Directory.CreateDirectory(supportFilesDestinationPath);
                IoMethods.CopyFile(StandardLibraryMethods.CombinePaths(supportFilesSourcePath, srvany), srvanyDestinationPath);
                IoMethods.CopyFile(StandardLibraryMethods.CombinePaths(supportFilesSourcePath, seleniumJarFile),
                                   StandardLibraryMethods.CombinePaths(supportFilesDestinationPath, seleniumJarFile));


                const string serviceRegCmd = @"ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\" + serviceName + "\\Parameters  /v ";
                const string regDataType   = " /t REG_SZ /d ";
                const string javaFolder    = @"C:\Program Files\Java\jre6\bin";
                var          parametersToSeleniumServer = "";
                if (AppTools.IsDevelopmentInstallation)
                {
                    var firefoxProfileFolderPath = StandardLibraryMethods.CombinePaths(supportFilesDestinationPath, "Firefox");
                    Directory.CreateDirectory(firefoxProfileFolderPath);
                    parametersToSeleniumServer = " -firefoxProfileTemplate \\\"" + firefoxProfileFolderPath + "\\\"";
                }

                // This is the code to add the registry parameters to the Selenium Server.  This only needs to be run once.
                StandardLibraryMethods.RunProgram("sc", "create " + serviceName + " binPath= \"" + srvanyDestinationPath + "\" start= auto", "", true);
                StandardLibraryMethods.RunProgram("REG",
                                                  serviceRegCmd + "Application" + regDataType + "\"" + StandardLibraryMethods.CombinePaths(javaFolder, "java.exe") + "\"",
                                                  "",
                                                  true);
                StandardLibraryMethods.RunProgram("REG", serviceRegCmd + "AppDirectory" + regDataType + "\"" + supportFilesDestinationPath + "\" ", "", true);
                StandardLibraryMethods.RunProgram("REG",
                                                  serviceRegCmd + "AppParameters" + regDataType + "\"-Xrs -jar " + seleniumJarFile + parametersToSeleniumServer + "\"",
                                                  "",
                                                  true);

                // Wait for the service to be created
                while (seleniumServerService == null)
                {
                    seleniumServerService = ServiceController.GetServices().Where(s => s.DisplayName == serviceName).SingleOrDefault();
                }
            }

            if (seleniumServerService.Status != ServiceControllerStatus.Running)
            {
                seleniumServerService.Start();
                seleniumServerService.WaitForStatus(ServiceControllerStatus.Running);
            }
        }
        void Operation.Execute(Installation genericInstallation, OperationResult operationResult)
        {
            var installation = genericInstallation as DevelopmentInstallation;

            var logicPackagesFolderPath = EwlStatics.CombinePaths(installation.GeneralLogic.Path, "Logic Packages");

            IoMethods.DeleteFolder(logicPackagesFolderPath);

            // Set up the main (build) object in the build message.
            var build = new InstallationSupportUtility.RsisInterface.Messages.BuildMessage.Build();

            build.SystemName      = installation.ExistingInstallationLogic.RuntimeConfiguration.SystemName;
            build.SystemShortName = installation.ExistingInstallationLogic.RuntimeConfiguration.SystemShortName;
            build.MajorVersion    = installation.CurrentMajorVersion;
            build.BuildNumber     = installation.NextBuildNumber;
            build.LogicSize       = ConfigurationLogic.NDependIsPresent && !installation.DevelopmentInstallationLogic.SystemIsEwl
                                                  ? GetLogicSize.GetNDependLocCount(installation, false) as int?
                                                  : null;
            var serverSideLogicFolderPath = EwlStatics.CombinePaths(logicPackagesFolderPath, "Server Side Logic");

            packageWebApps(installation, serverSideLogicFolderPath);
            packageWindowsServices(installation, serverSideLogicFolderPath);
            packageServerSideConsoleApps(installation, serverSideLogicFolderPath);
            packageGeneralFiles(installation, serverSideLogicFolderPath, true);
            build.ServerSideLogicPackage             = ZipOps.ZipFolderAsByteArray(serverSideLogicFolderPath);
            operationResult.NumberOfBytesTransferred = build.ServerSideLogicPackage.LongLength;

            // Set up the client side application object in the build message, if necessary.
            if (installation.DevelopmentInstallationLogic.DevelopmentConfiguration.clientSideAppProject != null)
            {
                build.ClientSideApp              = new InstallationSupportUtility.RsisInterface.Messages.BuildMessage.Build.ClientSideAppType();
                build.ClientSideApp.Name         = installation.DevelopmentInstallationLogic.DevelopmentConfiguration.clientSideAppProject.name;
                build.ClientSideApp.AssemblyName = installation.DevelopmentInstallationLogic.DevelopmentConfiguration.clientSideAppProject.assemblyName;
                var clientSideAppFolder = EwlStatics.CombinePaths(logicPackagesFolderPath, "Client Side Application");
                packageClientSideApp(installation, clientSideAppFolder);
                packageGeneralFiles(installation, clientSideAppFolder, false);
                build.ClientSideApp.Package = ZipOps.ZipFolderAsByteArray(clientSideAppFolder);
                operationResult.NumberOfBytesTransferred += build.ClientSideApp.Package.LongLength;
            }

            // Set up the list of installation objects in the build message.
            build.Installations = new InstallationSupportUtility.RsisInterface.Messages.BuildMessage.Build.InstallationsType();
            foreach (var installationConfigurationFolderPath in
                     Directory.GetDirectories(
                         EwlStatics.CombinePaths(
                             installation.ExistingInstallationLogic.RuntimeConfiguration.ConfigurationFolderPath,
                             InstallationConfiguration.InstallationConfigurationFolderName,
                             InstallationConfiguration.InstallationsFolderName)))
            {
                if (Path.GetFileName(installationConfigurationFolderPath) != InstallationConfiguration.DevelopmentInstallationFolderName)
                {
                    var buildMessageInstallation = new InstallationSupportUtility.RsisInterface.Messages.BuildMessage.Installation();

                    // Do not perform schema validation since the schema file on disk may not match this version of the ISU.
                    var installationConfigurationFile =
                        XmlOps.DeserializeFromFile <InstallationStandardConfiguration>(
                            EwlStatics.CombinePaths(installationConfigurationFolderPath, InstallationConfiguration.InstallationStandardConfigurationFileName),
                            false);

                    buildMessageInstallation.Id                 = installationConfigurationFile.rsisInstallationId;
                    buildMessageInstallation.Name               = installationConfigurationFile.installedInstallation.name;
                    buildMessageInstallation.ShortName          = installationConfigurationFile.installedInstallation.shortName;
                    buildMessageInstallation.IsLiveInstallation =
                        installationConfigurationFile.installedInstallation.InstallationTypeConfiguration is LiveInstallationConfiguration;
                    buildMessageInstallation.ConfigurationPackage = ZipOps.ZipFolderAsByteArray(installationConfigurationFolderPath);
                    build.Installations.Add(buildMessageInstallation);
                    operationResult.NumberOfBytesTransferred += buildMessageInstallation.ConfigurationPackage.LongLength;
                }
            }

            if (installation.DevelopmentInstallationLogic.SystemIsEwl)
            {
                build.NuGetPackages = packageEwl(installation, logicPackagesFolderPath);
            }

            var recognizedInstallation = installation as RecognizedDevelopmentInstallation;

            if (recognizedInstallation == null)
            {
                return;
            }

            build.SystemId = recognizedInstallation.KnownSystemLogic.RsisSystem.Id;

            operationResult.TimeSpentWaitingForNetwork = EwlStatics.ExecuteTimedRegion(
                delegate {
                using (var memoryStream = new MemoryStream()) {
                    // Understand that by doing this, we are not really taking advantage of streaming, but at least it will be easier to do it the right way some day (probably by implementing our own BuildMessageStream)
                    XmlOps.SerializeIntoStream(build, memoryStream);
                    memoryStream.Position = 0;

                    ConfigurationLogic.ExecuteIsuServiceMethod(
                        channel => channel.UploadBuild(new BuildUploadMessage {
                        AuthenticationKey = ConfigurationLogic.AuthenticationKey, BuildDocument = memoryStream
                    }),
                        "build upload");
                }
            });
        }
Esempio n. 9
0
        internal static IReadOnlyCollection <(string id, IReadOnlyList <byte[]> packages)> CreateEwlNuGetPackages(
            DevelopmentInstallation installation, PackagingConfiguration packagingConfiguration, bool useDebugAssembly, string outputFolderPath,
            IEnumerable <bool?> prereleaseValues)
        {
            var now      = DateTime.Now;
            var packages = new List <(string, IReadOnlyList <byte[]>)>();

            var mainId       = packagingConfiguration.SystemShortName;
            var mainPackages = prereleaseValues.Select(
                prerelease => {
                var localExportDateAndTime = prerelease.HasValue ? (DateTime?)null : now;

                IoMethods.ExecuteWithTempFolder(
                    folderPath => {
                    var ewlOutputFolderPath = EwlStatics.CombinePaths(
                        installation.GeneralLogic.Path,
                        EwlStatics.CoreProjectName,
                        EwlStatics.GetProjectOutputFolderPath(useDebugAssembly));
                    var libFolderPath = EwlStatics.CombinePaths(folderPath, @"lib\net472-full");
                    foreach (var fileName in new[] { "dll", "pdb", "xml" }.Select(i => "EnterpriseWebLibrary." + i))
                    {
                        IoMethods.CopyFile(EwlStatics.CombinePaths(ewlOutputFolderPath, fileName), EwlStatics.CombinePaths(libFolderPath, fileName));
                    }

                    IoMethods.CopyFile(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, @"Development Utility\Package Manager Console Commands.ps1"),
                        EwlStatics.CombinePaths(folderPath, @"tools\init.ps1"));

                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, EwlStatics.CoreProjectName, StaticFile.FrameworkStaticFilesSourceFolderPath),
                        EwlStatics.CombinePaths(folderPath, InstallationFileStatics.WebFrameworkStaticFilesFolderName),
                        false);
                    IoMethods.DeleteFolder(
                        EwlStatics.CombinePaths(folderPath, InstallationFileStatics.WebFrameworkStaticFilesFolderName, AppStatics.StaticFileLogicFolderName));

                    const string duProjectAndFolderName = "Development Utility";
                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(installation.GeneralLogic.Path, duProjectAndFolderName, EwlStatics.GetProjectOutputFolderPath(useDebugAssembly)),
                        EwlStatics.CombinePaths(folderPath, duProjectAndFolderName),
                        false);
                    packageGeneralFiles(installation, folderPath, false);
                    IoMethods.CopyFolder(
                        EwlStatics.CombinePaths(
                            installation.ExistingInstallationLogic.RuntimeConfiguration.ConfigurationFolderPath,
                            InstallationConfiguration.InstallationConfigurationFolderName,
                            InstallationConfiguration.InstallationsFolderName,
                            !prerelease.HasValue || prerelease.Value ? "Testing" : "Live"),
                        EwlStatics.CombinePaths(
                            folderPath,
                            InstallationConfiguration.ConfigurationFolderName,
                            InstallationConfiguration.InstallationConfigurationFolderName),
                        false);
                    if (File.Exists(installation.ExistingInstallationLogic.RuntimeConfiguration.InstallationSharedConfigurationFilePath))
                    {
                        IoMethods.CopyFile(
                            installation.ExistingInstallationLogic.RuntimeConfiguration.InstallationSharedConfigurationFilePath,
                            EwlStatics.CombinePaths(
                                folderPath,
                                InstallationConfiguration.ConfigurationFolderName,
                                InstallationConfiguration.InstallationConfigurationFolderName,
                                InstallationConfiguration.InstallationSharedConfigurationFileName));
                    }

                    var manifestPath = EwlStatics.CombinePaths(folderPath, "Package.nuspec");
                    using (var writer = IoMethods.GetTextWriterForWrite(manifestPath))
                        writeNuGetPackageManifest(
                            writer,
                            installation,
                            mainId,
                            "",
                            w => {
                            var lines = from line in File.ReadAllLines(
                                EwlStatics.CombinePaths(installation.GeneralLogic.Path, EwlStatics.CoreProjectName, "packages.config"))
                                        let trimmedLine = line.Trim()
                                                          where trimmedLine.StartsWith("<package ")
                                                          select trimmedLine;
                            foreach (var line in lines)
                            {
                                w.WriteLine(Regex.Replace(line.Replace("package", "dependency"), @" targetFramework=""[\w]+""", ""));
                            }
                        },
                            prerelease,
                            localExportDateAndTime);

                    StatusStatics.SetStatus(
                        TewlContrib.ProcessTools.RunProgram(
                            EwlStatics.CombinePaths(installation.GeneralLogic.Path, @"Solution Files\nuget"),
                            "pack \"" + manifestPath + "\" -OutputDirectory \"" + outputFolderPath + "\"",
                            "",
                            true));
                });

                return(File.ReadAllBytes(
                           EwlStatics.CombinePaths(
                               outputFolderPath,
                               EwlNuGetPackageSpecificationStatics.GetNuGetPackageFileName(
                                   mainId,
                                   installation.CurrentMajorVersion,
                                   !prerelease.HasValue || prerelease.Value ? installation.NextBuildNumber as int? : null,
                                   localExportDateAndTime: localExportDateAndTime))));
            })
                               .MaterializeAsList();

            packages.Add((mainId, mainPackages));

            var samlId       = mainId + ".Saml";
            var samlPackages = prereleaseValues.Select(
                prerelease => {
                var localExportDateAndTime = prerelease.HasValue ? (DateTime?)null : now;

                IoMethods.ExecuteWithTempFolder(
                    folderPath => {
                    foreach (var fileName in new[] { "dll", "pdb" }.Select(i => "EnterpriseWebLibrary.Saml." + i))
                    {
                        IoMethods.CopyFile(
                            EwlStatics.CombinePaths(
                                installation.GeneralLogic.Path,
                                EwlStatics.SamlProviderProjectPath,
                                EwlStatics.GetProjectOutputFolderPath(useDebugAssembly),
                                fileName),
                            EwlStatics.CombinePaths(folderPath, @"lib\net472-full", fileName));
                    }

                    var manifestPath = EwlStatics.CombinePaths(folderPath, "Package.nuspec");
                    using (var writer = IoMethods.GetTextWriterForWrite(manifestPath))
                        writeNuGetPackageManifest(
                            writer,
                            installation,
                            samlId,
                            "SAML Provider",
                            w => {
                            w.WriteLine(
                                "<dependency id=\"{0}\" version=\"[{1}]\" />".FormatWith(
                                    mainId,
                                    EwlNuGetPackageSpecificationStatics.GetNuGetPackageVersionString(
                                        installation.CurrentMajorVersion,
                                        !prerelease.HasValue || prerelease.Value ? (int?)installation.NextBuildNumber : null,
                                        localExportDateAndTime: localExportDateAndTime)));
                            w.WriteLine("<dependency id=\"ComponentSpace.Saml2.Net.Licensed\" version=\"5.0.0\" />");
                        },
                            prerelease,
                            localExportDateAndTime);

                    StatusStatics.SetStatus(
                        TewlContrib.ProcessTools.RunProgram(
                            EwlStatics.CombinePaths(installation.GeneralLogic.Path, @"Solution Files\nuget"),
                            "pack \"" + manifestPath + "\" -OutputDirectory \"" + outputFolderPath + "\"",
                            "",
                            true));
                });

                return(File.ReadAllBytes(
                           EwlStatics.CombinePaths(
                               outputFolderPath,
                               EwlNuGetPackageSpecificationStatics.GetNuGetPackageFileName(
                                   samlId,
                                   installation.CurrentMajorVersion,
                                   !prerelease.HasValue || prerelease.Value ? installation.NextBuildNumber as int? : null,
                                   localExportDateAndTime: localExportDateAndTime))));
            })
                               .MaterializeAsList();

            packages.Add((samlId, samlPackages));

            return(packages);
        }