/// <summary>
        /// GetLocalNodeInformations method implementation
        /// </summary>
        private ADFSNodeInformation GetLocalNodeInformations(RegistryVersion reg, string servername)
        {
            if (reg.IsWindows2012R2)
            {
                return(new ADFSNodeInformation()
                {
                    BehaviorLevel = 1,
                    HeartbeatTmeStamp = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0, DateTimeKind.Local)
                });
            }
            else
            {
                Runspace   SPRunSpace   = null;
                PowerShell SPPowerShell = null;
                try
                {
                    SPRunSpace            = RunspaceFactory.CreateRunspace();
                    SPPowerShell          = PowerShell.Create();
                    SPPowerShell.Runspace = SPRunSpace;
                    SPRunSpace.Open();

                    Pipeline pipeline  = SPRunSpace.CreatePipeline();
                    Command  exportcmd = new Command("(Get-AdfsFarmInformation).FarmNodes", true);

                    pipeline.Commands.Add(exportcmd);

                    Collection <PSObject> PSOutput = pipeline.Invoke();
                    foreach (var result in PSOutput)
                    {
                        string fqdn = result.Members["FQDN"].Value.ToString();
                        if (servername.ToLower().Equals(fqdn.ToLower()))
                        {
                            ADFSNodeInformation props = new ADFSNodeInformation
                            {
                                BehaviorLevel     = Convert.ToInt32(result.Members["BehaviorLevel"].Value),
                                HeartbeatTmeStamp = Convert.ToDateTime(result.Members["HeartbeatTimeStamp"].Value),
                            };
                            return(props);
                        }
                    }
                    return(new ADFSNodeInformation());
                }
                finally
                {
                    if (SPRunSpace != null)
                    {
                        SPRunSpace.Close();
                    }
                    if (SPPowerShell != null)
                    {
                        SPPowerShell.Dispose();
                    }
                }
            }
        }
        /// <summary>
        /// GetAllComputerInformations method implementation
        /// </summary>
        internal Dictionary <string, ADFSServerHost> GetAllComputerInformations(Dictionary <string, bool> servers)
        {
            string        fqdn        = Dns.GetHostEntry("localhost").HostName.ToLower();
            List <string> servernames = (from server in servers
                                         where (server.Key.ToLower() != fqdn.ToLower())
                                         select server.Key.ToLower()).ToList <string>();

            Dictionary <string, ADFSServerHost> dict = new Dictionary <string, ADFSServerHost>();
            RegistryVersion     reg      = new RegistryVersion();
            string              nodetype = GetLocalNodeType();
            ADFSNodeInformation node     = GetLocalNodeInformations(reg, fqdn);

            node.NodeType = nodetype;

            dict.Add(fqdn, new ADFSServerHost()
            {
                FQDN                      = fqdn,
                BehaviorLevel             = node.BehaviorLevel,
                HeartbeatTmeStamp         = node.HeartbeatTmeStamp,
                NodeType                  = node.NodeType,
                CurrentVersion            = reg.CurrentVersion,
                CurrentBuild              = reg.CurrentBuild,
                InstallationType          = reg.InstallationType,
                ProductName               = reg.ProductName,
                CurrentMajorVersionNumber = reg.CurrentMajorVersionNumber,
                CurrentMinorVersionNumber = reg.CurrentMinorVersionNumber
            });
            foreach (string srv in servernames)
            {
                WebAdminClient manager = new WebAdminClient();
                manager.Initialize(srv);
                try
                {
                    IWebAdminServices client = manager.Open();
                    try
                    {
                        dict.Add(srv, client.GetComputerInformations(srv, false));
                    }
                    catch (EndpointNotFoundException nf)
                    {
                        _log.WriteEntry(nf.Message, EventLogEntryType.Error, 2010);
                        continue;
                    }
                    finally
                    {
                        manager.Close(client);
                    }
                }
                finally
                {
                    manager.UnInitialize();
                }
            }
            return(dict);
        }
        /// <summary>
        /// GetComputerInformations method implementation
        /// </summary>
        internal ADFSNodeInformation GetNodeInformations(RegistryVersion reg, string servername, bool dispatch = true)
        {
            string fqdn = Dns.GetHostEntry("localhost").HostName.ToLower();

            if (fqdn.ToLower().Equals(servername.ToLower()))
            {
                string nodetype          = GetLocalNodeType();
                ADFSNodeInformation node = GetLocalNodeInformations(reg, servername);
                node.NodeType = nodetype;
                return(node);
            }
            else
            {
                if (dispatch)
                {
                    WebAdminClient manager = new WebAdminClient();
                    manager.Initialize(servername);
                    try
                    {
                        IWebAdminServices client = manager.Open();
                        try
                        {
                            string nodetype          = client.GetNodeType(servername, false);
                            ADFSNodeInformation node = node = GetLocalNodeInformations(reg, servername);
                            node.NodeType = nodetype;
                            return(node);
                        }
                        finally
                        {
                            manager.Close(client);
                        }
                    }
                    catch (Exception e)
                    {
                        _log.WriteEntry(string.Format("Error on WebAdminService Service GetNodeInformations method : {0} / {1}.", servername, e.Message), EventLogEntryType.Error, 2010);
                        throw e;
                    }
                    finally
                    {
                        manager.UnInitialize();
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
        }
        /// <summary>
        /// GetComputerInformations method implementation
        /// </summary>
        internal ADFSServerHost GetComputerInformations(string servername, bool dispatch = true)
        {
            string fqdn = Dns.GetHostEntry("localhost").HostName.ToLower();

            if (fqdn.ToLower().Equals(servername.ToLower()))
            {
                RegistryVersion     reg      = new RegistryVersion();
                string              nodetype = GetLocalNodeType();
                ADFSNodeInformation node     = GetLocalNodeInformations(reg, fqdn);
                node.NodeType = nodetype;
                return(new ADFSServerHost()
                {
                    FQDN = fqdn,
                    BehaviorLevel = node.BehaviorLevel,
                    HeartbeatTmeStamp = node.HeartbeatTmeStamp,
                    NodeType = node.NodeType,
                    CurrentVersion = reg.CurrentVersion,
                    CurrentBuild = reg.CurrentBuild,
                    InstallationType = reg.InstallationType,
                    ProductName = reg.ProductName,
                    CurrentMajorVersionNumber = reg.CurrentMajorVersionNumber,
                    CurrentMinorVersionNumber = reg.CurrentMinorVersionNumber
                });
            }
            else
            {
                if (dispatch)
                {
                    WebAdminClient manager = new WebAdminClient();
                    manager.Initialize(servername);
                    try
                    {
                        IWebAdminServices client = manager.Open();
                        try
                        {
                            return(client.GetComputerInformations(servername, false));
                        }
                        catch (CommunicationException nf)
                        {
                            _log.WriteEntry(nf.Message, EventLogEntryType.Error, 2010);
                            return(null);
                        }
                        finally
                        {
                            manager.Close(client);
                        }
                    }
                    catch (Exception e)
                    {
                        _log.WriteEntry(string.Format("Error on WebAdminService Service GetComputerInformations method : {0} / {1}.", servername, e.Message), EventLogEntryType.Error, 2010);
                        throw e;
                    }
                    finally
                    {
                        manager.UnInitialize();
                    }
                }
                else
                {
                    throw new Exception();
                }
            }
        }