Quantcast
Channel: わんくま同盟
Viewing all articles
Browse latest Browse all 994

ドメインのグループ用のクラス(C#)

$
0
0

ドメインのグループを表す DomainGroup クラスのC#のコードです。

 

[DataObject()]

public sealed classDomainGroup : DomainObject, IGroup

  #regionプライベートフィールド

  private readonly bool _security;

  private readonly string _scope, _type;

  private readonly DomainGroupScopeType _scopeType;

  #endregion

 

  #regionインターナルコンストラクタ

  //DirectoryEntry を指定して DomainGroup クラスの新しいインスタンスを初期化します。

  internal DomainGroup(DirectoryEntry entry)

    : base(entry)

  {

    var gtype = Convert.ToInt32(entry.Properties["groupType"].Value);

    if (gtype < 0)

    {

      _security = true;

      _type = "セキュリティ";

    }

    else

    {

      gtype += Int32.MinValue;

      _type = "配布";

    }

    _scopeType = (DomainGroupScopeType)Enum.ToObject(typeof(DomainGroupScopeType), gtype);

    _scope = GetGroupScope();  //グループのスコープを取得

  }

  #endregion

 

  #regionパブリックプロパティ

  //Entry の ADSI Group オブジェクトを取得します。

  public IADsGroup Native

  {

    get

    {

      if (base.IsDisposed)

      {

        throw newObjectDisposedException(this.GetType().Name);

      }

      return (IADsGroup)base.Entry.NativeObject;

    }

  }

 

  //グループのスコープを取得します。

  public string Scope

  {

    get

    {

      return _scope;

    }

  }

 

  //グループのスコープタイプを取得します。

  public DomainGroupScopeType ScopeType

  {

    get

    {

      return _scopeType;

    }

  }

 

  //セキュリティ グループかどうかを取得します。

  public bool SecurityEnabled

  {

    get

    {

      return _security;

    }

  }

 

  //グループの種類を取得します。

  public string Type

  {

    get

    {

      return _type;

    }

  }

  #endregion

 

  #regionパブリックメソッド

  //指定した名前のグループを検索します。このメソッドはデータバインド用です。

  [DataObjectMethod(DataObjectMethodType.Select)]

  public staticDomainGroup FindByName(string name)

  {

    return (DomainGroup)DirectoryAccess.FindDirectoryObject(name, CategoryType.Group);

  }

 

  //グループの一覧を取得します。このメソッドはデータバインド用です。

  [DataObjectMethod(DataObjectMethodType.Select)]

  public staticIList<DomainGroup> GetGroups()

  {

    returnDirectoryAccess.GetGroups<DomainGroup>();    //グループを取得

  }

  #endregion

 

  #regionプライベートメソッド

  //グループのスコープを取得します。

  private string GetGroupScope()

  {

    switch (this.ScopeType)

    {

      caseDomainGroupScopeType.BuiltInLocal:

        return"ビルトイン ローカル";

      caseDomainGroupScopeType.DomainLocal:

        return"ドメイン ローカル";

      caseDomainGroupScopeType.Global:

        return"グローバル";

      default:

        return"ユニバーサル";

    }

  }

  #endregion

}

 

少しですが説明はVBのコードの方に書いてます。

データバインド用のメソッドから呼び出している DirectoryAccess クラスのメソッドの実装は

FindDirectoryObject メソッド

GetGroups メソッド

を参照してください。


Viewing all articles
Browse latest Browse all 994

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>