private void ConfigureControls() { SolutionCheck check = (SolutionCheck)checks ["SolutionCheck"]; SPSolution solution = check.Solution; if (solution == null) { AddInstallControls(); } else { Version installedVersion = InstallConfiguration.InstalledVersion; Version newVersion = InstallConfiguration.SolutionVersion; Version minVersion = string.IsNullOrEmpty(InstallConfiguration.UpdateMinVersion) ? null : new Version(InstallConfiguration.UpdateMinVersion); if (newVersion != installedVersion) { Form.ContentControls.Add(Program.CreateUpgradeControl((minVersion == null) || (installedVersion == null) || (installedVersion >= minVersion))); } else { Form.ContentControls.Add(Program.CreateRepairControl((minVersion == null) || (installedVersion == null) || (installedVersion >= minVersion))); } } }
public void RetractSolution(Guid ID) { farm = SPFarm.Local; SPSolution sol = farm.Solutions[ID]; sol.Retract(DateTime.Now); }
private void ConfigureControls() { SolutionCheck check = (SolutionCheck)checks["SolutionCheck"]; SPSolution solution = check.Solution; if (solution == null) { AddInstallControls(); } else { Version installedVersion = InstallConfiguration.InstalledVersion; Version newVersion = InstallConfiguration.SolutionVersion; if (newVersion != installedVersion) { Form.ContentControls.Add(Program.CreateUpgradeControl()); } else { Form.ContentControls.Add(Program.CreateRepairControl()); } } }
public bool InstallSolution(string solutionFile, Guid solutionID) { try { SPSolution solution = LocateInFarm(solutionID); if (solution != null && solution.JobExists) { KillRunningJobs(solution); // force add solution = null; } // does not exist so add it if (solution == null) { solution = SPFarm.Local.Solutions.Add(solutionFile); } } catch (NullReferenceException) { return(false); } catch (Exception ee) { throw new Exception("Unable to install solution", ee); } return(true); }
protected internal override bool Execute() { try { SPSolution installedSolution = SPFarm.Local.Solutions [InstallConfiguration.SolutionId]; // // Remove existing job, if any. // if (installedSolution.JobExists) { RemoveExistingJob(installedSolution); } if (installedSolution.Deployed) { log.Info(res.SolutionRetraction); if (installedSolution.ContainsWebApplicationResource) { Collection <SPWebApplication> applications = installedSolution.DeployedWebApplications; installedSolution.Retract(GetImmediateJobTime(), applications); } else { installedSolution.Retract(GetImmediateJobTime()); } } return(true); } catch (SqlException ex) { throw new InstallException(ex.Message, ex); } }
protected internal override bool Rollback() { SPSolution installedSolution = SPFarm.Local.Solutions [InstallConfiguration.SolutionId]; // // Wait for job to end // if (installedSolution != null) { if (installedSolution.JobExists) { if (DateTime.Now > startTime.Add(JobTimeout)) { throw new InstallException(res.TimeoutError); } return(false); } else { log.Info(installedSolution.LastOperationDetails); } } return(true); }
protected override IEnumerable <SPFeature> RetrieveDataObjects() { List <SPFeature> features = new List <SPFeature>(); switch (ParameterSetName) { case "SPFeature": foreach (SPFeatureDefinitionPipeBind fdpb in Identity) { SPFeatureDefinition feature = fdpb.Read(); GetFeatureActivations(features, feature, NeedsUpgrade); } break; case "SPSolution": foreach (SPSolutionPipeBind spb in Solution) { SPSolution solution = spb.Read(); List <SPFeatureDefinition> featureDefinitions = SPFarm.Local.FeatureDefinitions.Where(fd => fd.SolutionId == solution.Id).ToList(); foreach (SPFeatureDefinition feature in featureDefinitions) { GetFeatureActivations(features, feature, NeedsUpgrade); } } break; } return(features); }
protected internal override bool Execute() { try { string filename = InstallConfiguration.SolutionFile; if (String.IsNullOrEmpty(filename)) { throw new InstallException(res.ConfigErrorNoSolution); } SPSolution installedSolution = SPFarm.Local.Solutions [InstallConfiguration.SolutionId]; // // Remove existing job, if any. // if (installedSolution.JobExists) { RemoveExistingJob(installedSolution); } log.Info(res.SolutionUpgrade); installedSolution.Upgrade(filename, GetImmediateJobTime()); return(true); } catch (SqlException ex) { throw new InstallException(ex.Message, ex); } }
protected internal override bool Execute() { string filename = InstallConfiguration.SolutionFile; if (String.IsNullOrEmpty(filename)) { throw new InstallException(res.ConfigErrorNoSolution); } #if DEBUG if (!File.Exists(filename)) { return(true); } #endif try { SPFarm farm = SPFarm.Local; SPSolution solution = farm.Solutions.Add(filename); return(true); } catch (IOException ex) { throw new InstallException(ex.Message, ex); } catch (ArgumentException ex) { throw new InstallException(ex.Message, ex); } catch (SqlException ex) { throw new InstallException(ex.Message, ex); } }
public static void AddWorklfowTemplate() { try { bool exists = false; SPSolutionCollection solutionCollection = SPFarm.Local.Solutions; foreach (SPSolution sol in solutionCollection) { if (sol.Name.ToLower() == "spdg workflow.wsp") { exists = true; break; } } if (!exists) { SPSolution solution = SPFarm.Local.Solutions.Add("SampleData\\SPDG Workflow.wsp"); solution.DeployLocal(true, true); } } catch (Exception ex) { Errors.Log(ex); } }
/// <summary> /// gets all of the currently configured applications for a solution /// </summary> /// <param name="solution">solution get get configured applications for</param> /// <param name="applications">the collection to add it to</param> private void AddAllConfiguredWebApplications(SPSolution solution, Collection <SPWebApplication> applications) { foreach (SPWebApplication app in solution.DeployedWebApplications) { applications.Add(app); } }
/// <summary> /// Upgrades a solution using a .wsp file to sharepoint server /// </summary> /// <param name="solutionFile">the full path to the solution package file</param> /// <param name="solutionID">the SolutionId (GUID) of the solution</param> /// <returns>true if it was able to upgrade the solution</returns> public bool UpgradeSolution(string solutionFile, Guid solutionID) { try { if (string.IsNullOrEmpty(solutionFile)) { throw new Exception("No solution file specified."); } if (!File.Exists(solutionFile)) { throw new Exception("Solution file not found."); } SPSolution solution = SPFarm.Local.Solutions[solutionID]; KillRunningJobs(solution); solution.Upgrade(solutionFile, Immediately); } catch (NullReferenceException) { return(false); } catch (InvalidOperationException) { return(DeploySolution(solutionFile, solutionID.ToString())); } catch (Exception eee) { throw new Exception("Unable to upgrade solution.", eee); } return(true); }
protected void CheckSolutionVersionsAndSetCaption() { SolutionCheck check = (SolutionCheck)checks["SolutionCheck"]; SPSolution solution = check.Solution; Version newVersion = InstallConfiguration.SolutionVersion; string solutionTitle = InstallConfiguration.SolutionTitle; string caption; if (solution == null) { caption = string.Format("Install {0} {1}", solutionTitle, newVersion); } else { Version installedVersion = InstallConfiguration.InstalledVersion; if (newVersion != installedVersion) { string upgradePrompt = string.Format( "Upgrade {0} from {1} to {2}", solutionTitle, installedVersion, newVersion); caption = upgradePrompt; } else { caption = string.Format("Repair/Remove {0} {1}", solutionTitle, newVersion); } } Form.SetSolutionInfo(caption); }
internal static OutputQueue RemoveExistingJob(SPSolution solution) { var outputQueue = new OutputQueue(); if (solution == null || !solution.JobExists) { return(outputQueue); } if (solution.JobStatus == SPRunningJobStatus.Initialized) { outputQueue.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.DeploySolutionError, solution.Name, Exceptions.DeploySolutionJobAlreadyRunning), OutputType.Warning); } var jobs = GetSolutionJobs(solution); foreach (var jobid in jobs.Keys) { var jobDefinition = jobs[jobid]; if (jobDefinition != null) { try { outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.DeploySolutionRemoveJob, jobDefinition.DisplayName, solution.Name)); jobDefinition.Delete(); } catch (Exception exception) { outputQueue.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.DeploySolutionRemoveJobFailed, jobDefinition.DisplayName, solution.Name, exception), OutputType.Warning); } } } return(outputQueue); }
public override void AddPackage(AddPackageContext context, Boolean autoActivate) { StorePackage package = context.StorePackage; try { Collection <SPWebApplication> webApps = new Collection <SPWebApplication>(); webApps.Add(context.TargetWeb.Site.WebApplication); bool previousUnsafeUpdatesContextWeb = context.SPContext.Web.AllowUnsafeUpdates; context.SPContext.Web.AllowUnsafeUpdates = true; SPSolution solution = SPFarm.Local.Solutions.Add(context.SolutionFilePath); solution.Deploy(DateTime.Now, true, webApps, true); if (!string.IsNullOrEmpty(package.SetupFeatureID)) { if (autoActivate) { SPSINStorePackageUtilities.AddPendingActivationFeature(context.TargetWeb, new Guid(package.SetupFeatureID)); } } context.SPContext.Web.AllowUnsafeUpdates = previousUnsafeUpdatesContextWeb; } catch (Exception exc) { throw new SPException(exc.ToString()); } }
private static void CreateNewLists(SPSolution solution) { foreach (SPWebApplication deployedWebApplication in solution.DeployedWebApplications) { foreach (SPFeature feature in deployedWebApplication.Features) { if (feature.DefinitionId.Equals(new Guid("b242c6bd-bbe3-4fb3-8596-9fe9272ed698"))) { foreach (SPSite site in deployedWebApplication.Sites) { SPWeb rootWeb = site.RootWeb; if (rootWeb != null) { SPList list = rootWeb.Lists.TryGetList("TranslationContents"); if (list != null) { var installerHelper = new InstallerHelper(); installerHelper.CreateConfigurationStoreServersList(rootWeb.Url); installerHelper.CreateTroubleshootingStoreServersList(rootWeb.Url); break; } } } break; } } } }
protected internal override bool Execute() { try { SPSolution installedSolution = SPFarm.Local.Solutions [InstallConfiguration.SolutionId]; if (installedSolution == null) #if DEBUG { return(true); } #else { return(false); } #endif // // Remove existing job, if any. // if (installedSolution.JobExists) { RemoveExistingJob(installedSolution); } log.Info(res.SolutionDeployment); if (installedSolution.ContainsWebApplicationResource && applications != null && applications.Count > 0) { installedSolution.Deploy(GetImmediateJobTime(), true, applications, true); } else { installedSolution.Deploy(GetImmediateJobTime(), true, true); } return(true); } catch (SPException ex) { throw new InstallException(ex.Message, ex); } catch (SqlException ex) { throw new InstallException(ex.Message, ex); } }
public bool UninstallSolution(Guid solutionId, Guid featureId) { try { SPSolution solution = LocateInFarm(solutionId); if (RetractSolution(solutionId, featureId)) { // Wait for it to end. WaitForJobToFinish(solution); SPFarm.Local.Solutions.Remove(solutionId); } } catch (NullReferenceException) { return(false); } catch (Exception ee) { throw new Exception("Unable to uninstall solution", ee); } return(true); }
protected internal override bool Rollback() { SPSolution installedSolution = SPFarm.Local.Solutions [InstallConfiguration.SolutionId]; if (installedSolution != null) { // // Remove existing job, if any. // if (installedSolution.JobExists) { RemoveExistingJob(installedSolution); } log.Info(res.SolutionRetraction); if (installedSolution.ContainsWebApplicationResource) { installedSolution.Retract(GetImmediateJobTime(), applications); } else { installedSolution.Retract(GetImmediateJobTime()); } } return(true); }
protected override SystemCheckResult DoExecute() { Guid solutionId = Guid.Empty; try { solutionId = InstallConfiguration.SolutionId; } catch (ArgumentNullException) { throw new InstallException(res.ConfigErrorNoSolutionID); } catch (FormatException) { throw new InstallException(res.ConfigErrorInvalidSolutionID); } try { solution = SPFarm.Local.Solutions [solutionId]; if (solution != null) { this.OkText = InstallConfiguration.FormatString(res.SolutionInstalled); } else { this.OkText = InstallConfiguration.FormatString(res.SolutionNotInstalled); } } catch (NullReferenceException) { throw new InstallException(res.SpDbError); } catch (Exception ex) { throw new InstallException(ex.Message, ex); } return(SystemCheckResult.Success); }
public FarmSolutionControl(SPSolution solution) { InitializeComponent(); _solution = solution; SolutionName.Text = solution.SolutionName; }
private void DeployButton_Click(object sender, EventArgs e) { if (OpenDialog.ShowDialog() == DialogResult.OK) { SPSolution solution = SPFarm.Local.Solutions.Add(OpenDialog.FileName); solution.Deploy(DateTime.Now, true, _utility.GetAllWebApplications(), true); } }
public static void UpgradeSolution(ISharePointCommandContext context, SolutionInfo solutionInfo) { SPSolution solution = SPFarm.Local.Solutions[solutionInfo.Name]; //Do not use this version as it causes SP to return success prior to timer execution so VS falselt notifies the user it is completed. https://cksdev.codeplex.com/workitem/9027 //solution.Upgrade(solutionInfo.LocalPath, DateTime.Now); solution.Upgrade(solutionInfo.LocalPath); }
public SolutionNode(SPSolution solution) { this.Tag = solution; this.SPParent = solution.Farm; this.Setup(); this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
public FarmSolutionDetail(SPSolution solution) { InitializeComponent(); _solution = solution; Text = solution.SolutionName; PopulateValues(); }
private void UpgradeSolution(ISharePointCommandContext context, string fullWspPath) { SPSolution solution = SPFarm.Local.Solutions[Path.GetFileName(fullWspPath)]; if (solution == null) { throw new InvalidOperationException("The solution has not been deployed."); } solution.Upgrade(fullWspPath); }
private Collection <SPWebApplication> GetDeployedApplications() { SPFarm farm = SPFarm.Local; SPSolution solution = farm.Solutions [InstallConfiguration.SolutionId]; if (solution.ContainsWebApplicationResource) { return(solution.DeployedWebApplications); } return(null); }
public bool CheckSolution(Guid SolutionGUID) { bool result = false; SPSolution sol = farm.Solutions[SolutionGUID]; if (sol != null) { result = true; } return(result); }
public void DeploySolution(Guid SolutionsGUID, string URL) { farm = SPFarm.Local; if (CheckSolution(SolutionsGUID)) { SPSolution sol = farm.Solutions[SolutionsGUID]; foreach (SPServer srv in sol.DeployedServers) { Console.WriteLine(srv.DisplayName); } } }
public bool RetractSolution(Guid solutionId, Guid featureId) { try { SPSolution solution = LocateInFarm(solutionId); if (solution == null) { throw new Exception("Solution currently not deployed to server. Can not retract."); } KillRunningJobs(solution); if (solution.Deployed) { if (solution.ContainsWebApplicationResource) { var deployedWebApplications = new Collection <SPWebApplication>(); AddAllConfiguredWebApplications(solution, deployedWebApplications); foreach (SPWebApplication deployedWebApplication in deployedWebApplications) { foreach (SPFeature feature in deployedWebApplication.Features) { if (feature.DefinitionId.Equals(featureId)) { deployedWebApplication.Features.Remove(featureId, true); break; } } } solution.Retract(Immediately, deployedWebApplications); } else { solution.Retract(Immediately); } // Wait for the retract job to finish WaitForJobToFinish(solution); } } catch (NullReferenceException) { return(false); } catch (Exception ee) { throw new Exception("Unable to retract solution", ee); } return(true); }
public static void Deploy(SPSolution solution, Collection<SPWebApplication> applications, int minCompat, int maxCompat, ILog log) { #if SP2013 SPSolutionLanguagePack languagePack = solution.GetLanguagePack(0); SPCompatibilityRange compatibilityRange = new SPCompatibilityRange(minCompat, maxCompat); Type deployType = languagePack.GetType(); Type[] argumentTypes = new Type[] { typeof(DateTime), applications.GetType(), typeof(SPSolutionDeploymentJobType), typeof(bool), typeof(bool), typeof(bool), compatibilityRange.GetType() }; ParameterModifier[] modifiers = new ParameterModifier[] { new ParameterModifier(7) }; MethodInfo deployMethod = deployType.GetMethod("CreateSolutionDeployTimerJob", BindingFlags.Instance | BindingFlags.NonPublic, null, argumentTypes, modifiers); DateTime jobTime = GetImmediateJobTime(); object[] args = new object[] { jobTime, applications, SPSolutionDeploymentJobType.Deploy, true, true, false, compatibilityRange }; deployMethod.Invoke(languagePack, args); #endif }