public void UpdateAssetsInFile() { var requestString = url + "/symbols"; var response = StaticUtility.GenerateRestUrl(requestString, key); var model = JsonConvert.DeserializeObject <List <SymbolModel> >(response.Content); var assetList = ReadAssets(model); if (!assetList.Any()) { throw new Exception("No assets has been found"); } if (File.Exists(filePath)) { File.Delete(filePath); } directoryManager.WriteAssetsToExcel(filePath, assetList); //File.AppendAllText(filePath, stringToFile); }
public bool LoadToCsv(string location) { var csv = new StringBuilder(); const string fs = "Time"; const string sc = "avg"; var newLine1 = $"{fs},{sc}{Environment.NewLine}"; //var location = manager.GenerateForecastFolder(coinName, period, DirSwitcher.Manual); csv.Append(newLine1); var counter = 0; var maxcount = 0; if (modelSet.Count == 0) { throw new Exception("File Is Empty"); } foreach (var model in modelSet) { foreach (var item in model) { maxcount++; } } foreach (var node in modelSet) { foreach (var item in node) { counter++; var d2 = StaticUtility.TimeConverter(item.TimeClose).ToLocalTime(); var formattedDate = d2.ToString("u").Replace("Z", "");// + " UTC"; decimal avg = 0; try { checked { avg = ((item.PriceClose + item.PriceHigh + item.PriceLow) / 3) * 100; } } catch (System.OverflowException e) { // The following line displays information about the error. Console.WriteLine("CHECKED and CAUGHT: " + e.ToString()); } var second = avg.ToString(CultureInfo.CurrentCulture); var newLine = counter < maxcount ? $"{formattedDate},{second}{Environment.NewLine}" : $"{formattedDate},{second}"; csv.Append(newLine); } } var saveTo = Path.Combine(location, fileName); if (csv.Length == 0) { lock (locker) { DirectoryManager.RemoveFolder(saveTo); return(false); } } lock (locker) { File.WriteAllText(saveTo, csv.ToString()); return(true); } }