public void Add(IStreamData data) { if (data != null) { lock (_lock) queue.Add(data); } }
/// <summary> /// Send a single item to the DataServer /// </summary> public void Add(IStreamData data) { Add(new List <IStreamData>() { data }); }
/// <summary> /// Add a single StreamData item /// </summary> public void Add(IStreamData streamData) { lock (_lock) { queue.Add(streamData); } }
public async Task <string> SaveAsync(IStreamData streamData) { var newEntity = StreamEntity.Create(streamData); await _streamsTableStorage.InsertAsync(newEntity); return(newEntity.Id); }
/// <summary> /// Write the single IStreamData object to the client stream /// </summary> /// <param name="data">The IStreamData object to write</param> /// <returns>The DataServer's Response Code</returns> private int WriteData(IStreamData data) { if (stream != null && data != null) { try { var json = Json.Convert.ToJson(data); if (!string.IsNullOrEmpty(json)) { // Write JSON to stream streamWriter.WriteLine(json); streamWriter.Flush(); // Read Response Code var response = streamReader.ReadLine(); if (!string.IsNullOrEmpty(response)) { int responseCode; if (int.TryParse(response, out responseCode)) { log.Trace(response); return(responseCode); } } } } catch (Exception ex) { log.Debug("Error While Sending Data. Send Failed."); log.Trace(ex); } } return(-1); }
/// <summary> /// Write a single Sample to the Data Server /// </summary> public void Write(IStreamData data) { var l = new List <IStreamData>() { data }; Write(l); }
public static bool AddToQueue(IStreamData data) { if (string.IsNullOrEmpty(Configuration.AuthenticationUrl) || ValidateApiKey(data)) { lock (_lock) Queue.Add(data); return(true); } return(false); }
public Task UpdateAsync(IStreamData streamData) { var partitionKey = StreamEntity.GeneratePartitionKey(); var rowKey = StreamEntity.GenerateRowKey(streamData.Id); return(_streamsTableStorage.ReplaceAsync(partitionKey, rowKey, itm => { itm.Update(streamData); return itm; })); }
public static StreamEntity Create(IStreamData src) { var id = Guid.NewGuid().ToString("N"); var result = new StreamEntity { PartitionKey = GeneratePartitionKey(), RowKey = id, Id = id, Name = src.Name, Stream = src.Stream, AuthorId = src.AuthorId, AuthorEmail = src.AuthorEmail }; return(result); }
private static bool ValidateApiKey(IStreamData data) { List <ApiKey> authenticatedKeys; List <ApiKey> unauthenticatedKeys; lock (_lock) { authenticatedKeys = AuthenticatedKeys.ToList(); unauthenticatedKeys = UnauthenticatedKeys.ToList(); } if (authenticatedKeys != null && unauthenticatedKeys != null) { // Check if already in AuthenticatedKey list var key = authenticatedKeys.Find(o => o.Key == data.ApiKey && o.DeviceId == data.DeviceId); if (key != null) { return(true); } else { // Check if already in UnauthenticatedKey list key = unauthenticatedKeys.Find(o => o.Key == data.ApiKey && o.DeviceId == data.DeviceId); if (key == null) { // Create new Device bool success = Device.Create(data.ApiKey, data.DeviceId, Configuration.AuthenticationUrl); if (success) { // Add to Authenticated list lock (_lock) AuthenticatedKeys.Add(new ApiKey(data.ApiKey, data.DeviceId)); return(true); } else { // Add to Unauthenticated list lock (_lock) UnauthenticatedKeys.Add(new ApiKey(data.ApiKey, data.DeviceId)); } } } } return(false); }
private static void OnStreamData(object sender, IStreamData data) { if (data.Topic == ETopic.Blockheight) { Blockheight blockheight = (Blockheight)data; Console.WriteLine(blockheight.BlockHeight); Log.Information($"BlockHeight: {blockheight.BlockHeight}"); } else if (data.Topic == ETopic.AllTickers) { AllTickersData allTickersData = (AllTickersData)data; Console.WriteLine(allTickersData.AllTickers[0].Symbol); } else if (data.Topic == ETopic.AllMiniTickers) { AllMiniTickersData allMiniTickersData = (AllMiniTickersData)data; Console.WriteLine(allMiniTickersData.AllMiniTickers[0].Symbol); } }
/// <summary> /// 向DatabaseQueue添加IStreamData /// </summary> /// <param name="data"></param> public List <IStreamData> GetSendList(IStreamData data) { return(GetSendList(new List <IStreamData> { data })); }
private bool RemoveFromFile(string path, List <string> ids) { if (File.Exists(path)) { try { string filename = Path.GetFileNameWithoutExtension(path); var d = new List <IStreamData>(); using (var f = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) using (var reader = new StreamReader(f)) { // Read records from file while (!reader.EndOfStream) { var line = reader.ReadLine(); IStreamData item = null; if (filename.StartsWith(FILENAME_CONNECTION_DEFINITIONS)) { item = Csv.FromCsv <ConnectionDefinitionData>(line); } if (filename.StartsWith(FILENAME_AGENT_DEFINITIONS)) { item = Csv.FromCsv <AgentDefinitionData>(line); } if (filename.StartsWith(FILENAME_DEVICE_DEFINITIONS)) { item = Csv.FromCsv <DeviceDefinitionData>(line); } if (filename.StartsWith(FILENAME_COMPONENT_DEFINITIONS)) { item = Csv.FromCsv <ComponentDefinitionData>(line); } if (filename.StartsWith(FILENAME_DATA_ITEM_DEFINITIONS)) { item = Csv.FromCsv <DataItemDefinitionData>(line); } if (filename.StartsWith(FILENAME_SAMPLES)) { item = Csv.FromCsv <SampleData>(line); } if (item != null && !ids.Exists(o => o == item.EntryId)) { d.Add(item); } } } // Delete previously used file File.Delete(path); // Write unremoved records back to file if (d.Count > 0) { // Create temporary file to store unremoved records in var tempFile = Path.GetTempFileName(); using (var writer = new StreamWriter(tempFile, true)) { foreach (var data in d) { string csv = Csv.ToCsv(data); if (!string.IsNullOrEmpty(csv)) { writer.WriteLine(csv); } } } File.Move(tempFile, path); } return(true); } catch (IOException ex) { log.Warn(ex, path); } catch (UnauthorizedAccessException ex) { log.Warn(ex, path); } catch (Exception ex) { log.Trace(ex, path); } } return(false); }
private void Client_StreamData(object sender, IStreamData data) { Blockheight blockheight = (Blockheight)data; }
/// <summary> /// 写入一个SerializedData /// </summary> /// <param name="stream"></param> /// <param name="data"></param> public static void WriteStreamData(Stream stream, IStreamData data) { data.WriteStreamData(stream); }
internal void Update(IStreamData src) { Name = src.Name; Stream = src.Stream; }
private Task OnReceive(string message) { var jObject = JObject.Parse(message); string stream = jObject.Value <string>("stream"); IStreamData streamData = null; if (stream == websocket.stream.Topic.ToTopic(ETopic.Orders)) { streamData = new OrdersData { Orders = JsonConvert.DeserializeObject <Payload <List <Order> > >(message).Data }; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.Accounts)) { streamData = new AccountsData { Accounts = JsonConvert.DeserializeObject <Payload <List <Account> > >(message).Data }; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.Transfers)) { streamData = JsonConvert.DeserializeObject <Payload <TransfersData> >(message).Data; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.Trades)) { streamData = new TradesData { Trades = JsonConvert.DeserializeObject <Payload <List <Trade> > >(message).Data }; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.MarketDiff)) { streamData = JsonConvert.DeserializeObject <Payload <MarketDiff> >(message).Data; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.MarketDepth)) { streamData = JsonConvert.DeserializeObject <Payload <MarketDepth> >(message).Data; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.KLine)) { streamData = JsonConvert.DeserializeObject <Payload <KLine> >(message).Data; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.Ticker)) { streamData = JsonConvert.DeserializeObject <Payload <Ticker> >(message).Data; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.AllTickers)) { streamData = new AllTickersData { AllTickers = JsonConvert.DeserializeObject <Payload <List <Ticker> > >(message).Data }; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.MiniTicker)) { streamData = JsonConvert.DeserializeObject <Payload <MiniTicker> >(message).Data; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.AllMiniTickers)) { streamData = new AllMiniTickersData { AllMiniTickers = JsonConvert.DeserializeObject <Payload <List <MiniTicker> > >(message).Data }; } else if (stream == websocket.stream.Topic.ToTopic(ETopic.Blockheight)) { streamData = JsonConvert.DeserializeObject <Payload <Blockheight> >(message).Data; } else { throw new WebSocketException($"Unhandled topic stream: {stream}"); } StreamData(this, streamData); return(Task.CompletedTask); }
public StreamController(IStreamData streamData, IEmailTemplatesData emailTemplatesData, IQueueManager queueManager) { _streamData = streamData; _emailTemplatesData = emailTemplatesData; _queueManager = queueManager; }