private void AddBBfield(BloombergDataInstrument bdi, RequestItemField Field, int id) { // Ignore duplicate field names if (!bdi.BBFields.ContainsKey(Field.Key)) { BloombergDataInstrumentField field = new BloombergDataInstrumentField(Field.Key); field.ID = id; foreach (OverrideField oField in Field.OverrideFields) { field.FieldOverrides.Add(oField.Name, oField.Value); } bdi.BBFields.Add(Field.Key, field); } }
private void AddResultsToRequestItems(List <BloombergDataInstrument> instruments) { // Now for all requests, find the data foreach (RequestItem ri in _requestItems) { if (!ri.SendToBloomberg) { continue; } ri.Errors = ""; BloombergDataInstrument source = null; source = instruments.FirstOrDefault(x => (ri.RequestType == BloombergDataInstrument.eRequestType.Reference && x.Ticker.ToUpper() == ri.BBTicker.ToUpper()) || (ri.RequestType != BloombergDataInstrument.eRequestType.Reference && x.ID == ri.ID)); if (source != null) { if (source.ResponseError != "") { ri.Errors = source.ResponseError; } else { if (source.IsSecurityValid) { // If we have dates coming back from Bloomberg, create an entry for each date returned // otherwise time stamp with Now if (source.BBFields.ContainsKey("date")) { List <object> list = (List <object>)source.BBFields["date"].Value; if (list != null) { foreach (object val in list) { DateTime timeStamp; if (DateTime.TryParse(val.ToString(), out timeStamp)) { ri.Data.Add(timeStamp, new string[source.BBFields.Count - 1]); } else { throw new Exception("Expected date not found in AddResultsToRequestItems"); } } } } else if (source.BBFields.ContainsKey("time")) { List <object> list = (List <object>)source.BBFields["time"].Value; if (list != null) { foreach (object val in list) { DateTime timeStamp; if (DateTime.TryParse(val.ToString(), out timeStamp)) { ri.Data.Add(timeStamp, new string[source.BBFields.Count - 1]); } else { throw new Exception("Expected time not found in AddResultsToRequestItems"); } } } } else { ri.Data.Add(DateTime.Now, new string[source.BBFields.Count]); } // As we need to get a list of values from a list of fields and add it to a dictionary, // it is easier to do using numbers and arrays List <string[]> array = new List <string[]>(); foreach (string[] sa in ri.Data.Values) { array.Add(sa); } // Loop through each field and find the values int fieldPos = 0; foreach (RequestItemField field in ri.riFields.Values) { BloombergDataInstrumentField fld = source.BBFields[field.Key]; if (fld.Name != "date" && fld.Name != "time") { // handled earlier and is the key in the ri.Data dictionary if (fld.Value != null) { if (fld.Value.GetType().Name == "List`1") { List <object> list = (List <object>)fld.Value; for (int timeLine = 0; timeLine < list.Count; timeLine++) { array[timeLine][fieldPos] = GetStringValue(list[timeLine]); } } else { array[0][fieldPos] = GetStringValue(fld.Value); } } else { string err = fld.Error; // Sometimes no error is returned even when the Value is null if (err == null) { err = "N.A."; } ri.Errors += string.Format("[{0}|{1}]", fld.Name, err); } fieldPos++; } } } else { // Invalid security ri.Errors = source.SecurityErrors; } } NLogger.Instance.Info("at end"); } else { // No data returned ri.Errors = "No data returned from BB"; } } }