Example #1
0
        // creates the Microsoft engines on their own
        // thread bound to the current Wisej session.
        private static ScriptEngine CreateThreadBoundEngine(EngineType type, string name, WindowsScriptEngineFlags flags)
        {
            ScriptEngine engine     = null;
            var          checkPoint = new ManualResetEventSlim();

            ApplicationBase.StartTask(() => {
                switch (type)
                {
                case EngineType.JScript:
                    engine = new JScriptEngine(name, flags);
                    break;

                case EngineType.VBScript:
                    engine = new VBScriptEngine(name, flags);
                    break;

                default:
                    throw new InvalidOperationException();
                }

                checkPoint.Set();
                Dispatcher.Run();
            });

            checkPoint.Wait();
            checkPoint.Reset();

            return(engine);
        }
        /// <summary>
        /// Invokes the translation service provider asynchronously and returns the result of the request in an instance
        /// of the <see cref="T:Wisej.Ext.Translation.TranslationResult"/> class.
        /// </summary>
        /// <param name="text">The text to translate.</param>
        /// <param name="from">The source language ("en", "de", ...) or null/empty to ask the provider to auto detect the source language.</param>
        /// <param name="to">The target language ("en", "de", ...)</param>
        /// <param name="resultCallback">Callback method that will receive the TranslationResult when ready.</param>
        public override void TranslateAsync(string text, string from, string to, Action <TranslationResult> resultCallback)
        {
            var callback = resultCallback;

            ApplicationBase.StartTask(() =>
            {
                TranslationResult result = this.Translate(text, from, to);
                callback(result);
            });
        }