コード例 #1
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();
        }
 protected void RemoveSolution()
 {
     try {
         SPFarm     farm     = SPFarm.Local;
         SPSolution solution = farm.Solutions [InstallConfiguration.SolutionId];
         if (solution != null)
         {
             if (!solution.Deployed)
             {
                 solution.Delete();
             }
         }
     } catch (SqlException ex) {
         throw new InstallException(ex.Message, ex);
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
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 {
                    }
                }
            }
        }