Ejemplo n.º 1
0
        private void PrepareRetractedState(FarmSolutionDefinition solutionDef,
                                           bool isWebApplication)
        {
            var deployDef = solutionDef.Inherit(def =>
            {
                def.ShouldDelete  = null;
                def.ShouldRetract = null;
                def.ShouldUpgrade = null;

                def.ShouldAdd    = true;
                def.ShouldDeploy = true;
            });

            var retractDef = solutionDef.Inherit(def =>
            {
                def.ShouldDelete  = null;
                def.ShouldDeploy  = null;
                def.ShouldUpgrade = null;

                def.ShouldAdd     = true;
                def.ShouldRetract = true;
            });

            TestFarmSolutionModel(deployDef, isWebApplication);
            TestFarmSolutionModel(retractDef, isWebApplication);
        }
Ejemplo n.º 2
0
        protected virtual void TestFarmSolutionModel(FarmSolutionDefinition solutionDef, bool isWebApplicationLevel)
        {
            var newSolutiondef = solutionDef.Inherit();

            if (isWebApplicationLevel)
            {
                var originalModel = SPMeta2Model.NewWebApplicationModel(webApp =>
                {
                    webApp.AddFarmSolution(solutionDef);
                });

                var newModel = SPMeta2Model.NewWebApplicationModel(farm =>
                {
                    farm.AddFarmSolution(newSolutiondef);
                });

                TestModel(originalModel);
                TestModel(newModel);
            }
            else
            {
                var originalModel = SPMeta2Model.NewFarmModel(farm =>
                {
                    farm.AddFarmSolution(solutionDef);
                });

                var newModel = SPMeta2Model.NewFarmModel(farm =>
                {
                    farm.AddFarmSolution(newSolutiondef);
                });

                TestModel(originalModel);
                TestModel(newModel);
            }
        }
        private void PrepareAddedState(FarmSolutionDefinition solutionDef)
        {
            var addDef = solutionDef.Inherit(def =>
            {
                def.ShouldDelete  = null;
                def.ShouldDeploy  = null;
                def.ShouldUpgrade = null;

                def.ShouldAdd     = true;
                def.ShouldRetract = null;
            });

            TestFarmSolutionModel(addDef);

            var retractDef = solutionDef.Inherit(def =>
            {
                def.ShouldDelete  = null;
                def.ShouldDeploy  = null;
                def.ShouldUpgrade = null;

                def.ShouldAdd     = true;
                def.ShouldRetract = true;
            });

            TestFarmSolutionModel(retractDef);
        }
Ejemplo n.º 4
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."));
            }
        }
Ejemplo n.º 5
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
            });
        }
Ejemplo n.º 6
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();
        }
        private void PrepareDeletedState(FarmSolutionDefinition solutionDef)
        {
            var deletedDef = solutionDef.Inherit(def =>
            {
                def.ShouldDeploy  = null;
                def.ShouldRetract = true;
                def.ShouldUpgrade = null;

                def.ShouldAdd    = false;
                def.ShouldDelete = true;
            });

            TestFarmSolutionModel(deletedDef);
        }
Ejemplo n.º 8
0
        //[SampleMetadataTag(Name = BuiltInTagNames.SampleHidden)]
        public void CanDeploySimpleFarmSolutionDefinition()
        {
            var solutionDef = new FarmSolutionDefinition
            {
                FileName   = "your-solution-file.wsp",
                SolutionId = new Guid("your-solution-id"),
                Content    = File.ReadAllBytes("path-to-your-solution-or-byte-array")
            };

            var model = SPMeta2Model.NewFarmModel(farm =>
            {
                farm.AddFarmSolution(solutionDef);
            });

            DeployModel(model);
        }
