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];

                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);
            }
        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);
        }
Exemplo n.º 4
0
        public void RetractSolution(Guid ID)
        {
            farm = SPFarm.Local;
            SPSolution sol = farm.Solutions[ID];

            sol.Retract(DateTime.Now);
        }
Exemplo n.º 5
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."));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retracts a solution using a .wsp file from a 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 retract the solution</returns>
        public bool RetractSolution(string solutionFile, Guid solutionID)
        {
            try
            {
                SPSolution solution = SPFarm.Local.Solutions[solutionID];
                if (solution == null)
                {
                    throw new Exception("Solution currently not deployed to server.  Can not retract.");
                }

                KillRunningJobs(solution);

                if (solution.Deployed)
                {
                    if (solution.ContainsWebApplicationResource)
                    {
                        Collection <SPWebApplication> deployedWebApplications = new Collection <SPWebApplication>();
                        AddAllConfiguredWebApplications(solution, deployedWebApplications);
                        solution.Retract(Immediately, deployedWebApplications);
                    }
                    else
                    {
                        solution.Retract(Immediately);
                    }
                    // Wait for the retract job to finish
                    WaitForJobToFinish(solution);
                }

                //try
                //{
                //    SPFarm.Local.Solutions.Remove(solution.Id);
                //}
                //catch { }
            }
            catch (NullReferenceException)
            {
                return(false);
            }
            catch (Exception ee)
            {
                throw new Exception("Unable to retract solution", ee);
            }
            return(true);
        }
        private bool Remove(Guid Solution, SPFarm farm, System.Collections.ObjectModel.Collection <SPWebApplication> apps)
        {
            SPSolution sol = farm.Solutions[Solution];

            SPContext.Current.Web.AllowUnsafeUpdates  = true;
            SPContext.Current.Site.AllowUnsafeUpdates = true;

            sol.Retract(DateTime.Now, apps);
            DateTime dtStart = DateTime.Now;

            while (sol.JobExists)
            {
                Thread.Sleep(5000);
                if (dtStart.AddMinutes(2) <= DateTime.Now)
                {
                    return(false);
                }
            }

            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);
        }
Exemplo n.º 9
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."));
            }
        }
Exemplo n.º 10
0
        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 {
                    }
                }
            }
        }