Ejemplo n.º 1
0
 private void OnCacheProductCreated(object sender, ProductCreatedEventArgs <EventArgs> e)
 {
     try
     {
         foreach (var args in e.Products)
         {
             if (args is TcpConnectingEventArgs)
             {
                 this.ShowTcpConnectingEvent(args as TcpConnectingEventArgs);
             }
             else if (args is TcpConnectedEventArgs)
             {
                 this.ShowTcpConnectedEvent(args as TcpConnectedEventArgs);
             }
             else if (args is TcpConnectFailedEventArgs)
             {
                 this.ShowTcpConnectFailedEvent(args as TcpConnectFailedEventArgs);
             }
             else if (args is TcpDisconnectedEventArgs)
             {
                 this.ShowTcpDisconnectedEvent(args as TcpDisconnectedEventArgs);
             }
             else if (args is TcpEndPointListeningEventArgs)
             {
                 this.ShowTcpEndPointListeningEvent(args as TcpEndPointListeningEventArgs);
             }
             else if (args is TcpEndPointListenFailedEventArgs)
             {
                 this.ShowTcpEndPointListenFailedEvent(args as TcpEndPointListenFailedEventArgs);
             }
             else if (args is NodeConnectedEventArgs)
             {
                 var theArgs = args as NodeConnectedEventArgs;
                 this.ShowNodeConnectedEvent(theArgs);
                 this.ShowNodeConnectionChangedOnLogListView(theArgs.LocalID, theArgs.RemoteID, true);
             }
             else if (args is NodeInterruptionEventArgs)
             {
                 var theArgs = args as NodeInterruptionEventArgs;
                 this.ShowNodeInterruptionEvent(theArgs);
                 this.ShowNodeConnectionChangedOnLogListView(theArgs.LocalID, theArgs.RemoteID, false);
             }
             else if (args is UserDataOutgoingEventArgs)
             {
                 this.ShowOutgoingUserDataEvent(args as UserDataOutgoingEventArgs);
             }
             else if (args is UserDataIncomingEventArgs)
             {
                 this.ShowIncomingUserDataEvent(args as UserDataIncomingEventArgs);
             }
         }
     }
     catch (System.Exception ex)
     {
         this.ShowLog(ex.Message);
     }
 }
Ejemplo n.º 2
0
 private void OnIncomingUserDataProductCreated(object sender, ProductCreatedEventArgs <IncomingPackage> e)
 {
     try
     {
         e.Products.ToList().ForEach(pkg =>
         {
             NotifyIncomingUserDataEvent(pkg);
         });
     }
     catch (System.Exception ex)
     {
         LogUtility.Error(string.Format("{0}", ex));
     }
 }
Ejemplo n.º 3
0
        private void OnCacheProductCreated(object sender, ProductCreatedEventArgs <Tuple <bool, DataCached> > e)
        {
            bool visible = false;

            try
            {
                foreach (var data in e.Products)
                {
                    if (!this.IsHandleCreated)
                    {
                        return;
                    }

                    var isIncomingData = data.Item1;
                    var remoteID       = data.Item2.RemoteDeviceID;

                    // 如果RemoteDevice中没有包含此ID,则添加。
                    if (!_remoteDeviceState.ContainsKey(remoteID))
                    {
                        _remoteDeviceState.Add(remoteID, false);
                        this.BeginInvoke(() => cbxRemoteIDs.Items.Add(remoteID));
                    }

                    // 如果允许显示,则更新界面。
                    visible = isIncomingData ? this.IncomingStreamVisable && this.IsHandleCreated : this.OutgoingStreamVisable && this.IsHandleCreated;
                    if (visible)
                    {
                        if (isIncomingData)
                        {
                            this.BeginInvoke(() => this.ShowIncomingStream(data.Item2 as IncomingData));
                        }
                        else
                        {
                            this.BeginInvoke(() => this.ShowOutgoingStream(data.Item2 as OutgoingData));
                        }
                    }
                }

                //
                this.BeginInvoke(() => { if (cbxRemoteIDs.Items.Count > 0 && cbxRemoteIDs.SelectedIndex == -1)
                                         {
                                             cbxRemoteIDs.SelectedIndex = 0;
                                         }
                                 });
            }
            catch (Exception /*ex*/)
            {
            }
        }
Ejemplo n.º 4
0
        private void OnProductCreated(object sender, ProductCreatedEventArgs <CommLogCreatedEventArgs> e)
        {
            try
            {
                e.Products.ToList().ForEach(p =>
                {
                    ICommStreamLogWriter writer = null;
                    var logKey = string.Format("{0}{1}-{2}{3}", p.LocalNodeType, p.LocalNodeCode, p.RemoteNodeType, p.RemoteNodeCode);

                    try
                    {
                        if (!_commLogWriters.TryGetValue(logKey, out writer))
                        {
                            writer = CreateStreamLogWriter(p);
                            _commLogWriters.GetOrAdd(logKey, writer);
                        }

                        // build a new record and write it to IO.
                        var record              = CommStreamLogFile.NewRecord();
                        record.Content          = p.Data;
                        record.Header.TimeStamp = p.Timestamp;
                        record.Header.Direction = p.IsIncomingData ? StreamDirection.Input : StreamDirection.Output;

                        writer.Write(record);
                    }
                    catch (Exception ex)
                    {
                        LogUtility.Error(string.Format("保存通信流日志时( {0})发生异常,{1}。\r\n 执行Rollover操作。", logKey, ex));

                        if (writer != null)
                        {
                            writer.Rollover();
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                LogUtility.Error(string.Format("保存通信日志时发生异常。{0}", ex));
            }
        }
Ejemplo n.º 5
0
        private void OnOutgoingUserDataProductCreated(object sender, ProductCreatedEventArgs <OutgoingPackage> e)
        {
            try
            {
                e.Products.ToList().ForEach(package =>
                {
                    try
                    {
                        this.SendOutgoingPackage(package);

                        this.NotityfyOutgoingUserDataEvent(package);
                    }
                    catch (System.Exception ex)
                    {
                        LogUtility.Error(string.Format("{0}", ex));
                    }
                });
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(string.Format("{0}", ex));
            }
        }