private void SendMarketData_i()
{
try
{
Queue activeQueue = null;
String UserID;
EDDNCommodity_v3 Data;
String TimeStamp;
String commodity;
throw new NotImplementedException("function SendMarketData_i ist not tested yet !!");
do{
TimeStamp = DateTime.Now.ToString("s", CultureInfo.InvariantCulture) + DateTime.Now.ToString("zzz", CultureInfo.InvariantCulture);
UserID = UserIdentification();
Data = new EDDNCommodity_v3();
// test or real ?
if((m_lDBCon.getIniValue(IBE.EDDN.EDDNView.DB_GROUPNAME, "Schema", "Real", false) == "Test") || (Program.actualCondition.GameversionIsBeta))
Data.SchemaRef = "http://schemas.elite-markets.net/eddn/commodity/3/test";
else
Data.SchemaRef = "http://schemas.elite-markets.net/eddn/commodity/3";
if(_Send_MarketData_API.Count > 0)
{
// fill the header
Data.Header = new EDDNCommodity_v3.Header_Class()
{
SoftwareName = "ED-IBE (API)",
SoftwareVersion = VersionHelper.Parts(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, 3),
GatewayTimestamp = TimeStamp,
UploaderID = UserID
};
activeQueue = _Send_MarketData_API;
}
else
{
// fill the header
Data.Header = new EDDNCommodity_v3.Header_Class()
{
SoftwareName = "ED-IBE (OCR)",
SoftwareVersion = VersionHelper.Parts(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, 3),
GatewayTimestamp = TimeStamp,
UploaderID = UserID
};
activeQueue = _Send_MarketData_OCR;
}
// prepare the message object
Data.Message = new EDDNCommodity_v3.Message_Class()
{
SystemName = "",
StationName = "",
Timestamp = TimeStamp,
Commodities = new EDDNCommodity_v3.Commodity_Class[activeQueue.Count]
};
// collect the commodity data
for (int i = 0; i <= Data.Message.Commodities.GetUpperBound(0); i++)
{
CsvRow Row = (CsvRow)activeQueue.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 EDDNCommodity_v3.Commodity_Class()
{
Name = commodity,
BuyPrice = (Int32)Math.Floor(Row.BuyPrice),
SellPrice = (Int32)Math.Floor(Row.SellPrice),
Demand = (Int32)Math.Floor(Row.Demand),
DemandBracket = (Row.DemandLevel == "") ? (int?)null : Int32.Parse(Row.DemandLevel),
Stock = (Int32)Math.Floor(Row.Supply),
StockBracket = (Row.SupplyLevel == "") ? (int?)null : Int32.Parse(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 }));
if(activeQueue == _Send_MarketData_API)
{
// data over api sent, set cooldown time
m_ID_of_Commodity_Station = new Tuple<String, DateTime>(m_ID_of_Commodity_Station.Item1, DateTime.Now);
}
m_CommoditySendingError = false;
DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedTypes.Commodity_V3, enTransmittedStates.Sent));
}
catch (WebException ex)
{
_logger.Log("Error uploading json (commodity)");
_logger.Log(ex.ToString());
_logger.Log(ex.Message);
_logger.Log(ex.StackTrace);
if (ex.InnerException != null)
_logger.Log(ex.InnerException.ToString());
using (WebResponse response = ex.Response)
{
using (Stream data = response.GetResponseStream())
{
if (data != null)
{
StreamReader sr = new StreamReader(data);
m_CommoditySendingError = true;
DataTransmittedEvent.Raise(this, new DataTransmittedEventArgs(enTransmittedTypes.Commodity_V3, enTransmittedStates.Error));
_logger.Log("Error while uploading commodity data to EDDN : " + sr.ReadToEnd());
}
}
}
}
finally
{
client.Dispose();
}
}
// retry, if the ocr-queue has entries and the last queue was then api-queue
} while ((activeQueue != _Send_MarketData_OCR) && (_Send_MarketData_OCR.Count > 0));
}
catch (Exception ex)
{
_logger.Log("Error uploading json (commodity)");
_logger.Log(ex.ToString());
_logger.Log(ex.Message);
_logger.Log(ex.StackTrace);
if (ex.InnerException != null)
_logger.Log(ex.InnerException.ToString());
CErr.processError(ex, "Error in EDDN-Sending-Thread (commodity)");
}
}