示例#1
0
        void Database.DeleteAndReCreateFromFile(string filePath, bool keepDbInStandbyMode)
        {
            using (var sw = new StringWriter()) {
                sw.WriteLine("DROP DATABASE IF EXISTS {0};".FormatWith(info.Database));
                sw.WriteLine("CREATE DATABASE {0};".FormatWith(info.Database));
                sw.WriteLine("use {0}".FormatWith(info.Database));
                sw.Write(File.ReadAllText(filePath));
                sw.WriteLine("quit");

                executeMethodWithDbExceptionHandling(
                    delegate {
                    try {
                        EwlStatics.RunProgram(
                            EwlStatics.CombinePaths(binFolderPath, "mysql"),
                            getHostAndAuthenticationArguments() + " --disable-reconnect --batch --disable-auto-rehash",
                            sw.ToString(),
                            true);
                    }
                    catch (Exception e) {
                        if (e.Message.Contains("ERROR") && e.Message.Contains("at line"))
                        {
                            throw new UserCorrectableException("Failed to create database from file. Please try the operation again after obtaining a new database file.", e);
                        }
                        throw DataAccessMethods.CreateDbConnectionException(info, "re-creating (from file)", e);
                    }
                });
            }
        }
 private void startWebSite(string webSiteName)
 {
     if (siteExistsInIis(webSiteName))
     {
         EwlStatics.RunProgram(appCmdPath, "Start Site \"" + webSiteName + "\"", "", true);
     }
 }
示例#3
0
        void Database.ExportToFile(string filePath)
        {
            Directory.CreateDirectory(dataPumpFolderPath);
            try {
                executeMethodWithDbExceptionHandling(
                    delegate {
                    try {
                        // We pass an enter keystroke as input in an attempt to kill the program if it gets stuck on a username prompt because of a bad logon string.
                        EwlStatics.RunProgram(
                            "expdp",
                            getLogonString() + " DIRECTORY=" + dataPumpOracleDirectoryName + " DUMPFILE=\"\"\"" + getDumpFileName() + "\"\"\" NOLOGFILE=y VERSION=12.1",
                            Environment.NewLine,
                            true);
                    }
                    catch (Exception e) {
                        throwUserCorrectableExceptionIfNecessary(e);
                        throw DataAccessMethods.CreateDbConnectionException(info, "exporting (to file)", e);
                    }
                });

                IoMethods.ExecuteWithTempFolder(
                    folderPath => {
                    IoMethods.CopyFile(getDumpFilePath(), EwlStatics.CombinePaths(folderPath, databaseFileDumpFileName));
                    File.WriteAllText(EwlStatics.CombinePaths(folderPath, databaseFileSchemaNameFileName), info.UserAndSchema);
                    ZipOps.ZipFolderAsFile(folderPath, filePath);
                });
            }
            finally {
                IoMethods.DeleteFile(getDumpFilePath());
            }
        }
 // NOTE: We do have the power to add and remove web sites here, and we can list just the stopped or just the started sites.
 // NOTE: When we add web sites with the ISU, we should NOT support host headers since WCF services have some restrictions with these. See http://stackoverflow.com/questions/561823/wcf-error-this-collection-already-contains-an-address-with-scheme-http
 private bool siteExistsInIis(string webSiteName)
 {
     if (!File.Exists(appCmdPath))
     {
         return(false);
     }
     return(EwlStatics.RunProgram(appCmdPath, "list sites", "", true).Contains("\"" + webSiteName + "\""));
 }
        /// <summary>
        /// Starts all web sites and services associated with this installation.
        /// </summary>
        public void Start()
        {
            var allServices = ServiceController.GetServices();

            foreach (var service in RuntimeConfiguration.WindowsServices.Select(
                         s => {
                var serviceController = allServices.SingleOrDefault(sc => sc.ServiceName == s.InstalledName);
                if (serviceController == null)
                {
                    throw new UserCorrectableException(
                        "The \"" + s.InstalledName + "\" service could not be found. Re-install the services for the installation to correct this error.");
                }
                return(serviceController);
            }))
            {
                try {
                    service.Start();
                }
                catch (InvalidOperationException e) {
                    const string message = "Failed to start service.";

                    // We have seen this happen when an exception was thrown while initializing global logic for the system.
                    if (e.InnerException is Win32Exception &&
                        e.InnerException.Message.Contains("The service did not respond to the start or control request in a timely fashion"))
                    {
                        throw new UserCorrectableException(message, e);
                    }

                    throw new ApplicationException(message, e);
                }
                service.WaitForStatusWithTimeOut(ServiceControllerStatus.Running);

                // Set failure actions.
                const int restartDelay = 60000;                 // milliseconds
                EwlStatics.RunProgram(
                    "sc",
                    "failure \"{0}\" reset= {1} actions= restart/{2}".FormatWith(service.ServiceName, serviceFailureResetPeriod, restartDelay),
                    "",
                    true);
                EwlStatics.RunProgram("sc", "failureflag \"{0}\" 1".FormatWith(service.ServiceName), "", true);
            }
            if (runtimeConfiguration.InstallationType != InstallationType.Development)
            {
                foreach (var site in runtimeConfiguration.WebSiteNames)
                {
                    startWebSite(site);
                }
            }
        }
        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\" />"));
            }
        }
