示例#1
0
        /// <summary>
        /// event-worker for JournalEventRecieved-event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void JournalEventRecieved(object sender, FileScanner.EDJournalScanner.JournalEventArgs e)
        {
            try
            {
                switch (e.EventType)
                {
                    case FileScanner.EDJournalScanner.JournalEvent.Docked:

                        if((!Program.actualCondition.System.EqualsNullOrEmpty(e.Data.Value<String>("StarSystem"))) || 
                           (!Program.actualCondition.Station.EqualsNullOrEmpty(e.Data.Value<String>("StationName"))))
                        {
                            if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_Visited", true.ToString(), false))
                                SaveEvent(DateTime.UtcNow, e.Data.Value<String>("StarSystem"), e.Data.Value<String>("StationName"), "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Visited", "");
                        }
                        else if(e.History.Find(x => ((x.EventType == FileScanner.EDJournalScanner.JournalEvent.Resurrect) && (e.History.IndexOf(x) < 2))) != null)
                        {
                            var resurrectEvent = e.History.Find(x => ((x.EventType == FileScanner.EDJournalScanner.JournalEvent.Resurrect) && (e.History.IndexOf(x) < 2)));

                            SaveEvent(e.Data.Value<DateTime>("timestamp"), 
                                      e.Data.Value<String>("StarSystem"), 
                                      e.Data.Value<String>("StationName"), 
                                      "", 
                                      "", 
                                      0, 
                                      0, 
                                      Program.CompanionIO.SGetCreditsTotal(), 
                                      "Resurrect", 
                                      String.Format("option: {0}\ncost: {1} cr.\nbankrupt = {2}", 
                                                    resurrectEvent.Data.Value<String>("Option"), 
                                                    resurrectEvent.Data.Value<Int32>("Cost"), 
                                                    resurrectEvent.Data.Value<Boolean>("Bankrupt") ? "yes" : "no"));

                        }
                        
                        break;
                    case FileScanner.EDJournalScanner.JournalEvent.FSDJump:
                        if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_JumpedTo", true.ToString(), false))
                        {
                            SaveEvent(e.Data.Value<DateTime>("timestamp"), 
                                      e.Data.Value<String>("StarSystem"),
                                      "", 
                                      "", 
                                      "", 
                                      0, 
                                      0, 
                                      Program.CompanionIO.SGetCreditsTotal(), 
                                      "Jumped To", 
                                      "", 
                                      e.Data.Value<Double>("JumpDist"));
                        }
                        break;

                    case FileScanner.EDJournalScanner.JournalEvent.Died:

                        String killInfo= "";
                        IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();  

                        if(e.Data.Value<String>("KillerName") != null)
                        {
                            
                            killInfo =  String.Format("killed by \t: {0}\n" +
                                                      "ship \t: {1}\n" +
                                                      "rank \t: {2}", 
                                                      (e.Data.Value<String>("KillerName_Localised") != null) ? e.Data.Value<String>("KillerName_Localised") : e.Data.Value<String>("KillerName"), 
                                                      cmpConverter.GetShipNameFromSymbol(Program.Data.BaseData.tbshipyardbase, e.Data.Value<String>("KillerShip")), 
                                                      e.Data.Value<String>("KillerRank")); 


                        }
                        else if(e.Data.Value<Object>("Killers") != null)
                        {
                            killInfo = "killed by wing:\n";
                            Int32 counter = 1;
                            foreach (JToken killerData in e.Data.SelectTokens("Killers.[*]"))
                            {

                                killInfo +=  String.Format("{4}{3}. \t{0}, \t{1}, \t{2}", 
                                                           killerData.Value<String>("Name"), 
                                                           cmpConverter.GetShipNameFromSymbol(Program.Data.BaseData.tbshipyardbase, killerData.Value<String>("Ship")), 
                                                           killerData.Value<String>("Rank"), 
                                                           counter, 
                                                           counter > 1 ? "\n":""); 
                                counter++;
                            }
                        }

                        SaveEvent(e.Data.Value<DateTime>("timestamp"), 
                                  Program.actualCondition.System, 
                                  "", 
                                  "", 
                                  "", 
                                  0, 
                                  0, 
                                  Program.CompanionIO.SGetCreditsTotal(), 
                                  "Died", 
                                  killInfo);
                        break;

                    case FileScanner.EDJournalScanner.JournalEvent.Resurrect:
                        break;

                    case FileScanner.EDJournalScanner.JournalEvent.Touchdown:
                        if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_TouchDown", true.ToString(), false))
                        {
                            SaveEvent(e.Data.Value<DateTime>("timestamp"), 
                                      Program.actualCondition.System,
                                      "", 
                                      "", 
                                      "", 
                                      0, 
                                      0, 
                                      Program.CompanionIO.SGetCreditsTotal(), 
                                      "Touchdown", 
                                      String.Format("landed on {0}{1}\n" +
                                                    "long: {3}\n" +
                                                    "lat : {2}",
                                                    Program.actualCondition.Body, 
                                                    String.IsNullOrWhiteSpace(Program.actualCondition.BodyType) ? "" : " (" + Program.actualCondition.BodyType + ")",
                                                    e.Data.Value<Double>("Latitude"), 
                                                    e.Data.Value<Double>("Longitude")));
                        }
                        break;

                    case FileScanner.EDJournalScanner.JournalEvent.Liftoff:
                        if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_Liftoff", true.ToString(), false))
                        {
                            SaveEvent(e.Data.Value<DateTime>("timestamp"), 
                                      Program.actualCondition.System,
                                      "", 
                                      "", 
                                      "", 
                                      0, 
                                      0, 
                                      Program.CompanionIO.SGetCreditsTotal(), 
                                      "Liftoff", 
                                      String.Format("liftoff from {0}{1}\n" +
                                                    "long: {3}\n" +
                                                    "lat : {2}",
                                                    Program.actualCondition.Body, 
                                                    String.IsNullOrWhiteSpace(Program.actualCondition.BodyType) ? "" : " (" + Program.actualCondition.BodyType + ")",
                                                    e.Data.Value<Double>("Latitude"), 
                                                    e.Data.Value<Double>("Longitude")));
                        }
                        break;

                    case FileScanner.EDJournalScanner.JournalEvent.Scan:
                        if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_Scan", true.ToString(), false))
                        {
                            TextHelper txtHelp = new TextHelper();

                            Font usedFont = m_GUI.dgvCommandersLog.Columns["notes"].DefaultCellStyle.Font != null ? m_GUI.dgvCommandersLog.Columns["notes"].DefaultCellStyle.Font : m_GUI.dgvCommandersLog.DefaultCellStyle.Font ; 
                            System.Text.StringBuilder data  = new System.Text.StringBuilder();
                            System.Text.StringBuilder rings = new System.Text.StringBuilder();
                         
                            Int32 fullLength = 170;

                            if(e.Data.Value<Object>("StarType") != null)
                            {
                                data.AppendLine(String.Format("{0} :   {1}   (Star)", txtHelp.FixedLength("Name", usedFont, fullLength),  e.Data.Value<String>("BodyName")));
                                data.AppendLine(String.Format("{0} :   {1}", txtHelp.FixedLength("Type", usedFont, fullLength),  e.Data.Value<String>("StarType")));
                                data.AppendLine(String.Format("{0} :   {1:N1} ls", txtHelp.FixedLength("Distance", usedFont, fullLength),  e.Data.Value<Double>("DistanceFromArrivalLS")));

                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Radius")))
                                    data.AppendLine(String.Format("{0} :   {1:N1} km", txtHelp.FixedLength("Radius", usedFont, fullLength),  e.Data.Value<Double>("Radius")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("StellarMass")))
                                    data.AppendLine(String.Format("{0} :   {1:N1} stellar masses", txtHelp.FixedLength("Mass", usedFont, fullLength),  e.Data.Value<Double>("StellarMass")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Age_MY")))
                                    data.AppendLine(String.Format("{0} :   {1:N1} my", txtHelp.FixedLength("Age", usedFont, fullLength),  e.Data.Value<Double>("Age_MY")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfaceTemperature")))
                                    data.AppendLine(String.Format("{0} :   {1:N1}°K  ( {2:N1}°C )", txtHelp.FixedLength("Temp.", usedFont, fullLength),  e.Data.Value<Double>("SurfaceTemperature"), e.Data.Value<Double>("SurfaceTemperature") - 273.15));
                            }
                            else
                            {
                                System.Text.StringBuilder materials = new System.Text.StringBuilder();

                                data.AppendLine(String.Format("{0} :   {1}   (Planet/Moon)", txtHelp.FixedLength("Name", usedFont, fullLength),  e.Data.Value<String>("BodyName")));
                                data.AppendLine(String.Format("{0} :   {1:N1} ls", txtHelp.FixedLength("Distance", usedFont, fullLength),  e.Data.Value<Double>("DistanceFromArrivalLS")));

                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("TerraformState")))
                                    data.AppendLine(String.Format("{0} :   {1}", txtHelp.FixedLength("Terraform", usedFont, fullLength),  e.Data.Value<String>("TerraformState")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("PlanetClass")))
                                    data.AppendLine(String.Format("{0} :   {1}", txtHelp.FixedLength("Class", usedFont, fullLength),  e.Data.Value<String>("PlanetClass")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Atmosphere")))
                                    data.AppendLine(String.Format("{0} :   {1}", txtHelp.FixedLength("Atmosphere", usedFont, fullLength),  e.Data.Value<String>("Atmosphere")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Volcanism")))
                                    data.AppendLine(String.Format("{0} :   {1}", txtHelp.FixedLength("Volcanism", usedFont, fullLength),  e.Data.Value<String>("Volcanism")));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfaceGravity")))
                                    data.AppendLine(String.Format("{0} :   {1:N2} g", txtHelp.FixedLength("Gravity", usedFont, fullLength),  e.Data.Value<Double>("SurfaceGravity")/10.0));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfaceTemperature")))
                                    data.AppendLine(String.Format("{0} :   {1:N1}°K  ( {2:N1}°C )", txtHelp.FixedLength("Temp.", usedFont, fullLength),  e.Data.Value<Double>("SurfaceTemperature"), e.Data.Value<Double>("SurfaceTemperature") - 273.15));
                                if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfacePressure")))
                                    data.AppendLine(String.Format("{0} :   {1:N1} atm", txtHelp.FixedLength("Pressure", usedFont, fullLength),  e.Data.Value<Double>("SurfacePressure") / 100000.0));
                                if((!String.IsNullOrWhiteSpace(e.Data.Value<String>("Landable"))) && e.Data.Value<Boolean>("Landable"))
                                    data.AppendLine(String.Format("{0} :   {1}", txtHelp.FixedLength("Landable", usedFont, fullLength),  e.Data.Value<Boolean>("Landable") ? "yes" : "no"));

                                if (e.Data.Value<Object>("Materials") != null)
                                {
                                    TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

                                    foreach (JProperty  material in e.Data.SelectToken("Materials"))
                                    {
                                        if(materials.Length == 0)
                                            materials.AppendFormat(String.Format("\n{0} :   ", txtHelp.FixedLength("Materials", usedFont, fullLength)));
                                        else
                                            materials.AppendFormat(", ");
                                        materials.AppendFormat("{0} : {1:N1}%", textInfo.ToTitleCase(material.Name), (Double)material.Value);
                                    }
                                    data.AppendLine(materials.ToString());
                                }
                            }

                            if(e.Data.Value<Object>("Rings") != null)
                            {
                                foreach (JObject ring in e.Data.SelectTokens("Rings.[*]"))
                                {
                                    String classname = ring.Value<String>("RingClass").Replace("eRingClass_","")
                                                                                      .Replace("Rich"," Rich")
                                                                                      .Replace("Metal","Metall");

                                    if(rings.Length == 0)
                                        rings.AppendLine(String.Format("\n{0} • {1} (Type: {2})", txtHelp.FixedLength("Belts", usedFont, 100), ring.Value<String>("Name"), classname));
                                    else
                                        rings.AppendLine(String.Format("{0} • {1} (Type: {2})", txtHelp.FixedLength("", usedFont, 100), ring.Value<String>("Name"), classname));
                                }

                                data.Append(rings);
                            }

                            SaveEvent(e.Data.Value<DateTime>("timestamp"), 
                                      Program.actualCondition.System,
                                      "", 
                                      "", 
                                      "", 
                                      0, 
                                      0, 
                                      Program.CompanionIO.SGetCreditsTotal(), 
                                      "Scan", 
                                      data.ToString());
                        }
                        break;


                }

            }
            catch (Exception ex)
            {
                CErr.processError(ex, "Error while processing the JournalEventRecieved-event");
            }
        }
示例#2
0
        /// <summary>
        /// send the outfitting data of this station
        /// </summary>
        /// <param name="stationData">json object with companion data</param>
        public void SendOutfittingData(JObject dataObject)
        {
            Int32 objectCount = 0;
            Boolean writeToFile = false;
            StreamWriter writer = null;
            String debugFile = @"C:\temp\outfitting_ibe.csv";
            SQL.Datasets.dsEliteDB.tboutfittingbaseDataTable baseData;
            System.Text.RegularExpressions.Regex allowedPattern = new System.Text.RegularExpressions.Regex("(^Hpt_|^Int_|_Armour_)");

            try
            {
                if(m_SenderIsActivated && m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostOutfittingData", true.ToString(), false))
                {
                    IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();
                    String systemName   = dataObject.SelectToken("lastSystem.name").ToString();
                    String stationName  = dataObject.SelectToken("lastStarport.name").ToString();

                    if((m_ID_of_Outfitting_Station.Item1 != systemName + "|" + stationName) || ((DateTime.Now - m_ID_of_Outfitting_Station.Item2).TotalMinutes >= 60))
                    { 
                        m_ID_of_Outfitting_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);

                        StringBuilder outfittingStringEDDN = new StringBuilder();

                        outfittingStringEDDN.Append(String.Format("\"message\": {{"));

                        outfittingStringEDDN.Append(String.Format("\"systemName\":\"{0}\", "    , dataObject.SelectToken("lastSystem.name").ToString()));
                        //outfittingStringEDDN.Append(String.Format("\"systemId\":\"{0}\", "      , dataObject.SelectToken("lastSystem.id").ToString()));
                        //outfittingStringEDDN.Append(String.Format("\"systemAddress\":\"{0}\", " , dataObject.SelectToken("lastSystem.address").ToString()));
                        

                        outfittingStringEDDN.Append(String.Format("\"stationName\":\"{0}\", " , dataObject.SelectToken("lastStarport.name").ToString()));
                        //outfittingStringEDDN.Append(String.Format("\"stationId\":\"{0}\", "   , dataObject.SelectToken("lastStarport.id").ToString()));

                        outfittingStringEDDN.Append(String.Format("\"timestamp\":\"{0}\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));

                        outfittingStringEDDN.Append(String.Format("\"modules\": ["));

                        if(writeToFile)
                        { 
                            if(File.Exists(debugFile))
                                File.Delete(debugFile);

                            writer = new StreamWriter(File.OpenWrite(debugFile));
                        }

                        baseData = new SQL.Datasets.dsEliteDB.tboutfittingbaseDataTable();
                        m_lDBCon.Execute("select * from tbOutfittingBase;", (System.Data.DataTable)baseData);
                        

                        foreach (JToken outfittingItem in dataObject.SelectTokens("lastStarport.modules.*"))
                        {

                            if(allowedPattern.IsMatch(outfittingItem.Value<String>("name")) && 
                              ((outfittingItem.Value<String>("sku") == null) || (outfittingItem.Value<String>("sku").Equals("ELITE_HORIZONS_V_PLANETARY_LANDINGS"))) && 
                              (!outfittingItem.Value<String>("name").Equals("Int_PlanetApproachSuite")))
                            { 
                                OutfittingObject outfitting = cmpConverter.GetOutfittingFromFDevIDs(baseData, outfittingItem, false);

                                if(objectCount > 0)
                                    outfittingStringEDDN.Append(", ");

                                if(writeToFile)
                                {
                                    writer.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", 
                                        systemName, stationName, outfitting.Category, outfitting.Name, outfitting.Mount, 
                                        outfitting.Guidance, outfitting.Ship, outfitting.Class, outfitting.Rating, 
                                        DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
                                }

                                outfittingStringEDDN.Append(String.Format("\"{0}\", ", outfittingItem.Value<String>("name")));

                                outfittingStringEDDN.Remove(outfittingStringEDDN.Length-1, 1);
                                outfittingStringEDDN.Replace(",", "", outfittingStringEDDN.Length-1, 1);

                                objectCount++;
                            }
                        } 

                        outfittingStringEDDN.Append("]}");

                        if(objectCount > 0)
                        { 
                            _Send_Outfitting.Enqueue(outfittingStringEDDN);
                            _SendDelayTimer_Outfitting.Start();
                            m_ID_of_Outfitting_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
                        }

                        if(writeToFile)
                        {
                            writer.Close();
                            writer.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while extracting outfitting data for eddn", ex);
            }
        }
示例#3
0
        /// <summary>
        /// send the shipyard data of this station
        /// </summary>
        /// <param name="stationData">json object with companion data</param>
        public void SendShipyardData(JObject dataObject)
        {
            Int32 objectCount = 0;
            Boolean writeToFile = false;
            StreamWriter writer = null;
            String debugFile = @"C:\temp\shipyard_ibe.csv";
            SQL.Datasets.dsEliteDB.tbshipyardbaseDataTable baseData;

            try
            {
                if(m_SenderIsActivated && m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostShipyardData", true.ToString(), false))
                {
                    IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();  

                    String systemName   = dataObject.SelectToken("lastSystem.name").ToString();
                    String stationName = dataObject.SelectToken("lastStarport.name").ToString();

                    if((m_ID_of_Shipyard_Station.Item1 != systemName + "|" + stationName) || ((DateTime.Now - m_ID_of_Shipyard_Station.Item2).TotalMinutes >= 60))
                    { 
                        StringBuilder shipyardStringEDDN = new StringBuilder();

                        shipyardStringEDDN.Append(String.Format("\"message\": {{"));

                        shipyardStringEDDN.Append(String.Format("\"systemName\":\"{0}\", ",dataObject.SelectToken("lastSystem.name").ToString()));
                        shipyardStringEDDN.Append(String.Format("\"stationName\":\"{0}\", ",dataObject.SelectToken("lastStarport.name").ToString()));

                        shipyardStringEDDN.Append(String.Format("\"timestamp\":\"{0}\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));

                        shipyardStringEDDN.Append(String.Format("\"ships\": ["));

                        if(writeToFile)
                        { 
                            if(File.Exists(debugFile))
                                File.Delete(debugFile);

                            writer = new StreamWriter(File.OpenWrite(debugFile));
                        }

                        if(dataObject.SelectToken("lastStarport.ships", false) != null)
                        { 
                            baseData = new SQL.Datasets.dsEliteDB.tbshipyardbaseDataTable();
                            m_lDBCon.Execute("select * from tbShipyardBase;", (System.Data.DataTable)baseData);

                            List<JToken> allShips = dataObject.SelectTokens("lastStarport.ships.shipyard_list.*").ToList();
                            allShips.AddRange(dataObject.SelectTokens("lastStarport.ships.unavailable_list.[*]").ToList());

                            foreach (JToken outfittingItem in allShips)
                            {
                                if(!String.IsNullOrWhiteSpace(outfittingItem.Value<String>("name")))
                                {
                                    ShipyardObject shipyardItem = cmpConverter.GetShipFromFDevIDs(baseData, outfittingItem, false);
                                    //ShipyardObject shipyardItem = cmpConverter.GetShipFromCompanion(outfittingItem, false);

                                    if(writeToFile)
                                    {
                                        writer.WriteLine(String.Format("{0},{1},{2},{3}", 
                                            systemName, stationName, shipyardItem.Name, 
                                            DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
                                    }

                                    shipyardStringEDDN.Append(String.Format("\"{0}\", ", outfittingItem.Value<String>("name")));

                                    objectCount++;
                                    
                                }
                            } 

                            shipyardStringEDDN.Remove(shipyardStringEDDN.Length-2, 2);
                            shipyardStringEDDN.Append("]}");

                            if(objectCount > 0)
                            { 
                                _Send_Shipyard.Enqueue(shipyardStringEDDN);
                                _SendDelayTimer_Shipyard.Start();
                                m_ID_of_Shipyard_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
                            }

                            if(writeToFile)
                            {
                                writer.Close();
                                writer.Dispose();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while extracting shipyard data for eddn", ex);
            }
        }
示例#4
0
        /// <summary>
        /// send the commodity data of this station
        /// </summary>
        /// <param name="stationData">json object with companion data</param>
        public void SendCommodityData(JObject dataObject)
        {
            Int32 objectCount = 0;
            Boolean writeToFile = false;
            StreamWriter writer = null;
            String debugFile = @"C:\temp\commodity_ibe.csv";
            SQL.Datasets.dsEliteDB.tbcommoditybaseDataTable baseData;

            try
            {
                if(m_SenderIsActivated && 
                   m_lDBCon.getIniValue<Boolean>(IBE.EDDN.EDDNView.DB_GROUPNAME, "EDDNPostCompanionData", true.ToString(), false))
                {
                    IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter();
                    String systemName   = dataObject.SelectToken("lastSystem.name").ToString();
                    String stationName  = dataObject.SelectToken("lastStarport.name").ToString();

                    if((m_ID_of_Commodity_Station.Item1 != systemName + "|" + stationName) || ((DateTime.Now - m_ID_of_Commodity_Station.Item2).TotalMinutes >= 60))
                    { 
                        m_ID_of_Commodity_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);

                        StringBuilder commodityStringEDDN = new StringBuilder();

                        commodityStringEDDN.Append(String.Format("\"message\": {{"));

                        commodityStringEDDN.Append(String.Format("\"systemName\":\"{0}\", "    , dataObject.SelectToken("lastSystem.name").ToString()));
                        //commodityStringEDDN.Append(String.Format("\"systemId\":\"{0}\", "      , dataObject.SelectToken("lastSystem.id").ToString()));
                        //commodityStringEDDN.Append(String.Format("\"systemAddress\":\"{0}\", " , dataObject.SelectToken("lastSystem.address").ToString()));
                        

                        commodityStringEDDN.Append(String.Format("\"stationName\":\"{0}\", " , dataObject.SelectToken("lastStarport.name").ToString()));
                        //commodityStringEDDN.Append(String.Format("\"stationId\":\"{0}\", "   , dataObject.SelectToken("lastStarport.id").ToString()));

                        commodityStringEDDN.Append(String.Format("\"timestamp\":\"{0}\", ", DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));

                        commodityStringEDDN.Append(String.Format("\"commodities\": ["));

                        if(writeToFile)
                        { 
                            if(File.Exists(debugFile))
                                File.Delete(debugFile);

                            writer = new StreamWriter(File.OpenWrite(debugFile));
                        }

                        baseData = new SQL.Datasets.dsEliteDB.tbcommoditybaseDataTable();
                        m_lDBCon.Execute("select * from tbcommodityBase;", (System.Data.DataTable)baseData);

                        foreach (JToken commodityItem in dataObject.SelectTokens("lastStarport.commodities[*]"))
                        {

                            if(!commodityItem.Value<String>("categoryname").Equals("NonMarketable", StringComparison.InvariantCultureIgnoreCase))
                            {

                                CommodityObject commodity = cmpConverter.GetCommodityFromFDevIDs(baseData, commodityItem, false);
                                //commodityObject commodity = cmpConverter.GetcommodityFromCompanion(commodityItem, false);

                                int? dbValue = String.IsNullOrWhiteSpace(commodityItem.Value<String>("demandBracket")) ? null : commodityItem.Value<int?>("demandBracket");

                                if((commodity != null) && (dbValue.HasValue))
                                { 

                                    if (objectCount > 0)
                                        commodityStringEDDN.Append(", {");
                                    else
                                        commodityStringEDDN.Append("{");

                                    if(writeToFile)
                                    {
                                        writer.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", 
                                            systemName, stationName, commodity.Id, commodity.Name, commodity.Category, commodity.Average, 
                                            DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture)));
                                    }

                                    commodityStringEDDN.Append(String.Format("\"name\":\"{0}\", ",    commodityItem.Value<String>("name")));
                                    //commodityStringEDDN.Append(String.Format("\"id\":\"{0}\", ",    commodity.Id));
                                    commodityStringEDDN.Append(String.Format("\"meanPrice\":{0}, ",   commodityItem.Value<Int32>("meanPrice")));
                                    commodityStringEDDN.Append(String.Format("\"buyPrice\":{0}, ",    commodityItem.Value<Int32>("buyPrice")));
                                    commodityStringEDDN.Append(String.Format("\"sellPrice\":{0}, ",   commodityItem.Value<Int32>("sellPrice")));
                                    

                                    commodityStringEDDN.Append(String.Format("\"demandBracket\":{0}, ", commodityItem.Value<int?>("demandBracket")));

                                    if (commodityItem.Value<int?>("demandBracket") == 0)
                                        commodityStringEDDN.Append(String.Format("\"demand\":{0}, ",      0));
                                    else
                                        commodityStringEDDN.Append(String.Format("\"demand\":{0}, ",      commodityItem.Value<Int32>("demand")));


                                    commodityStringEDDN.Append(String.Format("\"stockBracket\":{0}, ", commodityItem.Value<int?>("stockBracket")));

                                    if (commodityItem.Value<int?>("stockBracket") == 0)
                                        commodityStringEDDN.Append(String.Format("\"stock\":{0}, ",      0));
                                    else
                                        commodityStringEDDN.Append(String.Format("\"stock\":{0}, ",      commodityItem.Value<Int32>("demand")));

                                    
                                    if(commodityItem.SelectTokens("statusFlags.[*]").Count() > 0 )
                                    {
                                        commodityStringEDDN.Append(String.Format("\"statusFlags\": ["));
                                        foreach (JToken statusItem in commodityItem.SelectTokens("statusFlags.[*]"))
                                        {
                                            commodityStringEDDN.Append(String.Format("\"{0}\", ",      statusItem.Value<String>()));
                                        }

                                        commodityStringEDDN.Remove(commodityStringEDDN.Length-1, 1);
                                        commodityStringEDDN.Replace(",", "], ", commodityStringEDDN.Length-1, 1);
                                    }

                                    commodityStringEDDN.Remove(commodityStringEDDN.Length-1, 1);
                                    commodityStringEDDN.Replace(",", "}", commodityStringEDDN.Length-1, 1);

                                    objectCount++;
                                }
                            }
                        } 

                        commodityStringEDDN.Append("]}");

                        if(objectCount > 0)
                        { 
                            _Send_Commodity.Enqueue(commodityStringEDDN);
                            _SendDelayTimer_Commodity.Start();
                            m_ID_of_Commodity_Station = new Tuple<String, DateTime>(systemName +"|" + stationName, DateTime.Now);
                        }

                        if(writeToFile)
                        {
                            writer.Close();
                            writer.Dispose();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error while extracting commodity data for eddn", ex);
            }
        }