private void DeployArtifact(FarmModelHost modelHost, SPFarm farm, DeveloperDashboardSettingsDefinition ddsDefinition)
        {
            var currentSettings = GetCurrentSettings();

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = currentSettings,
                ObjectType       = typeof(SPDeveloperDashboardSettings),
                ObjectDefinition = ddsDefinition,
                ModelHost        = modelHost
            });

            if (!string.IsNullOrEmpty(ddsDefinition.DisplayLevel))
            {
                var displayLevel = (SPDeveloperDashboardLevel)Enum.Parse(typeof(SPDeveloperDashboardLevel), ddsDefinition.DisplayLevel);
                currentSettings.DisplayLevel = displayLevel;
                currentSettings.Update();
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentSettings,
                ObjectType       = typeof(SPDeveloperDashboardSettings),
                ObjectDefinition = ddsDefinition,
                ModelHost        = modelHost
            });
        }
        private void ValidateDefinition(FarmModelHost farmModelHost,
                                        SPFarm farm,
                                        DeveloperDashboardSettingsDefinition definition)
        {
            var spObject = GetCurrentSettings();
            var assert   = ServiceFactory.AssertService.NewAssert(definition, spObject);

            assert
            .ShouldNotBeNull(spObject);

            if (!string.IsNullOrEmpty(definition.DisplayLevel))
            {
                assert.ShouldBeEqual((p, s, d) =>
                {
                    var srcProp = s.GetExpressionValue(def => def.DisplayLevel);
                    var dstProp = d.GetExpressionValue(ct => ct.DisplayLevel);

                    return(new PropertyValidationResult
                    {
                        Tag = p.Tag,
                        Src = srcProp,
                        Dst = dstProp,
                        IsValid = dstProp.Value.ToString().ToUpper() == (srcProp.Value.ToString().ToUpper())
                    });
                });
            }
            else
            {
                assert.SkipProperty(m => m.DisplayLevel);
            }
        }
예제 #3
0
        protected virtual void RetractSolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution)
        {
            if (IsQARun)
            {
                definition.SetPropertyBagValue("HadRetractHit");
            }

            TraceService.Information((int)LogEventId.CoreCalls, string.Format("Retracting solution [{0}]", existingSolution.Name));

            if (existingSolution.Deployed)
            {
                var retracted = existingSolution.DeploymentState == SPSolutionDeploymentState.NotDeployed;
                existingSolution.Retract(DateTime.Now);

                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be false"));

                while (!retracted)
                {
                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond));
                    Thread.Sleep(SolutionDeploymentTimeoutInMillisecond);

                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Checkin .Deployed for solution [{0}] in [{1}] milliseconds...",
                                                           existingSolution.Name, SolutionDeploymentTimeoutInMillisecond));

                    existingSolution = FindExistingSolution(modelHost, definition);
                    retracted        = existingSolution.DeploymentState == SPSolutionDeploymentState.NotDeployed;
                }

                existingSolution = FindExistingSolution(modelHost, definition);

                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .JobExists status to be false"));
                var jobExists = existingSolution.JobExists;

                while (jobExists)
                {
                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond));
                    Thread.Sleep(SolutionDeploymentTimeoutInMillisecond);


                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Checkin .JobExists for solution [{0}] in [{1}] milliseconds...",
                                                           existingSolution.Name, SolutionDeploymentTimeoutInMillisecond));

                    existingSolution = FindExistingSolution(modelHost, definition);
                    jobExists        = existingSolution.JobExists;
                }

                existingSolution = FindExistingSolution(modelHost, definition);

                TraceService.Information((int)LogEventId.CoreCalls, string.Format(".Deployed and .JobExists are false"));
            }
            else
            {
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Solution was already retracted."));
            }
        }
