/// <summary> /// Logs the correctly formatted warning to execution log /// </summary> /// <typeparam name="T">The type of the incorrect value</typeparam> /// <param name="message">The <see cref="FeedMessage"/> containing the incorrect value</param> /// <param name="propertyName">The name of the property set to incorrect value</param> /// <param name="propertyValue">The incorrect value</param> private static void LogWarning <T>(FeedMessage message, string propertyName, T propertyValue) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(propertyName, nameof(propertyName)).NotNull().NotEmpty(); ExecutionLog.LogWarning($"Validation warning: message='{message}', property value {propertyName}={propertyValue} is not expected"); }
/// <summary> /// Validates the basic properties of the provided <see cref="FeedMessage"/> /// </summary> /// <param name="message">The message to be validated</param> /// <returns>True if the validation was successful, otherwise false</returns> private static bool ValidateMessage(FeedMessage message) { Guard.Argument(message, nameof(message)).NotNull(); var result = true; if (message.IsEventRelated) { if (message.SportId == null) { LogFailure(message, "SportId", message.SportId); return(false); } URN eventUrn; if (URN.TryParse(message.EventId, out eventUrn)) { message.EventURN = eventUrn; } else { LogFailure(message, "event_id", message.EventId); result = false; } } return(result); }
/// <summary> /// Validates and parses the provided market specifiers /// </summary> /// <param name="message">The <see cref="FeedMessage"/> instance containing the market whose specifiers are being validated</param> /// <param name="market">A <see cref="FeedMarket"/> instance containing the specifiers to validate</param> /// <param name="marketIndex">The index of the <code>market</code> in the <code>message</code></param> private static bool ValidateSpecifiers(FeedMessage message, FeedMarket market, int marketIndex) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(market, nameof(market)).NotNull(); Guard.Argument(marketIndex).NotNegative(); if (string.IsNullOrEmpty(market.SpecifierString)) { return(true); } try { market.Specifiers = FeedMapperHelper.GetSpecifiers(market.SpecifierString); return(true); } catch (Exception ex) { if (ex is FormatException || ex is ArgumentException) { market.ValidationFailed = true; LogWarning(message, $"markets[{marketIndex}].specifiers", market.SpecifierString); return(false); } throw; } }
/// <summary> /// Logs the correctly formatted failure to execution log /// </summary> /// <typeparam name="T">The type of the incorrect value</typeparam> /// <param name="message">The <see cref="FeedMessage"/> containing the incorrect value</param> /// <param name="propertyName">The name of the property set to incorrect value</param> /// <param name="propertyValue">The incorrect value</param> private static void LogFailure <T>(FeedMessage message, string propertyName, T propertyValue) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(propertyName, nameof(propertyName)).NotNull().NotEmpty(); ExecutionLog.ErrorFormat("Validation failure: message={{{0}}}, property value {1}={2} is not supported", message, propertyName, propertyValue); }
/// <summary> /// Logs the correctly formated failure to execution log /// </summary> /// <typeparam name="T">The type of the incorrect value</typeparam> /// <param name="message">The <see cref="FeedMessage"/> containing the incorrect value</param> /// <param name="propertyName">The name of the property set to incorrect value</param> /// <param name="propertyValue">The incorrect value</param> private static void LogFailure <T>(FeedMessage message, string propertyName, T propertyValue) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(propertyName, nameof(propertyName)).NotNull().NotEmpty(); ExecutionLog.LogError($"Validation failure: message='{message}', property value {propertyName}={propertyValue} is not supported"); }
private void OnMessage(FeedMessage obj) { Application.Current.Dispatcher.Invoke(() => { Messages.Add(obj); }); }
/// <summary> /// Returns a customized Entity set from the feed messages /// </summary> /// <param name="feedMessages"></param> /// <returns></returns> private Dictionary <VehicleEntity, Entity> GetEntitySet(FeedMessage feedMessages) { var entityFactory = new EntityFactory(); var entitySet = entityFactory.ProduceEntites(feedMessages); return(entitySet); }
/// <summary> /// Validates the provided <see cref="FeedMessage"/> and it's collection of <see cref="market"/> instances /// </summary> /// <param name="message">The message to be validated</param> /// <param name="markets">The message markets</param> /// <returns>A <see cref="ValidationResult"/> representing the result of the validation</returns> private ValidationResult ValidateMessageWithMarkets(FeedMessage message, market[] markets) { Contract.Requires(message != null); ValidateMessageProducer(message); if (!ValidateMessage(message) || markets == null) { return(ValidationResult.FAILURE); } if (!markets.Any()) { return(ValidationResult.SUCCESS); } var result = ValidationResult.SUCCESS; for (var i = 0; i < markets.Length; i++) { if (!ValidateSpecifiers(message, markets[i], i)) { result = ValidationResult.PROBLEMS_DETECTED; } if (!CheckSpecifiersAsync(message.ProducerId, markets[i].id, markets[i].Specifiers).Result) { result = ValidationResult.PROBLEMS_DETECTED; } } return(result); }
/// <summary> /// Validates the basic properties of the provided <see cref="FeedMessage"/> /// </summary> /// <param name="message">The message to be validated</param> /// <returns>True if the validation was successful, otherwise false</returns> private static bool ValidateMessage(FeedMessage message) { Contract.Requires(message != null); var result = true; if (message.IsEventRelated) { if (message.SportId == null) { LogFailure(message, "SportId", message.SportId); return(false); } URN eventUrn; if (URN.TryParse(message.EventId, out eventUrn)) { message.EventURN = eventUrn; } else { LogFailure(message, "event_id", message.EventId); result = false; } } return(result); }
/// <summary> /// Logs the correctly formated warning to execution log /// </summary> /// <typeparam name="T">The type of the incorrect value</typeparam> /// <param name="message">The <see cref="FeedMessage"/> containing the incorrect value</param> /// <param name="propertyName">The name of the property set to incorrect value</param> /// <param name="propertyValue">The incorrect value</param> private static void LogWarning <T>(FeedMessage message, string propertyName, T propertyValue) { Contract.Requires(message != null); Contract.Requires(!string.IsNullOrEmpty(propertyName)); ExecutionLog.WarnFormat("Validation warning: message={{{0}}}, property value {1}={2} is not expected", message, propertyName, propertyValue); }
/// <summary> /// Validates and parses the provided market specifiers /// </summary> /// <param name="message">The <see cref="FeedMessage"/> instance containing the market whose specifiers are being validated</param> /// <param name="market">A <see cref="FeedMarket"/> instance containing the specifiers to validate</param> /// <param name="marketIndex">The index of the <code>market</code> in the <code>message</code></param> private static bool ValidateSpecifiers(FeedMessage message, FeedMarket market, int marketIndex) { Contract.Requires(message != null); Contract.Requires(market != null); Contract.Requires(marketIndex >= 0); if (string.IsNullOrEmpty(market.SpecifierString)) { return(true); } try { market.Specifiers = FeedMapperHelper.GetSpecifiers(market.SpecifierString); return(true); } catch (Exception ex) { if (ex is FormatException || ex is ArgumentException) { market.ValidationFailed = true; LogWarning(message, $"markets[{marketIndex}].specifiers", market.SpecifierString); return(false); } throw; } }
/* * It serializes feed message object to json like structure * and writes it to file named TRIPUPDATES.JSON. * */ private static void WriteFeedMessageToFile(FeedMessage feedMessage) { var jsonFileName = ConfigurationManager.AppSettings["JSONPATH"]; var text = JsonConvert.SerializeObject(feedMessage, Formatting.Indented); File.WriteAllText(jsonFileName, text); }
/// <summary> /// Validates the provided <see cref="FeedMessage"/> and it's collection of <see cref="market"/> instances /// </summary> /// <param name="message">The message to be validated</param> /// <param name="markets">The message markets</param> /// <returns>A <see cref="ValidationResult"/> representing the result of the validation</returns> private ValidationResult ValidateMessageWithMarkets(FeedMessage message, market[] markets) { Guard.Argument(message, nameof(message)).NotNull(); ValidateMessageProducer(message); if (!ValidateMessage(message) || markets == null) { return(ValidationResult.FAILURE); } if (!markets.Any()) { return(ValidationResult.SUCCESS); } var result = ValidationResult.SUCCESS; foreach (var market in markets) { if (!ValidateSpecifiers(message, market, market.id)) { result = ValidationResult.PROBLEMS_DETECTED; } if (!CheckSpecifiersAsync(message.ProducerId, market.id, market.Specifiers).Result) { result = ValidationResult.PROBLEMS_DETECTED; } } return(result); }
/// <summary> /// Validates the basic properties of the provided <see cref="FeedMessage"/> /// </summary> /// <param name="message">The message to be validated</param> /// <returns>True if the validation was successful, otherwise false</returns> private static bool ValidateMessage(FeedMessage message) { Contract.Requires(message != null); var result = TestProducerManager.Create().Exists(message.ProducerId); if (message.IsEventRelated) { if (message.SportId == null) { return(false); } URN eventUrn; if (URN.TryParse(message.EventId, out eventUrn)) { message.EventURN = eventUrn; } else { result = false; } } if (message.RequestIdUsage == PropertyUsage.REQUIRED && message.RequestId < 1 || message.RequestIdUsage == PropertyUsage.OPTIONAL && message.RequestId.HasValue && message.RequestId.Value < 0) { result = false; } return(result); }
public override async Task <IDictionary <string, TDistributable> > SubscribeMany(IEnumerable <string> keys) { if (disposedValue) { throw new ObjectDisposedException(GetType().FullName); } if (!Connected) { await Connect(); } var sb = new StringBuilder(); var lnew = new Dictionary <string, TDistributable>(); lock (lockObj) { foreach (var sym in keys) { if (activeFeeds.ContainsKey(sym)) { if (!lnew.ContainsKey(sym)) { lnew.Add(sym, activeFeeds[sym]); } continue; } if (sb.Length > 0) { sb.Append(','); } sb.Append(sym); var obs = CreateFeed(sym); activeFeeds.Add(sym, obs); if (!lnew.ContainsKey(sym)) { lnew.Add(sym, activeFeeds[sym]); } } } var topic = $"{Topic}:{sb}"; var e = new FeedMessage() { Type = "subscribe", Id = connectId.ToString("d"), Topic = topic, Response = true, PrivateChannel = false }; await Send(e); State = FeedState.Subscribed; return(lnew); }
/// <summary> /// Raises the <see cref="FeedMessageReceived"/> event /// </summary> /// <param name="message">A <see cref="FeedMessage"/> instance used to construct the event args</param> /// <param name="rawMessage">A raw message received from the broker</param> private void RaiseMessageReceived(FeedMessage message, byte[] rawMessage) { Guard.Argument(message, nameof(message)).NotNull(); //no need to add interest, it is later used from session interest FeedMessageReceived?.Invoke(this, new FeedMessageReceivedEventArgs(message, null, rawMessage)); }
public JsonResult TrackMyBus(int stopId) { var resultPosition = VehiclePosition().Data; //var jsonPosition = JsonConvert.SerializeObject(((resultPosition.GetType().GetProperty("Result")) != null ? (resultPosition.GetType().GetProperty("Result")) : (resultPosition.GetType().GetProperty("result")).GetValue(resultPosition, null))); var jsonPosition = JsonConvert.SerializeObject(resultPosition.GetType().GetProperty("Result").GetValue(resultPosition, null)); FeedMessage vehiclePosition = JsonConvert.DeserializeObject <FeedMessage>(jsonPosition); var resultTrip = GetTripUpdates().Data; var jsonTrip = JsonConvert.SerializeObject(resultTrip.GetType().GetProperty("Result").GetValue(resultTrip, null)); FeedMessage tripUpdate = JsonConvert.DeserializeObject <FeedMessage>(jsonTrip); if (vehiclePosition.entity.Count == 0 || tripUpdate.entity.Count == 0) { return(Json(new { TripList = "Error" }, JsonRequestBehavior.AllowGet)); } List <FeedEntity> tripData = (from f in tripUpdate.entity from stu in f.trip_update.stop_time_update where stu.stop_id.Equals(stopId.ToString()) select f).ToList(); List <FeedEntity> vehiclePositionData = (from vp in vehiclePosition.entity from td in tripData where vp.vehicle.trip != null && vp.vehicle.trip.trip_id == td.trip_update.trip.trip_id select vp).ToList(); List <TripsFlattenedModel> trips = FormatTripData(tripData, vehiclePositionData); List <TripsFlattenedModel> tripsSelected = (from trip in trips from t in trip.Stops where t.StopId == stopId && trip.VehiclePosition.CurrentStopSequence <= t.StopSequence select trip).ToList(); return(Json(new { TripList = tripsSelected }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// This method is for getting vehicle by route id from transit-realtime api /// </summary> /// <param name="routeid"></param> /// <returns></returns> public JsonResult GetVehiclePositionFromRouteId(string routeid) { try { var resultPosition = VehiclePosition().Data; var jsonPosition = JsonConvert.SerializeObject(resultPosition.GetType().GetProperty("Result").GetValue(resultPosition, null)); FeedMessage vehiclePosition = JsonConvert.DeserializeObject <FeedMessage>(jsonPosition); var resultTrip = GetTripUpdates().Data; var jsonTrip = JsonConvert.SerializeObject(resultTrip.GetType().GetProperty("Result").GetValue(resultTrip, null)); FeedMessage tripUpdate = JsonConvert.DeserializeObject <FeedMessage>(jsonTrip); List <FeedEntity> tripData = tripUpdate.entity.Where(t => string.Equals(GetRoutIdFromTripId(t.trip_update.trip.trip_id), routeid)).ToList(); //tripData = tripData.OrderBy(t => (t.trip_update.stop_time_update.FirstOrDefault()) != null ? Convert.ToDateTime(FormatTimeStamp((t.trip_update.stop_time_update.FirstOrDefault()).departure.time)) : Convert.ToDateTime("23:59:59")).ToList(); List <FeedEntity> vehiclePositionData = (from vp in vehiclePosition.entity from td in tripData where vp.vehicle.trip != null && vp.vehicle.trip.trip_id == td.trip_update.trip.trip_id select vp).ToList(); return(Json(new { TripList = FormatTripData(tripData, vehiclePositionData) }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { TripList = "Error" }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// this method is to get the buses and stop lists from transit-realtime api /// </summary> /// <param name="sourceStop"></param> /// <param name="destinationStop"></param> /// <returns></returns> public JsonResult GetBussesFromOneStopToAnother(string sourceStop, string destinationStop) { try { var tripUpdateFeed = GetTripUpdates().Data; var tripJson = JsonConvert.SerializeObject(tripUpdateFeed.GetType().GetProperty("Result").GetValue(tripUpdateFeed, null)); FeedMessage tripUpdate = JsonConvert.DeserializeObject <FeedMessage>(tripJson); var positionFeed = VehiclePosition().Data; var positionJson = JsonConvert.SerializeObject(positionFeed.GetType().GetProperty("Result").GetValue(positionFeed, null)); FeedMessage vehiclePosition = JsonConvert.DeserializeObject <FeedMessage>(positionJson); int sourceId = (from s in dbContext.Stops.Where(t => t.stop_name.Equals(sourceStop)) select s).FirstOrDefault().stop_id; int destinationId = (from s in dbContext.Stops.Where(t => t.stop_name.Equals(destinationStop)) select s).FirstOrDefault().stop_id; List <FeedEntity> tripData = (from f in tripUpdate.entity from stu in f.trip_update.stop_time_update from stu2 in f.trip_update.stop_time_update where stu.stop_id.Equals(sourceId.ToString()) && stu2.stop_id.Equals(destinationId.ToString()) && stu.stop_sequence < stu2.stop_sequence select f).ToList(); List <FeedEntity> vehiclePositionData = (from vp in vehiclePosition.entity from td in tripData where vp.vehicle.trip != null && vp.vehicle.trip.trip_id == td.trip_update.trip.trip_id select vp).ToList(); return(Json(new { TripList = FormatTripData(tripData, vehiclePositionData) }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { TripList = "Error" }, JsonRequestBehavior.AllowGet)); } }
public static List <AlertData> GetAlerts(FeedMessage feedMessage) { var alerts = new List <AlertData>(); foreach (var entity in feedMessage.entity.Where(x => x.alert != null)) { if (entity.alert.description_text == null) { foreach (var headerTranslation in entity.alert.header_text.translation) { var alert = GetAlert(feedMessage, entity, null, headerTranslation); alerts.Add(alert); } } else { foreach (var translation in entity.alert.description_text.translation) { foreach (var headerTranslation in entity.alert.header_text.translation) { var alert = GetAlert(feedMessage, entity, translation, headerTranslation); alerts.Add(alert); } } } } return(alerts); }
/// <summary> /// Logs the correctly formated failure to execution log /// </summary> /// <typeparam name="T">The type of the incorrect value</typeparam> /// <param name="message">The <see cref="FeedMessage"/> containing the incorrect value</param> /// <param name="propertyName">The name of the property set to incorrect value</param> /// <param name="propertyValue">The incorrect value</param> private static void LogFailure <T>(FeedMessage message, string propertyName, T propertyValue) { Contract.Requires(message != null); Contract.Requires(!string.IsNullOrEmpty(propertyName)); ExecutionLog.ErrorFormat("Validation failure: message={{{0}}}, property value {1}={2} is not supported", message, propertyName, propertyValue); }
/// <summary> /// Processes and dispatches the provided <see cref="FeedMessage"/> instance /// </summary> /// <param name="message">A <see cref="FeedMessage"/> instance to be processed</param> /// <param name="interest">A <see cref="MessageInterest"/> specifying the interest of the associated session</param> /// <param name="rawMessage">A raw message received from the feed</param> public void ProcessMessage(FeedMessage message, MessageInterest interest, byte[] rawMessage) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(interest, nameof(interest)).NotNull(); _processors.First().ProcessMessage(message, interest, rawMessage); }
protected override async Task HandleMessage(FeedMessage msg) { await base.HandleMessage(msg); if (msg.Type == "message" && (msg.Topic?.Contains(Topic) ?? false)) { var i = msg.Topic.IndexOf(":"); var symbol = msg.Data.ToObject <ContractMarketData>(); if (i != -1) { symbol.Symbol = msg.Topic.Substring(i + 1); } if (msg.Subject == "mark.index.price") { symbol.Type = ContractDataType.MarkIndexPrice; } else if (msg.Subject == "funding.rate") { symbol.Type = ContractDataType.FundingRate; } await PushNext(symbol); } }
/// <summary> /// Logs the correctly formatted warning to execution log /// </summary> /// <typeparam name="T">The type of the incorrect value</typeparam> /// <param name="message">The <see cref="FeedMessage"/> containing the incorrect value</param> /// <param name="propertyName">The name of the property set to incorrect value</param> /// <param name="propertyValue">The incorrect value</param> private static void LogWarning <T>(FeedMessage message, string propertyName, T propertyValue) { Guard.Argument(message, nameof(message)).NotNull(); Guard.Argument(propertyName, nameof(propertyName)).NotNull().NotEmpty(); ExecutionLog.WarnFormat("Validation warning: message={{{0}}}, property value {1}={2} is not expected", message, propertyName, propertyValue); }
/// <summary> /// This method returns the vehicle positions /// </summary> /// <returns></returns> //[AllowAnonymous] public JsonResult VehiclePosition() { try { string userName = ConfigurationManager.AppSettings["userName"]; string password = ConfigurationManager.AppSettings["password"]; string url = "http://117.232.125.138/tms/data/gtfs/vehicle-positions.pb"; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(string.Format(url)); webReq.Method = "GET"; NetworkCredential networkCredential = new NetworkCredential(userName, password); CredentialCache myCredentialCache = new CredentialCache { { new Uri(url), "Basic", networkCredential } }; webReq.PreAuthenticate = true; webReq.Credentials = myCredentialCache; HttpWebResponse webResponse = (HttpWebResponse)webReq.GetResponse(); //I don't use the response for anything right now. But I might log the response answer later on. Stream answer = webResponse.GetResponseStream(); StreamReader _recivedAnswer = new StreamReader(answer); FeedMessage message = ProtoBuf.Serializer.Deserialize <FeedMessage>(_recivedAnswer.BaseStream); //var resct = _recivedAnswer.ReadToEnd(); return(Json(new { Result = message }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = "Error", Message = "Something went wrong." + ex.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Dispatches the provided <see cref="FeedMessage"/> /// </summary> /// <param name="feedMessage"></param> /// <param name="rawMessage"></param> public virtual void Dispatch(FeedMessage feedMessage, byte[] rawMessage) { var oddsChange = feedMessage as odds_change; if (oddsChange != null) { DispatchOddsChange(oddsChange, rawMessage); return; } var betStop = feedMessage as bet_stop; if (betStop != null) { DispatchBetStop(betStop, rawMessage); return; } var betSettlement = feedMessage as bet_settlement; if (betSettlement != null) { DispatchBetSettlement(betSettlement, rawMessage); return; } var rollbackBetSettlement = feedMessage as rollback_bet_settlement; if (rollbackBetSettlement != null) { DispatchRollbackBetSettlement(rollbackBetSettlement, rawMessage); return; } var betCancel = feedMessage as bet_cancel; if (betCancel != null) { DispatchBetCancel(betCancel, rawMessage); return; } var rollbackBetCancel = feedMessage as rollback_bet_cancel; if (rollbackBetCancel != null) { DispatchRollbackBetCancel(rollbackBetCancel, rawMessage); return; } var fixtureChange = feedMessage as fixture_change; if (fixtureChange != null) { DispatchFixtureChange(fixtureChange, rawMessage); return; } throw new ArgumentException($"FeedMessage of type '{feedMessage.GetType().Name}' is not supported."); }
/// <summary> /// Initializes a new instance of the <see cref="FeedMessageReceivedEventArgs"/> class /// </summary> /// <param name="message">a <see cref="FeedMessage"/> representing the received message</param> /// <param name="interest">a <see cref="MessageInterest"/> specifying the interest of the associated session or a null reference /// if no session is associated with the received message</param> /// <param name="rawMessage">The raw message</param> public FeedMessageReceivedEventArgs(FeedMessage message, MessageInterest interest, byte[] rawMessage) { Contract.Requires(message != null); Message = message; Interest = interest; RawMessage = rawMessage; }
/// <summary> /// Initializes a new instance of the <see cref="FeedMessageReceivedEventArgs"/> class /// </summary> /// <param name="message">a <see cref="FeedMessage"/> representing the received message</param> /// <param name="interest">a <see cref="MessageInterest"/> specifying the interest of the associated session or a null reference /// if no session is associated with the received message</param> /// <param name="rawMessage">The raw message</param> public FeedMessageReceivedEventArgs(FeedMessage message, MessageInterest interest, byte[] rawMessage) { Guard.Argument(message, nameof(message)).NotNull(); Message = message; Interest = interest; RawMessage = rawMessage; }
/// <summary> /// Processes the received <see cref="FeedMessage"/> /// </summary> /// <param name="feedMessage">The <see cref="FeedMessage"/> to process.</param> /// <param name="rawMessage">A raw message received from the feed</param> private void ProcessMessage(FeedMessage feedMessage, byte[] rawMessage) { if (feedMessage is alive alive) { var args = new FeedMessageReceivedEventArgs(alive, null, rawMessage); Dispatch(AliveReceived, args, "AliveReceived"); } }
protected override async Task HandleMessage(FeedMessage msg) { if (msg.Type == "message") { if (msg.Subject == Subject) { var i = msg.Topic.IndexOf(":"); if (i == -1) { return; } var ticker = new KlineFeedMessage <TCandle>(); var sk = SymbolKline.Parse(msg.Topic.Substring(i + 1)); // The JSON.NET documentation states clearly that // for tricky deserialization scenarios, the fastest // way is manual deserialization. ticker.Timestamp = EpochTime.NanosecondsToDate(msg.Data["time"].ToObject <long>()); ticker.Symbol = msg.Data["symbol"].ToObject <string>(); // Here we have the candle data efficiently served as an array of strings. // In C# we want to parse this array into a strongly-typed object. var values = msg.Data["candles"].ToObject <string[]>(); var candle = new TCandle { Timestamp = EpochTime.SecondsToDate(long.Parse(values[0])), // We are going to assume that the data from the feed is correctly formatted. // If an error is thrown here, then there is a deeper problem. OpenPrice = decimal.Parse(values[1]), ClosePrice = decimal.Parse(values[2]), HighPrice = decimal.Parse(values[3]), LowPrice = decimal.Parse(values[4]), Amount = decimal.Parse(values[5]), Volume = decimal.Parse(values[6]) }; // The candlestick does not need to be a typed candle, // but if it is, we will set that value, as well. if (candle is IFullKlineCandle <KlineType> wt) { wt.Type = sk.KlineType; } ticker.Candles = candle; // push the final object. await PushNext(ticker); } } }
public void UpdateFeedMessages () { var feeds = Feed.Provider.FetchAllMatching ( "IsSubscribed = 1 AND (LastDownloadTime = 0 OR LastDownloadError != 0) ORDER BY LastDownloadTime ASC").ToList (); lock (feed_messages) { var msgs = new List<FeedMessage> (); var cur = CurrentMessage as FeedMessage; if (cur != null && feeds.Contains (cur.Feed)) { cur.Update (); feeds.Remove (cur.Feed); feed_messages.Remove (cur); msgs.Add (cur); } feed_messages.ForEach (RemoveMessage); feed_messages.Clear (); foreach (var feed in feeds) { var msg = new FeedMessage (this, feed); if (msg.Valid) { msgs.Add (msg); PushMessage (msg); } } feed_messages = msgs; //last_feed_nag = DateTime.Now; // If there's at least one new message, notify the user if (msgs.Count > ((cur != null) ? 1 : 0)) { NotifyUser (); } } }