private void DumpResourceIpAddress(AmClusterResource resource, string typeName)
        {
            this.m_indentlevel += 1U;
            this.WriteLine("Address = [{0}]", new object[]
            {
                resource.GetPrivateProperty <string>("Address")
            });
            if (SharedHelper.StringIEquals(typeName, "IP Address"))
            {
                this.m_indentlevel += 1U;
                this.WriteLine("EnableDhcp = [{0}]", new object[]
                {
                    resource.GetPrivateProperty <int>("EnableDhcp")
                });
                this.m_indentlevel -= 1U;
            }
            string networkNameFromIpResource = AmClusterResourceHelper.GetNetworkNameFromIpResource(null, resource);

            this.m_indentlevel += 1U;
            this.WriteLine("Network = [{0}]", new object[]
            {
                networkNameFromIpResource
            });
            this.m_indentlevel -= 1U;
            this.m_indentlevel -= 1U;
        }
        private void DumpResourceNetName(AmClusterResource resource)
        {
            this.m_indentlevel += 1U;
            this.WriteLine("NetName = [{0}]", new object[]
            {
                resource.GetPrivateProperty <string>("Name")
            });
            int privateProperty = resource.GetPrivateProperty <int>("RequireKerberos");

            if (privateProperty != 0)
            {
                this.m_indentlevel += 1U;
                this.WriteLine("RequireKerberos = 1. Computer account created on DC '{0}'.", new object[]
                {
                    resource.GetPrivateProperty <string>("CreatingDC")
                });
                this.m_indentlevel -= 1U;
            }
            this.m_indentlevel -= 1U;
        }
        protected override void WriteResult(IConfigurable dataObject)
        {
            TaskLogger.LogEnter(new object[]
            {
                dataObject.Identity,
                dataObject
            });
            DatabaseAvailabilityGroup databaseAvailabilityGroup = (DatabaseAvailabilityGroup)dataObject;

            if (this.Status && !databaseAvailabilityGroup.IsDagEmpty())
            {
                List <ADObjectId> list      = new List <ADObjectId>(8);
                List <ADObjectId> list2     = new List <ADObjectId>(8);
                AmCluster         amCluster = null;
                try
                {
                    amCluster = AmCluster.OpenDagClus(databaseAvailabilityGroup);
                }
                catch (ClusterException exception)
                {
                    base.WriteError(exception, ErrorCategory.InvalidArgument, null);
                }
                if (amCluster != null)
                {
                    using (amCluster)
                    {
                        foreach (IAmClusterNode amClusterNode in amCluster.EnumerateNodes())
                        {
                            using (amClusterNode)
                            {
                                AmNodeState state = amClusterNode.GetState(false);
                                if (AmClusterNode.IsNodeUp(state))
                                {
                                    ADObjectId adobjectId = DagTaskHelper.FindServerAdObjectIdInDag(databaseAvailabilityGroup, amClusterNode.Name);
                                    if (adobjectId != null)
                                    {
                                        list.Add(adobjectId);
                                        if (state == AmNodeState.Paused)
                                        {
                                            list2.Add(adobjectId);
                                        }
                                    }
                                    else
                                    {
                                        this.WriteWarning(Strings.WarningClusterNodeNotFoundInDag(amClusterNode.Name.Fqdn, databaseAvailabilityGroup.Name));
                                    }
                                }
                            }
                        }
                        databaseAvailabilityGroup.OperationalServers   = list.ToArray();
                        databaseAvailabilityGroup.ServersInMaintenance = list2.ToArray();
                        DagNetworkConfiguration dagNetworkConfig = DagNetworkRpc.GetDagNetworkConfig(databaseAvailabilityGroup);
                        databaseAvailabilityGroup.ReplicationPort = dagNetworkConfig.ReplicationPort;
                        foreach (DatabaseAvailabilityGroupNetwork databaseAvailabilityGroupNetwork in dagNetworkConfig.Networks)
                        {
                            databaseAvailabilityGroup.NetworkNames.Add(databaseAvailabilityGroupNetwork.Name);
                        }
                        if (DagHelper.IsQuorumTypeFileShareWitness(amCluster))
                        {
                            IAmClusterGroup amClusterGroup = amCluster.FindCoreClusterGroup();
                            if (amClusterGroup == null)
                            {
                                databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration);
                                this.WriteWarning(Strings.WarningClusterGroupNotFormed(databaseAvailabilityGroup.Name));
                                goto IL_306;
                            }
                            using (amClusterGroup)
                            {
                                IEnumerable <AmClusterResource> enumerable = null;
                                try
                                {
                                    enumerable = amClusterGroup.EnumerateResourcesOfType("File Share Witness");
                                    AmClusterResource amClusterResource = enumerable.ElementAtOrDefault(0);
                                    if (amClusterResource == null)
                                    {
                                        databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration);
                                        this.WriteWarning(Strings.WarningFswNotFound(databaseAvailabilityGroup.Name));
                                    }
                                    else if (amClusterResource.GetState() == AmResourceState.Failed)
                                    {
                                        databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration);
                                        this.WriteWarning(Strings.WarningFswFailed(databaseAvailabilityGroup.Name));
                                    }
                                    else
                                    {
                                        string           privateProperty = amClusterResource.GetPrivateProperty <string>("SharePath");
                                        UncFileSharePath a;
                                        if (UncFileSharePath.TryParse(privateProperty, out a))
                                        {
                                            if (a == databaseAvailabilityGroup.FileShareWitness)
                                            {
                                                databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.Primary);
                                            }
                                            else if (a == databaseAvailabilityGroup.AlternateFileShareWitness)
                                            {
                                                databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.Alternate);
                                            }
                                            else
                                            {
                                                databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration);
                                                this.WriteWarning(Strings.WarningFswNotPrimaryOrAlternate(databaseAvailabilityGroup.Name));
                                            }
                                        }
                                        else
                                        {
                                            databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.InvalidConfiguration);
                                            this.WriteWarning(Strings.WarningFswNotValidPath(databaseAvailabilityGroup.Name, privateProperty));
                                        }
                                    }
                                }
                                finally
                                {
                                    if (enumerable != null)
                                    {
                                        foreach (AmClusterResource amClusterResource2 in enumerable)
                                        {
                                            using (amClusterResource2)
                                            {
                                            }
                                        }
                                    }
                                }
                                goto IL_306;
                            }
                        }
                        databaseAvailabilityGroup.WitnessShareInUse = new WitnessShareUsage?(WitnessShareUsage.None);
                        IL_306:;
                    }
                    this.UpdatePam(databaseAvailabilityGroup);
                    try
                    {
                        DeferredFailoverEntry[] serversInDeferredRecovery = DagTaskHelper.GetServersInDeferredRecovery(databaseAvailabilityGroup);
                        databaseAvailabilityGroup.ServersInDeferredRecovery = serversInDeferredRecovery;
                    }
                    catch (AmServerException ex)
                    {
                        this.WriteWarning(Strings.PAMOtherError(ex.Message));
                    }
                }
            }
            base.WriteResult(databaseAvailabilityGroup);
            TaskLogger.LogExit();
        }
        private void UpdateFileShareWitness()
        {
            if (this.m_allServers.Count == 0)
            {
                this.m_output.WriteErrorSimple(new DagTaskNoServersAreStartedException(this.m_dag.Name));
            }
            IEnumerable <AmServerName> amServerNamesFromServers = RestoreDatabaseAvailabilityGroup.GetAmServerNamesFromServers(this.m_allServers.Values);

            using (AmCluster amCluster = AmCluster.OpenByNames(amServerNamesFromServers))
            {
                bool   flag            = DagTaskHelper.IsQuorumTypeFileShareWitness(this.m_output, amCluster);
                bool   flag2           = DagTaskHelper.ShouldBeFileShareWitness(this.m_output, this.m_dag, amCluster, false);
                string fswShareCurrent = string.Empty;
                if (flag)
                {
                    using (AmClusterResource amClusterResource = amCluster.OpenQuorumResource())
                    {
                        if (amClusterResource != null)
                        {
                            fswShareCurrent = amClusterResource.GetPrivateProperty <string>("SharePath");
                        }
                    }
                }
                if (flag2)
                {
                    if (this.m_fsw != null)
                    {
                        try
                        {
                            this.m_output.AppendLogMessage("Creating/modififying the primary FSW, if needed.", new object[0]);
                            this.m_fsw.Create();
                            if (this.m_dag.Servers.Count == 0 && this.m_fsw.IsJustCreated)
                            {
                                this.m_fsw.Delete();
                            }
                        }
                        catch (LocalizedException ex)
                        {
                            if (this.m_fsw.GetExceptionType(ex) != FileShareWitnessExceptionType.FswDeleteError)
                            {
                                this.m_output.WriteWarning(ex.LocalizedString);
                            }
                        }
                    }
                    if (this.m_afsw != null && !this.m_afsw.Equals(this.m_fsw))
                    {
                        try
                        {
                            this.m_output.AppendLogMessage("Creating/modififying the alternate FSW, if needed.", new object[0]);
                            this.m_afsw.Create();
                            if (this.m_dag.Servers.Count == 0 && this.m_afsw.IsJustCreated)
                            {
                                this.m_afsw.Delete();
                            }
                        }
                        catch (LocalizedException ex2)
                        {
                            if (this.m_afsw.GetExceptionType(ex2) != FileShareWitnessExceptionType.FswDeleteError)
                            {
                                this.m_output.WriteWarning(ex2.LocalizedString);
                            }
                        }
                    }
                    bool useAlternateWitnessServer = this.m_useAlternateWitnessServer;
                    if (!this.m_skipDagValidation || (flag2 && !flag))
                    {
                        DagTaskHelper.ChangeQuorumToMnsOrFswAsAppropriate(this.m_output, this, this.m_dag, amCluster, this.m_fsw, this.m_afsw, flag2, this.m_useAlternateWitnessServer);
                    }
                }
                else if (!this.m_skipDagValidation && flag)
                {
                    DagTaskHelper.RevertToMnsQuorum(this.m_output, amCluster, fswShareCurrent);
                }
            }
        }