Пример #1
0
        // Node 状态变更。
        public void OnConnectionStatusChanged(IDtuConnection c, WorkingStatus oldStat, WorkingStatus newStat)
        {
            string dtuCode = c.DtuID;

            if (newStat == WorkingStatus.IDLE)
            {
                // Online;
                if (OnDTUConnectionStatusChanged != null)
                {
                    OnDTUConnectionStatusChanged.Invoke(new DTUConnectionStatusChangedMsg
                    {
                        DTUID             = dtuCode,
                        IsOnline          = true,
                        TimeStatusChanged = DateTime.Now //c.LoginTime
                    });
                }
                if (c is GprsDtuConnection)
                {
                    var cg = c as GprsDtuConnection;
                    Log.InfoFormat("Gprs Node Online: {0}, ip={1}, phone={2}.", cg.DtuID, cg.IP, cg.PhoneNumber);
                }
                else if (c is FileDtuConnection)
                {
                    var cf = c as FileDtuConnection;
                    Log.InfoFormat("File Node Online: {0}, path={1}.", cf.DtuID, cf.FilePath);
                }
                else
                {
                    Log.WarnFormat("Node Unkown Type Online");
                }
                CheckDtuInfo(c);
                DACWorker w = FindWorker(dtuCode);

                if (w != null)
                {
                    DacTaskContext ctx = w.GetContext();
                    ctx.UpdateConnection(c);
                    w.AssignContext(ctx);
                }
            }
            else if (newStat == WorkingStatus.NA)
            {
                if (c is GprsDtuConnection)
                {
                    var cg = c as GprsDtuConnection;
                    Log.InfoFormat("Gprs Node Offline: {0}, ip={1}, phone={2}.", cg.DtuID, cg.IP, cg.PhoneNumber);
                }
                else if (c is FileDtuConnection)
                {
                    var cf = c as FileDtuConnection;
                    Log.InfoFormat("File Node Offline: {0}, path={1}.", cf.DtuID, cf.FilePath);
                }
                else
                {
                    Log.WarnFormat("Node Unkown Type Offline");
                }
                // offline;
                if (OnDTUConnectionStatusChanged != null)
                {
                    OnDTUConnectionStatusChanged.Invoke(new DTUConnectionStatusChangedMsg
                    {
                        DTUID             = dtuCode,
                        IsOnline          = false,
                        TimeStatusChanged = DateTime.Now
                    });
                }
            }
        }