Пример #1
0
 private void SetBusy(Control sender, bool b)
 {
     ClientCommandState = b ? ClientCommandState.Executing : ClientCommandState.Init;
     sender.Background  = b ? Brushes.Orange : Brushes.WhiteSmoke;
     if (!b)
     {
         CommandManager.InvalidateRequerySuggested();
     }
 }
Пример #2
0
        /// <summary>
        /// no binding required and CanExecute not called
        /// </summary>
        internal object ExecuteSafe(ClientInstance <MT, T> clientEx, object par)
        {
            if (_client == null)
            {
                _client = clientEx;
            }
            else if (clientEx != null && clientEx != _client)
            {
                throw new ApplicationException("Wrong _client parameter");
            }
            try
            {
                Debug.Print("{2}: {1} started at {0}", DateTime.Now, GetType().Name, _client.ApplicationID);
                // if server was stopped till here there will be exception
                return(ExecuteCommand(par));
            }
            catch (FaultException ex)
            {
                ClientCommandState = ClientCommandState.Fault;

                // thrown inside of server
                // channels are NOT distroyed
                if (!_calledFromCode)
                {
                    Show(ex.Message);
                }
                return(ex.Message);
            }
            catch (PermissionException ex)
            {
                if (!_calledFromCode)
                {
                    Show(ex.Message);
                }
                return(ex.Message);
            }
            catch (ApplicationException ex)
            {
                // thrown on _client inside of ExecuteCommand
                _client.LastError = ex.Message;
                if (!_calledFromCode)
                {
                    Show(ex.Message);
                }
                return(ex.Message);
            }
            //like EndpointNotFoundException
            //  or CommunicationObjectFaultedException(thrown if _client requests killed server)
            catch (CommunicationException ex)
            {
                ClientCommandState = ClientCommandState.Fault;
                // channels are distroyed
                _client.CreateFactories();

                Show("Server is not started", ex.GetType().Name);
                return(ex.Message);
            }
            catch (ThreadAbortException)
            {
                return(null);
            }
            catch (Exception ex)
            {
                ClientCommandState = ClientCommandState.Fault;

                // channels are distroyed, but server has adequate state.
                // _client may reconnect automatically or wait for user reaction
                //      _client.CreateFactories(); does not help
                Show(ex.Message, ex.GetType().Name);
                return(null);
            }
            finally
            {
                Debug.Print("{2}: {0} finished at {1}", GetType().Name, DateTime.Now, _client.ApplicationID);
                // here additional session may be closed
            }
        }