예제 #4
0
        private void DeploySolution(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            var farm = modelHost.HostFarm;
            var existringSolution = FindExistingSolution(modelHost, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existringSolution,
                ObjectType       = typeof(SPSolution),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            var tmpWspDirectory     = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N"));
            var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory);

            Directory.CreateDirectory(tmpWspDirectoryPath);

            var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName);

            File.WriteAllBytes(tmpWspFilPath, definition.Content);

            if (existringSolution == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new farm solution");
                existringSolution = farm.Solutions.Add(tmpWspFilPath, (uint)definition.LCID);
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Upgrading existing farm solution");

                if (existringSolution.Deployed)
                {
                    existringSolution.Upgrade(tmpWspFilPath);
                }
                else
                {
                    // TODO
                    // https://github.com/SubPointSolutions/spmeta2/issues/324
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existringSolution,
                ObjectType       = typeof(SPSolution),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });
        }
예제 #5
0
        protected virtual void DeleteSolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution)
        {
            if (IsQARun)
            {
                definition.SetPropertyBagValue("HadDeleteHit");
            }

            TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deleting solution [{0}]", existingSolution.Name));
            existingSolution.Delete();
        }
예제 #6
0
 public override void DeployFarmModel(ModelNode model)
 {
     for (var provisionGeneration = 0; provisionGeneration < ProvisionGenerationCount; provisionGeneration++)
     {
         WithSSOMFarmContext(farm =>
         {
             _provisionService.DeployModel(FarmModelHost.FromFarm(farm), model);
             _validationService.DeployModel(FarmModelHost.FromFarm(farm), model);
         });
     }
 }
예제 #7
0
        protected SPSolution FindExistingSolution(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall,
                                       "Resolving farm solution by SolutionId: [{0}] and Name: [{1}]",
                                       new object[]
            {
                definition.SolutionId,
                definition.FileName
            });

            var farm = modelHost.HostFarm;

            return(farm.Solutions.FirstOrDefault(s =>
                                                 s.Name.ToUpper() == definition.FileName.ToUpper() ||
                                                 definition.SolutionId != Guid.Empty && s.SolutionId == definition.SolutionId));
        }
예제 #8
0
        private void DeployWebApplication(FarmModelHost farmModelHost, SPFarm farm, WebApplicationDefinition webApplicationDefinition)
        {
            var webApps = SPWebService.ContentService.WebApplications;

            var webAppBuilder = new SPWebApplicationBuilder(farm);

            webAppBuilder.Port = webApplicationDefinition.Port;
            webAppBuilder.ApplicationPoolId = webApplicationDefinition.ApplicationPoolId;

            if (!string.IsNullOrEmpty(webApplicationDefinition.ManagedAccount))
            {
                webAppBuilder.IdentityType = IdentityType.SpecificUser;

                var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
                var maccount        = managedAccounts.FindOrCreateAccount(webApplicationDefinition.ManagedAccount);

                webAppBuilder.ManagedAccount = maccount;
            }
            else
            {
                webAppBuilder.ApplicationPoolUsername = webApplicationDefinition.ApplicationPoolUsername;

                var password = new SecureString();

                foreach (char c in webApplicationDefinition.ApplicationPoolPassword.ToCharArray())
                {
                    password.AppendChar(c);
                }

                webAppBuilder.ApplicationPoolPassword = password;
            }

            webAppBuilder.CreateNewDatabase = webApplicationDefinition.CreateNewDatabase;

            webAppBuilder.DatabaseName   = webApplicationDefinition.DatabaseName;
            webAppBuilder.DatabaseServer = webApplicationDefinition.DatabaseServer;

            webAppBuilder.UseNTLMExclusively = webApplicationDefinition.UseNTLMExclusively;

            webAppBuilder.HostHeader            = webApplicationDefinition.HostHeader;
            webAppBuilder.AllowAnonymousAccess  = webApplicationDefinition.AllowAnonymousAccess;
            webAppBuilder.UseSecureSocketsLayer = webApplicationDefinition.UseSecureSocketsLayer;

            var webApp = webAppBuilder.Create();

            webApp.Provision();
        }
