Exemplo n.º 1
0
        internal IList <ObjectToken> FindMatchingTokens(string requiredAttributes, string optionalAttributes)
        {
            IList <ObjectToken>    list = new List <ObjectToken>();
            ISpObjectTokenCategory spObjectTokenCategory = null;
            IEnumSpObjectTokens    ppEnum = null;

            try
            {
                spObjectTokenCategory = (ISpObjectTokenCategory) new SpObjectTokenCategory();
                spObjectTokenCategory.SetId(_sKeyId, false);
                spObjectTokenCategory.EnumTokens(requiredAttributes, optionalAttributes, out ppEnum);
                uint pCount;
                ppEnum.GetCount(out pCount);
                for (uint num = 0u; num < pCount; num++)
                {
                    ISpObjectToken ppToken = null;
                    ppEnum.Item(num, out ppToken);
                    ObjectToken item = ObjectToken.Open(ppToken);
                    list.Add(item);
                }
                return(list);
            }
            finally
            {
                if (ppEnum != null)
                {
                    Marshal.ReleaseComObject(ppEnum);
                }
                if (spObjectTokenCategory != null)
                {
                    Marshal.ReleaseComObject(spObjectTokenCategory);
                }
            }
        }
Exemplo n.º 2
0
        internal IList <ObjectToken> FindMatchingTokens(string requiredAttributes, string optionalAttributes)
        {
            IList <ObjectToken>    objectTokenList = new List <ObjectToken>();
            ISpObjectTokenCategory category        = null;
            IEnumSpObjectTokens    enumTokens      = null;

            try
            {
                // Note - enumerated tokens should not be torn down/disposed by us (see SpInitTokenList in spuihelp.h)
                category = (ISpObjectTokenCategory) new SpObjectTokenCategory();
                category.SetId(_sKeyId, false);
                category.EnumTokens(requiredAttributes, optionalAttributes, out enumTokens);

                uint tokenCount;
                enumTokens.GetCount(out tokenCount);
                for (uint index = 0; index < tokenCount; ++index)
                {
                    ISpObjectToken spObjectToken = null;

                    enumTokens.Item(index, out spObjectToken);
                    ObjectToken objectToken = ObjectToken.Open(spObjectToken);
                    objectTokenList.Add(objectToken);
                }
            }
            finally
            {
                if (enumTokens != null)
                {
                    Marshal.ReleaseComObject(enumTokens);
                }
                if (category != null)
                {
                    Marshal.ReleaseComObject(category);
                }
            }

            return(objectTokenList);
        }