}//end detectOne public CloudCoin detectCoin(CloudCoin cc, int milliSecondsToTimeOut) { returnCoin = cc; var t00 = Task.Factory.StartNew(() => detectOne(00, cc.nn, cc.sn, cc.ans[00], cc.pans[00], cc.getDenomination())); var t01 = Task.Factory.StartNew(() => detectOne(01, cc.nn, cc.sn, cc.ans[01], cc.pans[01], cc.getDenomination())); var t02 = Task.Factory.StartNew(() => detectOne(02, cc.nn, cc.sn, cc.ans[02], cc.pans[02], cc.getDenomination())); var t03 = Task.Factory.StartNew(() => detectOne(03, cc.nn, cc.sn, cc.ans[03], cc.pans[03], cc.getDenomination())); var t04 = Task.Factory.StartNew(() => detectOne(04, cc.nn, cc.sn, cc.ans[04], cc.pans[04], cc.getDenomination())); var t05 = Task.Factory.StartNew(() => detectOne(05, cc.nn, cc.sn, cc.ans[05], cc.pans[05], cc.getDenomination())); var t06 = Task.Factory.StartNew(() => detectOne(06, cc.nn, cc.sn, cc.ans[06], cc.pans[06], cc.getDenomination())); var t07 = Task.Factory.StartNew(() => detectOne(07, cc.nn, cc.sn, cc.ans[07], cc.pans[07], cc.getDenomination())); var t08 = Task.Factory.StartNew(() => detectOne(08, cc.nn, cc.sn, cc.ans[08], cc.pans[08], cc.getDenomination())); var t09 = Task.Factory.StartNew(() => detectOne(09, cc.nn, cc.sn, cc.ans[09], cc.pans[09], cc.getDenomination())); var t10 = Task.Factory.StartNew(() => detectOne(10, cc.nn, cc.sn, cc.ans[10], cc.pans[10], cc.getDenomination())); var t11 = Task.Factory.StartNew(() => detectOne(11, cc.nn, cc.sn, cc.ans[11], cc.pans[11], cc.getDenomination())); var t12 = Task.Factory.StartNew(() => detectOne(12, cc.nn, cc.sn, cc.ans[12], cc.pans[12], cc.getDenomination())); var t13 = Task.Factory.StartNew(() => detectOne(13, cc.nn, cc.sn, cc.ans[13], cc.pans[13], cc.getDenomination())); var t14 = Task.Factory.StartNew(() => detectOne(14, cc.nn, cc.sn, cc.ans[14], cc.pans[14], cc.getDenomination())); var t15 = Task.Factory.StartNew(() => detectOne(15, cc.nn, cc.sn, cc.ans[15], cc.pans[15], cc.getDenomination())); var t16 = Task.Factory.StartNew(() => detectOne(16, cc.nn, cc.sn, cc.ans[16], cc.pans[16], cc.getDenomination())); var t17 = Task.Factory.StartNew(() => detectOne(17, cc.nn, cc.sn, cc.ans[17], cc.pans[17], cc.getDenomination())); var t18 = Task.Factory.StartNew(() => detectOne(18, cc.nn, cc.sn, cc.ans[18], cc.pans[18], cc.getDenomination())); var t19 = Task.Factory.StartNew(() => detectOne(19, cc.nn, cc.sn, cc.ans[19], cc.pans[19], cc.getDenomination())); var t20 = Task.Factory.StartNew(() => detectOne(20, cc.nn, cc.sn, cc.ans[20], cc.pans[20], cc.getDenomination())); var t21 = Task.Factory.StartNew(() => detectOne(21, cc.nn, cc.sn, cc.ans[21], cc.pans[21], cc.getDenomination())); var t22 = Task.Factory.StartNew(() => detectOne(22, cc.nn, cc.sn, cc.ans[22], cc.pans[22], cc.getDenomination())); var t23 = Task.Factory.StartNew(() => detectOne(23, cc.nn, cc.sn, cc.ans[23], cc.pans[23], cc.getDenomination())); var t24 = Task.Factory.StartNew(() => detectOne(24, cc.nn, cc.sn, cc.ans[24], cc.pans[24], cc.getDenomination())); var taskList = new List <Task> { t00, t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20, t21, t22, t23, t24 }; Task.WaitAll(taskList.ToArray(), milliSecondsToTimeOut); //Get data from the detection agents for (int i = 0; i < 25; i++) { if (responseArray[i] != null) { returnCoin.setPastStatus(responseArray[i].outcome, i); } else { returnCoin.setPastStatus("undetected", i); };// should be pass, fail, error or undetected. }//end for each detection agent returnCoin.setAnsToPansIfPassed(); returnCoin.calculateHP(); returnCoin.gradeCoin(); // sets the grade and figures out what the file extension should be (bank, fracked, counterfeit, lost returnCoin.calcExpirationDate(); returnCoin.grade(); return(returnCoin); }//end detect coin
}//end delete coin public CloudCoin fixCoin(CloudCoin brokeCoin) { /*0. RESET TICKETS IN RAIDA STATUS TO EMPTY*/ RAIDA_Status.resetTickets(); /*0. RESET THE DETECTION to TRUE if it is a new COIN */ RAIDA_Status.newCoin(); brokeCoin.setAnsToPans();// Make sure we set the RAIDA to the cc ans and not new pans. DateTime before = DateTime.Now; String fix_result = ""; FixitHelper fixer; /*START*/ /*1. PICK THE CORNER TO USE TO TRY TO FIX */ int corner = 1; // For every guid, check to see if it is fractured for (int raida_ID = 0; raida_ID < 25; raida_ID++) { // Console.WriteLine("Past Status for " + raida_ID + ", " + brokeCoin.pastStatus[raida_ID]); if (brokeCoin.getPastStatus(raida_ID).ToLower() == "fail") { Console.ForegroundColor = ConsoleColor.Cyan; Console.Out.WriteLine(""); Console.WriteLine(StringHolder.frackfixer_11); //"Attempting to fix RAIDA " + raida_ID); Console.Out.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; fixer = new FixitHelper(raida_ID, brokeCoin.ans); //trustedServerAns = new String[] { brokeCoin.ans[fixer.currentTriad[0]], brokeCoin.ans[fixer.currentTriad[1]], brokeCoin.ans[fixer.currentTriad[2]] }; corner = 1; while (!fixer.finnished) { Console.WriteLine(StringHolder.frackfixer_12 + corner); //" Using corner " + corner); fix_result = fixOneGuidCorner(raida_ID, brokeCoin, corner, fixer.currentTriad); // Console.WriteLine(" fix_result: " + fix_result + " for corner " + corner); if (fix_result.Contains("success")) { //Fixed. Do the fixed stuff brokeCoin.setPastStatus("pass", raida_ID); fixer.finnished = true; corner = 1; } else { //Still broken, do the broken stuff. corner++; fixer.setCornerToCheck(corner); } } //End whild fixer not finnished } //end if RAIDA past status is passed and does not need to be fixed } //end for each AN DateTime after = DateTime.Now; TimeSpan ts = after.Subtract(before); Console.WriteLine(StringHolder.frackfixer_13); //"Time spent fixing RAIDA in milliseconds: " + ts.Milliseconds); brokeCoin.calculateHP(); //how many fails did it get brokeCoin.gradeCoin(); // sets the grade and figures out what the file extension should be (bank, fracked, counterfeit, lost brokeCoin.calcExpirationDate(); brokeCoin.grade(); return(brokeCoin); } // end fix coin
}// end Detect constructor /* PUBLIC METHODS */ /// <summary> /// /// </summary> /// <returns></returns> public int[] detectAll() { // LOAD THE .suspect COINS ONE AT A TIME AND TEST THEM int[] results = new int[4]; // [0] Coins to bank, [1] Coins to fracked [2] Coins to Counterfeit String[] suspectFileNames = new DirectoryInfo(this.fileUtils.suspectFolder).GetFiles().Select(o => o.Name).ToArray(); //Get all files in suspect folder int totalValueToBank = 0; int totalValueToCounterfeit = 0; int totalValueToFractured = 0; int totalValueToKeptInSuspect = 0; bool coinSupect = false; CloudCoin newCC; for (int j = 0; j < suspectFileNames.Length; j++) { try { if (File.Exists(this.fileUtils.bankFolder + suspectFileNames[j])) { //Coin has already been imported. Delete it from import folder move to trash. Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(StringHolder.detector_3); // "You tried to import a coin that has already been imported."); File.Move(this.fileUtils.suspectFolder + suspectFileNames[j], this.fileUtils.trashFolder + suspectFileNames[j]); Console.Out.WriteLine(StringHolder.detector_4); //"Suspect CloudCoin was moved to Trash folder."); Console.ForegroundColor = ConsoleColor.White; } else { newCC = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.suspectFolder + suspectFileNames[j]); Console.Out.WriteLine(StringHolder.detector_5 + (j + 1) + " of " + suspectFileNames.Length + StringHolder.detector_6 + string.Format("{0:n0}", newCC.sn) + StringHolder.cloudcoin_denomination + newCC.getDenomination()); Console.Out.WriteLine(""); CloudCoin detectedCC = this.raida.detectCoin(newCC, detectTime); detectedCC.calcExpirationDate(); if (j == 0) //If we are detecting the first coin, note if the RAIDA are working { for (int i = 0; i < 25; i++) // Checks any servers are down so we don't try to check them again. { if (detectedCC.getPastStatus(i) != "pass" && detectedCC.getPastStatus(i) != "fail") { raida.raidaIsDetecting[i] = false;//Server is not working correctly, don't try it agian } } }//end if it is the first coin we are detecting detectedCC.consoleReport(); bool alreadyExists = false;//Does the file already been imported? switch (detectedCC.getFolder().ToLower()) { case "bank": totalValueToBank++; alreadyExists = this.fileUtils.writeTo(this.fileUtils.bankFolder, detectedCC); break; case "fracked": totalValueToFractured++; alreadyExists = this.fileUtils.writeTo(this.fileUtils.frackedFolder, detectedCC); break; case "counterfeit": totalValueToCounterfeit++; alreadyExists = this.fileUtils.writeTo(this.fileUtils.counterfeitFolder, detectedCC); break; case "suspect": totalValueToKeptInSuspect++; coinSupect = true; //Coin will remain in suspect folder break; }//end switch // end switch on the place the coin will go if (!coinSupect) //Leave coin in the suspect folder if RAIDA is down { File.Delete(this.fileUtils.suspectFolder + suspectFileNames[j]); //Take the coin out of the suspect folder } else { this.fileUtils.writeTo(this.fileUtils.suspectFolder, detectedCC); Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(StringHolder.detector_7); //"Not enough RAIDA were contacted to determine if the coin is authentic."); Console.Out.WriteLine(StringHolder.detector_8); //"Try again later."); Console.ForegroundColor = ConsoleColor.White; }//end if else }//end if file exists }catch (FileNotFoundException ex) { Console.Out.WriteLine(ex); }catch (IOException ioex) { Console.Out.WriteLine(ioex); } // end try catch } // end for each coin to import results[0] = totalValueToBank; results[1] = totalValueToCounterfeit; results[2] = totalValueToFractured; results[3] = totalValueToKeptInSuspect; return(results); }//Detect All
// end get JSON /* Writes a JPEG To the Export Folder */ public bool writeJpeg(CloudCoin cc, string tag) { // Console.Out.WriteLine("Writing jpeg " + cc.sn); bool fileSavedSuccessfully = true; /* BUILD THE CLOUDCOIN STRING */ String cloudCoinStr = "01C34A46494600010101006000601D05"; //THUMBNAIL HEADER BYTES for (int i = 0; (i < 25); i++) { cloudCoinStr = cloudCoinStr + cc.ans[i]; } // end for each an cloudCoinStr += "204f42455920474f4420262044454645415420545952414e545320";// Hex for " OBEY GOD & DEFEAT TYRANTS " cloudCoinStr += "00"; // HC: Has comments. 00 = No cloudCoinStr += "00"; // LHC = 100% cc.calcExpirationDate(); cloudCoinStr += cc.edHex; // 0x97E2;//Expiration date Sep. 2018 cloudCoinStr += "01"; // cc.nn;//network number String hexSN = cc.sn.ToString("X6"); String fullHexSN = ""; switch (hexSN.Length) { case 1: fullHexSN = ("00000" + hexSN); break; case 2: fullHexSN = ("0000" + hexSN); break; case 3: fullHexSN = ("000" + hexSN); break; case 4: fullHexSN = ("00" + hexSN); break; case 5: fullHexSN = ("0" + hexSN); break; case 6: fullHexSN = hexSN; break; } cloudCoinStr = (cloudCoinStr + fullHexSN); /* BYTES THAT WILL GO FROM 04 to 454 (Inclusive)*/ byte[] ccArray = this.hexStringToByteArray(cloudCoinStr); /* READ JPEG TEMPLATE*/ byte[] jpegBytes = null; switch (cc.getDenomination()) { case 1: jpegBytes = readAllBytes(this.templateFolder + "jpeg1.jpg"); break; case 5: jpegBytes = readAllBytes(this.templateFolder + "jpeg5.jpg"); break; case 25: jpegBytes = readAllBytes(this.templateFolder + "jpeg25.jpg"); break; case 100: jpegBytes = readAllBytes(this.templateFolder + "jpeg100.jpg"); break; case 250: jpegBytes = readAllBytes(this.templateFolder + "jpeg250.jpg"); break; }// end switch /* WRITE THE SERIAL NUMBER ON THE JPEG */ Bitmap bitmapimage; using (var ms = new MemoryStream(jpegBytes)) { bitmapimage = new Bitmap(ms); // bitmapimage.Save(fileName2, ImageFormat.Jpeg); } Graphics graphics = Graphics.FromImage(bitmapimage); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; PointF drawPointAddress = new PointF(10.0F, 10.0F); graphics.DrawString(String.Format("{0:N0}", cc.sn) + " of 16,777,216 on Network: 1", new Font("Arial", 20), Brushes.White, drawPointAddress); ImageConverter converter = new ImageConverter(); byte[] snBytes = (byte[])converter.ConvertTo(bitmapimage, typeof(byte[])); List <byte> b1 = new List <byte>(snBytes); List <byte> b2 = new List <byte>(ccArray); b1.InsertRange(4, b2); if (tag == "random") { Random r = new Random(); int rInt = r.Next(100000, 1000000); //for ints tag = rInt.ToString(); } string fileName = exportFolder + cc.fileName + tag + ".jpg"; File.WriteAllBytes(fileName, b1.ToArray()); Console.Out.WriteLine("Writing to " + fileName); return(fileSavedSuccessfully); }//end write JPEG