예제 #9
0
        protected virtual SPSolution AddSolution(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            if (IsQARun)
            {
                definition.SetPropertyBagValue("HadAddHit");
            }

            TraceService.Information((int)LogEventId.CoreCalls, string.Format("Adding solution [{0}]", definition.FileName));

            var farm = modelHost.HostFarm;

            var existringSolution = FindExistingSolution(modelHost, definition);

            var tmpWspDirectory     = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N"));
            var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory);

            Directory.CreateDirectory(tmpWspDirectoryPath);

            var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName);

            File.WriteAllBytes(tmpWspFilPath, definition.Content);

            if (existringSolution == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new farm solution");

                if (definition.LCID.HasValue)
                {
                    existringSolution = farm.Solutions.Add(tmpWspFilPath, (uint)definition.LCID);
                }
                else
                {
                    existringSolution = farm.Solutions.Add(tmpWspFilPath);
                }
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Farm solution exists. No need to add.");
            }

            return(existringSolution);
        }
예제 #10
0
        protected SPSolution FindExistingSolution(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall,
                                       "Resolving farm solution by SolutionId: [{0}] and Name: [{1}]",
                                       new object[]
            {
                definition.SolutionId,
                definition.FileName
            });

            var farm = modelHost.HostFarm;

            // always get anew instance of the farm
            // that would refresh the .Solution colleciton with the right state of the solutions
            farm = SPFarm.Local;

            return(farm.Solutions.FirstOrDefault(s =>
                                                 s.Name.ToUpper() == definition.FileName.ToUpper() ||
                                                 definition.SolutionId != Guid.Empty && s.SolutionId == definition.SolutionId));
        }
예제 #11
0
        private void DeployWebApplication(FarmModelHost farmModelHost,
                                          SPFarm farm,
                                          WebApplicationDefinition definition)
        {
            var webApps        = SPWebService.ContentService.WebApplications;
            var existingWebApp = FindWebApplication(definition, webApps);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingWebApp,
                ObjectType       = typeof(SPWebApplication),
                ObjectDefinition = definition,
                ModelHost        = farmModelHost
            });

            if (existingWebApp == null)
            {
                var webAppBuilder = new SPWebApplicationBuilder(farm);

                webAppBuilder.Port = definition.Port;
                webAppBuilder.ApplicationPoolId = definition.ApplicationPoolId;

                if (!string.IsNullOrEmpty(definition.ManagedAccount))
                {
                    webAppBuilder.IdentityType = IdentityType.SpecificUser;

                    var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
                    var maccount        = managedAccounts.FindOrCreateAccount(definition.ManagedAccount);

                    webAppBuilder.ManagedAccount = maccount;
                }
                else
                {
                    webAppBuilder.ApplicationPoolUsername = definition.ApplicationPoolUsername;

                    var password = new SecureString();

                    foreach (char c in definition.ApplicationPoolPassword.ToCharArray())
                    {
                        password.AppendChar(c);
                    }

                    webAppBuilder.ApplicationPoolPassword = password;
                }

                webAppBuilder.CreateNewDatabase = definition.CreateNewDatabase;

                webAppBuilder.DatabaseName   = definition.DatabaseName;
                webAppBuilder.DatabaseServer = definition.DatabaseServer;

                webAppBuilder.UseNTLMExclusively = definition.UseNTLMExclusively;

                webAppBuilder.HostHeader            = definition.HostHeader;
                webAppBuilder.AllowAnonymousAccess  = definition.AllowAnonymousAccess;
                webAppBuilder.UseSecureSocketsLayer = definition.UseSecureSocketsLayer;

                var webApp = webAppBuilder.Create();
                webApp.Provision();

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioned,
                    Object           = webApp,
                    ObjectType       = typeof(SPWebApplication),
                    ObjectDefinition = definition,
                    ModelHost        = farmModelHost
                });
            }
            else
            {
                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioned,
                    Object           = existingWebApp,
                    ObjectType       = typeof(SPWebApplication),
                    ObjectDefinition = definition,
                    ModelHost        = farmModelHost
                });
            }
        }
