Exemplo n.º 1
0
 public void CanFetchDataThatExists(string dataPath)
 {
     using (var stream = DataCacheProvider.Fetch(dataPath))
         using (var reader = new StreamReader(stream))
         {
             Assert.IsFalse(string.IsNullOrEmpty(reader.ReadLine()));
         }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalFileSubscriptionStreamReader"/> class.
        /// </summary>
        /// <param name="dataCacheProvider">The <see cref="IDataCacheProvider"/> used to retrieve a stream of data</param>
        /// <param name="source">The local file to be read</param>
        /// <param name="entryName">Specifies the zip entry to be opened. Leave null if not applicable,
        /// or to open the first zip entry found regardless of name</param>
        public LocalFileSubscriptionStreamReader(IDataCacheProvider dataCacheProvider, string source, string entryName = null)
        {
            var stream = dataCacheProvider.Fetch(source);

            if (stream != null)
            {
                _streamReader = new StreamReader(stream);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalFileSubscriptionStreamReader"/> class.
        /// </summary>
        /// <param name="dataCacheProvider">The <see cref="IDataCacheProvider"/> used to retrieve a stream of data</param>
        /// <param name="source">The local file to be read</param>
        /// <param name="entryName">Specifies the zip entry to be opened. Leave null if not applicable,
        /// or to open the first zip entry found regardless of name</param>
        public LocalFileSubscriptionStreamReader(IDataCacheProvider dataCacheProvider, string source, string entryName = null)
        {
            var stream = dataCacheProvider.Fetch(source);

            if (stream != null)
            {
                _streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("gbk"));
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalFileSubscriptionStreamReader"/> class.
        /// </summary>
        /// <param name="dataCacheProvider">The <see cref="IDataCacheProvider"/> used to retrieve a stream of data</param>
        /// <param name="source">The local file to be read</param>
        /// <param name="startingPosition">The position in the stream from which to start reading</param>
        public LocalFileSubscriptionStreamReader(IDataCacheProvider dataCacheProvider, string source, long startingPosition)
        {
            var stream = dataCacheProvider.Fetch(source);

            if (stream != null)
            {
                _streamReader = new StreamReader(stream);

                if (startingPosition != 0)
                {
                    _streamReader.BaseStream.Seek(startingPosition, SeekOrigin.Begin);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads an existing hourly or daily Lean zip file into a SortedDictionary
        /// </summary>
        protected virtual bool TryLoadFile(string fileName, string entryName, out SortedDictionary <DateTime, string> rows)
        {
            rows = new SortedDictionary <DateTime, string>();

            using (var stream = _dataCacheProvider.Fetch($"{fileName}#{entryName}"))
            {
                if (stream == null)
                {
                    return(false);
                }

                using (var reader = new StreamReader(stream))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        var time = DateTime.ParseExact(line.AsSpan(0, DateFormat.TwelveCharacter.Length), DateFormat.TwelveCharacter, CultureInfo.InvariantCulture);
                        rows[time] = line;
                    }
                }

                return(true);
            }
        }
Exemplo n.º 6
0
 private void ReadAndWrite(IDataCacheProvider dataCacheProvider, byte[] data)
 {
     dataCacheProvider.Fetch(_tempZipFileEntry);
     dataCacheProvider.Store(_tempZipFileEntry, data);
 }