Пример #1
0
        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();
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }