Пример #1
0
        public static OutputQueue CopyApplicationBinContent(int timeOut)
        {
            var output = new OutputQueue();

            Parallel.ForEach(LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)),
                             server =>
            {
                if (SPWebService.ContentService.Instances.Any(p => p.Server.Id == server.Id) || SPWebService.AdministrationService.Instances.Any(p => p.Server.Id == server.Id))
                {
                    var command = string.Format(CultureInfo.InvariantCulture, @"{0} -o copyappbincontent", SPUtility.GetGenericSetupPath(@"bin\stsadm.exe"));

                    output.Add(string.Format(CultureInfo.CurrentUICulture, UserDisplay.RunningCommandOn, command, server.Address));

                    try
                    {
                        var processWMI = new Threading.ProcessWMI();
                        processWMI.ExecuteRemoteProcessWMI(server.Address, command, timeOut);
                    }
                    catch (Exception exception)
                    {
                        output.Add(string.Format(CultureInfo.CurrentUICulture, Exceptions.ExceptionRunningCommandOn, command, server.Address, exception.Message), OutputType.Error, exception.ToString(), exception);
                    }
                }
            });

            return(output);
        }
Пример #2
0
        internal static SPPersistedObject Get(Type serviceType)
        {
            if (serviceType == null)
            {
                return(null);
            }

            foreach (var service in LocalFarm.Get().Services)
            {
                if (string.Equals(service.GetType().FullName, serviceType.FullName, StringComparison.OrdinalIgnoreCase))
                {
                    return(service);
                }
            }

            return(null);

            //var farm = SPFarm.Local;
            //var services = farm.Services;

            //var method = services.GetType().GetMethod("GetValue", new Type[] { });
            //var generic = method.MakeGenericMethod(serviceType);

            //return (SPPersistedObject)generic.Invoke(services, null);
        }
Пример #3
0
        public ReactivateFeatures(string literalPath)
        {
            this.literalPath = literalPath;

            // Timeout is 5 minutes multiplied by the number of servers in the farm
            this.Timeout = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count() * 300000;
        }
Пример #4
0
        public UpdateFeatures(Collection <Guid> solutionsIds)
        {
            this.SolutionIds = solutionsIds;

            // Timeout is 5 minutes multiplied by the number of servers in the farm
            this.Timeout = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count() * 300000;
        }
        internal static OutputQueue IsSupportedVersionOfSharePoint(out bool isSupported)
        {
            var outputQueue = new OutputQueue();

            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisite, UserDisplay.PrerequisiteSharePointVersion));
            try
            {
                isSupported = false;
                var farm = LocalFarm.Get();
                switch (farm.BuildVersion.Major)
                {
                case 14:
                    isSupported = farm.BuildVersion >= new Version(14, 0, 6029, 1000);     // SharePoint 2010 SP1
                    break;

                case 15:
                    isSupported = farm.BuildVersion >= new Version(15, 0, 4420, 1017);     // SharePoint 2013 RTM
                    break;

                case 16:
                    isSupported = farm.BuildVersion >= new Version(16, 0, 4306, 1001);     // SharePoint 2016 Beta 2, TODO: Replace with RTM
                    break;
                }
            }
            catch (Exception exception)
            {
                isSupported = false;
                outputQueue.Add(exception.Message, OutputType.Error, null, exception);
            }
            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisiteComplete, UserDisplay.PrerequisiteSharePointVersion, isSupported ? UserDisplay.CheckingPrerequisitePassed : UserDisplay.CheckingPrerequisiteFailed));
            return(outputQueue);
        }
Пример #6
0
 internal string GetDefaultDatabaseServer()
 {
     if (this._defaultDatabaseServer == null)
     {
         this._defaultDatabaseServer = new SPWebApplicationBuilder(LocalFarm.Get()).DatabaseServer;
     }
     return(this._defaultDatabaseServer);
 }
Пример #7
0
 internal static bool IsSolutionInstalled(SocialSitesSolution solution)
 {
     if (solution == null)
     {
         return(false);
     }
     return(LocalFarm.Get().Solutions[solution.SolutionName] != null);
 }
Пример #8
0
        public static Collection <SPManagedAccount> GetManagedAccounts()
        {
            var accounts = new Collection <SPManagedAccount>();

            foreach (SPManagedAccount account in new SPFarmManagedAccountCollection(LocalFarm.Get()))
            {
                accounts.Add(account);
            }
            return(accounts);
        }
Пример #9
0
        public SolutionAdd(string fileName, string filePath)
        {
            this.solutionName = fileName;
            this.solutionPath = filePath;

            // Timeout is 5 minutes multiplied by the number of servers in the farm
            var count = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count();

            this.Timeout = (count > 1 ? count : 2) * 300000;
        }
Пример #10
0
        public SolutionRemove(string solutionName, bool retract, bool force)
        {
            this.solutionToRemove = solutionName;
            this.forceRemoval     = force;
            this.retractSolution  = retract;

            // Timeout is 5 minutes multiplied by the number of servers in the farm
            var count = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count();

            this.Timeout = (count > 1 ? count : 2) * 300000;
        }
Пример #11
0
        private static OutputQueue ExecuteRecycleTimerJob(int timeout)
        {
            var output = new OutputQueue();

            try
            {
                var timerService = LocalFarm.Get().Services.Where(p => p is SPTimerService).First() as SPTimerService;
                var job          = timerService.JobDefinitions.Where(p => (p.Name.IndexOf(RecycleJobName, StringComparison.OrdinalIgnoreCase) > -1)).First();

                var lastRun = job.LastRunTime;
                job.RunNow();

                Func <bool> wait = () =>
                {
                    var complete = false;
                    while (!complete)
                    {
                        try
                        {
                            var waitTimerService = LocalFarm.Get().Services.Where(p => p is SPTimerService).First() as SPTimerService;
                            var waitJob          = waitTimerService.JobDefinitions.Where(p => (p.Name.IndexOf(RecycleJobName, StringComparison.OrdinalIgnoreCase) > -1)).First();

                            if (waitJob.LastRunTime > lastRun)
                            {
                                complete = true;
                            }

                            if (!complete)
                            {
                                Thread.Sleep(10000);
                            }
                        }
                        catch { }
                    }

                    return(complete);
                };

                var success = Threading.WaitFor <bool> .Run(TimeSpan.FromMilliseconds(timeout / 2), wait);

                if (!success)
                {
                    throw new System.TimeoutException();
                }
            }
            catch (Exception exception)
            {
                output.Add(string.Format(CultureInfo.CurrentUICulture, NewsGator.Install.Resources.Exceptions.TimerJobException, exception.Message), OutputType.Error, exception.ToString(), exception);
            }

            return(output);
        }