示例#7
0
 void Database.ExportToFile(string filePath)
 {
     executeMethodWithDbExceptionHandling(
         delegate {
         try {
             // The --hex-blob option prevents certain BLOBs from causing errors during database re-creation.
             EwlStatics.RunProgram(
                 EwlStatics.CombinePaths(binFolderPath, "mysqldump"),
                 getHostAndAuthenticationArguments() + " --single-transaction --hex-blob --result-file=\"{0}\" ".FormatWith(filePath) + info.Database,
                 "",
                 true);
         }
         catch (Exception e) {
             throw DataAccessMethods.CreateDbConnectionException(info, "exporting (to file)", e);
         }
     });
 }
 void Database.ExecuteSqlScriptInTransaction(string script)
 {
     executeMethodWithDbExceptionHandling(
         delegate {
         try {
             EwlStatics.RunProgram(
                 "sqlcmd",
                 (info.Server != null ? "-S " + info.Server + " " : "") + "-d " + info.Database + " -e -b",
                 "BEGIN TRAN" + Environment.NewLine + "GO" + Environment.NewLine + script + "COMMIT TRAN" + Environment.NewLine + "GO" + Environment.NewLine + "EXIT" +
                 Environment.NewLine,
                 true);
         }
         catch (Exception e) {
             throw DataAccessMethods.CreateDbConnectionException(info, "updating logic in", e);
         }
     });
 }
示例#9
0
        private void stopServices()
        {
            var allServices  = ServiceController.GetServices();
            var serviceNames = RuntimeConfiguration.WindowsServices.Select(s => s.InstalledName);

            foreach (var service in allServices.Where(sc => serviceNames.Contains(sc.ServiceName)))
            {
                // Clear failure actions.
                EwlStatics.RunProgram("sc", "failure \"{0}\" reset= {1} actions= \"\"".FormatWith(service.ServiceName, serviceFailureResetPeriod), "", true);

                if (service.Status == ServiceControllerStatus.Stopped)
                {
                    continue;
                }
                service.Stop();
                service.WaitForStatusWithTimeOut(ServiceControllerStatus.Stopped);
            }
        }
