/// <summary> /// To delete market data from the storage for the specified time period. /// </summary> /// <param name="storage">Market-data storage.</param> /// <param name="from">The start time for data deleting. If the value is not specified, the data will be deleted starting from the date <see cref="GetFromDate"/>.</param> /// <param name="to">The end time, up to which the data shall be deleted. If the value is not specified, data will be deleted up to the end date <see cref="GetToDate"/>, inclusive.</param> public static void Delete(this IMarketDataStorage storage, DateTimeOffset?from = null, DateTimeOffset?to = null) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } var range = GetRange(storage, from, to); if (range == null) { return; } var info = (IMarketDataStorageInfo)storage; var min = range.Min.UtcDateTime; var max = range.Max.UtcDateTime.EndOfDay(); for (var date = min; date <= max; date = date.AddDays(1)) { if (date == min) { var metaInfo = storage.GetMetaInfo(date.Date); if (metaInfo == null) { continue; } if (metaInfo.FirstTime >= date && max.Date != min.Date) { storage.Delete(date.Date); } else { var data = storage.Load(date.Date).ToList(); data.RemoveWhere(d => { var time = info.GetTime(d); return(time.UtcDateTime < min || time > range.Max); }); storage.Delete(data); } } else if (date.Date < max.Date) { storage.Delete(date.Date); } else { var data = storage.Load(date.Date).ToList(); data.RemoveWhere(d => info.GetTime(d) > range.Max); storage.Delete(data); } } }
/// <summary> /// Удалить маркет-данные из хранилища для заданного периода. /// </summary> /// <param name="storage">Хранилище маркет-данных.</param> /// <param name="from">Время начала, с которого необходимо удалять данные. Если значение не указано, то будут удалены данные с начальной даты <see cref="GetFromDate"/>.</param> /// <param name="to">Время окончания, до которого включительно необходимо удалять данные. Если значение не указано, то будут удалены данные до конечной даты <see cref="GetToDate"/> включительно.</param> public static void Delete(this IMarketDataStorage storage, DateTimeOffset?from = null, DateTimeOffset?to = null) { if (storage == null) { throw new ArgumentNullException("storage"); } var range = GetRange(storage, from, to); if (range == null) { return; } var info = (IMarketDataStorageInfo)storage; var max = range.Max.Date.EndOfDay(); for (var date = range.Min; date <= max; date = date.AddDays(1)) { if (date == range.Min) { var metaInfo = storage.GetMetaInfo(date.Date); if (metaInfo.FirstTime >= date.UtcDateTime && range.Max.Date != range.Min.Date) { storage.Delete(date.Date); } else { var data = storage.Load(date.Date).Cast <object>().ToList(); data.RemoveWhere(d => info.GetTime(d) < range.Min); storage.Delete(data); } } else if (date.Date < range.Max.Date) { storage.Delete(date.Date); } else { var data = storage.Load(date.Date).Cast <object>().ToList(); data.RemoveWhere(d => info.GetTime(d) > range.Max); storage.Delete(data); } } }
IMarketDataMetaInfo IMarketDataStorage.GetMetaInfo(DateTime date) { return(_messageStorage.GetMetaInfo(date)); }