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
展开阅读全文

没有更多推荐了,返回首页