private async static Task ProcessInput(int input) { switch (input) { case 1: await EchoRaidas(); break; case 2: showCoins(); break; case 3: //await detect(); FS.LoadFileSystem(); await RAIDA.ProcessCoins(false); break; case 4: ExportCoins(); //export(); break; case 6: try { Process.Start(FS.RootPath); } catch (Exception e) { updateLog(e.Message); } ShowFolders(); break; case 5: Fix(); //fix(timeout); break; case 7: help(); break; //case 8: // Console.Write("Enter New Network Number - "); // int nn = Convert.ToInt16(Console.ReadLine()); // await SwitchNetwork(nn); // break; case 8: await SendCoinsTT(); break; default: break; } }
/* CONSTRUCTORS */ public Frack_Fixer(FileUtils fileUtils, int timeout) { this.fileUtils = fileUtils; raida = new RAIDA(); totalValueToBank = 0; totalValueToCounterfeit = 0; totalValueToFractured = 0; }//constructor
static async void DownloadCoin(string hash) { using (System.Net.Http.HttpClient cli = new System.Net.Http.HttpClient()) { var httpResponse = await cli.GetAsync("https://escrow.cloudcoin.digital/cc.php?h=" + hash); var ccstack = await httpResponse.Content.ReadAsStringAsync(); File.WriteAllText(FS.ImportFolder + Path.DirectorySeparatorChar + "CloudCoins.FromTrustedTrade.stack", ccstack); await RAIDA.ProcessCoins(false); DisplayMenu(); } }
} // end show folders public static void Setup() { // Create the Folder Structure FS.CreateFolderStructure(); // Populate RAIDA Nodes raida = RAIDA.GetInstance(); //raida.Echo(); FS.LoadFileSystem(); //Connect to Trusted Trade Socket tts = new TrustedTradeSocket("wss://escrow.cloudcoin.digital/ws/", 10, OnWord, OnStatusChange, OnReceive, OnProgress); tts.Connect().Wait(); //Load Local Coins // Console.Read(); }
public async static Task SwitchNetwork(int NewNetworkNumber) { int oldRAIDANumber = NetworkNumber; RAIDA oldRAIDA = raida; NetworkNumber = NewNetworkNumber; raida = (from x in RAIDA.networks where x.NetworkNumber == NetworkNumber select x).FirstOrDefault(); if (raida == null) { updateLog("Selected Network Number not found. Reverting to previous network."); raida = oldRAIDA; } else { updateLog("Network Number set to " + NetworkNumber); await EchoRaida(); } }
public static void SetupRAIDA() { RAIDA.FileSystem = new FileSystem(rootFolder); try { RAIDA.Instantiate(); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } if (RAIDA.networks.Count == 0) { updateLog("No Valid Network found.Quitting!!"); Environment.Exit(1); } else { updateLog(RAIDA.networks.Count + " Networks found."); raida = (from x in RAIDA.networks where x.NetworkNumber == NetworkNumber select x).FirstOrDefault(); raida.FS = FS; RAIDA.ActiveRAIDA = raida; if (raida == null) { updateLog("Selected Network Number not found. Quitting."); Environment.Exit(0); } else { updateLog("Network Number set to " + NetworkNumber); } } //networks[0] }
/* CONSTRUCTOR */ public Detector(FileUtils fileUtils, int timeout) { this.raida = new RAIDA(timeout); this.fileUtils = fileUtils; }// end Detect constructor
}// end Detect constructor /* PUBLIC METHODS */ public int[] gradeAll(int msToFixDangerousFracked, int msToRedetectDangerous) { String[] detectedFileNames = new DirectoryInfo(this.fileUtils.detectedFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder int totalValueToBank = 0; int totalValueToCounterfeit = 0; int totalValueToFractured = 0; int totalValueToKeptInSuspect = 0; int totalValueToLost = 0; CloudCoin newCC; for (int j = 0; j < detectedFileNames.Length; j++)//for every coins in the detected folder { try { if (File.Exists(this.fileUtils.bankFolder + detectedFileNames[j]) || File.Exists(this.fileUtils.frackedFolder + detectedFileNames[j])) {//Coin has already been imported. Delete it from import folder move to trash. //THIS SHOULD NOT HAPPEN - THE COIN SHOULD HAVE BEEN CHECKED DURING IMPORT BEFORE DETECTION TO SEE IF IT WAS IN THE BANK FOLDER Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine("You tried to import a coin that has already been imported."); CoreLogger.Log("You tried to import a coin that has already been imported."); updateLog("You tried to import a coin that has already been imported."); if (File.Exists(this.fileUtils.trashFolder + detectedFileNames[j])) { File.Delete(this.fileUtils.trashFolder + detectedFileNames[j]); } File.Move(this.fileUtils.detectedFolder + detectedFileNames[j], this.fileUtils.trashFolder + detectedFileNames[j]); Console.Out.WriteLine("Suspect CloudCoin was moved to Trash folder."); CoreLogger.Log("Suspect CloudCoin was moved to Trash folder."); updateLog("Suspect CloudCoin was moved to Trash folder."); Console.ForegroundColor = ConsoleColor.White; } else { newCC = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.detectedFolder + detectedFileNames[j]); CoinUtils cu = new CoinUtils(newCC); //CoinUtils detectedCC = cu; //cu.sortToFolder();//Tells the Coin Utils to set what folder the coins should go to. cu.consoleReport(); //Suspect, Counterfeit, Fracked, Bank, Trash, Detected, Lost, Dangerous switch (cu.getFolder().ToLower()) { case "bank": totalValueToBank++; fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc); break; case "fracked": totalValueToFractured++; fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc); break; case "counterfeit": totalValueToCounterfeit++; fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc); break; case "lost": totalValueToLost++; fileUtils.writeTo(this.fileUtils.lostFolder, cu.cc); break; case "suspect": totalValueToKeptInSuspect++; fileUtils.writeTo(this.fileUtils.suspectFolder, cu.cc); Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(" Not enough RAIDA were contacted to determine if the coin is authentic."); Console.Out.WriteLine(" Try again later."); CoreLogger.Log(" Not enough RAIDA were contacted to determine if the coin is authentic. Try again later."); Console.ForegroundColor = ConsoleColor.White; break; case "dangerous": Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(" WARNING: Strings may be attached to this coins"); Console.ForegroundColor = ConsoleColor.White; Console.Out.WriteLine(" Now fixing fracked for " + (j + 1) + " of " + detectedFileNames.Length + " . SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination()); CoreLogger.Log(" Now fixing fracked for " + (j + 1) + " of " + detectedFileNames.Length + " . SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination()); updateLog("Some of your CloudCoins are still being processed. This should take just a moment."); Frack_Fixer ff = new Frack_Fixer(fileUtils, msToFixDangerousFracked); ff.txtLogs = txtLogs; RAIDA raida = new RAIDA(); Console.WriteLine("folder is " + cu.getFolder().ToLower()); while (cu.getFolder().ToLower() == "dangerous") { // keep fracking fixing until all fixed or no more improvments possible. Console.WriteLine(" calling fix Coin"); cu = ff.fixCoin(cu.cc, msToFixDangerousFracked).Result; Console.WriteLine(" sorting after fixing"); cu.sortFoldersAfterFixingDangerous(); } //while folder still dangerous for (int i = 0; i < 25; i++) { cu.pans[i] = cu.generatePan(); } // end for each pan cu = raida.detectCoin(cu, msToRedetectDangerous); //Detect again to make sure it is powned cu.consoleReport(); cu.sortToFolder(); //Tells the Coin Utils to set what folder the coins should go to. switch (cu.getFolder().ToLower()) { case "bank": totalValueToBank++; fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc); break; case "fracked": totalValueToFractured++; fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc); break; default: totalValueToCounterfeit++; fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc); break; } //end switch break; }//end switch File.Delete(this.fileUtils.detectedFolder + detectedFileNames[j]);//Take the coin out of the detected folder }//end if file exists } catch (FileNotFoundException ex) { Console.Out.WriteLine(ex); CoreLogger.Log(ex.ToString()); } catch (IOException ioex) { Console.Out.WriteLine(ioex); CoreLogger.Log(ioex.ToString()); } // end try catch } // end for each coin to import results[0] = totalValueToBank; results[1] = totalValueToFractured; results[2] = totalValueToCounterfeit; results[3] = totalValueToKeptInSuspect; results[4] = totalValueToLost; return(results); }//Detect All
/* CONSTRUCTOR */ public MultiDetect(FileUtils fileUtils) { raida = new RAIDA(); this.fileUtils = fileUtils; }// end Detect constructor
} // End print welcome public static bool echoRaida() { RAIDA_Status.resetEcho(); RAIDA raida1 = new RAIDA(5000); Response[] results = raida1.echoAll(5000); int totalReady = 0; Console.Out.WriteLine(""); //For every RAIDA check its results int longestCountryName = 15; Console.Out.WriteLine(); for (int i = 0; i < 25; i++) { int padding = longestCountryName - countries[i].Length; string strPad = ""; for (int j = 0; j < padding; j++) { strPad += " "; }//end for padding // Console.Out.Write(RAIDA_Status.failsEcho[i]); if (RAIDA_Status.failsEcho[i]) { Console.ForegroundColor = ConsoleColor.Red; Console.Out.Write(strPad + countries[i]); } else { Console.ForegroundColor = ConsoleColor.Green; Console.Out.Write(strPad + countries[i]); totalReady++; } if (i == 4 || i == 9 || i == 14 || i == 19) { Console.WriteLine(); } }//end for Console.ForegroundColor = ConsoleColor.White; Console.Out.WriteLine(""); Console.Out.WriteLine(""); Console.Out.Write(" RAIDA Health: " + totalReady + " / 25: ");//"RAIDA Health: " + totalReady ); //Check if enough are good if (totalReady < 16)// { Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(" Not enough RAIDA servers can be contacted to import new coins."); // ); Console.Out.WriteLine(" Is your device connected to the Internet?"); // ); Console.Out.WriteLine(" Is a router blocking your connection?"); // ); Console.ForegroundColor = ConsoleColor.White; return(false); } else { Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine("The RAIDA is ready for counterfeit detection.");// ); Console.ForegroundColor = ConsoleColor.White; return(true); } //end if enough RAIDA } //End echo
public static void Main(params string[] args) { Setup(); updateLog("Loading Network Directory"); SetupRAIDA(); FS.LoadFileSystem(); RAIDA.logger = logger; fixer = new Frack_Fixer(FS, Config.milliSecondsToTimeOut); Console.Clear(); // Program.exe <-g|--greeting|-$ <greeting>> [name <fullname>] // [-?|-h|--help] [-u|--uppercase] #region CommandLineArguments CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false); CommandArgument names = null; commandLineApplication.Command("name", (target) => names = target.Argument( "fullname", "Enter the full name of the person to be greeted.", multipleValues: true)); CommandOption greeting = commandLineApplication.Option( "-$|-g |--greeting <greeting>", "The greeting to display. The greeting supports" + " a format string where {fullname} will be " + "substituted with the full name.", CommandOptionType.NoValue); CommandOption uppercase = commandLineApplication.Option( "-u | --uppercase", "Display the greeting in uppercase.", CommandOptionType.NoValue); commandLineApplication.HelpOption("-? | -h | --help"); CommandOption stats = commandLineApplication.Option( "-$|-s |--stats ", "Displays RAIDA statistics of all networks", CommandOptionType.NoValue); CommandOption echo = commandLineApplication.Option( "-$|-e |--echo ", "The greeting to display. The greeting supports" + " a format string where {fullname} will be " + "substituted with the full name.", CommandOptionType.NoValue); CommandOption total = commandLineApplication.Option( "-$|-b |--bank ", "Shows details of your coins in bank.", CommandOptionType.NoValue); CommandOption backup = commandLineApplication.Option( "-$|-ba |--backup ", "Backup your coins to specified folder.", CommandOptionType.SingleValue); CommandOption folders = commandLineApplication.Option( "-$|-f |--folders ", "The command to display CloudCoin Working Folder Structure", CommandOptionType.NoValue); CommandOption pown = commandLineApplication.Option( "-$|-p |--pown ", "The command to pown/detect/import your CloudCoins.", CommandOptionType.NoValue); CommandOption detection = commandLineApplication.Option( "-$|-d |--detect ", "The command to pown/detect/import your CloudCoins.", CommandOptionType.NoValue); CommandOption import = commandLineApplication.Option( "-$|-i |--import ", "The command to pown/detect/import your CloudCoins.", CommandOptionType.NoValue); #endregion if (args.Length < 1) { printWelcome(); while (true) { try { int input = DisplayMenu(); ProcessInput(input).Wait(); if (input == 9) { break; } } catch (Exception e) { break; } } } else { commandLineApplication.OnExecute(async() => { if (echo.HasValue()) { //ech(); await EchoRaidas(); } if (folders.HasValue()) { ShowFolders(); } if (pown.HasValue() || detection.HasValue() || import.HasValue()) { await RAIDA.ProcessCoins(false); } if (greeting.HasValue()) { printWelcome(); } if (stats.HasValue()) { await EchoRaidas(); } if (total.HasValue()) { showCoins(); } if (backup.HasValue()) { Console.WriteLine(backup.Value()); } return(0); }); commandLineApplication.Execute(args); } }