COM+ Yönetim Kataloğunu Kullanma Tanıtım Örneği

COM+ Yönetim kataloğunu program aracılığıyla kullanırken, genellikle aşağıdaki genel adımları gerçekleştirirsiniz (burada kesin bir sırada verilmez):

  • Yerel makinede COM+ kataloğuyla bir oturum açın. İsteğe bağlı olarak, uzak bir makinede COM+ kataloğuna bağlanın.
  • Belirli bir COM+ uygulamasıyla ilgili olmayan hizmetleri başlatma veya durdurma gibi eylemler gerçekleştirin.
  • COM+ uygulamalarını yükleme veya dışarı aktarma ya da uygulamalara bileşen yükleme gibi eylemler gerçekleştirin; bu eylemler dosyalardan okuma veya dosyalara yazma ile ilgili eylemlerdir.
  • "Uygulamalar" koleksiyonuna yeni bir öğe ekleyerek yeni bir COM+ uygulaması oluşturma gibi koleksiyonlara yeni öğeler ekleyin.
  • Koleksiyondaki bir öğede özellikleri ayarlama veya alma.
  • Katalogda bekleyen değişiklikleri kaydedin veya atın.
  • Oluşabilecek hataları ele alın.

COMAdmin nesnelerini kullandığınızda bu adımların nasıl göründüğünü göstermek için aşağıda bir Microsoft Visual Basic örneği verilmiştir. Koleksiyonları bulma, bir öğeyi almak için bir koleksiyonda numaralandırma ve bu öğedeki özellikleri ayarlama gibi, yukarıda açıklanan tipik adımlardan bazılarını kısaca gösterir.

Aşağıdaki örnekte aşağıdaki eylemleri gerçekleştirebilirsiniz:

  1. "MyHomeZoo" adlı yeni bir COM+ uygulaması oluşturun.
  2. Uygulamaya Kedi ve Köpek gibi bazı bileşenleri yükleyin. Her iki bileşen de zaten var olması gereken tek bir DLL'de bulunur: MyZoo.dll.
  3. İki rol tanımlayarak uygulama için rol tabanlı güvenlik yapılandırın: ZooKeeper ve AllergicToCats.
  4. ZooKeeper rol erişimini uygulamanın tamamına atayın.
  5. AllergicToCats rol erişimini yalnızca Köpek bileşenine atayın.
  6. Uygulama için rol denetiminin zorunlu kılınması için güvenlik özelliklerini açın.
  7. MyHomeZoo uygulamasını başka bilgisayarlara yüklenebilmesi için bir dosyaya aktarın.

Visual Basic'ten bu örneği kullanmak için COM+ Yönetim Tür Kitaplığı'na bir referans ekleyin.

