} // End constructor /* PUBLIC METHODS */ // This loads a JSON file (.stack) from the hard drive that contains only one CloudCoin and turns it into an object. // This uses Newton soft but causes a enrror System.IO.FileNotFoundException. Could not load file 'Newtonsoft.Json' public CloudCoin loadOneCloudCoinFromJsonFile(String loadFilePath) { CloudCoin returnCC = new CloudCoin(); //Load file as JSON String incomeJson = this.importJSON(loadFilePath); //STRIP UNESSARY test int secondCurlyBracket = ordinalIndexOf(incomeJson, "{", 2) - 1; int firstCloseCurlyBracket = ordinalIndexOf(incomeJson, "}", 0) - secondCurlyBracket; // incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket); incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket + 1); // Console.Out.WriteLine(incomeJson); //Deserial JSON try { returnCC = JsonConvert.DeserializeObject <CloudCoin>(incomeJson); } catch (JsonReaderException) { Console.WriteLine("There was an error reading files in your bank."); CoreLogger.Log("There was an error reading files in your bank."); Console.WriteLine("You may have the aoid memo bug that uses too many double quote marks."); Console.WriteLine("Your bank files are stored using and older version that did not use properly formed JSON."); Console.WriteLine("Would you like to upgrade these files to the newer standard?"); Console.WriteLine("Your files will be edited."); Console.WriteLine("1 for yes, 2 for no."); KeyboardReader reader = new KeyboardReader(); int answer = reader.readInt(1, 2); if (answer == 1) { //Get rid of ed and aoid //Get file names in bank folder String[] fileNames = new DirectoryInfo(bankFolder).GetFiles().Select(o => o.Name).ToArray(); for (int i = 0; i < fileNames.Length; i++) { Console.WriteLine("Fixing " + bankFolder + "\\" + fileNames[i]); CoreLogger.Log("Fixing " + bankFolder + "\\" + fileNames[i]); string text = File.ReadAllText(bankFolder + "\\" + fileNames[i]); text = text.Replace("\"aoid\": [\"memo\"=\"\"]", ""); File.WriteAllText(bankFolder + "\\" + fileNames[i], text); }//End for all files in bank CoreLogger.Log("Done Fixing. The program will now exit. Please restart. Press any key."); Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key."); Console.Read(); Environment.Exit(0); } else { CoreLogger.Log("Leaving files as is. You maybe able to fix the manually by editing the files."); Console.WriteLine("Leaving files as is. You maybe able to fix the manually by editing the files."); Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key."); Console.Read(); Environment.Exit(0); } } return(returnCC); }//end load one CloudCoin from JSON
} // End main /* STATIC METHODS */ public static void run() { bool restart = false; while (!restart) { Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(""); // Console.Out.WriteLine("========================================"); Console.Out.WriteLine(""); Console.Out.WriteLine(" Commands Available:");//"Commands Available:"; Console.ForegroundColor = ConsoleColor.White; int commandCounter = 1; foreach (String command in commandsAvailable) { Console.Out.WriteLine(" " + commandCounter + (". " + command)); commandCounter++; } Console.ForegroundColor = ConsoleColor.Green; Console.Out.Write(prompt); Console.ForegroundColor = ConsoleColor.White; int commandRecieved = reader.readInt(1, 9); switch (commandRecieved) { case 1: echoRaida(); break; case 2: showCoins(); break; case 3: import(); break; case 4: export(); break; case 5: fix(); break; case 6: showFolders(); break; case 7: dump(); break; case 8: Environment.Exit(0); break; case 9: //testMind(); partialImport(); break; case 10: toMind(); break; case 11: fromMind(); break; default: Console.Out.WriteLine("Command failed. Try again."); //"Command failed. Try again."; break; }// end switch } // end while } // end run method
public static void ExportCoins() { Console.Out.WriteLine(" Do you want to export your CloudCoin to (1)jpgs , (2) stack (JSON) , (3) QR Code (4) 2D Bar code (5) CSV file?"); int file_type = reader.readInt(1, 5); int exp_1 = 0; int exp_5 = 0; int exp_25 = 0; int exp_100 = 0; int exp_250 = 0; if (onesTotalCount > 0) { Console.Out.WriteLine(" How many 1s do you want to export?"); exp_1 = reader.readInt(0, (onesTotalCount)); } // if 1s not zero if (fivesTotalCount > 0) { Console.Out.WriteLine(" How many 5s do you want to export?"); exp_5 = reader.readInt(0, (fivesTotalCount)); } // if 1s not zero if ((qtrTotalCount > 0)) { Console.Out.WriteLine(" How many 25s do you want to export?"); exp_25 = reader.readInt(0, (qtrTotalCount)); } // if 1s not zero if (hundredsTotalCount > 0) { Console.Out.WriteLine(" How many 100s do you want to export?"); exp_100 = reader.readInt(0, (hundredsTotalCount)); } // if 1s not zero if (twoFiftiesTotalCount > 0) { Console.Out.WriteLine(" How many 250s do you want to export?"); exp_250 = reader.readInt(0, (twoFiftiesTotalCount)); } Console.Out.WriteLine(" What tag will you add to the file name?"); String tag = reader.readString(); int totalSaved = exp_1 + (exp_5 * 5) + (exp_25 * 25) + (exp_100 * 100) + (exp_250 * 250); List <CloudCoin> totalCoins = IFileSystem.bankCoins.ToList(); totalCoins.AddRange(IFileSystem.frackedCoins); var onesToExport = (from x in totalCoins where x.denomination == 1 select x).Take(exp_1); var fivesToExport = (from x in totalCoins where x.denomination == 5 select x).Take(exp_5); var qtrToExport = (from x in totalCoins where x.denomination == 25 select x).Take(exp_25); var hundredsToExport = (from x in totalCoins where x.denomination == 100 select x).Take(exp_100); var twoFiftiesToExport = (from x in totalCoins where x.denomination == 250 select x).Take(exp_250); List <CloudCoin> exportCoins = onesToExport.ToList(); exportCoins.AddRange(fivesToExport); exportCoins.AddRange(qtrToExport); exportCoins.AddRange(hundredsToExport); exportCoins.AddRange(twoFiftiesToExport); // Export Coins as jPeg Images if (file_type == 1) { String filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ""); if (File.Exists(filename)) { // tack on a random number if a file already exists with the same tag Random rnd = new Random(); int tagrand = rnd.Next(999); filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ""); }//end if file exists foreach (var coin in exportCoins) { string OutputFile = FS.ExportFolder + coin.FileName + tag + ".jpg"; bool fileGenerated = FS.WriteCoinToJpeg(coin, FS.GetCoinTemplate(coin), OutputFile, ""); if (fileGenerated) { updateLog("CloudCoin exported as Jpeg to " + OutputFile); } } FS.RemoveCoins(exportCoins, FS.BankFolder); FS.RemoveCoins(exportCoins, FS.FrackedFolder); } // Export Coins as Stack if (file_type == 2) { String filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ""); if (File.Exists(filename)) { // tack on a random number if a file already exists with the same tag Random rnd = new Random(); int tagrand = rnd.Next(999); filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ""); }//end if file exists FS.WriteCoinsToFile(exportCoins, filename, ".stack"); FS.RemoveCoins(exportCoins, FS.BankFolder); FS.RemoveCoins(exportCoins, FS.FrackedFolder); } // Export Coins as QR Code if (file_type == 3) { foreach (var coin in exportCoins) { string OutputFile = FS.ExportFolder + coin.FileName + ".qr" + tag + ".jpg"; bool fileGenerated = FS.WriteCoinToQRCode(coin, OutputFile, tag); if (fileGenerated) { updateLog("CloudCoin Exported as QR code to " + OutputFile); } } FS.RemoveCoins(exportCoins, FS.BankFolder); FS.RemoveCoins(exportCoins, FS.FrackedFolder); } // Export Coins as 2D Bar code - PDF417 if (file_type == 4) { foreach (var coin in exportCoins) { string OutputFile = FS.ExportFolder + coin.FileName + ".qr" + tag + ".jpg"; bool fileGenerated = FS.WriteCoinToBARCode(coin, OutputFile, tag); if (fileGenerated) { updateLog("CloudCoin Exported as Bar code to " + OutputFile); } } FS.RemoveCoins(exportCoins, FS.BankFolder); FS.RemoveCoins(exportCoins, FS.FrackedFolder); } if (file_type == 5) { String filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ".csv"); if (File.Exists(filename)) { // tack on a random number if a file already exists with the same tag Random rnd = new Random(); int tagrand = rnd.Next(999); filename = (FS.ExportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ""); }//end if file exists var csv = new StringBuilder(); var coins = exportCoins; var headerLine = string.Format("sn,denomination,nn,"); string headeranstring = ""; for (int i = 0; i < CloudCoinCore.Config.NodeCount; i++) { headeranstring += "an" + (i + 1) + ","; } // Write the Header Record csv.AppendLine(headerLine + headeranstring); // Write the Coin Serial Numbers foreach (var coin in coins) { string anstring = ""; for (int i = 0; i < CloudCoinCore.Config.NodeCount; i++) { anstring += coin.an[i] + ","; } var newLine = string.Format("{0},{1},{2},{3}", coin.sn, coin.denomination, coin.nn, anstring); csv.AppendLine(newLine); } File.WriteAllText(filename, csv.ToString()); //FS.WriteCoinsToFile(exportCoins, filename, ".s"); FS.RemoveCoins(exportCoins, FS.BankFolder); FS.RemoveCoins(exportCoins, FS.FrackedFolder); } }