Esempio n. 1
0
        public static void BuildIISEntities(CreateServiceInstanceRequest request, string servicesPhysicalPath)
        {
            var appPoolName = GetEffectiveAppPoolName(request.ServicesName);

            CreateAppPool(appPoolName, request.AppPoolUserName, request.AppPoolUserPassword);
            CreateVirtualApplication(request.ServicesName, servicesPhysicalPath, appPoolName);
            SetServiceInstanceAuth(request.ServicesName, true, true);
        }
Esempio n. 2
0
 public static string PreValidateBuildIISEntities(CreateServiceInstanceRequest request)
 {
     if (!request.AllowServiceInstanceOverwrite)
     {
         if (VirtualApplicationExists(request.ServicesName))
             return string.Format(CultureInfo.InvariantCulture, "Virtual application named ({0}) already exists under IIS web application ({1}).", request.ServicesName, HostingEnvironment.SiteName);
     }
     return null;
 }
        public static void CreateServiceInstance(CreateServiceInstanceRequest request)
        {
            lock (_threadLock)
            {
                // Validate new service instance parameters
                var validationErrors = PreValidateCreateServiceInstance(request);

                if (!string.IsNullOrEmpty(validationErrors))
                    throw new BusinessException(validationErrors);

                if (!request.ValidateOnly)
                {
                    // Provision the business service database
                    var database = new BusinessServiceDatabase(request.DatabaseInstanceName, request.DatabaseName, request.AppPoolUserName, request.ServicesName, request.DatabaseBehavior, request.SampleDataScript);
                    database.Create();
                    database.CreateServiceUser(request.DefaultAdminUserName, request.DefaultAdminUserPassword, 3);
                    database.CreateServiceUser(request.DefaultPublicUserName, request.DefaultPublicUserPassword, 2);

                    // Create services folder structure
                    var auditSiteSubscriptionId = GetEffectiveAuditSiteSubscriptionId(request.AuditSiteSubscriptionId, request.ServicesName);
                    var targetFolder = GetServicesInstancePhysicalPath(request.ServicesName);

                    FileUtilties.CreateDirectory(targetFolder);
                    FileUtilties.Copy(AdminServicesPhysicalPath, targetFolder);

                    // Create IIS configuration
                    IISUtilities.BuildIISEntities(request, targetFolder);

                    // Create web.config file for service instance
                    BusinessServiceConfiguration.CreateCustomConfig(Path.Combine(targetFolder, "Web.config"), database, request.ServicesName, auditSiteSubscriptionId);

                    // Register new instance with auditing service
                    AuditingServiceManager.AddAuditSiteSubscriptionId(auditSiteSubscriptionId);
                    AuditingServiceManager.RestartAuditingService();
                }
            }
        }
        private void Save()
        {
            try
            {
                var overwriteServicesIfExists = bool.Parse(CommonUtils.GetFieldValue(_viewModel.Fields, _overwriteServicesIfExistsFieldName));
                var overwriteDatabaseIfExists = bool.Parse(CommonUtils.GetFieldValue(_viewModel.Fields, _overwriteDatabaseIfExistsFieldName));

                var request = new CreateServiceInstanceRequest
                {
                    AllowServiceInstanceOverwrite = overwriteServicesIfExists,
                    ServicesName = CommonUtils.GetFieldValue(_viewModel.Fields, _servicesNameFieldName),
                    AppPoolUserName = CommonUtils.GetFieldValue(_viewModel.Fields, _appPoolUserFieldName),
                    AppPoolUserPassword = CommonUtils.GetFieldValue(_viewModel.Fields, _appPoolPasswordFieldName),
                    DatabaseInstanceName = CommonUtils.GetFieldValue(_viewModel.Fields, _serviceDatabaseInstanceFieldName),
                    DatabaseName = CommonUtils.GetFieldValue(_viewModel.Fields, _serviceDatabaseNameFieldName),
                    DatabaseBehavior = overwriteDatabaseIfExists ? CreateDatabaseBehavior.DestroyExistingAndCreate : CreateDatabaseBehavior.ReuseExistingOrCreate,
                    DefaultAdminUserName = CommonUtils.GetFieldValue(_viewModel.Fields, _adminUserNameFieldName),
                    DefaultAdminUserPassword = CommonUtils.GetFieldValue(_viewModel.Fields, _adminUserPasswordFieldName),
                    DefaultPublicUserName = CommonUtils.GetFieldValue(_viewModel.Fields, _publicUserNameFieldName),
                    DefaultPublicUserPassword = CommonUtils.GetFieldValue(_viewModel.Fields, _publicUserPasswordFieldName)
                };

                var handler = new CreateServiceInstanceHandler();
                var response = handler.Handle(request) as CreateServiceInstanceResponse;

                if (!response.IsSuccess)
                    throw new Exception("Unknown error");
            }
            catch (Exception ex)
            {
                throw new Exception("Services Instance creation failed. " + ex.Message);
            }
        }
        private static string PreValidateCreateServiceInstance(CreateServiceInstanceRequest request)
        {
            var validationErrors = new StringBuilder();
            string validationError = string.Empty;

            if (!ServiceContext.HostSettings.IsAdminServiceHost)
            {
                validationErrors.AppendLine("New service instances can only be created from the admin service instance.");
            }
            else
            {
                // Validate service database creation
                var database = new BusinessServiceDatabase(request.DatabaseInstanceName, request.DatabaseName, request.AppPoolUserName, request.ServicesName, request.DatabaseBehavior, request.SampleDataScript);
                validationError = database.PreValidateCreate();

                if (!string.IsNullOrEmpty(validationError))
                    validationErrors.AppendLine(validationError);

                // Validate target folder for service files
                if (!request.AllowServiceInstanceOverwrite)
                {
                    var targetFolder = GetServicesInstancePhysicalPath(request.ServicesName);

                    if (Directory.Exists(targetFolder))
                        validationErrors.AppendLine(string.Format(CultureInfo.InvariantCulture, "A physical folder for services ({0}) already exists at: {1}", request.ServicesName, targetFolder));
                }

                // Validate IIS configuration for service
                validationError = IISUtilities.PreValidateBuildIISEntities(request);

                if (!string.IsNullOrEmpty(validationError))
                    validationErrors.AppendLine(validationError);

                // Validate Audit configuration
                validationError = AuditingServiceManager.PreValidateAddAuditSiteSubscriptionId();

                if (!string.IsNullOrEmpty(validationError))
                    validationErrors.AppendLine(validationError);
            }

            return validationErrors.ToString();
        }
Esempio n. 6
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;
                    }
            }
        }