Function SetupMyZoo() As Boolean  ' Return False if any errors occur.

    '  Initialize error handling for this function.
    SetupMyZoo = False 
    On Error GoTo My_Error_Handler

    '  Open a session with the catalog.
    '  Instantiate a COMAdminCatalog object. 
    Dim objCatalog As COMAdminCatalog
    Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog")

    '  Create a new COM+ application.
    '  First get the "Applications" collection from the catalog.
    Dim objApplicationsColl As COMAdminCatalogCollection
    Set objApplicationsColl = objCatalog.GetCollection("Applications")

    '  Add a new item to this collection. 
    Dim objZooApp As COMAdminCatalogObject
    Set objZooApp = objApplicationsColl.Add

    '  The "Applications" collection determines the available properties.
    '  Set the "Name" property of the new application item. 
    objZooApp.Value("Name") = "MyHomeZoo"

    '  Set the "Description" property of the new application item. 
    objZooApp.Value("Description") = "My pets at home"

    '  Save changes made to the "Applications" collection. 
    objApplicationsColl.SaveChanges

    '  Install components into the application.
    '  Use the InstallComponent method on COMAdminCatalog. 
    '  In this case, the last two parameters are passed as empty strings.
    objCatalog.InstallComponent "MyHomeZoo","MyZoo.DLL","","" 

    '  Define the roles ZooKeeper and AllergicToCats 
    '  by adding them to the "Roles" collection related to MyHomeZoo. 
    '  First get the "Roles" collection related to MyHomeZoo.
    '  Use the GetCollection method on COMAdminCatalogCollection,
    '  passing in the name of the desired collection, "Roles", 
    '  and the Key property value of objZooApp.   
    '  The Key property uniquely identifies the object, serving
    '  here to distinguish the "Roles" collection related 
    '  to MyHomeZoo from that of any other application. 
    Dim objRolesColl As COMAdminCatalogCollection
    Set objRolesColl = objApplicationsColl.GetCollection("Roles", objZooApp.Key)

    '  Add new items to this "Roles" collection. 
    Dim objZooKeeperRole As COMAdminCatalogObject
    Dim objAllergicToCatsRole As COMAdminCatalogObject
    Set objZooKeeperRole = objRolesColl.Add
    Set objAllergicToCatsRole = objRolesColl.Add

    '  Set the "Name" for the new items.
    objZooKeeperRole.Value("Name") = "ZooKeeper" 
    objAllergicToCatsRole.Value("Name") = "AllergicToCats" 

    '  Save changes made to any items in this "Roles" collection. 
    objRolesColl.SaveChanges

    '  Assign the AllergicToCats role to the Dog component to 
    '  restrict its scope of access. (The ZooKeeper role, if assigned
    '  only at the application level, can access the whole application.)
    '  First get the "Components" collection related to MyHomeZoo.
    '  Use the GetCollection method on COMAdminCatalogCollection,
    '  passing in the name of the desired collection, "Components", and
    '  the Key property value of objZooApp. 
    Dim objZooComponentsColl As COMAdminCatalogCollection
    Set objZooComponentsColl = objApplicationsColl.GetCollection("Components", objZooApp.Key) 

    '  Find the Dog component item in this "Components" collection.
    '  First Populate the collection to read in data for all its items. 
    objZooComponentsColl.Populate

    '  Enumerate through the "Components" collection 
    '  until the Dog component item is located. 
    Dim objDog As COMAdminCatalogObject 
    For Each objDog in objZooComponentsColl
        If objDog.Name = "Dog" Then 
            Exit For
        End If
    Next 
    '  Set the role checking property at the component level for Dog.
        objDog.Value("ComponentAccessChecksEnabled") = True 

    '  Save these changes.
        objZooComponentsColl.SaveChanges
    '  Get the "RolesForComponent" collection related to the 
    '  Dog component, using the Key property of objDog. 
    Dim objRolesForDogColl As COMAdminCatalogCollection 
    Set objRolesForDogColl = objZooComponentsColl.GetCollection("RolesForComponent", objDog.Key) 

    '  Add a new item to this "RolesForComponent" collection. 
    Dim objCatSneezerRole As COMAdminCatalogObject
    Set objCatSneezerRole = objRolesForDogColl.Add

    '  Set the "Name" of the new item to be "AllergicToCats". 
    objCatSneezerRole.Value("Name") = "AllergicToCats" 

    '  Save changes made to this "RolesForComponent" collection. 
    objRolesForDogColl.SaveChanges

    '  Now set properties to enforce role-based security. 
    '  First set role-based security at the application level.
    objZooApp.Value("ApplicationAccessChecksEnabled") = True 
    objZooApp.Value("AccessChecksLevel") = COMAdminAccessChecksApplicationComponentLevel 

    '  Save these changes.
    objApplicationsColl.SaveChanges

    '  Finally, export the new configured MyHomeZoo application to an 
    '  MSI file, used to install the application on other machines.
    '  Use the ExportApplication method on COMAdminCatalogObject.
    objCatalog.ExportApplication "MyHomeZoo", "c:\Program Files\COM applications\MyHomeZoo.MSI", 4

    '  Exit the function gracefully.
    SetupMyZoo = True

My_Error_Handler:
    If Not SetupMyZoo Then
        MsgBox "Error # " & Err.Number & " (Hex: " & Hex(Err.Number) & ")" & vbNewLine & Err.Description
    End If
    objCatSneezerRole = Nothing
    objRolesForDogColl = Nothing
    objDog = Nothing
    objZooComponentsColl = Nothing
    objAllergicToCatsRole = Nothing
    objZooKeeperRole = Nothing
    objRolesColl = Nothing
    objZooApp = Nothing
    objApplicationsColl = Nothing
    objCatalog = Nothing
Exit Function

İşlemler İçinde COM+ Yönetim İşlemleri

COM+ Yönetim Hatalarını İşleme

COMAdmin Nesneleri Genel Bakış

COM+ Kataloğunda Koleksiyonları Getirme

Özellikleri Ayarlama ve Değişiklikleri COM+ Kataloğuna Kaydetme