コード例 #1
0
        private void AddRoleFor(String target, Hashtable cache)
        {
            DBG.Info(DBG.Registration, "Adding role " + _role + " for " + target);
            ICatalogCollection coll = (ICatalogCollection)(cache[target + "Collection"]);
            ICatalogObject     obj  = (ICatalogObject)(cache[target]);

            // Navigate to the RolesForTarget collection:
            ICatalogCollection roles = (ICatalogCollection)(coll.GetCollection(CollectionName.RolesFor(target), obj.Key()));

            roles.Populate();

            if (Platform.IsLessThan(Platform.W2K))
            {
                // MTS uses RoleUtil method
                // TODO:  Can we use this on w2k?  It would make stuff easier.
                IRoleAssociationUtil util = (IRoleAssociationUtil)(roles.GetUtilInterface());
                util.AssociateRoleByName(_role);
            }
            else
            {
                // See if the desired role is already part of the collection:
                ICatalogObject queryObj = Search(roles, "Name", _role);
                if (queryObj != null)
                {
                    return;
                }

                // We didn't find it, go ahead and add it.
                DBG.Info(DBG.Registration, "\tNew role: " + _role);
                ICatalogObject newRole = (ICatalogObject)(roles.Add());
                newRole.SetValue("Name", _role);
                DBG.Info(DBG.Registration, "Done!");
                roles.SaveChanges();

                roles.Populate();
                DBG.Info(DBG.Registration, "\tRole collection: " + roles.Name());
                DBG.Info(DBG.Registration, "\tOn " + target + ": " + obj.Name());
                for (int i = 0; i < roles.Count(); i++)
                {
                    ICatalogObject tobj = (ICatalogObject)(roles.Item(i));
                    DBG.Info(DBG.Registration, "\tRole: " + tobj.Name());
                }
            }
        }
コード例 #2
0
        private void AddRoleFor(string target, Hashtable cache)
        {
            ICatalogCollection catalogs   = (ICatalogCollection)cache[target + "Collection"];
            ICatalogObject     obj2       = (ICatalogObject)cache[target];
            ICatalogCollection collection = (ICatalogCollection)catalogs.GetCollection(CollectionName.RolesFor(target), obj2.Key());

            collection.Populate();
            if (this.Search(collection, "Name", this._role) == null)
            {
                ((ICatalogObject)collection.Add()).SetValue("Name", this._role);
                collection.SaveChanges();
                collection.Populate();
                for (int i = 0; i < collection.Count(); i++)
                {
                    ICatalogObject obj1 = (ICatalogObject)collection.Item(i);
                }
            }
        }