/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System; using System.IO; using QuantConnect.Data; using QuantConnect.Interfaces; namespace QuantConnect.Lean.Engine.DataFeeds { /// /// Provides a factory method for creating instances /// public static class SubscriptionDataSourceReader { /// /// Creates a new capable of handling the specified /// /// The subscription data source to create a factory for /// Used to cache data /// The configuration of the subscription /// The date to be processed /// True for live mode, false otherwise /// A new that can read the specified public static ISubscriptionDataSourceReader ForSource(SubscriptionDataSource source, IDataCacheProvider dataCacheProvider, SubscriptionDataConfig config, DateTime date, bool isLiveMode) { switch (source.Format) { case FileFormat.Csv: return new TextSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode); case FileFormat.Collection: return new CollectionSubscriptionDataSourceReader(dataCacheProvider, config, date, isLiveMode); case FileFormat.ZipEntryName: return new ZipEntryNameSubscriptionDataSourceReader(config, date, isLiveMode); default: throw new NotImplementedException("SubscriptionFactory.ForSource(" + source + ") has not been implemented yet."); } } /// /// Creates cache directory if not existing and deletes old files from the cache /// public static void CheckRemoteFileCache() { // create cache directory if not existing if (!Directory.Exists(Globals.Cache)) Directory.CreateDirectory(Globals.Cache); // clean old files out of the cache foreach (var file in Directory.EnumerateFiles(Globals.Cache)) { if (File.GetCreationTime(file) < DateTime.Now.AddHours(-24)) File.Delete(file); } } } }