Inheritance: System.EventArgs
Esempio n. 1
0
        /// <summary>
        /// parses the incoming eddn data
        /// </summary>
        /// <param name="RawData"></param>
        private void ParseEDDNRawData(String RawData)
        {
            try
            {
                EDDNRecievedArgs ArgsObject;
                
                if (RawData.Contains(@"ED-IBE"))
                    Debug.Print("here");

                if (RawData.Contains(@"commodity/1"))
                {
                    // new v2 schema
                    Debug.Print("recieved v1 commodities message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data commodities message (v1)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Commodity_v1_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };

                }
                if (RawData.Contains(@"commodity/2"))
                {
                    // new v2 schema
                    Debug.Print("recieved v2 commodities message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data commodities message (v2)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Commodity_v2_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };

                }
                else if (RawData.Contains(@"commodity/3"))
                {
                    // new v2 schema
                    Debug.Print("recieved v3 commodities message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data commodities message (v3)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Commodity_v3_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };
                }
                else if (RawData.Contains(@"outfitting/1"))
                {
                    // outfitting schema
                    Debug.Print("recieved outfitting v1 message");
                    
                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data outfitting message (v1)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Outfitting_v1_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };

                }
                else if (RawData.Contains(@"outfitting/2"))
                {
                    // outfitting schema
                    Debug.Print("recieved outfitting v2 message");
                    
                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data outfitting message (v2)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Outfitting_v2_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };

                }
                else if (RawData.Contains(@"shipyard/1"))
                {
                    // shipyardItem schema
                    Debug.Print("recieved shipyard v1 message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data shipyard message (v1)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Shipyard_v1_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };

                }
                else if (RawData.Contains(@"shipyard/2"))
                {
                    // shipyardItem schema
                    Debug.Print("recieved shipyard v2 message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved data shipyard message (v2)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Shipyard_v2_Recieved,
                        RawData = RawData,
                        Data = JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress = m_Adress
                    };

                }
                else
                {
                    // other unknown data

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message = "recieved unknown data message",
                        InfoType = EDDNRecievedArgs.enMessageInfo.UnknownData,
                        RawData = RawData,
                        Data = null,
                        Adress = m_Adress
                    };
                }

                if(ArgsObject != null)
                {
                    // only for one listener per time this is allowed
                    lock (m_RecieveLocker)
                    { 
                        DataRecieved(this, ArgsObject);
                    }
                }
            }
            catch (Exception ex)
            {
                DataRecieved(this, new EDDNRecievedArgs()
                {
                    Message = "Error while parsing recieved EDDN data :" + Environment.NewLine + ex.GetBaseException().Message.ToString() + Environment.NewLine + ex.StackTrace,
                    InfoType = EDDNRecievedArgs.enMessageInfo.ParseError,
                    RawData = RawData,
                    Data = null
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// parses the incoming eddn data
        /// </summary>
        /// <param name="RawData"></param>
        private void ParseEDDNRawData(String RawData)
        {
            try
            {
                EDDNRecievedArgs ArgsObject;

                if (RawData.Contains(@"ED-IBE"))
                {
                    Debug.Print("here");
                }

                if (RawData.Contains(@"commodity/1"))
                {
                    // new v2 schema
                    Debug.Print("recieved v1 commodities message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data commodities message (v1)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Commodity_v1_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                if (RawData.Contains(@"commodity/2"))
                {
                    // new v2 schema
                    Debug.Print("recieved v2 commodities message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data commodities message (v2)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Commodity_v2_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                else if (RawData.Contains(@"commodity/3"))
                {
                    // new v2 schema
                    Debug.Print("recieved v3 commodities message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data commodities message (v3)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Commodity_v3_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                else if (RawData.Contains(@"outfitting/1"))
                {
                    // outfitting schema
                    Debug.Print("recieved outfitting v1 message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data outfitting message (v1)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Outfitting_v1_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                else if (RawData.Contains(@"outfitting/2"))
                {
                    // outfitting schema
                    Debug.Print("recieved outfitting v2 message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data outfitting message (v2)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Outfitting_v2_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                else if (RawData.Contains(@"shipyard/1"))
                {
                    // shipyardItem schema
                    Debug.Print("recieved shipyard v1 message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data shipyard message (v1)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Shipyard_v1_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                else if (RawData.Contains(@"shipyard/2"))
                {
                    // shipyardItem schema
                    Debug.Print("recieved shipyard v2 message");

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved data shipyard message (v2)",
                        InfoType = EDDNRecievedArgs.enMessageInfo.Shipyard_v2_Recieved,
                        RawData  = RawData,
                        Data     = JsonConvert.DeserializeObject <Newtonsoft.Json.Linq.JObject>(RawData),
                        Adress   = m_Adress
                    };
                }
                else
                {
                    // other unknown data

                    ArgsObject = new EDDNRecievedArgs()
                    {
                        Message  = "recieved unknown data message",
                        InfoType = EDDNRecievedArgs.enMessageInfo.UnknownData,
                        RawData  = RawData,
                        Data     = null,
                        Adress   = m_Adress
                    };
                }

                if (ArgsObject != null)
                {
                    // only for one listener per time this is allowed
                    lock (m_RecieveLocker)
                    {
                        DataRecieved(this, ArgsObject);
                    }
                }
            }
            catch (Exception ex)
            {
                DataRecieved(this, new EDDNRecievedArgs()
                {
                    Message  = "Error while parsing recieved EDDN data :" + Environment.NewLine + ex.GetBaseException().Message.ToString() + Environment.NewLine + ex.StackTrace,
                    InfoType = EDDNRecievedArgs.enMessageInfo.ParseError,
                    RawData  = RawData,
                    Data     = null
                });
            }
        }