Пример #12
0
        private static SPJobDefinition GetJob(Guid id)
        {
            var timerService = LocalFarm.Get().TimerService;

            foreach (SPJobDefinition job in timerService.JobDefinitions)
            {
                if (job.Name == id.ToString())
                {
                    return(job);
                }
            }
            return(null);
        }
Пример #13
0
        private static string ExecutableConfig()
        {
            switch (LocalFarm.Get().BuildVersion.Major)
            {
            case 16:
                return(Config.ExecutableConfig2016);

            case 15:
                return(Config.ExecutableConfig2013);

            default:
                return(Config.ExecutableConfig2010);
            }
        }
Пример #14
0
        private static Dictionary <Guid, SPJobDefinition> GetSolutionJobs(SPSolution solution)
        {
            var            jobs      = new Dictionary <Guid, SPJobDefinition>();
            SPFarm         localFarm = LocalFarm.Get();
            SPTimerService service   = localFarm.TimerService;

            foreach (SPJobDefinition definition in service.JobDefinitions)
            {
                if (definition.Title != null && CultureInfo.InvariantCulture.CompareInfo.IndexOf(definition.Title, solution.Name, CompareOptions.IgnoreCase) != -1)
                {
                    jobs.Add(definition.Id, definition);
                }
            }
            return(jobs);
        }
Пример #15
0
        internal static string WriteInstallConfigFile(bool force = false, bool ngPSConfig = false)
        {
            var executionPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ServiceApplicationConfiguration)).Location);

            if (executionPath.Contains("file:\\"))
            {
                executionPath = executionPath.Replace("file:\\", "");
            }
            if (!executionPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase))
            {
                executionPath += "\\";
            }

            return(WriteConfigFile(LocalFarm.Get().BuildVersion.Major, executionPath, force, ngPSConfig));
        }
Пример #16
0
        public SolutionUpdate(string fileName, string filePath, Collection <string> webApps)
        {
            this.solutionName    = fileName;
            this.solutionPath    = filePath;
            this.webApplications = webApps;

            // Timeout is 10 minutes multiplied by the number of servers in the farm
            var count = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count();

            this.Timeout = (count > 2 ? count : 3) * 1200000;

            if (this.webApplications != null && this.webApplications.Count > 2)
            {
                this.Timeout = this.Timeout * this.webApplications.Count;
            }
        }
 internal static void TryUpdate(this SPFarm farm)
 {
     if (farm != null)
     {
         try
         {
             farm.Update();
         }
         catch
         {
             try
             {
                 LocalFarm.Get().Update();
             }
             catch { }
         }
     }
 }
Пример #18
0
        internal static OutputQueue IsFarmAdministrator(out bool isFarmAdmin)
        {
            var outputQueue = new OutputQueue();

            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisite, UserDisplay.PrerequisiteUserIsFarmAdmin));
            try
            {
                isFarmAdmin = LocalFarm.Get().CurrentUserIsAdministrator();
            }
            catch (Exception exception)
            {
                isFarmAdmin = false;
                outputQueue.Add(exception.Message, OutputType.Error, null, exception);
            }
            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisiteComplete, UserDisplay.PrerequisiteUserIsFarmAdmin, isFarmAdmin ? UserDisplay.CheckingPrerequisitePassed : UserDisplay.CheckingPrerequisiteFailed));

            return(outputQueue);
        }
        private void Initialize()
        {
            var socialSitesServiceApplicationType = ServiceApplications.SocialServiceApplication.ServiceApplicationType;

            if (socialSitesServiceApplicationType != null)
            {
                foreach (var svc in LocalFarm.Get().Services)
                {
                    foreach (var serviceApp in svc.Applications)
                    {
                        if (serviceApp.GetType() == socialSitesServiceApplicationType)
                        {
                            var db      = new Database();
                            var connStr = Utilities.Reflection.GetPropertyValue(socialSitesServiceApplicationType, serviceApp, "DatabaseConnection").ToString();
                            try
                            {
                                this.Version = db.GetDatabaseVersion(connStr);
                            }
                            catch
                            {
                                this.Version = null;
                            }
                            try
                            {
                                var sqlFarmConfiguration = db.GetFarmConfiguration(connStr);
                                if (sqlFarmConfiguration != null)
                                {
                                    using (var writer = new StringWriter(CultureInfo.InvariantCulture))
                                    {
                                        sqlFarmConfiguration.WriteXml(writer);
                                        this.SqlFarmConfiguration = writer.ToString();
                                    }
                                }
                            }
                            catch
                            {
                                this.SqlFarmConfiguration = null;
                            }
                        }
                    }
                }
            }
        }
Пример #20
0
        public static Collection <string> IisGetAllWebAppFolders()
        {
            var folders = new Collection <string>();

            var serverAddresses = LocalFarm.Get().Servers.Where(server => Server.ValidSPServerRole(server.Role) && (SPWebService.ContentService.Instances.Any(p => p.Server.Id == server.Id) || SPWebService.AdministrationService.Instances.Any(p => p.Server.Id == server.Id))).Select(server => server.Address).ToArray();

            foreach (var webApp in LocalFarm.Get().Services.OfType <SPWebService>().SelectMany(ws => ws.WebApplications))
            {
                foreach (SPUrlZone zone in webApp.IisSettings.Keys)
                {
                    foreach (var m in serverAddresses.Select(a => Path.Combine(string.Format(CultureInfo.InvariantCulture, "\\\\{0}", a), webApp.IisSettings[zone].Path.ToString().Replace(':', '$'))))
                    {
                        folders.Add(m);
                    }
                }
            }

            return(folders);
        }
