Esempio 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();
            }
        }
Esempio n. 2
0
 private void serviceHost_Faulted(object sender, EventArgs e)
 {
     serviceHost.Close();
     logError("WCF服务失败");
     ReportError("状态:已停止,WCF服务失败");
     Faulted?.Invoke(this, new ErrorEventArgs("WCF服务失败"));
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
     }
 }
Esempio n. 7
0
 public void Run()
 {
     Running?.Invoke(this);
     try
     {
         RunInternal();
     }
     catch (Exception ex)
     {
         Faulted?.Invoke(this, ex);
         return;
     }
     Success?.Invoke(this);
 }
Esempio n. 8
0
        public void Shutdown(Exception e = null)
        {
            if (running)
            {
                if (e != null)
                {
                    AppTools.TryInvoke(() =>
                    {
                        Faulted?.Invoke(this, new EndPointExceptionEventArgs(e));
                    });
                }

                shutdown = true;
            }
        }
Esempio 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);
                }
            }
        }
Esempio 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);
            }
        }
Esempio 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;
        }
Esempio 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;
                }
            }
        }
Esempio n. 13
0
 public bool FaultedIsHooked()
 {
     return(Faulted != null && Faulted.GetInvocationList().Length > 0);
 }
 private void OnChannelFaulted(object sender, EventArgs e)
 {
     Faulted?.Invoke(sender, e);
 }
Esempio n. 15
0
 private void HandleFaulted(AggregateException exception)
 {
     IsFaulted = true;
     Faulted?.Invoke(exception);
 }
Esempio 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());
                });
            }
        }
Esempio 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);
 }
Esempio n. 18
0
 private void OnFaulted(object sender, ProtocolErrorEventArgs e)
 {
     Faulted?.Invoke(this, new FaultedPluginEventArgs(this, e.Exception));
 }
Esempio n. 19
0
 protected virtual void OnFaulted()
 {
     Faulted?.Invoke(this, System.EventArgs.Empty);
 }
Esempio n. 20
0
 private void OnProcessFaulted(Task task)
 {
     Faulted?.Invoke(this, task.Exception);
 }
Esempio 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);
 }
 public SensorFaultedMesssage(Faulted faultedEvent)
 {
 }
Esempio n. 24
0
 private void InnerDuplexChannel_Faulted(object sender, EventArgs e)
 {
     Faulted?.Invoke(this, e);
 }
Esempio 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);
 }
Esempio n. 26
0
 private void OnFaulted(object sender, EventArgs e)
 {
     Faulted?.Invoke(this, e);
 }
Esempio n. 27
0
 private void OnFaulted(object sender, ProtocolErrorEventArgs e)
 {
     Faulted?.Invoke(this, e);
 }