The automation of COM+ configuration via COMAdmin (COM)

Initialization:
COMAdminCatalog.Connect("127.0.0.1");
 
Get Collections (COMAdminCatalogCollection):
For the 1st level (e.g. Applications):
applicationCollection  = COMAdminCatalog.GetCollection(“Applications”);
 
For other levels (e.g. Components, Roles, Users)
roleCollection = applicationCollection.GetCollection("Roles", theApplication.Key);
userCollection = roleCollection.GetCollection("UsersInRole", theRole.Key);
ShutDown/Start Application:
COMAdminCatalog.ShutdownApplication(appName)
COMAdminCatalog.StartApplication(appName)
 
Delete Application:
COMAdminCatalogCollection pCollection = GetCollection("Applications");
pCollection.Populate();
for (int i = 0; i < pCollection.Populate(); i++)
{
            pCatalog = (ICatalogObject)pCollection.get_Item(i);
             if (appName == (string)pCatalog.get_Value("Name"))
             {
                  pCollection.Remove(i);
                  pCollection.SaveChanges();
                  return;
}
}
 
Create Application
 
// Create the Application
COMAdminCatalogCollection applicationCollection = GetCollection("Applications");
COMAdminCatalogObject newApplication = (COMAdminCatalogObject)collection.Add();
// Set attributes
newApplication.set_Value(“AttributeName”, “AttributeValue”);
applicationCollection.SaveChanges();
 
Note: 1) the Attribute Name for Applications could be found in Applications (COM+) (http://msdn.microsoft.com/library/en-us/cossdk/html/c0c46592-5282-412d-8f54-67637be8218a.asp)
2) All the attribute value must be number. For bool type attribute, use 1 for true and 0 for false
For Enum type attribue, use the number instead of enum elements.
 
Create Role
 
COMAdminCatalogCollection roles = (COMAdminCatalogCollection) newApplication.GetCollection("Roles", newApplication.Key);
roles.Populate();
COMAdminCatalogObject newRole = (COMAdminCatalogObject)roles.Add();
newRole.set_Value("Name", "CreatorOwner");
roles.SaveChanges();
 
Create User
COMAdminCatalogCollection users = (COMAdminCatalogCollection)roles.GetCollection("UsersInRole", newRole.Key);
users.Populate();
COMAdminCatalogObject newUser = (COMAdminCatalogObject)users.Add();
string currentUser = string.Format("{0}//{1}", System.Environment.UserDomainName, System.Environment.UserName);
newUser.set_Value("User", currentUser);
users.SaveChanges();
 
Install DLL
 
COMAdminCatalogObject.InstallComponent(appName, dllName, string.Empty, string.Empty);
COMAdminCatalogCollection pComCollection = (COMAdminCatalogCollection)collection.GetCollection("Components", application.Key);
ICatalogObject pCom;
pComCollection.Populate();
int l_Count = pComCollection.Count;
 
for (int i = 0; i < l_Count; i++)
{
    pCom = (ICatalogObject)pComCollection.get_Item(i);
    if (dllName == (string)pCom.get_Value("DLL"))
    {
          pCom.set_Value(“AttributeName”, “AttributeValue”);
    }
}
pComCollection.SaveChanges();
 
Note: 1) the Attribute Name for Components could be found in COM+ Administration Collections/ Components (http://msdn.microsoft.com/library/en-us/cossdk/html/f502ba60-b2b1-4556-8f91-22a474e60e0d.asp)
2) Why the dlls can not be installed by Collection.Add(). The reason is the Collection. AddEnabled for Components is false…I don’t know the root cause neither:P. But the fact is I have to use COMAdminCatalogObject.InstallComponent() to install dlls
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值