Beispiel #1
0
        /// <summary>
        /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
        /// will attempt to recognize the language in which the input text is written.
        /// </summary>
        /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
        /// requirements for the input format. This parameter cannot be set to null.</param>
        /// <param name="length">Length, in characters, of the text specified in text.</param>
        /// <param name="index">Index inside the specified text to be used by the service. This value should be
        /// between 0 and length-1. If the application wants to process the entire text, it should set this
        /// parameter to 0.</param>
        /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
        /// behavior of text recognition. The application does not have to specify values for all object members.
        /// This parameter can be set to null to use the default mapping options.</param>
        /// <returns>A <see cref="MappingPropertyBag">MappingPropertyBag</see> object in which the service has stored its results. The structure is filled
        /// with information produced by the service during text recognition.</returns>
        public MappingPropertyBag RecognizeText(string text, int length, int index, MappingOptions options)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (length > text.Length || length < 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            UInt32             hResult = LinguisticException.Fail;
            MappingPropertyBag bag     = new MappingPropertyBag(options, text);

            try
            {
                hResult = Win32NativeMethods.MappingRecognizeText(
                    _service, bag._text.AddrOfPinnedObject(), (uint)length, (uint)index,
                    bag._options, ref bag._win32PropertyBag);
                if (hResult != 0)
                {
                    throw new LinguisticException(hResult);
                }
                return(bag);
            }
            catch
            {
                bag.Dispose();
                throw;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
 /// will attempt to recognize the language in which the input text is written. The execution will be
 /// handled in a thread from the managed thread pool, and the asynchronous wait handle of the returned
 /// <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object will be notified when the operation completes. The results of
 /// the call will be stored inside the <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object.
 /// </summary>
 /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
 /// requirements for the input format. This parameter cannot be set to null.</param>
 /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
 /// behavior of text recognition. The application does not have to specify values for all object members.
 /// This parameter can be set to null to use the default mapping options.</param>
 /// <param name="asyncCallback">An application callback delegate to receive callbacks with the results from
 /// the recognize operation. Cannot be set to null.</param>
 /// <param name="callerData">Optional. Private application object passed to the callback function
 /// by a service after text recognition is complete. The application must set this parameter to null to
 /// indicate no private application data.</param>
 /// <returns>A <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object describing the asynchronous operation.</returns>
 public MappingRecognizeAsyncResult BeginRecognizeText(string text, MappingOptions options, AsyncCallback asyncCallback, object callerData)
 {
     if (text == null)
     {
         throw new ArgumentNullException("text");
     }
     return(BeginRecognizeText(text, text.Length, 0, options, asyncCallback, callerData));
 }
Beispiel #3
0
 /// <summary>
 /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
 /// will attempt to recognize the language in which the input text is written.
 /// </summary>
 /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
 /// requirements for the input format. This parameter cannot be set to null.</param>
 /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
 /// behavior of text recognition. The application does not have to specify values for all object members.
 /// This parameter can be set to null to use the default mapping options.</param>
 /// <returns>A <see cref="MappingPropertyBag">MappingPropertyBag</see> object in which the service has stored its results. The structure is filled
 /// with information produced by the service during text recognition.</returns>
 public MappingPropertyBag RecognizeText(string text, MappingOptions options)
 {
     if (text == null)
     {
         throw new ArgumentNullException("text");
     }
     return(RecognizeText(text, text.Length, 0, options));
 }
 internal MappingRecognizeAsyncResult(
     object callerData,
     AsyncCallback asyncCallback,
     string text,
     int length,
     int index,
     MappingOptions options)
     : base(callerData, asyncCallback)
 {
     _text = text;
     _length = length;
     _index = index;
     _options = options;
 }
 internal MappingPropertyBag(MappingOptions options, string text)
 {
     _serviceCache = ServiceCache.Instance;
     if (!_serviceCache.RegisterResource())
     {
         throw new LinguisticException();
     }
     _win32PropertyBag._size = InteropTools.SizeOfWin32PropertyBag;
     if (options != null)
     {
         _options = InteropTools.Pack(ref options._win32Options);
     }
     _text = GCHandle.Alloc(text, GCHandleType.Pinned);
 }
Beispiel #6
0
 internal MappingRecognizeAsyncResult(
     object callerData,
     AsyncCallback asyncCallback,
     string text,
     int length,
     int index,
     MappingOptions options)
     : base(callerData, asyncCallback)
 {
     Text    = text;
     Length  = length;
     Index   = index;
     Options = options;
 }
Beispiel #7
0
 /// <summary>
 /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
 /// will attempt to recognize the language in which the input text is written. The execution will be
 /// handled in a thread from the managed thread pool, and the asynchronous wait handle of the returned
 /// <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object will be notified when the operation completes. The results of
 /// the call will be stored inside the <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object.
 /// </summary>
 /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
 /// requirements for the input format. This parameter cannot be set to null.</param>
 /// <param name="length">Length, in characters, of the text specified in text.</param>
 /// <param name="index">Index inside the specified text to be used by the service. This value should be
 /// between 0 and length-1. If the application wants to process the entire text, it should set this
 /// parameter to 0.</param>
 /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
 /// behavior of text recognition. The application does not have to specify values for all object members.
 /// This parameter can be set to null to use the default mapping options.</param>
 /// <param name="asyncCallback">An application callback delegate to receive callbacks with the results from
 /// the recognize operation. Cannot be set to null.</param>
 /// <param name="callerData">Optional. Private application object passed to the callback function
 /// by a service after text recognition is complete. The application must set this parameter to null to
 /// indicate no private application data.</param>
 /// <returns>A <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object describing the asynchronous operation.</returns>
 public MappingRecognizeAsyncResult BeginRecognizeText(string text, int length, int index, MappingOptions options, AsyncCallback asyncCallback, object callerData)
 {
     if (asyncCallback == null)
     {
         throw new ArgumentNullException("asyncCallback");
     }
     MappingRecognizeAsyncResult result = new MappingRecognizeAsyncResult(callerData, asyncCallback, text, length, index, options);
     try
     {
         ThreadPool.QueueUserWorkItem(this.RunRecognizeText, result);
         return result;
     }
     catch
     {
         result.Dispose();
         throw;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
 /// will attempt to recognize the language in which the input text is written. The execution will be
 /// handled in a thread from the managed thread pool, and the asynchronous wait handle of the returned
 /// <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object will be notified when the operation completes. The results of
 /// the call will be stored inside the <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object.
 /// </summary>
 /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
 /// requirements for the input format. This parameter cannot be set to null.</param>
 /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
 /// behavior of text recognition. The application does not have to specify values for all object members.
 /// This parameter can be set to null to use the default mapping options.</param>
 /// <param name="asyncCallback">An application callback delegate to receive callbacks with the results from
 /// the recognize operation. Cannot be set to null.</param>
 /// <param name="callerData">Optional. Private application object passed to the callback function
 /// by a service after text recognition is complete. The application must set this parameter to null to
 /// indicate no private application data.</param>
 /// <returns>A <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object describing the asynchronous operation.</returns>
 public MappingRecognizeAsyncResult BeginRecognizeText(string text, MappingOptions options, AsyncCallback asyncCallback, object callerData)
 {
     if (text == null)
     {
         throw new ArgumentNullException("text");
     }
     return BeginRecognizeText(text, text.Length, 0, options, asyncCallback, callerData);
 }
Beispiel #9
0
        /// <summary>
        /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
        /// will attempt to recognize the language in which the input text is written.
        /// </summary>
        /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
        /// requirements for the input format. This parameter cannot be set to null.</param>
        /// <param name="length">Length, in characters, of the text specified in text.</param>
        /// <param name="index">Index inside the specified text to be used by the service. This value should be
        /// between 0 and length-1. If the application wants to process the entire text, it should set this
        /// parameter to 0.</param>
        /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
        /// behavior of text recognition. The application does not have to specify values for all object members.
        /// This parameter can be set to null to use the default mapping options.</param>
        /// <returns>A <see cref="MappingPropertyBag">MappingPropertyBag</see> object in which the service has stored its results. The structure is filled
        /// with information produced by the service during text recognition.</returns>
        public MappingPropertyBag RecognizeText(string text, int length, int index, MappingOptions options)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            if (length > text.Length || length < 0)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            UInt32 hResult = LinguisticException.Fail;
            MappingPropertyBag bag = new MappingPropertyBag(options, text);
            try
            {
                hResult = Win32NativeMethods.MappingRecognizeText(
                    _service, bag._text.AddrOfPinnedObject(), (uint)length, (uint)index,
                    bag._options, ref bag._win32PropertyBag);
                if (hResult != 0)
                {                    
                    throw new LinguisticException(hResult);
                }
                return bag;
            }
            catch
            {
                bag.Dispose();
                throw;
            }

        }
Beispiel #10
0
 /// <summary>
 /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
 /// will attempt to recognize the language in which the input text is written.
 /// </summary>
 /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
 /// requirements for the input format. This parameter cannot be set to null.</param>
 /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
 /// behavior of text recognition. The application does not have to specify values for all object members.
 /// This parameter can be set to null to use the default mapping options.</param>
 /// <returns>A <see cref="MappingPropertyBag">MappingPropertyBag</see> object in which the service has stored its results. The structure is filled
 /// with information produced by the service during text recognition.</returns>
 public MappingPropertyBag RecognizeText(string text, MappingOptions options)
 {
     if (text == null)
     {
         throw new ArgumentNullException("text");
     }
     return RecognizeText(text, text.Length, 0, options);
 }
Beispiel #11
0
        /// <summary>
        /// Calls an ELS service to recognize text. For example, the Microsoft Language Detection service
        /// will attempt to recognize the language in which the input text is written. The execution will be
        /// handled in a thread from the managed thread pool, and the asynchronous wait handle of the returned
        /// <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object will be notified when the operation completes. The results of
        /// the call will be stored inside the <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object.
        /// </summary>
        /// <param name="text">The text to recognize. The text must be UTF-16, but some services have additional
        /// requirements for the input format. This parameter cannot be set to null.</param>
        /// <param name="length">Length, in characters, of the text specified in text.</param>
        /// <param name="index">Index inside the specified text to be used by the service. This value should be
        /// between 0 and length-1. If the application wants to process the entire text, it should set this
        /// parameter to 0.</param>
        /// <param name="options">Optional. A <see cref="MappingOptions">MappingOptions</see> object containing options that affect the result and
        /// behavior of text recognition. The application does not have to specify values for all object members.
        /// This parameter can be set to null to use the default mapping options.</param>
        /// <param name="asyncCallback">An application callback delegate to receive callbacks with the results from
        /// the recognize operation. Cannot be set to null.</param>
        /// <param name="callerData">Optional. Private application object passed to the callback function
        /// by a service after text recognition is complete. The application must set this parameter to null to
        /// indicate no private application data.</param>
        /// <returns>A <see cref="MappingRecognizeAsyncResult">MappingRecognizeAsyncResult</see> object describing the asynchronous operation.</returns>
        public MappingRecognizeAsyncResult BeginRecognizeText(string text, int length, int index, MappingOptions options, AsyncCallback asyncCallback, object callerData)
        {
            if (asyncCallback == null)
            {
                throw new ArgumentNullException("asyncCallback");
            }
            MappingRecognizeAsyncResult result = new MappingRecognizeAsyncResult(callerData, asyncCallback, text, length, index, options);

            try
            {
                ThreadPool.QueueUserWorkItem(this.RunRecognizeText, result);
                return(result);
            }
            catch
            {
                result.Dispose();
                throw;
            }
        }