예제 #12
0
 public static void DeployFarmModel(this SSOMProvisionService modelHost, SPFarm farm, ModelNode model)
 {
     modelHost.DeployModel(FarmModelHost.FromFarm(farm), model);
 }
예제 #13
0
        protected virtual void UpgradeSolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution)
        {
            definition.SetPropertyBagValue("HadUpgradetHit");

            // ensure deployment state first
            TraceService.Information((int)LogEventId.CoreCalls, string.Format("Ensuring deployment state. Solution must be deployed before upgrading."));
            DeploySolution(modelHost, definition, existingSolution);

            // upgrade
            var tmpWspDirectory     = string.Format("{0}_{1}", Path.GetFileNameWithoutExtension(definition.FileName), Guid.NewGuid().ToString("N"));
            var tmpWspDirectoryPath = Path.Combine(Path.GetTempPath(), tmpWspDirectory);

            Directory.CreateDirectory(tmpWspDirectoryPath);

            var tmpWspFilPath = Path.Combine(tmpWspDirectoryPath, definition.FileName);

            File.WriteAllBytes(tmpWspFilPath, definition.Content);

            var isNowDeployment = false;

            if (definition.UpgradeDate.HasValue)
            {
                existingSolution.Upgrade(tmpWspFilPath, definition.UpgradeDate.Value);
            }
            else
            {
                existingSolution.Upgrade(tmpWspFilPath, DateTime.Now);
                isNowDeployment = true;
            }

            var deployed = existingSolution.Deployed;

            if (isNowDeployment)
            {
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be true"));

                while (!deployed)
                {
                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond));
                    Thread.Sleep(SolutionDeploymentTimeoutInMillisecond);

                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Checkin .Deployed for solution [{0}] in [{1}] milliseconds...",
                                                           existingSolution.Name, SolutionDeploymentTimeoutInMillisecond));

                    existingSolution = FindExistingSolution(modelHost, definition);
                    deployed         = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed;
                }

                existingSolution = FindExistingSolution(modelHost, definition);
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be false"));
                var jobExists = existingSolution.JobExists;

                while (jobExists)
                {
                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond));
                    Thread.Sleep(SolutionDeploymentTimeoutInMillisecond);


                    TraceService.Information((int)LogEventId.CoreCalls,
                                             string.Format("Checkin .JobExists for solution [{0}] in [{1}] milliseconds...",
                                                           existingSolution.Name, SolutionDeploymentTimeoutInMillisecond));

                    existingSolution = FindExistingSolution(modelHost, definition);
                    jobExists        = existingSolution.JobExists;
                }

                TraceService.Information((int)LogEventId.CoreCalls, string.Format(".Deployed is true AND .JobExists is false"));
            }
            else
            {
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Future upgrade. Passing wait."));
            }
        }
예제 #14
0
 private void ValidateWebApplication(FarmModelHost farmModelHost, Microsoft.SharePoint.Administration.SPFarm sPFarm, WebApplicationDefinition webApplicationDefinition)
 {
 }
