Ejemplo n.º 1
0
        internal void Invoke(string nodeName, CancellationTokenSource tokenSource, TimeSpan timeout)
        {
            try
            {
                var timeoutTime = timeout.GetTime();

                var node = this._stateMachine.GetNode(nodeName);

                this._stateMachine.StateExecute(node, tokenSource.Token, timeoutTime);

                Completed?.Invoke(this, new StateMachineCompletedEventArgs(_stateMachine));
            }
            catch (TimeoutException ex) when(ex.Message == "Timeout")
            {
                Faulted?.Invoke(this, new StateMachineFaultedEventArgs(_stateMachine, FaultType.ByTimeout, ex));
            }
            catch (OperationCanceledException ex)
            {
                Faulted?.Invoke(this, new StateMachineFaultedEventArgs(_stateMachine, FaultType.ByToken, ex));
            }
            catch (System.Exception ex)
            {
                Faulted?.Invoke(this, new StateMachineFaultedEventArgs(_stateMachine, FaultType.ByException, ex));
            }
            finally
            {
                tokenSource.Dispose();
            }
        }
Ejemplo n.º 2
0
 private void serviceHost_Faulted(object sender, EventArgs e)
 {
     serviceHost.Close();
     logError("WCF服务失败");
     ReportError("状态:已停止,WCF服务失败");
     Faulted?.Invoke(this, new ErrorEventArgs("WCF服务失败"));
 }
Ejemplo n.º 3
0
        private void ChangeState(CommunicationState state)
        {
            this.State = state;
            switch (state)
            {
            case CommunicationState.Opening:
                Opening?.Invoke(this, EventArgs.Empty);
                break;

            case CommunicationState.Opened:
                Opened?.Invoke(this, EventArgs.Empty);
                break;

            case CommunicationState.Closing:
                Closing?.Invoke(this, EventArgs.Empty);
                break;

            case CommunicationState.Closed:
                Closed?.Invoke(this, EventArgs.Empty);
                break;

            case CommunicationState.Faulted:
                Faulted?.Invoke(this, EventArgs.Empty);
                break;
            }
        }
        public void Handle(CoreProjectionStatusMessage.Faulted message)
        {
            var command = new Faulted {
                Id = message.ProjectionId.ToString("N"), FaultedReason = message.FaultedReason,
            };

            _writer.PublishCommand("$faulted", command);
        }
Ejemplo n.º 5
0
        protected void FireFaultEvent(Exception exception, Message message)
        {
            var ex        = new ProtocolException(Strings.Plugin_ProtocolException, exception);
            var eventArgs = message == null
                ? new ProtocolErrorEventArgs(ex) : new ProtocolErrorEventArgs(ex, message);

            Faulted?.Invoke(this, eventArgs);
        }
Ejemplo n.º 6
0
 private void FileChanged(object sender, FileSystemEventArgs fse)
 {
     if (Regions == null)
     {
         return;
     }
     try {
         ReflectDelta(fse);
         ConfigReloaded.Invoke(fse);
     }
     catch (Exception e) {
         Faulted.Invoke(fse, e);
     }
 }
Ejemplo n.º 7
0
 public void Run()
 {
     Running?.Invoke(this);
     try
     {
         RunInternal();
     }
     catch (Exception ex)
     {
         Faulted?.Invoke(this, ex);
         return;
     }
     Success?.Invoke(this);
 }
Ejemplo n.º 8
0
        public void Shutdown(Exception e = null)
        {
            if (running)
            {
                if (e != null)
                {
                    AppTools.TryInvoke(() =>
                    {
                        Faulted?.Invoke(this, new EndPointExceptionEventArgs(e));
                    });
                }

                shutdown = true;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Update current sensor Value with the reading.
        /// </summary>
        /// <param name="timestamp">Time when reading was sampled</param>
        /// <param name="val">Value that was read</param>
        /// <param name="bias">Optional bias to add to value</param>
        public void UpdateValue(DateTime timestamp, float?val, float?bias)
        {
            if (DeviceState == SensorDeviceState.Simulated && GetSimValue != null)
            {
                val = GetSimValue();
            }
            if (DeviceState != SensorDeviceState.Offline && val.HasValue)
            {
                Value = val.Value;
                if (bias.HasValue)
                {
                    Value += bias.Value;
                }

                var fault = new SensorFault();

                if (Value > DangerHi)
                {
                    fault.Type = SensorFaultType.FromDangerHi;
                }
                else if (Value < DangerLo)
                {
                    fault.Type = SensorFaultType.FromDangerLo;
                }
                if (Triggers != null)
                {
                    foreach (var t in Triggers)
                    {
                        if ((t.cmp > 0 && Value > t.val) || (t.cmp < 0 && Value < t.val))
                        {
                            fault.Type = SensorFaultType.FromTrigger;
                            fault.Id   = t.id;
                        }
                    }
                }

                if (FaultState != SensorFaultState.Faulted && fault.Type != SensorFaultType.NoFault)
                {
                    FaultState = SensorFaultState.Faulted;
                    Faulted?.Invoke(this, fault, timestamp);
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Raise the Faulted event.
        /// </summary>
        protected virtual void OnExecutableFaulted(Exception ex, IUnityContainer runtimeContainer)
        {
            if (Faulted == null)
            {
                return;
            }

            try
            {
                var clock = runtimeContainer.TryGetTypeRegistration <IClock>();
                Faulted?.Invoke(this, new FaultedEventArgs(ex, clock));
            }
            catch (Exception nex)
            {
                var logger = runtimeContainer.TryGetTypeRegistration <ILog>();
                //TODO: what if the logger is null?
                logger?.Error($"{nex.GetType().Name} while raising event '{nameof(Faulted)}' in behavior '{Name}':  {nex.Message}.", nex);
            }
        }
Ejemplo n.º 11
0
        void job()
        {
            using (source)
                using (manualResetEvent)
                {
                    try
                    {
                        ReportStatus("状态:正在运行");
                        while (true)
                        {
                            if (source.Token.IsCancellationRequested)
                            {
                                break;
                            }

                            int millisecondsTimeout = ServiceCore(source.Token);

                            //让服务歇一会儿
                            if (millisecondsTimeout > 0)
                            {
                                manualResetEvent.WaitOne(millisecondsTimeout);
                            }
                        }
                        ReportStatus("状态:停止运行");
                    }
                    catch (OperationCanceledException) { ReportStatus("状态:停止运行"); } //捕获掉取消操作异常,当作停止运行来处理
#if !DEBUG
                    catch (Exception ex)
                    {
                        logError($"承载服务失败:{ex.Message}", ex);
                        ReportError("状态:已停止,承载服务失败", ex);
                        Faulted?.Invoke(this, new ErrorEventArgs(ex));
                    }
#endif
                    finally { }
                }
            source           = null;
            manualResetEvent = null;
        }
Ejemplo n.º 12
0
        private void CacheAllConfigs()
        {
            string extension = ConfigBuilder.GetExtension();

            WriteDefaultConfig(extension);

            Regions.Add(new Region(ConfigBuilder));
            foreach (string config in Directory.EnumerateFiles(RootPath, '*' + extension, SearchOption.AllDirectories))
            {
                try {
                    AddRegion(config);
                }
                catch (Exception exception) {
                    WatcherChangeTypes type = WatcherChangeTypes.Created;
                    string             dir  = Path.GetDirectoryName(config);
                    string             name = Path.GetFileName(config);
                    var eventArgs           = new FileSystemEventArgs(type, dir, name);
                    Faulted.Invoke(eventArgs, exception);
                    return;
                }
            }
        }
Ejemplo n.º 13
0
 public bool FaultedIsHooked()
 {
     return(Faulted != null && Faulted.GetInvocationList().Length > 0);
 }
 private void OnChannelFaulted(object sender, EventArgs e)
 {
     Faulted?.Invoke(sender, e);
 }
Ejemplo n.º 15
0
 private void HandleFaulted(AggregateException exception)
 {
     IsFaulted = true;
     Faulted?.Invoke(exception);
 }
Ejemplo n.º 16
0
        void ClientThread()
        {
            try
            {
                socket.Blocking = false;
                var check = new List <Socket>();

                var buffer  = new byte[0x1000];
                var current = new StringBuilder();

                while (!shutdown)
                {
                    check.Add(socket);
                    Socket.Select(check, null, null, 1000000);
                    if (check.Count == 0)
                    {
                        continue;
                    }

                    var len = socket.Receive(buffer, buffer.Length, SocketFlags.None);
                    if (len == 0)
                    {
                        break;
                    }

                    foreach (var c in PacketBase.Encoding.GetString(buffer, 0, len))
                    {
                        if (c == PacketBase.Delimiter)
                        {
                            var result = false;
                            AppTools.TryInvoke(() =>
                            {
                                result = HandlePacket(current.ToString());
                            });

                            if (!result)
                            {
                                Flush();
                                goto Breakout;
                            }

                            current.Clear();
                            continue;
                        }

                        current.Append(c);
                    }

                    Flush();
                }

                Breakout :;
            }

            catch (ThreadAbortException) { }
            catch (Exception e)
            {
                AppTools.TryInvoke(() =>
                {
                    Faulted?.Invoke(this, new EndPointExceptionEventArgs(e));
                });
            }

            finally
            {
                try
                {
                    socket.Close();
                    socket = null;
                    if (callback != null)
                    {
                        AppTools.TryInvoke(() =>
                        {
                            callback();
                        });
                    }
                }
                catch (Exception ea)
                {
                    AppTools.TryInvoke(() =>
                    {
                        Faulted?.Invoke(this, new EndPointExceptionEventArgs(ea));
                    });
                }

                shutdown = false;
                running  = false;
                AppTools.TryInvoke(() =>
                {
                    Disconnected?.Invoke(this, new EventArgs());
                });
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Invokes Faulted event
 /// </summary>
 /// <remarks>Deliberately not async as used only for interactive testing</remarks>
 /// <param name="e"></param>
 protected void OnFaulted(AsyncServiceFaultedEventArgs e)
 {
     Faulted?.Invoke(this, e);
 }
Ejemplo n.º 18
0
 private void OnFaulted(object sender, ProtocolErrorEventArgs e)
 {
     Faulted?.Invoke(this, new FaultedPluginEventArgs(this, e.Exception));
 }
Ejemplo n.º 19
0
 protected virtual void OnFaulted()
 {
     Faulted?.Invoke(this, System.EventArgs.Empty);
 }
Ejemplo n.º 20
0
 private void OnProcessFaulted(Task task)
 {
     Faulted?.Invoke(this, task.Exception);
 }
Ejemplo n.º 21
0
 public bool IsStarted(ReceiveEndpoint instance)
 {
     return(Started.Equals(instance.CurrentState) || Ready.Equals(instance.CurrentState) || Faulted.Equals(instance.CurrentState));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FaultedTest"/> class.
 /// </summary>
 public FaultedTest()
 {
     this._genome         = new ImmutableGenome(new Genome());
     this._faultedMessage = new Faulted <TestInstance>(this._genome, FaultedTest.instance, this._exception);
 }
Ejemplo n.º 23
0
 public SensorFaultedMesssage(Faulted faultedEvent)
 {
 }
Ejemplo n.º 24
0
 private void InnerDuplexChannel_Faulted(object sender, EventArgs e)
 {
     Faulted?.Invoke(this, e);
 }
Ejemplo n.º 25
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Faulted obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Ejemplo n.º 26
0
 private void OnFaulted(object sender, EventArgs e)
 {
     Faulted?.Invoke(this, e);
 }
Ejemplo n.º 27
0
 private void OnFaulted(object sender, ProtocolErrorEventArgs e)
 {
     Faulted?.Invoke(this, e);
 }