示例#10
0
        private void generateXmlSchemaLogic(string projectPath, string schemaPathInProject, string nameSpace, string codeFileName, bool useSvcUtil)
        {
            var projectGeneratedCodeFolderPath = EwlStatics.CombinePaths(projectPath, "Generated Code");

            if (useSvcUtil)
            {
                try {
                    EwlStatics.RunProgram(
                        EwlStatics.CombinePaths(AppStatics.DotNetToolsFolderPath, "SvcUtil"),
                        "/d:\"" + projectGeneratedCodeFolderPath + "\" /noLogo \"" + EwlStatics.CombinePaths(projectPath, schemaPathInProject) + "\" /o:\"" + codeFileName +
                        "\" /dconly /n:*," + nameSpace + " /ser:DataContractSerializer",
                        "",
                        true);
                }
                catch (Exception e) {
                    throw new UserCorrectableException("Failed to generate XML schema logic using SvcUtil.", e);
                }
            }
            else
            {
                Directory.CreateDirectory(projectGeneratedCodeFolderPath);
                try {
                    EwlStatics.RunProgram(
                        EwlStatics.CombinePaths(AppStatics.DotNetToolsFolderPath, "xsd"),
                        "/nologo \"" + EwlStatics.CombinePaths(projectPath, schemaPathInProject) + "\" /c /n:" + nameSpace + " /o:\"" + projectGeneratedCodeFolderPath + "\"",
                        "",
                        true);
                }
                catch (Exception e) {
                    throw new UserCorrectableException("Failed to generate XML schema logic using xsd.", e);
                }
                var outputCodeFilePath  = EwlStatics.CombinePaths(projectGeneratedCodeFolderPath, Path.GetFileNameWithoutExtension(schemaPathInProject) + ".cs");
                var desiredCodeFilePath = EwlStatics.CombinePaths(projectGeneratedCodeFolderPath, codeFileName);
                if (outputCodeFilePath != desiredCodeFilePath)
                {
                    try {
                        IoMethods.MoveFile(outputCodeFilePath, desiredCodeFilePath);
                    }
                    catch (IOException e) {
                        throw new UserCorrectableException("Failed to move the generated code file for an XML schema. Please try the operation again.", e);
                    }
                }
            }
        }
示例#11
0
 private void runInstallutil(WindowsService service, bool uninstall)
 {
     try {
         EwlStatics.RunProgram(
             EwlStatics.CombinePaths(RuntimeEnvironment.GetRuntimeDirectory(), "installutil"),
             (uninstall ? "/u " : "") + "\"" +
             EwlStatics.CombinePaths(GetWindowsServiceFolderPath(service, true), service.NamespaceAndAssemblyName + ".exe" /* file extension is required */) + "\"",
             "",
             true);
     }
     catch (Exception e) {
         const string message = "Installer tool failed.";
         if (e.Message.Contains(typeof(EmailSendingException).Name))
         {
             throw new UserCorrectableException(message, e);
         }
         throw new ApplicationException(message, e);
     }
 }
示例#12
0
        void Database.ExecuteSqlScriptInTransaction(string script)
        {
            using (var sw = new StringWriter()) {
                // Carriage returns seem to be significant here.
                sw.WriteLine("WHENEVER SQLERROR EXIT SQL.SQLCODE;");
                sw.Write(script);
                sw.WriteLine("EXIT SUCCESS COMMIT;");

                executeMethodWithDbExceptionHandling(
                    delegate {
                    try {
                        // -L option stops it from prompting on failed logon.
                        EwlStatics.RunProgram("sqlplus", "-L " + getLogonString(), sw.ToString(), true);
                    }
                    catch (Exception e) {
                        throw DataAccessMethods.CreateDbConnectionException(info, "updating logic in", e);
                    }
                });
            }
        }
示例#13
0
        void Database.ExecuteSqlScriptInTransaction(string script)
        {
            using (var sw = new StringWriter()) {
                sw.WriteLine("START TRANSACTION;");
                sw.Write(script);
                sw.WriteLine("COMMIT;");
                sw.WriteLine("quit");

                executeMethodWithDbExceptionHandling(
                    delegate {
                    try {
                        EwlStatics.RunProgram(
                            EwlStatics.CombinePaths(binFolderPath, "mysql"),
                            getHostAndAuthenticationArguments() + " " + info.Database + " --disable-reconnect --batch --disable-auto-rehash",
                            sw.ToString(),
                            true);
                    }
                    catch (Exception e) {
                        throw DataAccessMethods.CreateDbConnectionException(info, "updating logic in", e);
                    }
                });
            }
        }
