Esempio 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);
                }
            }
        }
Esempio n. 2
0
        protected ObjectToken(ISpObjectToken sapiObjectToken, bool disposeSapiToken)
            : base(sapiObjectToken)
        {
            ArgumentNullException.ThrowIfNull(sapiObjectToken);

            _sapiObjectToken        = sapiObjectToken;
            _disposeSapiObjectToken = disposeSapiToken;
        }
Esempio n. 3
0
 protected ObjectToken(ISpObjectToken sapiObjectToken, bool disposeSapiToken)
     : base(sapiObjectToken)
 {
     if (sapiObjectToken == null)
     {
         throw new ArgumentNullException("sapiObjectToken");
     }
     _sapiObjectToken        = sapiObjectToken;
     _disposeSapiObjectToken = disposeSapiToken;
 }
Esempio n. 4
0
 // ISpRecognizer Methods
 internal void SetRecognizer(ISpObjectToken recognizer)
 {
     try
     {
         _proxy.Invoke2(delegate { _proxy.Recognizer.SetRecognizer(recognizer); });
     }
     catch (InvalidCastException)
     {
         // The Interop layer maps the SAPI error that an interface cannot by QI to an Invalid cast exception
         // Map the InvalidCastException
         throw new PlatformNotSupportedException(SR.Get(SRID.NotSupportedWithThisVersionOfSAPI));
     }
 }
        private static string GetTokenIdFromToken(ISpObjectToken sapiToken)
        {
            IntPtr ppszCoMemTokenId = IntPtr.Zero;

            try
            {
                sapiToken.GetId(out ppszCoMemTokenId);
                return(Marshal.PtrToStringUni(ppszCoMemTokenId));
            }
            finally
            {
                Marshal.FreeCoTaskMem(ppszCoMemTokenId);
            }
        }
 internal void SetRecognizer(ISpObjectToken recognizer)
 {
     try
     {
         _proxy.Invoke2(delegate
         {
             _proxy.Recognizer.SetRecognizer(recognizer);
         });
     }
     catch (InvalidCastException)
     {
         throw new PlatformNotSupportedException(SR.Get(SRID.NotSupportedWithThisVersionOfSAPI));
     }
 }
Esempio n. 7
0
        internal static ObjectToken Open(string sCategoryId, string sTokenId, bool fCreateIfNotExist)
        {
            ISpObjectToken spObjectToken = (ISpObjectToken) new SpObjectToken();

            try
            {
                spObjectToken.SetId(sCategoryId, sTokenId, fCreateIfNotExist);
            }
            catch (Exception)
            {
                Marshal.ReleaseComObject(spObjectToken);
                return(null);
            }
            return(new ObjectToken(spObjectToken, true));
        }
Esempio n. 8
0
        private static string GetTokenIdFromToken(ISpObjectToken sapiToken)
        {
            IntPtr sapiTokenId = IntPtr.Zero;
            string tokenId;

            try
            {
                sapiToken.GetId(out sapiTokenId);
                tokenId = Marshal.PtrToStringUni(sapiTokenId);
            }
            finally
            {
                Marshal.FreeCoTaskMem(sapiTokenId);
            }

            return(tokenId);
        }
        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);
        }
Esempio n. 10
0
 protected override void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             if (_disposeSapiObjectToken && _sapiObjectToken != null)
             {
                 Marshal.ReleaseComObject(_sapiObjectToken);
                 _sapiObjectToken = null;
             }
             if (_attributes != null)
             {
                 _attributes.Dispose();
                 _attributes = null;
             }
         }
     }
     finally
     {
         base.Dispose(disposing);
     }
 }
 protected RegistryDataKey(ISpObjectToken sapiToken)
     : this(GetTokenIdFromToken(sapiToken), sapiToken, false)
 {
 }
Esempio n. 12
0
 protected ObjectToken(ISpObjectToken sapiObjectToken !!, bool disposeSapiToken)
Esempio n. 13
0
 /// <summary>
 /// Creates a ObjectToken from an already-existing ISpObjectToken.
 /// Assumes the token was created through enumeration, thus should not be disposed by us.
 /// </summary>
 /// <returns>ObjectToken object</returns>
 internal static ObjectToken Open(ISpObjectToken sapiObjectToken)
 {
     return(new ObjectToken(sapiObjectToken, false));
 }