public static void Install(InstallAuditingServiceRequest request)
        {
            bool isFirstTimeInstall = false;

            try
            {
                // Determine if auditing service needs to be installed
                if (!File.Exists(AuditingServiceConfigFilePath))
                {
                    isFirstTimeInstall = true;

                    // Execute steps for first-time setup and install of auditing service
                    var auditDatabaseInstanceName = (!string.IsNullOrEmpty(request.AuditDatabaseInstanceName)) ? request.AuditDatabaseInstanceName : ServiceContext.HostSettings.ServiceHostDBInstanceName;

                    if (string.IsNullOrEmpty(auditDatabaseInstanceName))
                        throw new InvalidOperationException("AuditDatabaseInstanceName cannot be null.");

                    if (File.Exists(AuditingServiceConfigTemplateFilePath))
                    {
                        CreateAuditingServiceConfig(auditDatabaseInstanceName);
                        ReinstallAuditingService();
                    }
                    else
                    {
                        ServiceContext.Logger.Error("Auditing Service failed to install. Configuration file template is missing.", "ConfigurationFileTemplatePath", AuditingServiceConfigTemplateFilePath);
                    }
                }
                else
                {
                    RestartAuditingService();
                }
            }
            catch (Exception ex)
            {
                if(isFirstTimeInstall)
                    ServiceContext.Logger.Error("Auditing Service failed to install due to an unexpected error.", ex);
                else
                    ServiceContext.Logger.Error("Auditing Service failed to restart due to an unexpected error.", ex);
            }
        }
示例#2
0
        /// <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;
                    }
            }
        }