Пример #21
0
        public static OutputQueue EnableUserProfileJob()
        {
            var output = new OutputQueue();

            try
            {
                foreach (var service in LocalFarm.Get().Services)
                {
                    foreach (var job in service.JobDefinitions.Where(p => p.Name.EndsWith(JobName, StringComparison.OrdinalIgnoreCase)))
                    {
                        job.IsDisabled = false;
                        job.Update();
                    }
                }
            }
            catch (Exception exception)
            {
                output.Add(string.Format(CultureInfo.CurrentUICulture, NewsGator.Install.Resources.Exceptions.EnableUserProfileJobException, exception.Message), OutputType.Error, exception.ToString(), exception);
            }

            return(output);
        }
        public SolutionDeploy(string solutionNameToDeploy, Collection <string> webApps, bool force, string compatibilityLevel)
        {
            this.solutionName    = solutionNameToDeploy;
            this.webApplications = webApps;
            this.forceDeploy     = force;

            this.overrideCompatibility = !string.IsNullOrEmpty(compatibilityLevel);
            if (this.overrideCompatibility)
            {
                this.compatibilityLevel = compatibilityLevel;
            }

            // Timeout is 10 minutes multiplied by the number of servers in the farm
            var count = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count();

            this.Timeout = (count > 2 ? count : 3) * 1200000;

            if (this.webApplications != null && this.webApplications.Count > 2)
            {
                this.Timeout = this.Timeout * this.webApplications.Count;
            }
        }
Пример #23
0
        internal static OutputQueue IsWMIAvailable(out bool isWMIAvailable)
        {
            var outputQueue = new OutputQueue();

            isWMIAvailable = true;

            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisite, UserDisplay.PrerequisiteWMIAvailable));
            try
            {
                var farm = LocalFarm.Get();
                foreach (var server in farm.Servers.Where(f => Server.ValidSPServerRole(f.Role)))
                {
                    var machineServices = ServiceController.GetServices(server.Address);
                    if (null == machineServices || machineServices.Length == 0)
                    {
                        isWMIAvailable = false;
                        outputQueue.Add("Unable to list services on server.", OutputType.Error, "Unable to list services on server: " + server.Address);
                        break;
                    }

                    // var command = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "where.exe");
                    // https://fogbugz.corp.newsgator.com/default.asp?304837
                    // Removing specific path and providing parameter for the where command
                    var command    = "where.exe iisreset.exe";
                    var processWMI = new Threading.ProcessWMI();
                    processWMI.ExecuteRemoteProcessWMI(server.Address, command, 15000);
                }
            }
            catch (Exception exception)
            {
                isWMIAvailable = false;
                outputQueue.Add(exception.Message, OutputType.Error, null, exception);
            }
            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisiteComplete, UserDisplay.PrerequisiteWMIAvailable, isWMIAvailable ? UserDisplay.CheckingPrerequisitePassed : UserDisplay.CheckingPrerequisiteFailed));

            return(outputQueue);
        }
Пример #24
0
        public static OutputQueue EnsureApplicationPools()
        {
            var output = new OutputQueue();

            Parallel.ForEach(LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)),
                             server =>
            {
                if (SPWebService.ContentService.Instances.Any(p => p.Server.Id == server.Id) || SPWebService.AdministrationService.Instances.Any(p => p.Server.Id == server.Id))
                {
                    var applicationPoolNames = new List <string>();

                    if (SPWebService.ContentService.Instances.Any(p => p.Server.Id == server.Id))
                    {
                        applicationPoolNames.AddRange(SPWebService.ContentService.WebApplications.Select(p => p.ApplicationPool.Name).Distinct());
                    }

                    if (SPWebService.AdministrationService.Instances.Any(p => p.Server.Id == server.Id))
                    {
                        applicationPoolNames.AddRange(SPWebService.AdministrationService.WebApplications.Select(p => p.ApplicationPool.Name).Distinct());
                    }

                    var applicationPoolPaths = new List <string>();

                    var serverName = server.Address;
                    foreach (var appPoolName in applicationPoolNames)
                    {
                        applicationPoolPaths.Add(string.Format(CultureInfo.InvariantCulture, WMIAppPoolPathFormat, serverName, appPoolName));
                    }

                    output.Add(string.Format(CultureInfo.InvariantCulture, "Stopping IIS Application Pools: {0}", serverName));
                    foreach (var appPoolPath in applicationPoolPaths)
                    {
                        try
                        {
                            output.Add(string.Format(CultureInfo.InvariantCulture, "Checking IIS Application Pool Status: {0}", appPoolPath));
                            using (var entry = new DirectoryEntry(appPoolPath))
                            {
                                var status = (int)entry.InvokeGet("AppPoolState");
                                if (status == 2)
                                {
                                    output.Add(string.Format(CultureInfo.InvariantCulture, "Stopping IIS Application Pool: {0}", appPoolPath));
                                    entry.Invoke("Stop", null);
                                }
                                else if (status == 4)
                                {
                                    output.Add(string.Format(CultureInfo.InvariantCulture, "IIS Application Pool Already Stopped: {0}", appPoolPath));
                                }
                                else
                                {
                                    output.Add(string.Format(CultureInfo.InvariantCulture, "Unknown State for IIS Application Pool: {0}", appPoolPath));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            if (exception.Message.IndexOf("The system cannot find the path specified", StringComparison.OrdinalIgnoreCase) == -1)
                            {
                                output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
                            }
                        }
                    }

                    output.Add(string.Format(CultureInfo.InvariantCulture, "Starting IIS Application Pools: {0}", serverName));
                    foreach (var appPoolPath in applicationPoolPaths)
                    {
                        try
                        {
                            output.Add(string.Format(CultureInfo.InvariantCulture, "Checking IIS Application Pool Status: {0}", appPoolPath));
                            using (var entry = new DirectoryEntry(appPoolPath))
                            {
                                var status = (int)entry.InvokeGet("AppPoolState");
                                if (status == 4)
                                {
                                    output.Add(string.Format(CultureInfo.InvariantCulture, "Starting IIS Application Pool: {0}", appPoolPath));
                                    entry.Invoke("Start", null);
                                }
                                else if (status == 2)
                                {
                                    output.Add(string.Format(CultureInfo.InvariantCulture, "IIS Application Pool Already Started: {0}", appPoolPath));
                                }
                                else
                                {
                                    output.Add(string.Format(CultureInfo.InvariantCulture, "Unknown State for IIS Application Pool: {0}", appPoolPath));
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            if (exception.Message.IndexOf("The system cannot find the path specified", StringComparison.OrdinalIgnoreCase) == -1)
                            {
                                output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
                            }
                        }
                    }
                }
            });

            return(output);
        }
Пример #25
0
        internal static OutputQueue ProcessSolutionsStatus(ref Collection <SocialSitesSolution> solutions, string literalPath, bool ignoreMissingSolutions = false)
        {
            var outputQueue = new OutputQueue();

            if (solutions == null)
            {
                solutions = new Collection <SocialSitesSolution>();
            }

            // Check for WSP files
            var filePaths = Directory.GetFiles(literalPath, "*.wsp");

            foreach (var filePath in filePaths)
            {
                var knownSolution = false;
                var solutionName  = Path.GetFileName(filePath);

                if (string.IsNullOrEmpty(solutionName))
                {
                    continue;
                }

                // Known Solution
                foreach (var solution in solutions.Where(solution => string.Equals(solutionName.Trim(), solution.SolutionName.Trim(), StringComparison.OrdinalIgnoreCase)))
                {
                    if (!solution.Ignore)
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.KnownSolutionFound, solution.SolutionName));
                    }
                    else
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.KnownSolutionFoundIgnoring, solution.SolutionName));
                    }

                    solution.IsWspAvailable = true;
                    knownSolution           = true;
                }

                // Unknown Solution
                if (!knownSolution)
                {
                    outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.UnknownSolutionFound, solutionName));
                    var solution = new SocialSitesSolution()
                    {
                        IsWspAvailable = true,
                        SolutionName   = solutionName,
                        SolutionSet    = SolutionSet.Unknown,
                        InstallOrder   = 99
                    };
                    var majorVersion = 0;
                    outputQueue.Add(Files.SolutionManifestVersion(solution, literalPath, out majorVersion));
                    if (majorVersion >= 14)
                    {
                        solution.MinimumVersion = majorVersion;
                    }
                    solutions.Add(solution);
                }
            }

            // Check if WSP files are installed
            var farm = LocalFarm.Get();

            if (solutions != null)
            {
                foreach (var solution in solutions)
                {
                    solution.IsInstalled = IsSolutionInstalled(solution);
                }
            }

            // Validate Required Solutions are Available
            if (!ignoreMissingSolutions)
            {
                var majorVersion         = farm.BuildVersion.Major;
                var missingCoreSolutions = solutions.Where(p => (p.SolutionSet == SolutionSet.SocialPlatform) && (!p.IsWspAvailable) && (p.MinimumVersion <= majorVersion) && (p.Required) && (!p.Ignore));
                if (missingCoreSolutions.Count() > 0)
                {
                    var missingSolutions = string.Empty;
                    foreach (var solution in missingCoreSolutions)
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.MissingSolution, solution.SolutionName), OutputType.Error);
                        missingSolutions += string.Format(CultureInfo.CurrentCulture, Exceptions.SolutionMissingFormat, solution.SolutionName);
                    }

                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Exceptions.RequiredSolutionsMissing, missingSolutions));
                }

                var missingInstalledSolutions = solutions.Where(p => (p.IsInstalled) && (!p.IsWspAvailable) && (!p.Ignore));
                if (missingInstalledSolutions.Count() > 0)
                {
                    var missingSolutions = string.Empty;
                    foreach (var solution in missingInstalledSolutions)
                    {
                        outputQueue.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.MissingSolution, solution.SolutionName), OutputType.Error);
                        missingSolutions += string.Format(CultureInfo.CurrentCulture, Exceptions.SolutionMissingFormat, solution.SolutionName);
                    }

                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Exceptions.InstalledSolutionsMissing, missingSolutions));
                }
            }

            return(outputQueue);
        }
