public SymbologySearch(Profile profile, JSONRequest request) { _endPoint = "SymbologySearch"; _profile = profile; _logger = _profile.CreateLogger <SymbologySearch>(); _jsonRequest = request; }
public NewsHeadlines(Profile profile, JSONRequest request) { _endPoint = "News_Headlines"; _profile = profile; _logger = _profile.CreateLogger <NewsHeadlines>(); _jsonRequest = request; }
public DataGrid(Profile profile, JSONRequest request) { _endPoint = "DataGrid"; _profile = profile; _logger = _profile.CreateLogger <DataGrid>(); _jsonRequest = request; }
public NewsStory(Profile profile, JSONRequest request) { _endPoint = "News_Story"; _profile = profile; _logger = _profile.CreateLogger <NewsStory>(); _jsonRequest = request; }
//private string _endPoint = "TimeSeries"; //private Profile _profile; //private ILogger _logger = null; public TimeSeries(Profile profile, JSONRequest request) { _endPoint = "TimeSeries"; _profile = profile; _logger = _profile.CreateLogger <TimeSeries>(); _jsonRequest = request; }
public string SendJSONRequest <T>(string entity, T obj, bool ignoreNull) { string payload = JsonConvert.SerializeObject(obj, new JsonSerializerSettings { NullValueHandling = ignoreNull?NullValueHandling.Ignore:NullValueHandling.Include }); return(JSONRequest.SendJSONRequest(Logger, entity, payload)); }
private Eikon() { Profile = new Profile(); JSONRequest = new JSONRequest(Profile); DataGrid = new DataGrid(Profile, JSONRequest); TimeSeries = new TimeSeries(Profile, JSONRequest); NewsHeadlines = new NewsHeadlines(Profile, JSONRequest); NewsStory = new NewsStory(Profile, JSONRequest); SymbologySearch = new SymbologySearch(Profile, JSONRequest); Logger = Profile.CreateLogger <Eikon>(); }
//public void CreateLogger(ILoggerFactory factory) //{ // _logger = factory.CreateLogger<Profile>(); //} private uint GetScriptingProxyPort() { //throw new NotImplementedException(); uint port = 36036; foreach (string appName in AppNames) { string path = ""; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { path = Path.Combine(new string[] { AppDataFolder, AppAuthor, appName, FileName }); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { path = Path.Combine(new string[] { AppDataFolder, "Library", "Application Support", appName, FileName }); } // string path = Path.Combine(new string[] { AppDataFolder, AppAuthor, appName, FileName }); if (File.Exists(path)) { _logger?.LogInformation("Find port in a file: {0}", path); try { port = Convert.ToUInt16(File.ReadAllText(path)); }catch (Exception ex) { _logger?.LogWarning("Can't convert port to a number: {0}", JSONRequest.GetInnerMostException(ex).Message.ToString()); continue; //Log Error } break; } } _logger?.LogInformation("use port: {0}", port); return(port); }
public async Task <Tuple <string, EikonException> > SendJSONRequestAsync(ILogger logger, string entity, string payload, uint id = 123) { string udfRequest = $"{{\"Entity\":{{\"E\":\"{entity}\",\"W\":{payload}}},\"ID\":\"{id}\" }}"; string jsonData; HttpResponseMessage response = null; EikonException error = null; logger?.LogDebug("UDF Request: {0}", udfRequest); //using (HttpClient client = new HttpClient()) { var request = new HttpRequestMessage(HttpMethod.Post, profile.Url); request.Headers.Add("x-tr-applicationid", profile.AppId); request.Content = new StringContent(udfRequest); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); try { response = await client.SendAsync(request); } catch (Exception ex) { error = new EikonException(HttpStatusCode.InternalServerError, JSONRequest.GetInnerMostException(ex).Message.ToString(), ex.InnerException); error.Source = "JSONRequest"; jsonData = null; logger?.LogError(JsonConvert.SerializeObject(error)); throw (error); //return new Tuple<string, EikonException>(jsonData, error); } if (response.IsSuccessStatusCode) { jsonData = await response.Content.ReadAsStringAsync(); logger?.LogDebug("UDF Response: {0}", jsonData); if (jsonData.StartsWith("<") && jsonData.EndsWith(">")) { error = new EikonException(HttpStatusCode.InternalServerError, $"Invalid JSON: {jsonData}"); error.Source = "JSONRequest"; jsonData = null; logger?.LogError(JsonConvert.SerializeObject(error)); throw (error); } else if (jsonData.Contains("ErrorCode") && jsonData.Contains("ErrorMessage")) { var eikonError = JsonConvert.DeserializeObject <EikonError>(jsonData); error.ErrorCode = (HttpStatusCode)Enum.ToObject(typeof(HttpStatusCode), eikonError.ErrorCode); error.Source = "JSONRequest"; jsonData = null; logger?.LogError(JsonConvert.SerializeObject(error)); throw (error); } else if (jsonData.Contains("error") && jsonData.Contains("transactionId")) { error = new EikonException(HttpStatusCode.InternalServerError, jsonData); error.Source = "JSONRequest"; logger?.LogError(JsonConvert.SerializeObject(error)); throw (error); } } else { error = new EikonException(response.StatusCode, response.ToString()); jsonData = null; logger?.LogError(JsonConvert.SerializeObject(error)); } return(new Tuple <string, EikonException>(jsonData, error)); } }
public string SendJSONRequest(string entity, string payload) { return(JSONRequest.SendJSONRequest(Logger, entity, payload)); }
public void SetTimeout(int millisec) { Profile.Timeout = millisec; JSONRequest.SetTimeout(millisec); //JSONRequest.SetTimeout(millisec); }