public static void UpgradeServiceInstances(UpgradeServiceInstancesRequest request) { lock (_threadLock) { // Get service instances to upgrade var serviceInstances = IISUtilities.GetServiceInstances(); if (!request.UpgradeAllInstances) { request.InstanceNames = request.InstanceNames.Select(n => n.ToLowerInvariant()); serviceInstances = serviceInstances.Where(i => request.InstanceNames.Contains(i.ServicesName.ToLowerInvariant())); } // Upgrade each service instance foreach (var serviceInstance in serviceInstances) { IISUtilities.StopAppPool(serviceInstance.PhysicalPath); // Update service instance database schema var database = new BusinessServiceDatabase(serviceInstance.PhysicalPath, request.DatabaseBehavior, request.SampleDataScript); if (request.DatabaseBehavior == CreateDatabaseBehavior.DestroyExistingAndCreate) database.Create(); else database.Update(); // Update service instance files var targetFolder = GetServicesInstancePhysicalPath(serviceInstance.ServicesName); FileUtilties.Copy(AdminServicesPhysicalPath, targetFolder); // Update service instance configuration BusinessServiceConfiguration.UpdateCustomConfig(serviceInstance.PhysicalPath, serviceInstance.ServicesName); IISUtilities.StartAppPool(serviceInstance.PhysicalPath); } } }
private void UpgradeInstance() { if(_upgradeIsRunning) { _viewModel.SetErrorMessage("A Service Instance upgrade is already running"); return; } lock (_threadLock) { try { _upgradeIsRunning = true; var serviceContext = QueryData(); var request = new UpgradeServiceInstancesRequest() { DatabaseBehavior = CreateDatabaseBehavior.ReuseExistingOrCreate, InstanceNames = new List<string> { serviceContext.ServicesName } }; var handler = new UpgradeServiceInstancesHandler(); handler.Handle(request); _viewModel.SetSuccessMessage("Service Instance Upgraded Successfully"); } finally { _upgradeIsRunning = false; } } }
/// <summary> /// Executes the specified install action. /// </summary> /// <param name="action">The action.</param> public void ExecuteInstallAction(InstallAction action) { Application.DoEvents(); LoggingUtils.WriteInfo(string.Format(CultureInfo.InvariantCulture, "[----- Executing Action {0} -----]", action.ToString()), ConsoleColor.Cyan); string adminServicesAddress = string.Format("net.tcp://{0}:{1}/Agatha.Common.WCF.IWcfRequestProcessor.svc", Environment.MachineName, AppSettings.NettcpPort); string defaultServicesInstanceAddress = string.Format("net.tcp://{0}:{1}/{2}/Agatha.Common.WCF.IWcfRequestProcessor.svc", Environment.MachineName, AppSettings.NettcpPort, AppSettings.VirtualApplicationName); // Execute action switch (action) { case InstallAction.ClearNetTempFiles: IOUtils.ClearDotNetTempFiles(); break; case InstallAction.StopAuditingService: WindowsServiceUtils.StopService(WindowsService.MEDSEEKAuditingService); break; case InstallAction.StartAuditingService: WindowsServiceUtils.StartService(WindowsService.MEDSEEKAuditingService); break; case InstallAction.CopyApplicationFiles: { var adminServiceInstancePath = Path.Combine(AppSettings.ApplicationFilePath, Constants.BusinessFolder); IISUtils.StopAppPool(adminServiceInstancePath); if (AppSettings.ApplicationMode == ApplicationMode.Install) IOUtils.BuildDirectoryStructure(); IOUtils.CopyFiles(); IISUtils.StartAppPool(adminServiceInstancePath); break; } case InstallAction.CreateAdminServicesInstance: { IISUtils.BuildIISEntities(); break; } case InstallAction.TestAdminServicesInstance: { if (!ServiceUtils.TestServices(adminServicesAddress, 3)) throw new InvalidOperationException("Admin services test failed."); break; } case InstallAction.InstallAuditingService: { var installAuditRequest = new InstallAuditingServiceRequest() { AuditDatabaseInstanceName = AppSettings.AuditDatabaseInstanceName }; SimpleRequestDispatcher.Get<InstallAuditingServiceResponse>(installAuditRequest, adminServicesAddress); break; } case InstallAction.CreateDefaultServicesInstance: { var createServiceInstanceRequest = new CreateServiceInstanceRequest() { ServicesName = AppSettings.VirtualApplicationName, AppPoolUserName = AppSettings.VirtualApplicationPoolIdentity, AppPoolUserPassword = AppSettings.VirtualApplicationPoolIdentityPassword, DefaultAdminUserName = AppSettings.ServicesAdminUserName, DefaultAdminUserPassword = AppSettings.ServicesAdminUserPassword, DefaultPublicUserName = AppSettings.ServicesPublicUserName, DefaultPublicUserPassword = AppSettings.ServicesPublicUserPassword, DatabaseInstanceName = AppSettings.DatabaseInstanceName, DatabaseName = AppSettings.DatabaseName, SampleDataScript = AppSettings.LoadSampleData ? AppSettings.SampleDataScript : null, AuditSiteSubscriptionId = AppSettings.VirtualApplicationAuditSiteSubscriptionId, AllowServiceInstanceOverwrite = CommandLineArgs.Dev, DatabaseBehavior = CommandLineArgs.Dev ? CreateDatabaseBehavior.DestroyExistingAndCreate : CreateDatabaseBehavior.ReuseExistingOrCreate }; SimpleRequestDispatcher.Get<CreateServiceInstanceResponse>(createServiceInstanceRequest, adminServicesAddress); break; } case InstallAction.UpgradeServicesInstances: { var upgradeServiceInstancesRequest = new UpgradeServiceInstancesRequest() { DatabaseBehavior = AppSettings.CreateDatabaseBehavior, SampleDataScript = AppSettings.LoadSampleData ? AppSettings.SampleDataScript : null, UpgradeAllInstances = AppSettings.UpgradeAllInstances, InstanceNames = AppSettings.UpgradeInstances.Split(",".ToCharArray()) }; SimpleRequestDispatcher.Get<UpgradeServiceInstancesResponse>(upgradeServiceInstancesRequest, adminServicesAddress); break; } case InstallAction.TestDefaultServicesInstance: { if (!string.IsNullOrEmpty(AppSettings.VirtualApplicationName)) { if (!ServiceUtils.TestServices(defaultServicesInstanceAddress, 3)) throw new InvalidOperationException("Default services test failed."); } break; } } }