示例#14
0
        /// <summary>
        /// This is the code to install and start the SeleniumRC service.
        /// </summary>
        public static void InstallSeleniumServiceIfNecessary()
        {
            var          supportFilesDestinationPath = EwlStatics.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.
                    EwlStatics.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 = EwlStatics.CombinePaths(supportFilesDestinationPath, srvany);
                // Create c:\Red Stapler\Selenium Support
                Directory.CreateDirectory(supportFilesDestinationPath);
                IoMethods.CopyFile(EwlStatics.CombinePaths(supportFilesSourcePath, srvany), srvanyDestinationPath);
                IoMethods.CopyFile(
                    EwlStatics.CombinePaths(supportFilesSourcePath, seleniumJarFile),
                    EwlStatics.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 (ConfigurationStatics.IsDevelopmentInstallation)
                {
                    var firefoxProfileFolderPath = EwlStatics.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.
                EwlStatics.RunProgram("sc", "create " + serviceName + " binPath= \"" + srvanyDestinationPath + "\" start= auto", "", true);
                EwlStatics.RunProgram("REG", serviceRegCmd + "Application" + regDataType + "\"" + EwlStatics.CombinePaths(javaFolder, "java.exe") + "\"", "", true);
                EwlStatics.RunProgram("REG", serviceRegCmd + "AppDirectory" + regDataType + "\"" + supportFilesDestinationPath + "\" ", "", true);
                EwlStatics.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);
            }
        }
示例#15
0
        void Database.DeleteAndReCreateFromFile(string filePath)
        {
            executeDbMethodWithSpecifiedDatabaseInfo(
                new OracleInfo(
                    (info as DatabaseInfo).SecondaryDatabaseName,
                    info.DataSource,
                    "sys",
                    ConfigurationLogic.OracleSysPassword,
                    info.SupportsConnectionPooling,
                    info.SupportsLinguisticIndexes),
                cn => {
                executeLongRunningCommand(cn, "CREATE OR REPLACE DIRECTORY " + dataPumpOracleDirectoryName + " AS '" + dataPumpFolderPath + "'");
                deleteAndReCreateUser(cn);
            });

            try {
                IoMethods.ExecuteWithTempFolder(
                    tempFolderPath => {
                    var folderPath = EwlStatics.CombinePaths(tempFolderPath, "Database File");
                    ZipOps.UnZipFileAsFolder(filePath, folderPath);
                    try {
                        IoMethods.CopyFile(EwlStatics.CombinePaths(folderPath, databaseFileDumpFileName), getDumpFilePath());

                        executeMethodWithDbExceptionHandling(
                            delegate {
                            try {
                                EwlStatics.RunProgram(
                                    "impdp",
                                    getLogonString() + " DIRECTORY=" + dataPumpOracleDirectoryName + " DUMPFILE=\"\"\"" + getDumpFileName() + "\"\"\" NOLOGFILE=y REMAP_SCHEMA=" +
                                    File.ReadAllText(EwlStatics.CombinePaths(folderPath, databaseFileSchemaNameFileName)) + ":" + info.UserAndSchema,
                                    "",
                                    true);
                            }
                            catch (Exception e) {
                                throwUserCorrectableExceptionIfNecessary(e);
                                if (e is FileNotFoundException)
                                {
                                    throw new UserCorrectableException("The schema name file was not found, probably because of a corrupt database file in the data package.", e);
                                }

                                // Secondary databases such as RLE cause procedure compilation errors when imported, and since we have no way of
                                // distinguishing these from legitimate import problems, we have no choice but to ignore all exceptions.
                                if ((info as DatabaseInfo).SecondaryDatabaseName.Length == 0)
                                {
                                    throw DataAccessMethods.CreateDbConnectionException(info, "re-creating (from file)", e);
                                }
                            }
                        });
                    }
                    finally {
                        IoMethods.DeleteFile(getDumpFilePath());
                    }
                });
            }
            catch {
                // We don't want to leave a partial user/schema on the machine since it may confuse future ISU operations.
                executeDbMethodWithSpecifiedDatabaseInfo(
                    new OracleInfo(
                        (info as DatabaseInfo).SecondaryDatabaseName,
                        info.DataSource,
                        "sys",
                        ConfigurationLogic.OracleSysPassword,
                        info.SupportsConnectionPooling,
                        info.SupportsLinguisticIndexes),
                    deleteUser);

                throw;
            }
        }
示例#16
0
        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.SystemManagerInterface.Messages.BuildMessage.Build();

            build.SystemName      = installation.ExistingInstallationLogic.RuntimeConfiguration.SystemName;
            build.SystemShortName = installation.ExistingInstallationLogic.RuntimeConfiguration.SystemShortName;
            build.MajorVersion    = installation.CurrentMajorVersion;
            build.BuildNumber     = installation.NextBuildNumber;

            var hgOutput = Directory.Exists(EwlStatics.CombinePaths(installation.GeneralLogic.Path, ".hg"))
                                               ? EwlStatics.RunProgram(
                @"C:\Program Files\TortoiseHg\hg",
                "--debug identify --id \"{0}\"".FormatWith(installation.GeneralLogic.Path),
                "",
                true)
                           .Trim()
                                               : "";

            build.HgChangesetId = hgOutput.Length == 40 ? hgOutput : "";

            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.SystemManagerInterface.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.SystemManagerInterface.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.SystemManagerInterface.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 InstallationSupportUtility.SystemManagerInterface.Messages.BuildUploadMessage
                    {
                        AuthenticationKey = ConfigurationLogic.AuthenticationKey,
                        BuildDocument     = memoryStream
                    }),
                        "build upload");
                }
            });
        }
        internal static byte[] CreateEwlNuGetPackage(DevelopmentInstallation installation, bool useDebugAssembly, string outputFolderPath, bool?prerelease)
        {
            var localExportDateAndTime = prerelease.HasValue ? null as DateTime? : DateTime.Now;

            IoMethods.ExecuteWithTempFolder(
                folderPath => {
                var ewlOutputFolderPath = EwlStatics.CombinePaths(
                    installation.GeneralLogic.Path,
                    AppStatics.CoreProjectName,
                    EwlStatics.GetProjectOutputFolderPath(useDebugAssembly));
                var libFolderPath = EwlStatics.CombinePaths(folderPath, @"lib\net451-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"));

                var webSitePath = EwlStatics.CombinePaths(installation.GeneralLogic.Path, "Web Site");
                var webProjectFilesFolderPath = EwlStatics.CombinePaths(folderPath, AppStatics.WebProjectFilesFolderName);
                IoMethods.CopyFolder(
                    EwlStatics.CombinePaths(webSitePath, StaticFileHandler.EwfFolderName),
                    EwlStatics.CombinePaths(webProjectFilesFolderPath, StaticFileHandler.EwfFolderName),
                    false);
                IoMethods.CopyFile(
                    EwlStatics.CombinePaths(webSitePath, AppStatics.StandardLibraryFilesFileName),
                    EwlStatics.CombinePaths(webProjectFilesFolderPath, AppStatics.StandardLibraryFilesFileName));

                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);

                var manifestPath = EwlStatics.CombinePaths(folderPath, "Package.nuspec");
                using (var writer = IoMethods.GetTextWriterForWrite(manifestPath))
                    writeNuGetPackageManifest(installation, prerelease, localExportDateAndTime, writer);

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

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