Ejemplo n.º 1
0
        static void TranslateCompleted(object operationState)
        {
            TranslateCompletedEventArgs e =
                operationState as TranslateCompletedEventArgs;

            e.TranslateState.OnTranslateCompleted(e);
        }
Ejemplo n.º 2
0
        public static void CancelAsync(AsyncTranslateState translateState)
        {
            if (translateState == null)
            {
                throw new ArgumentNullException("translateState");
            }

            AsyncOperation asyncOp = translateState.AsyncOperation;

            translateState.RemoveTimers();

            TranslateCompletedEventArgs e =
                new TranslateCompletedEventArgs(
                    translateState,
                    null,
                    true,
                    translateState);

            // The asyncOp object is responsible for marshaling
            // the call.
            try
            {           //some time operation already completed
                asyncOp.PostOperationCompleted(TranslateCompleted, e);
            }
            catch (InvalidOperationException)
            {
            }
            translateState.IsTerminated = true;
        }
Ejemplo n.º 3
0
 public void OnTranslateCompleted(
     TranslateCompletedEventArgs e)
 {
     if (TranslateCompleted != null)
     {
         TranslateCompleted(this, e);
     }
 }
Ejemplo n.º 4
0
        public void RaiseProgressChanged(Result translateResult)
        {
            results.Add(translateResult);
            processed++;

            TranslateProgressChangedEventArgs e = new TranslateProgressChangedEventArgs(
                translateResult,
                this,
                (int)(((double)processed) / ((double)count) * 100),
                this
                );

            if (ProgressChanged != null)
            {
                ProgressChanged(this, e);
            }

            if (IsTerminated)
            {
                return;
            }

            if (processed == count)
            {
                TranslateCompletedEventArgs args =
                    new TranslateCompletedEventArgs(
                        this,
                        null,
                        false,
                        this);

                try
                {
                    asyncOperation.PostOperationCompleted(RaiseTranslateCompleted, args);
                }
                catch (System.InvalidOperationException)
                {
                    //ignore exception raised sometime from here
                }
                IsTerminated = true;
            }
        }
Ejemplo n.º 5
0
        internal void TranslateCompletedEventHandler(object sender, TranslateCompletedEventArgs e)
        {
            if(TranslateOptions.Instance.ResultWindowOptions.ShowQueryStatistics)
                resBrowser.SetStatistics(DateTime.Now.Ticks - startTranslateTicks);

            resBrowser.SetEndData(e.TranslateState);

            ResourceManager resources = new ResourceManager("Translate.Common.Icons", Assembly.GetExecutingAssembly());
            miAnimatedIcon.Image = (((System.Drawing.Icon)(resources.GetObject("StaticIcon")))).ToBitmap();

            ignoreProfileReposition = true;
            tsbTranslate.Image = (((System.Drawing.Icon)(resources.GetObject("StaticIcon")))).ToBitmap();
            ignoreProfileReposition = false;

            //don't generate any statistics calls to avoid overloading of googlepages
            //if(!e.Cancelled && e.Error == null && e.TranslateState.Results.Count > 0)
            //	resBrowser.AddAdvertisement(e.TranslateState);

            if(activeTranslateState == e.TranslateState)
            {
                activeTranslateState = null;
            }
            pbMain.Visible = false;
            StatManager.IncrementCalls();
        }
Ejemplo n.º 6
0
        public static void CancelAsync(AsyncTranslateState translateState)
        {
            if(translateState == null)
                throw new ArgumentNullException("translateState");

            AsyncOperation asyncOp = translateState.AsyncOperation;

            translateState.RemoveTimers();

            TranslateCompletedEventArgs e =
                new TranslateCompletedEventArgs(
                translateState,
                null,
                true,
                translateState);

            // The asyncOp object is responsible for marshaling
            // the call.
            try
            {	//some time operation already completed
                asyncOp.PostOperationCompleted(TranslateCompleted, e);
            }
            catch (InvalidOperationException)
            {

            }
            translateState.IsTerminated = true;
        }
Ejemplo n.º 7
0
        public void RaiseProgressChanged(Result translateResult)
        {
            results.Add(translateResult);
            processed++;

            TranslateProgressChangedEventArgs e = new TranslateProgressChangedEventArgs(
                translateResult,
                this,
                (int)(((double)processed)/((double)count)*100),
                this
            );

            if (ProgressChanged != null)
            {
                ProgressChanged(this, e);
            }

            if(IsTerminated) return;

            if(processed == count)
            {
                TranslateCompletedEventArgs args =
                    new TranslateCompletedEventArgs(
                    this,
                    null,
                    false,
                    this);

                try
                {
                    asyncOperation.PostOperationCompleted(RaiseTranslateCompleted, args);
                }
                catch(System.InvalidOperationException)
                {
                    //ignore exception raised sometime from here
                }
                IsTerminated = true;
            }
        }
Ejemplo n.º 8
0
 public void OnTranslateCompleted(
     TranslateCompletedEventArgs e)
 {
     if (TranslateCompleted != null)
     {
         TranslateCompleted(this, e);
     }
 }