コード例 #1
0
 /// <summary>
 /// Stops all web sites and services associated with this installation.
 /// </summary>
 public void Stop(bool stopServices)
 {
     if (runtimeConfiguration.WebApplications.Any(i => i.IisApplication != null) && runtimeConfiguration.InstallationType != InstallationType.Development)
     {
         IsuStatics.StopIisAppPool(IisAppPoolName);
     }
     if (stopServices)
     {
         this.stopServices();
     }
 }
コード例 #2
0
		public static void UpdateIisApplications( ExistingInstalledInstallationLogic newLogic, ExistingInstalledInstallationLogic oldLogic ) {
			var appGetter =
				new Func<ExistingInstalledInstallationLogic, IEnumerable<WebApplication>>(
					logic =>
					logic?.existingInstallationLogic.RuntimeConfiguration.WebApplications.Where( i => i.IisApplication != null ).ToImmutableArray() ??
					Enumerable.Empty<WebApplication>() );
			var newApps = appGetter( newLogic );
			var oldApps = appGetter( oldLogic );

			if( newApps.Any() )
				IsuStatics.UpdateIisAppPool( newLogic.existingInstallationLogic.IisAppPoolName );

			var newSiteNames = new HashSet<string>();
			var newVirtualDirectoryNames = new HashSet<string>();
			foreach( var app in newApps ) {
				var site = app.IisApplication as Site;
				if( site != null ) {
					IsuStatics.UpdateIisSite( getIisSiteName( newLogic, app ), newLogic.existingInstallationLogic.IisAppPoolName, app.Path, site.HostNames );
					newSiteNames.Add( getIisSiteName( newLogic, app ) );
					continue;
				}
				var virtualDirectory = app.IisApplication as VirtualDirectory;
				if( virtualDirectory != null ) {
					IsuStatics.UpdateIisVirtualDirectory( virtualDirectory.Site, virtualDirectory.Name, newLogic.existingInstallationLogic.IisAppPoolName, app.Path );
					newVirtualDirectoryNames.Add( virtualDirectory.Name );
					continue;
				}
				throw new ApplicationException( "unrecognized IIS application type" );
			}

			foreach( var app in oldApps ) {
				var site = app.IisApplication as Site;
				if( site != null ) {
					if( !newSiteNames.Contains( getIisSiteName( oldLogic, app ) ) )
						IsuStatics.DeleteIisSite( getIisSiteName( oldLogic, app ) );
					continue;
				}
				var virtualDirectory = app.IisApplication as VirtualDirectory;
				if( virtualDirectory != null ) {
					if( !newVirtualDirectoryNames.Contains( virtualDirectory.Name ) )
						IsuStatics.DeleteIisVirtualDirectory( virtualDirectory.Site, virtualDirectory.Name );
					continue;
				}
				throw new ApplicationException( "unrecognized IIS application type" );
			}

			if( oldApps.Any() && ( !newApps.Any() || newLogic.existingInstallationLogic.IisAppPoolName != oldLogic.existingInstallationLogic.IisAppPoolName ) )
				IsuStatics.DeleteIisAppPool( oldLogic.existingInstallationLogic.IisAppPoolName );
		}