Пример #26
0
        internal static void WaitForSolutionJob(string solutionName, int timeout)
        {
            LocalFarm.Get().TryUpdate();

            // Ensure solution exists
            if (LocalFarm.Get().Solutions[solutionName] == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, NewsGator.Install.Resources.Exceptions.SolutionNotAddedToFarm, solutionName));
            }

            var solution = LocalFarm.Get().Solutions[solutionName];
            var jobName  = GenerateJobName(solution.Name, solution.Id, 0);

            var time     = DateTime.Now.AddMilliseconds(timeout);
            var complete = false;

            while (!complete && DateTime.Now < time)
            {
                solution = LocalFarm.Get().Solutions[solutionName];

                var waitTimerService = LocalFarm.Get().Services.Where(p => p is SPTimerService).First() as SPTimerService;
                complete = !(waitTimerService.JobDefinitions.Any(p => p.Name.Equals(jobName, StringComparison.OrdinalIgnoreCase))) &&
                           !solution.JobExists;

                if (!complete)
                {
                    LocalFarm.Get().TryUpdate();
                    Thread.Sleep(10000);
                }
            }

            if (!complete)
            {
                var timerService = LocalFarm.Get().Services.Where(p => p is SPTimerService).First() as SPTimerService;
                var jobs         = timerService.JobDefinitions.Where(p => p.Name.Equals(jobName, StringComparison.OrdinalIgnoreCase));

                foreach (var job in jobs)
                {
                    job.Delete();
                }

                throw new TimeoutException(string.Format(CultureInfo.CurrentUICulture, NewsGator.Install.Resources.Exceptions.SolutionJobTimeout, solutionName));
            }

            //Func<bool> wait = () =>
            //    {
            //        var complete = false;
            //        while (!complete)
            //        {
            //            var waitTimerService = LocalFarm.Get().Services.Where(p => p is SPTimerService).First() as SPTimerService;
            //            complete = !(waitTimerService.JobDefinitions.Any(p => p.Name.Equals(jobName, StringComparison.OrdinalIgnoreCase)));

            //            if (!complete)
            //            {
            //                LocalFarm.Get().TryUpdate();
            //                Thread.Sleep(10000);
            //            }
            //        }

            //        return complete;
            //    };

            //var success = Threading.WaitFor<bool>.Run(TimeSpan.FromMilliseconds(timeout), wait);
            //if (!success)
            //{
            //    var timerService = LocalFarm.Get().Services.Where(p => p is SPTimerService).First() as SPTimerService;
            //    var jobs = timerService.JobDefinitions.Where(p => p.Name.Equals(jobName, StringComparison.OrdinalIgnoreCase));

            //    foreach (var job in jobs)
            //    {
            //        job.Delete();
            //    }

            //    throw new TimeoutException(string.Format(CultureInfo.CurrentUICulture, NewsGator.Install.Resources.Exceptions.SolutionJobTimeout, solutionName));
            //}
        }
