public DataSender(ConnectionBase interf, IDispatchData data)
        {
            _sendState.In(SendState.Idle).ExecuteOnEntry(() => Debug.WriteLine("DataSender: idle"))
                .On(SendEvent.Send).Goto(SendState.Wait1).Execute(SendData);

            _sendState.In(SendState.Wait1).ExecuteOnEntry(() => Debug.WriteLine("DataSender: Wait1"))
                .On(SendEvent.Retry).Goto(SendState.Wait2).Execute(SendData)
                .On(SendEvent.Succes).Goto(SendState.Finished).Execute(Succeed);

            _sendState.In(SendState.Wait2).ExecuteOnEntry(() => Debug.WriteLine("DataSender: Wait2"))
                .On(SendEvent.Retry).Goto(SendState.Wait3).Execute(SendData)
                .On(SendEvent.Succes).Goto(SendState.Finished).Execute(Succeed);

            _sendState.In(SendState.Wait3).ExecuteOnEntry(() => Debug.WriteLine("DataSender: Wait3"))
                .On(SendEvent.Retry).Goto(SendState.Wait4).Execute(SendData)
                .On(SendEvent.Succes).Goto(SendState.Finished).Execute(Succeed);

            _sendState.In(SendState.Wait4).ExecuteOnEntry(() => Debug.WriteLine("DataSender: Erronuous"))
               .On(SendEvent.Retry).Goto(SendState.Finished).Execute(Retry3)
               .On(SendEvent.Succes).Goto(SendState.Finished).Execute(Succeed);

            _sendState.In(SendState.Finished).ExecuteOnEntry(() =>
            {
                Dispose();
                Debug.WriteLine("DataSender: Finished");
            });

            _interface = interf;
            _data = data;

            _interface.DataReceived += InterfaceOnDataReceived;

            _sendState.Initialize(SendState.Idle);
            _sendState.Start();
        }
        public DispatchDataViewModel(IDispatchData data)
        {
            _data        = data;
            _data.Error += (q, r) =>
            {
                RaisePropertyChanged(() => ErrorMessage);
                RaisePropertyChanged(() => HasErrors);
            };

            _data.Dispatched += () => RaisePropertyChanged(() => IsDispatched);
        }
        public static void AddData(IDispatchData data)
        {
            if (data == null)
            {
                return;
            }
            var con = OpenConnections.FirstOrDefault(d => d.UnitId == data.DestinationAddress);

            if (con != null)
            {
                con.Connection.EnQueue(data);
            }
        }
Esempio n. 4
0
 public static void AddData(IDispatchData data)
 {
     CommunicationViewModel.AddData(data);
 }
        private async void Send(IDispatchData data)
        {
            var ds = new DataSender(_interf, data);

            WeakEventManager<DataQueue, EventArgs>.AddHandler(this, GenericMethods.GetPropertyName(() => Cancel), ds.Stop);

            data.Error += data_Error;

            ds.Start();

            var succes = await ds.SendCompleteAsync();
            if (succes)
            {
                _queueState.Fire(QueueEvent.DataSend);
            }
            else
            {
                data_Error(data, new ErrorEventArgs { Exception = new Exception("receive failed " + ds.ErrorMessage) });
            }

            data.Error -= data_Error;
        }
        public void EnqueData(IDispatchData data)
        {
            lock (_lock)
            {
                if (McuDisp.Contains(data))
                {
                    McuDisp.Remove(data);
                }

                Interlocked.Increment(ref _numsend);
                data.Id = _numsend;

                Debug.WriteLine("Enqueued data, count = " + McuDisp.Count);
                McuDisp.Add(data);

                _queueState.Fire(QueueEvent.Push);
            }
        }
 private void QueueData(IDispatchData data)
 {
     if (_dataQueue == null) throw new Exception("No connection to queue data");
     _dataQueue.EnqueData(data);
 }
 public void EnQueue(IDispatchData data)
 {
     _mcucomm.Fire(Cevts.QueueAdded, data);
 }