コード例 #3
0
        /// <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)
            {
                var serviceController = allServices.SingleOrDefault(sc => sc.ServiceName == service.InstalledName);
                if (serviceController == null)
                {
                    TelemetryStatics.ReportFault(
                        "Failed to start the \"{0}\" service because it is missing. Re-install the services for the installation to correct this error.".FormatWith(
                            service.InstalledName));
                    continue;
                }

                try {
                    serviceController.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);
                }
                serviceController.WaitForStatusWithTimeOut(ServiceControllerStatus.Running);

                TewlContrib.ProcessTools.RunProgram("sc", "config \"{0}\" start= delayed-auto".FormatWith(serviceController.ServiceName), "", true);

                // Set failure actions.
                const int restartDelay = 60000;                 // milliseconds
                TewlContrib.ProcessTools.RunProgram(
                    "sc",
                    "failure \"{0}\" reset= {1} actions= restart/{2}".FormatWith(serviceController.ServiceName, serviceFailureResetPeriod, restartDelay),
                    "",
                    true);
                TewlContrib.ProcessTools.RunProgram("sc", "failureflag \"{0}\" 1".FormatWith(serviceController.ServiceName), "", true);
            }
            if (runtimeConfiguration.WebApplications.Any(i => i.IisApplication != null) && runtimeConfiguration.InstallationType != InstallationType.Development)
            {
                IsuStatics.StartIisAppPool(IisAppPoolName);
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets a data package, either by downloading one or using the last one that was downloaded. Returns the path to the ZIP file for the package. Also
        /// archives downloaded data packages and deletes those that are too old to be useful. Installation Support Utility use only.
        /// </summary>
        public string GetDataPackage(bool forceNewPackageDownload, OperationResult operationResult)
        {
            var dataExportToRsisWebSiteNotPermitted = InstallationTypeElements is LiveInstallationElements liveInstallationElements &&
                                                      liveInstallationElements.DataExportToRsisWebSiteNotPermitted;

            if (dataExportToRsisWebSiteNotPermitted ? !File.Exists(IsuStatics.GetDataPackageZipFilePath(FullName)) : !DataPackageSize.HasValue)
            {
                return("");
            }

            var downloadedPackagesFolder = EwlStatics.CombinePaths(ConfigurationLogic.DownloadedDataPackagesFolderPath, FullName);

            var packageZipFilePath = "";

            // See if we can re-use an existing package.
            if (!forceNewPackageDownload && Directory.Exists(downloadedPackagesFolder))
            {
                var downloadedPackages = IoMethods.GetFilePathsInFolder(downloadedPackagesFolder);
                if (downloadedPackages.Any())
                {
                    packageZipFilePath = downloadedPackages.First();
                }
            }

            // Download a package from RSIS if the user forces this behavior or if there is no package available on disk.
            if (forceNewPackageDownload || packageZipFilePath.Length == 0)
            {
                packageZipFilePath = EwlStatics.CombinePaths(downloadedPackagesFolder, "{0}-Package.zip".FormatWith(DateTime.Now.ToString("yyyy-MM-dd")));

                // If the update data installation is a live installation for which data export to the RSIS web site is not permitted, get the data package from disk.
                if (dataExportToRsisWebSiteNotPermitted)
                {
                    IoMethods.CopyFile(IsuStatics.GetDataPackageZipFilePath(FullName), packageZipFilePath);
                }
                else
                {
                    operationResult.TimeSpentWaitingForNetwork =
                        EwlStatics.ExecuteTimedRegion(() => operationResult.NumberOfBytesTransferred = downloadDataPackage(packageZipFilePath));
                }
            }

            deleteOldFiles(downloadedPackagesFolder, InstallationTypeElements is LiveInstallationElements);
            return(packageZipFilePath);
        }
コード例 #5
0
        void Operation.Execute(Installation genericInstallation, OperationResult operationResult)
        {
            IsuStatics.ConfigureIis(true, false);
            Console.WriteLine("Configured IIS Express.");

            // This block exists because of https://enduracode.kilnhg.com/Review/K164316.
            try {
                IsuStatics.ConfigureIis(false, false);
                Console.WriteLine("Configured full IIS.");
            }
            catch {
                Console.WriteLine("Did not configure full IIS.");
            }

            var installation = genericInstallation as DevelopmentInstallation;

            DatabaseOps.UpdateDatabaseLogicIfUpdateFileExists(
                installation.DevelopmentInstallationLogic.Database,
                installation.ExistingInstallationLogic.DatabaseUpdateFilePath,
                true);

            try {
                copyInEwlFiles(installation);
            }
            catch (Exception e) {
                var message = "Failed to copy {0} files into the installation. Please try the operation again.".FormatWith(EwlStatics.EwlName);
                if (e is UnauthorizedAccessException || e is IOException)
                {
                    throw new UserCorrectableException(message, e);
                }
                throw new ApplicationException(message, e);
            }

            // Generate code.
            if (installation.DevelopmentInstallationLogic.SystemIsEwl)
            {
                generateCodeForProject(
                    installation,
                    AppStatics.CoreProjectName,
                    writer => {
                    writer.WriteLine("using System;");
                    writer.WriteLine("using System.Globalization;");
                    writer.WriteLine("using System.Reflection;");
                    writer.WriteLine("using System.Runtime.InteropServices;");
                    writer.WriteLine();
                    writeAssemblyInfo(writer, installation, "");
                    writer.WriteLine();
                    writer.WriteLine("namespace EnterpriseWebLibrary {");
                    writer.WriteLine("partial class EwlStatics {");
                    CodeGenerationStatics.AddSummaryDocComment(writer, "The date/time at which this version of EWL was built.");
                    writer.WriteLine(
                        "public static readonly DateTimeOffset EwlBuildDateTime = {0};".FormatWith(AppStatics.GetLiteralDateTimeExpression(DateTimeOffset.UtcNow)));
                    writer.WriteLine("}");
                    writer.WriteLine("}");
                });
                generateCodeForProject(
                    installation,
                    "Development Utility",
                    writer => {
                    writer.WriteLine("using System.Reflection;");
                    writer.WriteLine("using System.Runtime.InteropServices;");
                    writeAssemblyInfo(writer, installation, "Development Utility");
                });
            }
            generateLibraryCode(installation);
            foreach (var webProject in installation.DevelopmentInstallationLogic.DevelopmentConfiguration.webProjects ?? new WebProject[0])
            {
                generateWebConfigAndCodeForWebProject(installation, webProject);
            }
            foreach (var service in installation.ExistingInstallationLogic.RuntimeConfiguration.WindowsServices)
            {
                generateWindowsServiceCode(installation, service);
            }
            foreach (var project in installation.DevelopmentInstallationLogic.DevelopmentConfiguration.ServerSideConsoleProjectsNonNullable)
            {
                generateServerSideConsoleProjectCode(installation, project);
            }
            if (installation.DevelopmentInstallationLogic.DevelopmentConfiguration.clientSideAppProject != null)
            {
                generateCodeForProject(
                    installation,
                    installation.DevelopmentInstallationLogic.DevelopmentConfiguration.clientSideAppProject.name,
                    writer => {
                    writer.WriteLine("using System.Reflection;");
                    writer.WriteLine("using System.Runtime.InteropServices;");
                    writeAssemblyInfo(writer, installation, installation.DevelopmentInstallationLogic.DevelopmentConfiguration.clientSideAppProject.name);
                });
            }

            generateXmlSchemaLogicForCustomInstallationConfigurationXsd(installation);
            generateXmlSchemaLogicForOtherXsdFiles(installation);

            if (!installation.DevelopmentInstallationLogic.SystemIsEwl && Directory.Exists(EwlStatics.CombinePaths(installation.GeneralLogic.Path, ".hg")))
            {
                updateMercurialIgnoreFile(installation);
            }
        }