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); } }
internal static SPSolution DeploySolution(System.IO.FileInfo _fi, SPWebApplication _wa, TimeSpan _timeout) { try { SPSolution _sol = Farm.Solutions.Add(_fi.FullName); if (_wa != null) { Collection <SPWebApplication> _collection = new Collection <SPWebApplication>(); _collection.Add(_wa); _sol.Deploy(DateTime.Now, true, _collection, true); } else { _sol.Deploy(DateTime.Now, true, false); } Stopwatch _runTime = new Stopwatch(); _runTime.Start(); while (!_sol.Deployed) { Thread.Sleep(200); string _msg = String.Format( "Waiting for the solution to be deployed DeploymentState={0}, LastOperationResult={1}, Status={2}", _sol.DeploymentState, _sol.LastOperationResult, _sol.Status); if (_sol.JobExists) { _msg += String.Format(" JobStatus={0}", _sol.JobStatus); } Tracing.TraceEvent.TraceVerbose(80, "DeploySolution", _msg); if (_runTime.Elapsed > _timeout) { string _tom = String.Format(Resources.DeplymentTimeout, _sol.DeploymentState, _sol.Status, _sol.LastOperationResult, _sol.LastOperationDetails); throw new ApplicationException(_tom); } //if } ; //while (!_sol.Deployed) Tracing.TraceEvent.TraceVerbose(81, "DeploySolution", String.Format(Resources.DeploymentSuccess, _runTime.Elapsed)); return(_sol); } catch (Exception ex) { string _msg = String.Format(Resources.DeployFarmSolutionFailed, _fi.Name, ex.Message); throw new ApplicationException(_msg); } }
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 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); } }
/// <summary> /// Deploys a solution .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> /// <param name="deployToAllWebApplications">true if you want to register package with all of the WebApplications on sharepoint server</param> /// <param name="deployToAllContentWebApplications">true if you want to register package with all of the content WebApplications on the sharepoint server</param> /// <returns>true if it was able to deploy</returns> public bool DeploySolution(string solutionFile, Guid solutionID, bool deployToAllWebApplications, bool deployToAllContentWebApplications) { 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) { Log.Verbose("WSP package installing."); solution = SPFarm.Local.Solutions.Add(solutionFile); } // check to see if this has web application stuff if (solution.ContainsWebApplicationResource) { Collection <SPWebApplication> webApplications = new Collection <SPWebApplication>(); // add request web applications if (deployToAllWebApplications) { AddAllWebApplications(webApplications); } if (deployToAllContentWebApplications) { AddAllContentWebApplications(webApplications); } if (webApplications.Count == 0) // try to make sure we have at least one { SPWebApplication app = SPWebService.AdministrationService.WebApplications.GetEnumerator().Current; if (app == null) { app = SPWebService.ContentService.WebApplications.GetEnumerator().Current; } } // deploy it Log.Verbose("WSP package deploying to " + webApplications.Count + " webapplication(s)."); solution.Deploy(Installer.Immediately, true, webApplications, true); } else { Log.Verbose("WSP package deploying global."); // deploy it without web app stuff solution.Deploy(Installer.Immediately, true, true); } } catch (NullReferenceException) { return(false); } catch (Exception ee) { throw new Exception("Unable to deploy solution", ee); } return(true); }
public bool InstallSolution(string solutionFile, Guid solutionId, Guid featureId, bool upgradeDeployed) { try { var deployedWebApplications = new Collection <SPWebApplication>(); var activatedFeatureWebApplications = new Collection <SPWebApplication>(); SPSolution solution = LocateInFarm(solutionId); if (solution != null) { if (solution.JobExists) { KillRunningJobs(solution); } if (upgradeDeployed && solution.Deployed) { if (solution.ContainsWebApplicationResource) { AddAllConfiguredWebApplications(solution, deployedWebApplications); foreach (SPWebApplication deployedWebApplication in deployedWebApplications) { foreach (SPFeature feature in deployedWebApplication.Features) { if (feature.DefinitionId.Equals(featureId)) { deployedWebApplication.Features.Remove(featureId, true); activatedFeatureWebApplications.Add(deployedWebApplication); break; } } } solution.Retract(Immediately, deployedWebApplications); } else { solution.Retract(Immediately); } // Wait for the retract job to finish WaitForJobToFinish(solution); } solution.Delete(); } // does not exist so add it solution = SPFarm.Local.Solutions.Add(solutionFile); // Wait for the retract job to finish WaitForJobToFinish(solution); if (deployedWebApplications.Count > 0) { solution.Deploy(Immediately, true, deployedWebApplications, true); // Wait for the retract job to finish WaitForJobToFinish(solution); foreach (SPWebApplication deployedWebApplication in activatedFeatureWebApplications) { deployedWebApplication.Features.Add(featureId, true); } } } catch (NullReferenceException) { return(false); } catch (Exception ee) { throw new Exception("Unable to install solution", ee); } return(true); }
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)); } } }
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)); } }
static void Main(string [] args) { //Thread.CurrentThread.CurrentUICulture= new System.Globalization.CultureInfo ("de"); Console.BackgroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Black; Console.Clear(); string caUrlHost = "http://" + Environment.MachineName; string caUrlPath = "_admin/solutions.aspx?"; string cfgMossAsmCheck, cfgSolutionName, cfgSolutionTitle; Guid cfgSolutionId = Guid.Empty, cfgFeatureId; try { Console.Title = "ROXORITY " + res.Title; Console.WriteLine("=================="); Console.WriteLine(res.DontQuit); Console.WriteLine("==================\n"); Console.TreatControlCAsInput = true; Console.WriteLine(res.Step1); NameValueCollection cfg = ConfigurationManager.AppSettings; if (string.IsNullOrEmpty(cfgSolutionName = cfg ["SolutionName"]) || string.IsNullOrEmpty(cfg ["SolutionId"])) { throw new Exception(res.Step1Fail); } if (string.IsNullOrEmpty(cfgSolutionTitle = cfg ["SolutionTitle"])) { cfgSolutionTitle = cfgSolutionName; } cfgSolutionId = new Guid(cfg ["SolutionId"]); cfgFeatureId = new Guid(cfg ["FeatureId"]); caUrlPath = "_layouts/" + cfgSolutionName + "/default.aspx?doc=intro&postsetup=1"; Console.Title = cfgSolutionTitle + " " + res.Title; Console.WriteLine(res.Step2); SPFarm farm = SPFarm.Local; if (farm == null) { throw new Exception(res.Step2Fail); } bool is14 = farm.BuildVersion.Major > 12; cfgMossAsmCheck = cfg ["Asm" + (is14 ? "14" : "12")]; Console.WriteLine(res.Step3); SPSolution solution = farm.Solutions [cfgSolutionId]; if (solution != null) { if (solution.Deployed) { Console.WriteLine("\t" + res.Step3Retract); writeWait(); solution.Retract(DateTime.Now, solution.DeployedWebApplications); solution.Update(true); while (solution.Deployed || solution.DeploymentState != SPSolutionDeploymentState.NotDeployed) { Thread.Sleep(500); } solution.Update(true); } Console.WriteLine("\t" + res.Step3Delete); solution.Delete(); solution = null; } writeColor("\n" + cfgSolutionTitle + " " + res.Step3Uninstalled, ConsoleColor.DarkGreen); bool useWss = false; if (!string.IsNullOrEmpty(cfgMossAsmCheck)) { try { Assembly a1 = Assembly.Load(cfgMossAsmCheck + ", Culture=Neutral, Version=" + farm.BuildVersion.Major + ".0.0.0, PublicKeyToken=71e9bce111e9429c"); Assembly a2 = Assembly.Load(cfgMossAsmCheck + ", Culture=Neutral, Version=14.0.0.0, PublicKeyToken=71e9bce111e9429c"); if ((a1 == null) && (a2 == null)) { useWss = true; } } catch { useWss = true; } } string wspFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, cfgSolutionName + "_" + (is14 ? "xiv" : "xii") + ".wsp"); if (useWss) { wspFilePath = wspFilePath.Substring(0, wspFilePath.LastIndexOf('.')) + "_wss.wsp"; } clearKeys(); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("\n" + res.Step4Prompt1 + Path.GetFileName(wspFilePath) + res.Step4Prompt2); Console.ForegroundColor = ConsoleColor.Black; Console.Write("\t" + res.Step4Prompt3); if (Console.ReadKey(true).Key == ConsoleKey.Enter) { Console.WriteLine("\n\n" + res.Step4); solution = farm.Solutions.Add(wspFilePath); farm.Solutions.Ensure(solution); solution.Update(true); enable(cfgSolutionId); farm.Update(true); Collection <SPWebApplication> webApps = new Collection <SPWebApplication> (), cWebApps = new Collection <SPWebApplication> (); foreach (SPWebApplication wapp in SPWebService.ContentService.WebApplications) { webApps.Add(wapp); cWebApps.Add(wapp); foreach (SPAlternateUrl url in wapp.AlternateUrls) { if (!string.IsNullOrEmpty(caUrlHost = url.Uri.ToString())) { break; } } } foreach (SPWebApplication wapp in SPWebService.AdministrationService.WebApplications) { webApps.Add(wapp); foreach (SPAlternateUrl url in wapp.AlternateUrls) { if (!string.IsNullOrEmpty(caUrlHost = url.Uri.ToString())) { break; } } } Console.WriteLine("\t" + res.Step4Deploy); Thread.Sleep(TimeSpan.FromSeconds(webApps.Count * 2)); writeWait(); solution.Deploy(DateTime.Now, true, webApps, true); solution.Update(true); do { Thread.Sleep(500); } while ((!solution.Deployed) || (solution.DeploymentState != SPSolutionDeploymentState.GlobalAndWebApplicationDeployed)); solution.Synchronize(); foreach (SPWebApplication wapp in cWebApps) { try { for (int i = 0; i < wapp.Sites.Count; i++) { try { SPSite site = wapp.Sites [i]; try { site.AllowUnsafeUpdates = true; } catch { } try { site.Features.Add(cfgFeatureId, true); } catch { } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } catch { } } writeColor("\n" + res.Success, ConsoleColor.DarkGreen); } else { caUrlHost = ""; writeColor(res.Cancelled, ConsoleColor.DarkRed); } } catch (Exception ex) { caUrlHost = ""; writeColor(res.Error + "\n" + ex.ToString(), ConsoleColor.DarkRed); } finally { enable(cfgSolutionId); clearKeys(); Console.WriteLine("\n" + res.ExitPrompt); Console.ReadKey(true); Console.WriteLine(res.Exiting); if (!string.IsNullOrEmpty(caUrlHost)) { try { ProcessStartInfo proc = new ProcessStartInfo("iexplore", caUrlHost.TrimEnd('/') + "/" + caUrlPath.TrimStart('/')); proc.ErrorDialog = false; proc.UseShellExecute = true; proc.WindowStyle = ProcessWindowStyle.Maximized; Process.Start(proc); } catch { } } } }