Exemplo n.º 1
0
        /// <summary>
        /// parses the incoming eddn data
        /// </summary>
        /// <param name="RawData"></param>
        private void parseEDDNRawData(String RawData)
        {
            try{
                Schema_v1        V1_Data;
                Schema_v2        V2_Data;
                RecievedEDDNArgs ArgsObject;

                if (RawData.Contains(@"commodity/1"))
                {
                    // old v1 schema

                    Debug.Print("recieved v1 message");
                    V1_Data = JsonConvert.DeserializeObject <Schema_v1>(RawData);

                    ArgsObject = new RecievedEDDNArgs()
                    {
                        Message  = "recieved data message (v1)",
                        InfoType = RecievedEDDNArgs.enMessageInfo.Commodity_v1_Recieved,
                        RawData  = RawData,
                        Data     = V1_Data
                    };
                }
                else if (RawData.Contains(@"commodity/2"))
                {
                    // new v2 schema
                    Debug.Print("recieved v2 message");
                    V2_Data = JsonConvert.DeserializeObject <Schema_v2>(RawData);

                    ArgsObject = new RecievedEDDNArgs()
                    {
                        Message  = "recieved data message (v2)",
                        InfoType = RecievedEDDNArgs.enMessageInfo.Commodity_v2_Recieved,
                        RawData  = RawData,
                        Data     = V2_Data
                    };
                }
                else
                {
                    // other unknown data

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

                DataRecieved(this, ArgsObject);
            }catch (Exception ex) {
                DataRecieved(this, new RecievedEDDNArgs()
                {
                    Message  = "Error while parsing recieved EDDN data :" + Environment.NewLine + ex.GetBaseException().Message.ToString() + Environment.NewLine + ex.StackTrace,
                    InfoType = RecievedEDDNArgs.enMessageInfo.ParseError,
                    RawData  = RawData,
                    Data     = null
                });
            }
        }
        /// <summary>
        /// parses the incoming eddn data
        /// </summary>
        /// <param name="RawData"></param>
        private void parseEDDNRawData(String RawData){
            try{
                Schema_v1           V1_Data;
                Schema_v2           V2_Data;
                RecievedEDDNArgs    ArgsObject;

                if(RawData.Contains(@"commodity/1")){
                    // old v1 schema

                    Debug.Print("recieved v1 message");
                    V1_Data = JsonConvert.DeserializeObject<Schema_v1>(RawData);

                    ArgsObject = new RecievedEDDNArgs() { Message     = "recieved data message (v1)",
                                                          InfoType    = RecievedEDDNArgs.enMessageInfo.Commodity_v1_Recieved, 
                                                          RawData     = RawData, 
                                                          Data        = V1_Data};

                }else if(RawData.Contains(@"commodity/2")){
                    // new v2 schema
                    Debug.Print("recieved v2 message");
                    V2_Data = JsonConvert.DeserializeObject<Schema_v2>(RawData);

                    ArgsObject = new RecievedEDDNArgs() { Message     = "recieved data message (v2)",
                                                          InfoType    = RecievedEDDNArgs.enMessageInfo.Commodity_v2_Recieved, 
                                                          RawData     = RawData, 
                                                          Data        = V2_Data};
                }else{ 
                    // other unknown data

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

                DataRecieved(this, ArgsObject);

            }catch (Exception ex){
                
                DataRecieved(this, new RecievedEDDNArgs() { Message     = "Error while parsing recieved EDDN data :" + Environment.NewLine + ex.GetBaseException().Message.ToString() + Environment.NewLine + ex.StackTrace,
                                                            InfoType    = RecievedEDDNArgs.enMessageInfo.ParseError, 
                                                            RawData     = RawData, 
                                                            Data        = null});
            }
        }