Пример #1
0
        protected void OnDataReceived(object sender, DataGram dg)
        {
            lock (Locker)
            {
                SactaMsg.Deserialize(dg.Data, (msg) =>
                {
                    ManageOnLan(sender as UdpSocket, dg.Client.Address, (lan) =>
                    {
                        try
                        {
                            if (IsValid(msg))
                            {
                                switch (msg.Type)
                                {
                                case SactaMsg.MsgType.Init:
                                case SactaMsg.MsgType.Presence:
                                case SactaMsg.MsgType.Sectorization:
                                    Logger.Debug <ScvManager>($"On {Cfg.Id} from Sacta Lan {lan} Valid message {msg.Type} received");
                                    if (msg.Type == SactaMsg.MsgType.Init)
                                    {
                                        // todo
                                    }
                                    else if (msg.Type == SactaMsg.MsgType.Sectorization)
                                    {
                                        if (IsSecondSectMsg(msg) == false)
                                        {
                                            ProccessSectorization(msg, (ok, error) =>
                                            {
                                                // Será llamado por el WorkingThread del servicio PPAL en la gestion del evento que se genere...
                                                lock (Locker)
                                                {
                                                    if (ok)
                                                    {
                                                        Logger.Info <ScvManager>($"On {Cfg.Id}. Sectorization {msg.Id} Processed.");
                                                        SendSectAnsw((int)((SactaMsg.SectInfo)(msg.Info)).Version, 1);
                                                    }
                                                    else
                                                    {
                                                        Logger.Warn <ScvManager>($"On {Cfg.Id}. Sectorization {msg.Id} Rejected => {error}");
                                                        SendSectAnsw((int)((SactaMsg.SectInfo)(msg.Info)).Version, 0);
                                                    }
                                                    GlobalState = SactaState.SendingPresences;
                                                }
                                            });
                                        }
                                        else
                                        {
                                            Logger.Info <ScvManager>($"Sectorization Request (Red = {lan}, Versión = {((SactaMsg.SectInfo)(msg.Info)).Version}, IGNORED. Already in Progress...");
                                        }
                                    }
                                    else
                                    {
                                        // todo
                                    }
                                    break;

                                default:
                                    Logger.Warn <ScvManager>($"On {Cfg.Id} from Sacta Lan {lan} Invalid message {msg.Type} received");
                                    Logger.Trace <ScvManager>($"On {Cfg.Id} from Sacta Lan {lan} Invalid message received: {msg.ToString()}");
                                    break;
                                }
                            }
                            else
                            {
                                Logger.Warn <ScvManager>($"On {Cfg.Id} from Sacta Lan {lan} Invalid message {msg.Type} received");
                                Logger.Trace <ScvManager>($"On {Cfg.Id} from Sacta Lan {lan} Invalid message received: {msg.ToString()}");
                            }
                        }
                        catch (Exception x)
                        {
                            Logger.Exception <ScvManager>(x, $"On {Cfg.Id}");
                        }
                    });
                },
                                     (error) => // Error en el Deserialize.
                {
                    Logger.Warn <ScvManager>($"On {Cfg.Id} Deserialize Error: {error}");
                });
            }
        }
Пример #2
0
        protected void OnDataReceived(object sender, DataGram dg)
        {
            lock (Locker)
            {
                SactaMsg.Deserialize(dg.Data, (msg) =>
                {
                    ManageOnLan(sender as UdpSocket, (lan) =>
                    {
                        try
                        {
                            if (IsValid(msg))
                            {
                                switch (msg.Type)
                                {
                                case SactaMsg.MsgType.Init:
                                case SactaMsg.MsgType.Presence:
                                case SactaMsg.MsgType.SectAsk:
                                case SactaMsg.MsgType.SectAnswer:
                                    Logger.Debug <PsiManager>($"On PSI from Scv Lan {lan} Valid message {msg.Type} received.  Id = {msg.Id}");
                                    if (msg.Type == SactaMsg.MsgType.Init)
                                    {
                                        ScvInfo.LastSectMsgId = -1;
                                    }
                                    else if (msg.Type == SactaMsg.MsgType.Presence)
                                    {
                                    }
                                    else if (msg.Type == SactaMsg.MsgType.SectAsk)
                                    {
                                        Logger.Info <PsiManager>($"On PSI from Scv Lan {lan} Sectorization Sectoriztion Request Received");
                                        if (ScvInfo.LastSectMsgId != msg.Id)
                                        {
                                            // Si el mensaje llega por las dos redes solo respondo una vez...
                                            SafeLaunchEvent <SectorizationRequestArgs>(EventSectRequest, new SectorizationRequestArgs());
                                            ScvInfo.LastSectMsgId = msg.Id;
                                        }
                                    }
                                    else if (msg.Type == SactaMsg.MsgType.SectAnswer)
                                    {
                                        SactaMsg.SectAnswerInfo info = (SactaMsg.SectAnswerInfo)(msg.Info);
                                        Logger.Info <PsiManager>($"On PSI from Scv Lan {lan} Sectorization {info.Version} {(info.Result == 1 ? "Accepted" : "Rejected")}.");
                                    }
                                    break;

                                default:
                                    Logger.Warn <PsiManager>($"On PSI from SCV Lan {lan} Invalid message {msg.Type} received");
                                    Logger.Trace <PsiManager>($"On PSI from SCV Lan {lan} Invalid message received: {msg.ToString()}");
                                    break;
                                }
                            }
                            else
                            {
                                Logger.Warn <PsiManager>($"On PSI from SCV Lan {lan} Invalid message {msg.Type} received");
                                Logger.Trace <PsiManager>($"On PSI from SCV Lan {lan} Invalid message received: {msg.ToString()}");
                            }
                        }
                        catch (Exception x)
                        {
                            Logger.Exception <PsiManager>(x, $"On PSI");
                        }
                    });
                },
                                     (error) => // Error en el Deserialize.
                {
                    Logger.Warn <PsiManager>($"On PSI Deserialize Error: {error}");
                });
            }
        }