예제 #15
0
        private void DeployFarmManagedProperty(object modelHost, FarmModelHost farmModelHost, ManagedPropertyDefinition definition)
        {
            farmModelHost.ShouldUpdateHost = false;

            ManagedPropertyCollection  properties;
            List <CrawledPropertyInfo> crawledProps;

            var existingProperty = GetCurrentObject(modelHost, definition, out properties, out crawledProps);

            var isNewMapping = existingProperty == null;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingProperty,
                ObjectType       = typeof(ManagedProperty),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (existingProperty == null)
            {
                existingProperty = properties.Create(definition.Name, (ManagedDataType)Enum.Parse(typeof(ManagedDataType), definition.ManagedType));
            }

            existingProperty.Description = definition.Description ?? string.Empty;

            if (definition.Searchable.HasValue)
            {
                existingProperty.HasMultipleValues = definition.Searchable.Value;
            }

            if (definition.Queryable.HasValue)
            {
                existingProperty.Queryable = definition.Queryable.Value;
            }

            if (definition.Retrievable.HasValue)
            {
                existingProperty.Retrievable = definition.Retrievable.Value;
            }

            if (definition.HasMultipleValues.HasValue)
            {
                existingProperty.HasMultipleValues = definition.HasMultipleValues.Value;
            }

            if (definition.Refinable.HasValue)
            {
                existingProperty.Refinable = definition.Refinable.Value;
            }

            if (definition.Sortable.HasValue)
            {
                existingProperty.Sortable = definition.Sortable.Value;
            }

            if (definition.SafeForAnonymous.HasValue)
            {
                existingProperty.SafeForAnonymous = definition.SafeForAnonymous.Value;
            }

            if (definition.TokenNormalization.HasValue)
            {
                existingProperty.TokenNormalization = definition.TokenNormalization.Value;
            }


            //if (isNewMapping)
            //{
            var mappings = existingProperty.GetMappings();

            foreach (var managedPropertyMappping in definition.Mappings)
            {
                var crawledProp = crawledProps
                                  .FirstOrDefault(p => p.Name.ToUpper() == managedPropertyMappping.CrawledPropertyName.ToUpper());

                if (crawledProp == null)
                {
                    continue;
                }

                var mapping = new Mapping
                {
                    CrawledPropertyName = crawledProp.Name,
                    ManagedPid          = existingProperty.PID,
                    CrawledPropset      = crawledProp.Propset,
                };

                mappings.Add(mapping);
            }

            existingProperty.SetMappings(mappings);
            //}

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingProperty,
                ObjectType       = typeof(ManagedProperty),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            // Write the changes back
            existingProperty.Update();
        }
        private void DeployAftifact(FarmModelHost modelHost, SPFarm spFarm, TrustedAccessProviderDefinition definition)
        {
            var currentObject = GetCurrentTrustedAccessProvider(spFarm, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = currentObject,
                ObjectType       = typeof(SPTrustedAccessProvider),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (currentObject == null)
            {
                var securityTokenService = SPSecurityTokenServiceManager.Local;

                if (securityTokenService == null)
                {
                    throw new SPMeta2Exception("SPSecurityTokenServiceManager.Local is NULL");
                }

                if (definition != null && definition.Certificate.Count() > 0)
                {
                    var certificate = new X509Certificate2(definition.Certificate);

                    currentObject = new SPTrustedAccessProvider(securityTokenService,
                                                                definition.Name,
                                                                definition.Description ?? string.Empty,
                                                                certificate);
                }
                else
                {
                    currentObject = new SPTrustedAccessProvider(securityTokenService,
                                                                definition.Name,
                                                                definition.Description ?? string.Empty);
                }
            }

#if !NET35
            if (!string.IsNullOrEmpty(definition.MetadataEndPoint))
            {
                if (currentObject.MetadataEndPoint != null)
                {
                    if (currentObject.MetadataEndPoint.AbsoluteUri.ToUpper() !=
                        new Uri(definition.MetadataEndPoint).AbsoluteUri.ToUpper())
                    {
                        currentObject.MetadataEndPoint = new Uri(definition.MetadataEndPoint);
                    }
                }
                else
                {
                    currentObject.MetadataEndPoint = new Uri(definition.MetadataEndPoint);
                }
            }
#endif

            if (definition != null && definition.Certificate.Count() > 0)
            {
                var certificate = new X509Certificate2(definition.Certificate);

                if (currentObject.SigningCertificate.Thumbprint != certificate.Thumbprint)
                {
                    currentObject.SigningCertificate = certificate;
                }
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentObject,
                ObjectType       = typeof(SPTrustedAccessProvider),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            currentObject.Update();
        }
예제 #17
0
        protected virtual void DeploySolution(FarmModelHost modelHost, FarmSolutionDefinition definition, SPSolution existingSolution)
        {
            definition.SetPropertyBagValue("HadDeploymentHit");

            if (!existingSolution.Deployed)
            {
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying farm solution:[{0}]", existingSolution.Name));

                var isNowDeployment = false;

                if (definition.DeploymentDate.HasValue)
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying solution on date [{0}]", definition.DeploymentDate.Value));

                    existingSolution.Deploy(definition.DeploymentDate.Value,
                                            definition.DeploymentGlobalInstallWPPackDlls,
                                            definition.DeploymentForce);
                }
                else
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying solution NOW."));

                    existingSolution.Deploy(DateTime.Now,
                                            definition.DeploymentGlobalInstallWPPackDlls,
                                            definition.DeploymentForce);

                    isNowDeployment = true;
                }

                var deployed = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed;

                if (isNowDeployment)
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be true"));

                    while (!deployed)
                    {
                        TraceService.Information((int)LogEventId.CoreCalls,
                                                 string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond));
                        Thread.Sleep(SolutionDeploymentTimeoutInMillisecond);

                        TraceService.Information((int)LogEventId.CoreCalls,
                                                 string.Format("Checkin .Deployed for solution [{0}] in [{1}] milliseconds...",
                                                               existingSolution.Name, SolutionDeploymentTimeoutInMillisecond));

                        existingSolution = FindExistingSolution(modelHost, definition);
                        deployed         = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed;
                    }

                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Checking .Deployed status to be false"));
                    var jobExists = existingSolution.JobExists;

                    while (jobExists)
                    {
                        TraceService.Information((int)LogEventId.CoreCalls,
                                                 string.Format("Sleeping [{0}] milliseconds...", SolutionDeploymentTimeoutInMillisecond));
                        Thread.Sleep(SolutionDeploymentTimeoutInMillisecond);


                        TraceService.Information((int)LogEventId.CoreCalls,
                                                 string.Format("Checkin .JobExists for solution [{0}] in [{1}] milliseconds...",
                                                               existingSolution.Name, SolutionDeploymentTimeoutInMillisecond));

                        existingSolution = FindExistingSolution(modelHost, definition);
                        jobExists        = existingSolution.JobExists;
                    }

                    TraceService.Information((int)LogEventId.CoreCalls, string.Format(".Deployed is true AND .JobExists is false"));
                }
                else
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Future deployment. Passing wait."));
                }
            }
            else
            {
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Farm solution:[{0}] was already deployed.", existingSolution.Name));
            }
        }