Пример #27
0
        internal static OutputQueue ProcessSolutionSetsStatus(ref Collection <SolutionSet> sets, Collection <SocialSitesSolution> solutions)
        {
            var outputQueue = new OutputQueue();

            if (sets == null)
            {
                sets = new Collection <SolutionSet>();
            }

            var majorVersion = LocalFarm.Get().BuildVersion.Major;

            outputQueue.Add(UserDisplay.SolutionsSetsChecking);

            // Core
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetCore));
            var coreSolutions = solutions.WhereSolutionSet(SolutionSet.SocialPlatform, majorVersion);

            if (!coreSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetCore));
            }
            else if (!coreSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetCore));
                sets.Add(SolutionSet.SocialPlatform);
            }

            // Ideas
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetIdeas));
            var ideaSolutions = solutions.WhereSolutionSet(SolutionSet.IdeaStream, majorVersion);

            if (!ideaSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetIdeas));
            }
            else if (!ideaSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetIdeas));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetIdeas, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetIdeas));
                sets.Add(SolutionSet.IdeaStream);
            }

            // Spotlight

            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetSpotlight));
            var spotlightSolutions = solutions.WhereSolutionSet(SolutionSet.Spotlight, majorVersion);

            if (!spotlightSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetSpotlight));
            }
            else if (!spotlightSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetSpotlight));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetSpotlight, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetSpotlight));
                sets.Add(SolutionSet.Spotlight);
            }

            // InterComm
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetInterComm));
            var interCommSolutions = solutions.WhereSolutionSet(SolutionSet.InterComm, majorVersion);

            if (!interCommSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetInterComm));
            }
            else if (!interCommSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetInterComm));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetInterComm, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetInterComm));
                sets.Add(SolutionSet.InterComm);
            }

            // News
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetNews));
            var newsSolutions = solutions.WhereSolutionSet(SolutionSet.NewsStream, majorVersion);

            if (!newsSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetNews));
            }
            else if (!newsSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetNews));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetNews, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetNews));
                sets.Add(SolutionSet.NewsStream);
            }

            // Pivot Viewer
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetPivotViewer));
            var pivotSolutions = solutions.WhereSolutionSet(SolutionSet.PivotViewer, majorVersion);

            if (!pivotSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetPivotViewer));
            }
            else if (!pivotSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetPivotViewer));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetPivotViewer, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetPivotViewer));
                sets.Add(SolutionSet.PivotViewer);
            }

            // Scorecard
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetScorecard));
            var scorecardSolutions = solutions.WhereSolutionSet(SolutionSet.Scorecard, majorVersion);

            if (!scorecardSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetScorecard));
            }
            else if (!scorecardSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetScorecard));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetScorecard, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetScorecard));
                sets.Add(SolutionSet.Scorecard);
            }

            // CA Common
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetCanada));
            var canadaSolutions = solutions.WhereSolutionSet(SolutionSet.CanadaCommon, majorVersion);

            if (!canadaSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetCanada));
            }
            else if (!canadaSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetCanada));
            }
            else if (!sets.Contains(SolutionSet.SocialPlatform))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetCanada, UserDisplay.SolutionsSetCore));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetCanada));
                sets.Add(SolutionSet.CanadaCommon);
            }

            // Video
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetVideo));
            var videoSolutions = solutions.WhereSolutionSet(SolutionSet.VideoStream, majorVersion);

            if (!videoSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetVideo));
            }
            else if (!videoSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetVideo));
            }
            else if (!sets.Contains(SolutionSet.CanadaCommon))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetVideo, UserDisplay.SolutionsSetCanada));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetVideo));
                sets.Add(SolutionSet.VideoStream);
            }

            // Video ScreenCast
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetScreenCast));
            var videoScreenCastSolutions = solutions.WhereSolutionSet(SolutionSet.VideoScreenCast, majorVersion);

            if (!videoScreenCastSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetScreenCast));
            }
            else if (!videoScreenCastSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetScreenCast));
            }
            else if (!sets.Contains(SolutionSet.VideoStream))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetScreenCast, UserDisplay.SolutionsSetVideo));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetScreenCast));
                sets.Add(SolutionSet.VideoScreenCast);
            }

            // Enrich
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetLearning));
            var learningSolutions = solutions.WhereSolutionSet(SolutionSet.Enrich, majorVersion);

            if (!learningSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetLearning));
            }
            else if (!learningSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetLearning));
            }
            else if (!sets.Contains(SolutionSet.CanadaCommon))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetLearning, UserDisplay.SolutionsSetCanada));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetLearning));
                sets.Add(SolutionSet.Enrich);
            }

            // Enrich Video Scenarios
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetVideoLearning));
            var videoLearningSolutions = solutions.WhereSolutionSet(SolutionSet.EnrichVideoScenarios, majorVersion);

            if (!videoLearningSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetVideoLearning));
            }
            else if (!videoLearningSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetVideoLearning));
            }
            else if (!sets.Contains(SolutionSet.VideoStream))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetVideoLearning, UserDisplay.SolutionsSetVideo));
            }
            else if (!sets.Contains(SolutionSet.Enrich))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetVideoLearning, UserDisplay.SolutionsSetLearning));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetVideoLearning));
                sets.Add(SolutionSet.EnrichVideoScenarios);
            }

            // Innovation
            outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetChecking, UserDisplay.SolutionsSetInnovation));
            var innovationSolutions = solutions.WhereSolutionSet(SolutionSet.Innovation, majorVersion);

            if (!innovationSolutions.Any(p => p.IsWspAvailable))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetNotFound, UserDisplay.SolutionsSetInnovation));
            }
            else if (!innovationSolutions.IsSolutionSetComplete())
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetIncomplete, UserDisplay.SolutionsSetInnovation));
            }
            else if (!sets.Contains(SolutionSet.CanadaCommon))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetInnovation, UserDisplay.SolutionsSetCanada));
            }
            else if (!sets.Contains(SolutionSet.IdeaStream))
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFoundMissingPrerequisiteSet, UserDisplay.SolutionsSetInnovation, UserDisplay.SolutionsSetIdeas));
            }
            else
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentCulture, UserDisplay.SolutionsSetFound, UserDisplay.SolutionsSetInnovation));
                sets.Add(SolutionSet.Innovation);
            }
            outputQueue.Add(UserDisplay.SolutionsSetsCheckingComplete);

            return(outputQueue);
        }
 public ExecuteAdminServiceJobsTask(bool useTimerJob)
 {
     this.UseTimerJob = useTimerJob;
     this.Timeout     = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count() * 300000;
 }
 public ExecuteAdminServiceJobsTask()
 {
     // Timeout is 5 minutes multiplied by the number of servers in the farm
     this.Timeout = LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)).Count() * 300000;
 }
        private void Initialize()
        {
            var farm = LocalFarm.Get();

            if (farm != null)
            {
                this.Id      = farm.Id;
                this.Version = farm.BuildVersion.ToString();
                this.Name    = farm.DisplayName;
                this.Status  = farm.Status.ToString();

                this.ManagedAccounts = Utilities.ApplicationPools.GetManagedAccountsNames();

                try
                {
                    this.DefaultServiceAccount = farm.DefaultServiceAccount.LookupName();
                }
                catch
                {
                    this.DefaultServiceAccount = null;
                }

                this.Products = new Collection <Guid>();
                if ((farm.Products != null) && (farm.Products.Any()))
                {
                    this.Products.AddRange(farm.Products);
                }

                if ((farm.Servers != null) && (farm.Servers.Count > 0))
                {
                    this.Servers = new Collection <SharePointServer>();
                    foreach (var farmServer in farm.Servers)
                    {
                        var server = new SharePointServer();
                        server.Address = farmServer.Address;
                        server.Id      = farmServer.Id;
                        server.Name    = farmServer.DisplayName;
                        server.Role    = farmServer.Role.ToString();
                        server.Status  = farmServer.Status.ToString();

                        if ((farmServer.ServiceInstances != null) && (farmServer.ServiceInstances.Count > 0))
                        {
                            server.Services = new Collection <SharePointService>();
                            foreach (var serverService in farmServer.ServiceInstances)
                            {
                                var service = new SharePointService();
                                service.Id     = serverService.Id;
                                service.Name   = serverService.DisplayName;
                                service.Status = serverService.Status.ToString();
                                server.Services.Add(service);
                            }
                        }

                        this.Servers.Add(server);
                    }
                }

                if ((farm.Services != null) && (farm.Services.Count > 0))
                {
                    this.Services = new Collection <SharePointService>();
                    foreach (var farmService in farm.Services)
                    {
                        var service = new SharePointService();
                        service.Id     = farmService.Id;
                        service.Name   = farmService.DisplayName;
                        service.Status = farmService.Status.ToString();
                        this.Services.Add(service);
                    }
                }

                if ((farm.Properties != null) && (farm.Properties.Count > 0))
                {
                    this.Properties = Utilities.Conversions.GetSharePointPropertiesFromHashtable(farm.Properties);
                }

                if ((farm.Solutions != null) && (farm.Solutions.Count > 0))
                {
                    this.FarmSolutions = new Collection <SharePointSolution>();
                    foreach (var farmSolution in farm.Solutions)
                    {
                        var solution = new SharePointSolution();
                        solution.Deployed = farmSolution.Deployed;
                        solution.Id       = farmSolution.Id;
                        solution.Name     = farmSolution.DisplayName;

                        if ((farmSolution.ContainsWebApplicationResource) && (farmSolution.Deployed) && (farmSolution.DeployedWebApplications != null) && (farmSolution.DeployedWebApplications.Count > 0))
                        {
                            solution.WebApplications = new Collection <string>();
                            solution.WebApplications.AddRange(farmSolution.DeployedWebApplications.Select(p => Utilities.WebApplications.GetWebApplicationName(p)));
                        }

                        this.FarmSolutions.Add(solution);
                    }
                }

                if ((farm.FeatureDefinitions != null) && (farm.FeatureDefinitions.Count > 0))
                {
                    this.FeatureDefinitions = new Collection <SharePointFeature>();
                    foreach (var farmFeature in farm.FeatureDefinitions)
                    {
                        var feature = new SharePointFeature();
                        feature.Id    = farmFeature.Id;
                        feature.Name  = farmFeature.DisplayName;
                        feature.Scope = farmFeature.Scope.ToString();
                        this.FeatureDefinitions.Add(feature);
                    }
                }

                var adminService   = SPWebService.AdministrationService;
                var contentService = SPWebService.ContentService;

                if ((adminService.Features != null) && (adminService.Features.Count > 0))
                {
                    this.FarmFeatures = new Collection <SharePointFeature>();
                    foreach (var farmFeature in adminService.Features)
                    {
                        var feature = new SharePointFeature();
                        feature.Id    = farmFeature.DefinitionId;
                        feature.Name  = farmFeature.Definition.DisplayName;
                        feature.Scope = farmFeature.FeatureDefinitionScope.ToString();
                        this.FarmFeatures.Add(feature);
                    }
                }

                var webApplications     = new Collection <SharePointWebApplication>();
                var farmWebApplications = new Collection <SPWebApplication>();

                if ((adminService.WebApplications != null) && (adminService.WebApplications.Count > 0))
                {
                    farmWebApplications.AddRange(adminService.WebApplications);
                }
                if ((contentService.WebApplications != null) && (contentService.WebApplications.Count > 0))
                {
                    farmWebApplications.AddRange(contentService.WebApplications);
                }

                if (farmWebApplications.Count > 0)
                {
                    foreach (var farmWebApplication in farmWebApplications)
                    {
                        var webApp = new SharePointWebApplication();
                        webApp.Id     = farmWebApplication.Id;
                        webApp.Name   = farmWebApplication.DisplayName;
                        webApp.Status = farmWebApplication.Status.ToString();
                        if ((farmWebApplication.Properties != null) && (farmWebApplication.Properties.Count > 0))
                        {
                            webApp.Properties = Utilities.Conversions.GetSharePointPropertiesFromHashtable(farmWebApplication.Properties);
                        }
                        webApp.IsCentralAdministration = farmWebApplication.IsAdministrationWebApplication;

                        webApp.UrlZoneCustom   = Utilities.WebApplications.GetWebApplicationZoneUrl(farmWebApplication, SPUrlZone.Custom);
                        webApp.UrlZoneDefault  = Utilities.WebApplications.GetWebApplicationZoneUrl(farmWebApplication, SPUrlZone.Default);
                        webApp.UrlZoneExtranet = Utilities.WebApplications.GetWebApplicationZoneUrl(farmWebApplication, SPUrlZone.Extranet);
                        webApp.UrlZoneInternet = Utilities.WebApplications.GetWebApplicationZoneUrl(farmWebApplication, SPUrlZone.Internet);
                        webApp.UrlZoneIntranet = Utilities.WebApplications.GetWebApplicationZoneUrl(farmWebApplication, SPUrlZone.Intranet);

                        if ((farmWebApplication.Features != null) && (farmWebApplication.Features.Count > 0))
                        {
                            webApp.Features = new Collection <SharePointFeature>();
                            foreach (var farmFeature in farmWebApplication.Features)
                            {
                                var feature = new SharePointFeature();
                                feature.Id    = farmFeature.DefinitionId;
                                feature.Name  = farmFeature.Definition.DisplayName;
                                feature.Scope = farmFeature.FeatureDefinitionScope.ToString();
                                webApp.Features.Add(feature);
                            }
                        }

                        if ((farmWebApplication.Sites != null) && (farmWebApplication.Sites.Count > 0))
                        {
                            webApp.SiteCollections = new Collection <SharePointSiteCollection>();
                            foreach (SPSite webAppSite in farmWebApplication.Sites)
                            {
                                var site = new SharePointSiteCollection();
                                site.Id  = webAppSite.ID;
                                site.Url = webAppSite.Url;

                                if ((webAppSite.EventReceivers != null) && (webAppSite.EventReceivers.Count > 0))
                                {
                                    site.EventReceivers = new Collection <SharePointEventReceiver>();
                                    foreach (SPEventReceiverDefinition siteEventReceiver in webAppSite.EventReceivers)
                                    {
                                        var eventReceiver = new SharePointEventReceiver();
                                        eventReceiver.Assembly = siteEventReceiver.Assembly;
                                        eventReceiver.Class    = siteEventReceiver.Class;
                                        eventReceiver.Id       = siteEventReceiver.Id;
                                        eventReceiver.Name     = siteEventReceiver.Name;
                                        site.EventReceivers.Add(eventReceiver);
                                    }
                                }

                                if ((webAppSite.Features != null) && (webAppSite.Features.Count > 0))
                                {
                                    site.Features = new Collection <SharePointFeature>();
                                    foreach (var farmFeature in webAppSite.Features)
                                    {
                                        var feature = new SharePointFeature();
                                        feature.Id    = farmFeature.DefinitionId;
                                        feature.Name  = farmFeature.Definition.DisplayName;
                                        feature.Scope = farmFeature.FeatureDefinitionScope.ToString();
                                        site.Features.Add(feature);
                                    }
                                }

                                if ((webAppSite.AllWebs != null) && (webAppSite.AllWebs.Count > 0))
                                {
                                    site.Webs = new Collection <SharePointWeb>();
                                    foreach (SPWeb siteWeb in webAppSite.AllWebs)
                                    {
                                        try
                                        {
                                            var web = new SharePointWeb();
                                            web.Id = siteWeb.ID;
                                            web.CustomMasterPageUrl = siteWeb.CustomMasterUrl;
                                            web.Description         = siteWeb.Description;
                                            web.IsRootWeb           = siteWeb.IsRootWeb;
                                            web.LogoUrl             = siteWeb.SiteLogoUrl;
                                            web.MasterPageUrl       = siteWeb.MasterUrl;
                                            if (!siteWeb.IsRootWeb)
                                            {
                                                web.ParentWebId = siteWeb.ParentWebId;
                                            }
                                            if ((siteWeb.AllProperties != null) && (siteWeb.AllProperties.Count > 0))
                                            {
                                                web.Properties = Utilities.Conversions.GetSharePointPropertiesFromHashtable(siteWeb.AllProperties);
                                            }
                                            web.Title       = siteWeb.Title;
                                            web.UIVersion   = siteWeb.UIVersion;
                                            web.Url         = siteWeb.Url;
                                            web.WebTemplate = siteWeb.WebTemplate;

                                            if ((siteWeb.EventReceivers != null) && (siteWeb.EventReceivers.Count > 0))
                                            {
                                                web.EventReceivers = new Collection <SharePointEventReceiver>();
                                                foreach (SPEventReceiverDefinition webEventReceiver in siteWeb.EventReceivers)
                                                {
                                                    var eventReceiver = new SharePointEventReceiver();
                                                    eventReceiver.Assembly = webEventReceiver.Assembly;
                                                    eventReceiver.Class    = webEventReceiver.Class;
                                                    eventReceiver.Id       = webEventReceiver.Id;
                                                    eventReceiver.Name     = webEventReceiver.Name;
                                                    web.EventReceivers.Add(eventReceiver);
                                                }
                                            }

                                            if ((siteWeb.Features != null) && (siteWeb.Features.Count > 0))
                                            {
                                                web.Features = new Collection <SharePointFeature>();
                                                foreach (var farmFeature in siteWeb.Features)
                                                {
                                                    var feature = new SharePointFeature();
                                                    feature.Id    = farmFeature.DefinitionId;
                                                    feature.Name  = farmFeature.Definition.DisplayName;
                                                    feature.Scope = farmFeature.FeatureDefinitionScope.ToString();
                                                    web.Features.Add(feature);
                                                }
                                            }

                                            if ((siteWeb.Lists != null) && (siteWeb.Lists.Count > 0))
                                            {
                                                web.Lists = new Collection <SharePointList>();
                                                foreach (SPList webList in siteWeb.Lists)
                                                {
                                                    try
                                                    {
                                                        var list = new SharePointList();
                                                        list.Description = webList.Description;
                                                        list.Id          = webList.ID;
                                                        list.ItemCount   = webList.ItemCount;
                                                        list.Title       = webList.Title;
                                                        list.Url         = webList.DefaultViewUrl;

                                                        if ((webList.EventReceivers != null) && (webList.EventReceivers.Count > 0))
                                                        {
                                                            list.EventReceivers = new Collection <SharePointEventReceiver>();
                                                            foreach (SPEventReceiverDefinition listEventReceiver in webList.EventReceivers)
                                                            {
                                                                var eventReceiver = new SharePointEventReceiver();
                                                                eventReceiver.Assembly = listEventReceiver.Assembly;
                                                                eventReceiver.Class    = listEventReceiver.Class;
                                                                eventReceiver.Id       = listEventReceiver.Id;
                                                                eventReceiver.Name     = listEventReceiver.Name;
                                                                list.EventReceivers.Add(eventReceiver);
                                                            }
                                                        }

                                                        web.Lists.Add(list);
                                                    }
                                                    catch { } // Don't Care
                                                }
                                            }

                                            siteWeb.Dispose();
                                            site.Webs.Add(web);
                                        }
                                        catch
                                        { } // Don't Care
                                    }

                                    if (webAppSite.ContentDatabase != null)
                                    {
                                        site.Database = new SharePointDatabase()
                                        {
                                            Id       = webAppSite.ContentDatabase.Id,
                                            Name     = webAppSite.ContentDatabase.DisplayName,
                                            Server   = webAppSite.ContentDatabase.Server,
                                            Username = webAppSite.ContentDatabase.Username
                                        };
                                    }
                                }

                                webAppSite.Dispose();
                                webApp.SiteCollections.Add(site);
                            }
                        }

                        if ((farmWebApplication.ContentDatabases != null) && (farmWebApplication.ContentDatabases.Count > 0))
                        {
                            webApp.Databases = new Collection <SharePointDatabase>();
                            foreach (var webAppDatabase in farmWebApplication.ContentDatabases)
                            {
                                webApp.Databases.Add(new SharePointDatabase()
                                {
                                    Id       = webAppDatabase.Id,
                                    Name     = webAppDatabase.DisplayName,
                                    Server   = webAppDatabase.Server,
                                    Username = webAppDatabase.Username
                                });
                            }
                        }

                        webApplications.Add(webApp);
                    }
                }
                this.WebApplications = webApplications;

                this.ApplicationPools = new Collection <SharePointApplicationPool>();
                if ((adminService.ApplicationPools != null) && (adminService.ApplicationPools.Count > 0))
                {
                    foreach (var farmApplicationPool in adminService.ApplicationPools)
                    {
                        var appPool = new SharePointApplicationPool();
                        appPool.Id             = farmApplicationPool.Id;
                        appPool.ManagedAccount = farmApplicationPool.ManagedAccount == null ? null : farmApplicationPool.ManagedAccount.DisplayName;
                        appPool.Name           = farmApplicationPool.DisplayName;
                        appPool.ProcessAccount = farmApplicationPool.ProcessAccount == null ? null : farmApplicationPool.ProcessAccount.ToString();
                        appPool.TypeName       = farmApplicationPool.TypeName;
                        appPool.Username       = farmApplicationPool.Username;
                        this.ApplicationPools.Add(appPool);
                    }
                }
                if ((contentService.ApplicationPools != null) && (contentService.ApplicationPools.Count > 0))
                {
                    foreach (var farmApplicationPool in contentService.ApplicationPools)
                    {
                        var appPool = new SharePointApplicationPool();
                        appPool.Id             = farmApplicationPool.Id;
                        appPool.ManagedAccount = farmApplicationPool.ManagedAccount == null ? null : farmApplicationPool.ManagedAccount.DisplayName;
                        appPool.Name           = farmApplicationPool.DisplayName;
                        appPool.ProcessAccount = farmApplicationPool.ProcessAccount == null ? null : farmApplicationPool.ProcessAccount.ToString();
                        appPool.TypeName       = farmApplicationPool.TypeName;
                        appPool.Username       = farmApplicationPool.Username;
                        this.ApplicationPools.Add(appPool);
                    }
                }

                this.ServiceApplications = new Collection <SharePointServiceApplication>();
                foreach (var service in farm.Services)
                {
                    foreach (var farmServiceApp in service.Applications)
                    {
                        var farmServiceApplication = farmServiceApp as SPIisWebServiceApplication;
                        if (farmServiceApplication != null)
                        {
                            var serviceApp = new SharePointServiceApplication();
                            serviceApp.Id               = farmServiceApplication.Id;
                            serviceApp.Name             = farmServiceApplication.DisplayName;
                            serviceApp.Status           = farmServiceApplication.Status.ToString();
                            serviceApp.Version          = farmServiceApplication.ApplicationVersion;
                            serviceApp.AccessRules      = new Collection <SharePointAccessRule>();
                            serviceApp.AdminAccessRules = new Collection <SharePointAccessRule>();

                            foreach (var accessRule in farmServiceApplication.GetAdministrationAccessControl().GetAccessRules())
                            {
                                serviceApp.AdminAccessRules.Add(new SharePointAccessRule()
                                {
                                    AllowedObjectRights = accessRule.AllowedObjectRights.ToString(),
                                    AllowedRights       = accessRule.AllowedRights.ToString(),
                                    Description         = accessRule.Description,
                                    Name = accessRule.Name
                                });
                            }

                            foreach (var accessRule in farmServiceApplication.GetAccessControl().GetAccessRules())
                            {
                                serviceApp.AccessRules.Add(new SharePointAccessRule()
                                {
                                    AllowedObjectRights = accessRule.AllowedObjectRights.ToString(),
                                    AllowedRights       = accessRule.AllowedRights.ToString(),
                                    Description         = accessRule.Description,
                                    Name = accessRule.Name
                                });
                            }

                            this.ServiceApplications.Add(serviceApp);
                        }
                    }
                }

                this.MySiteHostUrls = Utilities.MySite.FindMySiteUrls();

                if (adminService != null)
                {
                    var centralAdminWebApp = adminService.WebApplications.Where(p => p.IsAdministrationWebApplication).FirstOrDefault();
                    if (centralAdminWebApp != null)
                    {
                        var centralAdminWebAppUrl = Utilities.WebApplications.GetWebApplicationZoneUrl(centralAdminWebApp);
                        if (centralAdminWebAppUrl != null)
                        {
                            using (var centralAdminSite = new SPSite(centralAdminWebAppUrl))
                            {
                                if (centralAdminSite != null)
                                {
                                    var centralAdminWeb = centralAdminSite.RootWeb;
                                    if (centralAdminWeb != null)
                                    {
                                        this.CentralAdministrationUsers = new Collection <SharePointUser>();
                                        foreach (SPUser farmUser in centralAdminWeb.AllUsers)
                                        {
                                            var user = new SharePointUser()
                                            {
                                                Username    = farmUser.LoginName,
                                                Permissions = new Collection <string>()
                                            };

                                            var effectivePermissions = centralAdminWeb.GetUserEffectivePermissions(farmUser.LoginName);

                                            foreach (SPBasePermissions permission in Enum.GetValues(typeof(SPBasePermissions)))
                                            {
                                                if ((effectivePermissions & permission) != 0)
                                                {
                                                    user.Permissions.Add(permission.ToString());
                                                }
                                            }

                                            this.CentralAdministrationUsers.Add(user);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }