示例#1
0
        /// <summary>
        /// This Trigger was called from the IPC Service Instance for status update
        /// </summary>
        /// <param name="result"></param>
        private void ServiceOnTranslation(TranslateOperationResult result)
        {
            if (this.InvokeRequired)
            {
                TranslationResult = result;
                MethodInvoker uiThreadHandler = new MethodInvoker(ServiceOnTranslationInUIThread);
                this.Invoke(uiThreadHandler);
            }
            else
            {
                switch (result.State)
                {
                case TranslateOperationState.Sucseed:

                    int imageIndex = 1;
                    if (result.Requested.Trim().Equals(result.Result, StringComparison.InvariantCultureIgnoreCase))
                    {
                        imageIndex = 2;
                    }
                    DisplayMessage(string.Format("Translation sucseed \"{0}\"=>\"{1}\"; FromLocalCache={2}", result.Requested, result.Result, result.Cached), imageIndex);
                    break;

                case TranslateOperationState.Error:
                    DisplayMessage(string.Format("Translation failed because {0}", result.Exception.ToString()), 3);
                    break;

                default:
                    throw new IndexOutOfRangeException("state");
                }
            }
        }
示例#2
0
 /// <summary>
 /// Helper method to perform a status update in UI thread
 /// </summary>
 private void ServiceOnTranslationInUIThread()
 {
     if (null != TranslationResult)
     {
         ServiceOnTranslation(TranslationResult);
         TranslationResult = null;
     }
 }
示例#3
0
        /// <summary>
        /// This method was called from the IPC Service instance for state updates
        /// This is a very stupid solution because the service is calling the view directly and wait until its finished
        /// Never do this in a real-life scenario because the view can block/slow down the service
        /// </summary>
        /// <param name="result">operation state</param>
        private void ServiceOnTranslation(TranslateOperationResult result)
        {
            if (this.InvokeRequired)
            {
                Action <TranslateOperationResult> invoker = ServiceOnTranslation;
                invoker.Invoke(result);
            }
            else
            {
                switch (result.State)
                {
                case TranslateOperationState.Sucseed:
                    DisplayTranslationMessage(result.Requested, result.Result, result.Cached);
                    break;

                case TranslateOperationState.Error:
                    DisplayFailedMessage(result.Exception);
                    break;

                default:
                    throw new IndexOutOfRangeException("state");
                }
            }
        }