예제 #18
0
        private void DeploySolutionDefinition(FarmModelHost modelHost, FarmSolutionDefinition definition)
        {
            var farm             = modelHost.HostFarm;
            var existingSolution = FindExistingSolution(modelHost, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingSolution,
                ObjectType       = typeof(SPSolution),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            // should retract?
            if (existingSolution != null && definition.ShouldRetract == true)
            {
                RetractSolution(modelHost, definition, existingSolution);
                existingSolution = FindExistingSolution(modelHost, definition);
            }
            else if (existingSolution == null && definition.ShouldRetract == true)
            {
                // set up flag for nn existing solution
                if (IsQARun)
                {
                    definition.SetPropertyBagValue("HadRetractHit");
                }
            }


            // should delete?
            if (existingSolution != null && definition.ShouldDelete == true)
            {
                DeleteSolution(modelHost, definition, existingSolution);
                existingSolution = FindExistingSolution(modelHost, definition);
            }

            // should add?
            if (definition.ShouldAdd == true)
            {
                // add solution to the farm
                existingSolution = AddSolution(modelHost, definition);
            }

            if (existingSolution != null && definition.ShouldUpgrade == true)
            {
                // should upgrade?
                UpgradeSolution(modelHost, definition, existingSolution);
            }
            else if (existingSolution != null && definition.ShouldDeploy == true)
            {
                // should deploy?
                DeploySolution(modelHost, definition, existingSolution);
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingSolution,
                ObjectType       = typeof(SPSolution),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });
        }