/// <summary> /// Creates compressed file. If source == dest, this will replace source file /// </summary> /// <param name="source"></param> /// <param name="dest"></param> /// <param name="filter"></param> public void CompressFile(string source, string dest, Func <DateTime, DateTime> filter) { List <DataAtom> bigList = new List <DataAtom>(); using (StreamReader sr = File.OpenText(source)) { string line; while ((line = sr.ReadLine()) != null) { bigList.Add(DataAtom.FromString(line)); } } var compressed = Compress(bigList, filter); string tempfile = Path.GetRandomFileName(); using (StreamWriter sw = File.CreateText(tempfile)) { foreach (var item in compressed) { sw.WriteLine(item.ToString()); } } File.Copy(tempfile, dest, true); File.Delete(tempfile); }
private void LoadDataFromFile() { //int offset = _inMemoryList.Count; // This should be optimized // Create few performance load tests, real life type event. 1/4/8hr tests lock (_storeFile) { List <DataAtom> allFile = new List <DataAtom>(); if (File.Exists(_storeFile)) { using (StreamReader sr = File.OpenText(_storeFile)) { string line; while ((line = sr.ReadLine()) != null) { allFile.Add(DataAtom.FromString(line)); } } } lock (_inMemoryList) { _inMemoryList.Clear(); _inMemoryList = allFile; } } }