Ejemplo n.º 9
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));
        }
        protected virtual void TestFarmSolutionModel(FarmSolutionDefinition solutionDef)
        {
            var newSolutiondef = solutionDef.Inherit();

            var originalModel = SPMeta2Model.NewFarmModel(farm =>
            {
                farm.AddFarmSolution(solutionDef);
            });

            var newModel = SPMeta2Model.NewFarmModel(farm =>
            {
                farm.AddFarmSolution(newSolutiondef);
            });

            TestModel(originalModel);
            TestModel(newModel);
        }
Ejemplo n.º 11
0
        protected virtual SPSolution AddSolution(
            object modelHost,
            SPFarm farm,
            SPWebApplication webApplication,
            FarmSolutionDefinition definition)
        {
            if (IsQARun)
            {
                definition.SetPropertyBagValue("HadAddHit");
            }

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

            var existringSolution = FindExistingSolution(modelHost, farm, webApplication, 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);
        }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
0
        protected virtual void DeploySolution(object modelHost,
                                              SPFarm farm,
                                              SPWebApplication webApplication,
                                              FarmSolutionDefinition definition,
                                              SPSolution existingSolution)
        {
            definition.SetPropertyBagValue("HadDeploymentHit");

            var webAppCollection = new Collection <SPWebApplication>();

            if (webApplication != null)
            {
                webAppCollection.Add(webApplication);
            }

            // either not deploed or not deployed to a particular web app
            if (!existingSolution.Deployed ||
                (webAppCollection.Any() && !existingSolution.DeployedWebApplications.Contains(webAppCollection.First())))
            {
                TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying farm solution:[{0}]", existingSolution.Name));

                var isNowDeployment = false;

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


                        existingSolution.Deploy(definition.DeploymentDate.Value,
                                                definition.DeploymentGlobalInstallWPPackDlls,
                                                webAppCollection,
                                                definition.DeploymentForce);
                    }
                    else
                    {
                        TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying solution globally on date [{0}]", definition.DeploymentDate.Value));

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

                        existingSolution.Deploy(DateTime.Now,
                                                definition.DeploymentGlobalInstallWPPackDlls,
                                                webAppCollection,
                                                definition.DeploymentForce);
                    }
                    else
                    {
                        TraceService.Information((int)LogEventId.CoreCalls, string.Format("Deploying solution globaly 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, farm, webApplication, 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, farm, webApplication, 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
            {
                if (webAppCollection.Any())
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Farm solution:[{0}] was already deployed to web app", existingSolution.Name));
                }
                else
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Farm solution:[{0}] was already deployed.", existingSolution.Name));
                }
            }
        }
 public static TModelNode AddFarmSolution <TModelNode>(this TModelNode model, FarmSolutionDefinition definition,
                                                       Action <FarmSolutionModelNode> action)
     where TModelNode : ModelNode, IFarmModelNode, new()
 {
     return(model.AddTypedDefinitionNode(definition, action));
 }
 public static TModelNode AddFarmSolution <TModelNode>(this TModelNode model, FarmSolutionDefinition definition)
     where TModelNode : ModelNode, IFarmModelNode, new()
 {
     return(AddFarmSolution(model, definition, null));
 }
        private void CheckWebApplicationDeployment(object modelHost, SPFarm farm, SPWebApplication webApp, SPSolution solution, FarmSolutionDefinition definition)
        {
            // might come from the deleting operation
            if (solution != null)
            {
                // web app scope deployment
                if (webApp != null)
                {
                    if (!solution.Deployed)
                    {
                        return;
                    }

                    if (solution.DeploymentState == SPSolutionDeploymentState.GlobalDeployed ||
                        solution.DeploymentState == SPSolutionDeploymentState.NotDeployed)
                    {
                        throw new SPMeta2Exception(
                                  string.Format("Solution is not expected to have deployment state:[{0}]",
                                                solution.DeploymentState));
                    }

                    if (solution.DeployedWebApplications.Count == 0)
                    {
                        throw new SPMeta2Exception("Web scoped solution is expected to be deployed under at least one web application");
                    }

                    if (!solution.DeployedWebApplications.Contains(webApp))
                    {
                        throw new SPMeta2Exception(
                                  string.Format("Web scoped solution is expected to be deployed under web application:[{0}]", webApp));
                    }
                }
                else
                {
                    // farm, global deployment

                    if (!solution.Deployed)
                    {
                        return;
                    }

                    if (solution.DeploymentState == SPSolutionDeploymentState.WebApplicationDeployed ||
                        solution.DeploymentState == SPSolutionDeploymentState.NotDeployed)
                    {
                        throw new SPMeta2Exception(
                                  string.Format("Farm scoped solution is not expected to have deployment state:[{0}]",
                                                solution.DeploymentState));
                    }
                }
            }
        }
Ejemplo n.º 17
0
 public static ModelNode AddHostFarmSolution(this ModelNode model, FarmSolutionDefinition definition, Action <ModelNode> action)
 {
     return(model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing()));
 }
Ejemplo n.º 18
0
 public static ModelNode AddHostFarmSolution(this ModelNode model, FarmSolutionDefinition definition)
 {
     return(AddHostFarmSolution(model, definition, null));
 }
Ejemplo n.º 19
0
 public static ModelNode AddFarmSolution(this ModelNode model, FarmSolutionDefinition definition, Action <ModelNode> action)
 {
     return(model.AddDefinitionNode(definition, action));
 }
Ejemplo n.º 20
0
        protected virtual void RetractSolution(
            object modelHost,
            SPFarm farm,
            SPWebApplication webApplication,
            FarmSolutionDefinition definition,
            SPSolution existingSolution)
        {
            var webAppCollection = new Collection <SPWebApplication>();

            if (webApplication != null)
            {
                webAppCollection.Add(webApplication);
            }

            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;

                if (webAppCollection.Any())
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Retracting solution from web application [{0}]", existingSolution.Name));
                    existingSolution.Retract(DateTime.Now, webAppCollection);
                }
                else
                {
                    TraceService.Information((int)LogEventId.CoreCalls, string.Format("Retracting solution from the farm [{0}]", existingSolution.Name));
                    existingSolution.Retract(DateTime.Now);
                }

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

                if (webAppCollection.Any())
                {
                    // this is bad but we don't expext more than one web app here
                    var webApp = webAppCollection.First();

                    while (existingSolution.DeployedWebApplications.Contains(webApp))
                    {
                        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, farm, webApplication, definition);
                        retracted        = existingSolution.DeploymentState == SPSolutionDeploymentState.NotDeployed;
                    }
                }
                else
                {
                    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, farm, webApplication, definition);
                        retracted        = existingSolution.DeploymentState == SPSolutionDeploymentState.NotDeployed;
                    }
                }

                existingSolution = FindExistingSolution(modelHost, farm, webApplication, 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, farm, webApplication, definition);
                    jobExists        = existingSolution.JobExists;
                }

                existingSolution = FindExistingSolution(modelHost, farm, webApplication, 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."));
            }
        }
Ejemplo n.º 21
0
        protected virtual void UpgradeSolution(object modelHost,
                                               SPFarm farm,
                                               SPWebApplication webApplication,
                                               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, farm, webApplication, 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, farm, webApplication, definition);
                    deployed         = existingSolution.DeploymentState != SPSolutionDeploymentState.NotDeployed;
                }

                existingSolution = FindExistingSolution(modelHost, farm, webApplication, 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, farm, webApplication, 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."));
            }
        }
Ejemplo n.º 22
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));
            }
        }
Ejemplo n.º 23
0
        private void DeploySolutionDefinition(object modelHost,
                                              SPFarm farm,
                                              SPWebApplication webApplication,
                                              FarmSolutionDefinition definition)
        {
            var existingSolution = FindExistingSolution(modelHost, farm, webApplication, 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, farm, webApplication, definition, existingSolution);
                existingSolution = FindExistingSolution(modelHost, farm, webApplication, 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, farm, webApplication, definition, existingSolution);
                existingSolution = FindExistingSolution(modelHost, farm, webApplication, definition);
            }

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

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

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