Ejemplo n.º 1
0
        /// <summary>
        /// sending routine for registered data:
        /// It's called by the delay-timer "_SendDelayTimer"
        /// </summary>
        private void sendToEDDN()
        {
            try
            {
                String    UserID;
                Schema_v2 Data = new Schema_v2();
                String    TimeStamp;
                String    commodity;

                TimeStamp = DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture);

                UserID = Form1.RegulatedNoiseSettings.GetUserID();

                // test or real ?
                if (Form1.RegulatedNoiseSettings.UseEddnTestSchema)
                {
                    Data.SchemaRef = "http://schemas.elite-markets.net/eddn/commodity/2/test";
                }
                else
                {
                    Data.SchemaRef = "http://schemas.elite-markets.net/eddn/commodity/2";
                }

                // fill the header
                Data.Header = new Schema_v2.Header_Class()
                {
                    SoftwareName     = "RegulatedNoise__DJ",
                    SoftwareVersion  = Form1.RegulatedNoiseSettings.getVersionString(),
                    GatewayTimestamp = TimeStamp,
                    UploaderID       = UserID
                };

                // prepare the message object
                Data.Message = new Schema_v2.Message_Class()
                {
                    SystemName  = "",
                    StationName = "",
                    Timestamp   = TimeStamp,
                    Commodities = new Schema_v2.Commodity_Class[_SendItems.Count]
                };

                // collect the commodity data
                for (int i = 0; i <= Data.Message.Commodities.GetUpperBound(0); i++)
                {
                    CsvRow Row = (CsvRow)_SendItems.Dequeue();

                    commodity = _caller.getCommodityBasename(Row.CommodityName);

                    // if it's a user added commodity send it anyhow to see that there's a unknown commodity
                    if (commodity.Equals(Program.COMMODITY_NOT_SET))
                    {
                        commodity = Row.CommodityName;
                    }

                    Data.Message.Commodities[i] = new Schema_v2.Commodity_Class()
                    {
                        Name        = commodity,
                        BuyPrice    = (Int32)Math.Floor(Row.BuyPrice),
                        SellPrice   = (Int32)Math.Floor(Row.SellPrice),
                        Demand      = (Int32)Math.Floor(Row.Demand),
                        DemandLevel = (Row.DemandLevel == "") ? null : Row.DemandLevel,
                        Supply      = (Int32)Math.Floor(Row.Supply),
                        SupplyLevel = (Row.SupplyLevel == "") ? null : Row.SupplyLevel,
                    };

                    if (i == 0)
                    {
                        Data.Message.SystemName  = Row.SystemName;
                        Data.Message.StationName = Row.StationName;
                    }
                }

                using (var client = new WebClient())
                {
                    try
                    {
                        Debug.Print(JsonConvert.SerializeObject(Data, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        }));

                        client.UploadString("http://eddn-gateway.elite-markets.net:8080/upload/", "POST", JsonConvert.SerializeObject(Data, new JsonSerializerSettings()
                        {
                            NullValueHandling = NullValueHandling.Ignore
                        }));
                    }
                    catch (WebException ex)
                    {
                        _logger.Log("Error uploading Json (v2)", true);
                        _logger.Log(ex.ToString(), true);
                        _logger.Log(ex.Message, true);
                        _logger.Log(ex.StackTrace, true);
                        if (ex.InnerException != null)
                        {
                            _logger.Log(ex.InnerException.ToString(), true);
                        }

                        using (WebResponse response = ex.Response)
                        {
                            using (Stream data = response.GetResponseStream())
                            {
                                if (data != null)
                                {
                                    StreamReader sr = new StreamReader(data);
                                    MsgBox.Show(sr.ReadToEnd(), "Error while uploading to EDDN (v2)");
                                }
                            }
                        }
                    }
                    finally
                    {
                        client.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Log("Error uploading Json (v2)", true);
                _logger.Log(ex.ToString(), true);
                _logger.Log(ex.Message, true);
                _logger.Log(ex.StackTrace, true);
                if (ex.InnerException != null)
                {
                    _logger.Log(ex.InnerException.ToString(), true);
                }

                cErr.showError(ex, "Error in EDDN-Sending-Thread (v2)");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// sending routine for registered data:
        /// It's called by the delay-timer "_SendDelayTimer"
        /// </summary>
        private void sendToEDDN()
        {
            try
            {
                String          UserID;
                Schema_v2       Data            = new Schema_v2();
                String          TimeStamp;
                String          commodity;

                TimeStamp = DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture);

                UserID = Program.DBCon.getIniValue<String>(IBE.MTSettings.tabSettings.DB_GROUPNAME, "UserName", Guid.NewGuid().ToString(), false, true);

                // test or real ?
                if (Program.DBCon.getIniValue<Boolean>(IBE.MTSettings.tabSettings.DB_GROUPNAME, "UseEddnTestSchema", false.ToString(), true))
                    Data.SchemaRef = "http://schemas.elite-markets.net/eddn/commodity/2/test";
                else
                    Data.SchemaRef = "http://schemas.elite-markets.net/eddn/commodity/2";

                // fill the header
                Data.Header = new Schema_v2.Header_Class() {SoftwareName        = "RegulatedNoise__DJ",
                                                            SoftwareVersion     = VersionHelper.Parts(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, 3),
                                                            GatewayTimestamp    = TimeStamp,
                                                            UploaderID          = UserID};

                // prepare the message object
                Data.Message    = new Schema_v2.Message_Class() {SystemName     = "",
                                                                 StationName    = "",
                                                                 Timestamp      = TimeStamp,
                                                                 Commodities    = new Schema_v2.Commodity_Class[_SendItems.Count]};

                // collect the commodity data
                for (int i = 0; i <= Data.Message.Commodities.GetUpperBound(0); i++)
                {
                    CsvRow Row      = (CsvRow)_SendItems.Dequeue();

                    commodity = Row.CommodityName;

                    // if it's a user added commodity send it anyhow to see that there's a unknown commodity
                    if(commodity.Equals(Program.COMMODITY_NOT_SET))
                        commodity = Row.CommodityName;

                    Data.Message.Commodities[i] = new Schema_v2.Commodity_Class()  {Name            = commodity,
                                                                                    BuyPrice        = (Int32)Math.Floor(Row.BuyPrice),
                                                                                    SellPrice       = (Int32)Math.Floor(Row.SellPrice),
                                                                                    Demand          = (Int32)Math.Floor(Row.Demand),
                                                                                    DemandLevel     = (Row.DemandLevel == "") ? null : Row.DemandLevel,
                                                                                    Supply          = (Int32)Math.Floor(Row.Supply),
                                                                                    SupplyLevel     = (Row.SupplyLevel == "") ? null : Row.SupplyLevel,
                                                                                    };

                    if(i==0){
                        Data.Message.SystemName     = Row.SystemName;
                        Data.Message.StationName    = Row.StationName;

                    }

                }

                using (var client = new WebClient())
                {
                    try
                    {
                        Debug.Print(JsonConvert.SerializeObject(Data, new JsonSerializerSettings() {NullValueHandling = NullValueHandling.Ignore}));

                        client.UploadString("http://eddn-gateway.elite-markets.net:8080/upload/", "POST", JsonConvert.SerializeObject(Data, new JsonSerializerSettings() {NullValueHandling = NullValueHandling.Ignore}));
                    }
                    catch (WebException ex)
                    {
                        _logger.Log("Error uploading Json (v2)", true);
                        _logger.Log(ex.ToString(), true);
                        _logger.Log(ex.Message, true);
                        _logger.Log(ex.StackTrace, true);
                        if (ex.InnerException != null)
                            _logger.Log(ex.InnerException.ToString(), true);

                        using (WebResponse response = ex.Response)
                        {
                            using (Stream data = response.GetResponseStream())
                            {
                                if (data != null)
                                {
                                    StreamReader sr = new StreamReader(data);
                                    MsgBox.Show(sr.ReadToEnd(), "Error while uploading to EDDN (v2)");
                                }
                            }
                        }
                    }
                    finally
                    {
                        client.Dispose();
                    }
                }

            }
            catch (Exception ex)
            {
                _logger.Log("Error uploading Json (v2)", true);
                _logger.Log(ex.ToString(), true);
                _logger.Log(ex.Message, true);
                _logger.Log(ex.StackTrace, true);
                if (ex.InnerException != null)
                    _logger.Log(ex.InnerException.ToString(), true);

                cErr.showError(ex, "Error in EDDN-Sending-Thread (v2)");
            }
        }