}//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
}//constructor public string fixOneGuidCorner(int raida_ID, CloudCoin cc, int corner, int[] trustedTriad) { /*1. WILL THE BROKEN RAIDA FIX? check to see if it has problems echo, detect, or fix. */ if (RAIDA_Status.failsFix[raida_ID] || RAIDA_Status.failsEcho[raida_ID] || RAIDA_Status.failsEcho[raida_ID]) { Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(""); Console.Out.WriteLine(StringHolder.frackfixer_1); // "RAIDA Fails Echo or Fix. Try again when RAIDA online."); Console.Out.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; return("RAIDA Fails Echo or Fix. Try again when RAIDA online."); } else { /*2. ARE ALL TRUSTED RAIDA IN THE CORNER READY TO HELP?*/ // Console.Out.WriteLine("Fails echo 0 " + RAIDA_Status.failsEcho[trustedTriad[0]]); // Console.Out.WriteLine("Fails echo 1 " + RAIDA_Status.failsEcho[trustedTriad[1]]); // Console.Out.WriteLine("Fails echo 2 " + RAIDA_Status.failsEcho[trustedTriad[2]]); // Console.Out.WriteLine("Fails failsDetect 0 " + RAIDA_Status.failsDetect[trustedTriad[0]]); // Console.Out.WriteLine("Fails failsDetect 1 " + RAIDA_Status.failsDetect[trustedTriad[1]]); // Console.Out.WriteLine("Fails failsDetect 2 " + RAIDA_Status.failsDetect[trustedTriad[2]]); if (!RAIDA_Status.failsEcho[trustedTriad[0]] || !RAIDA_Status.failsDetect[trustedTriad[0]] || !RAIDA_Status.failsEcho[trustedTriad[1]] || !RAIDA_Status.failsDetect[trustedTriad[1]] || !RAIDA_Status.failsEcho[trustedTriad[2]] || !RAIDA_Status.failsDetect[trustedTriad[2]]) { /*3. GET TICKETS AND UPDATE RAIDA STATUS TICKETS*/ string[] ans = { cc.ans[trustedTriad[0]], cc.ans[trustedTriad[1]], cc.ans[trustedTriad[2]] }; raida.get_Tickets(trustedTriad, ans, cc.nn, cc.sn, cc.getDenomination(), 3000); /*4. ARE ALL TICKETS GOOD?*/ if (RAIDA_Status.hasTicket[trustedTriad[0]] && RAIDA_Status.hasTicket[trustedTriad[0]] && RAIDA_Status.hasTicket[trustedTriad[0]]) { /*5.T YES, so REQUEST FIX*/ DetectionAgent da = new DetectionAgent(raida_ID, 5000); Response fixResponse = da.fix(trustedTriad, RAIDA_Status.tickets[trustedTriad[0]], RAIDA_Status.tickets[trustedTriad[1]], RAIDA_Status.tickets[trustedTriad[2]], cc.ans[raida_ID]); /*6. DID THE FIX WORK?*/ if (fixResponse.success) { Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(""); Console.Out.WriteLine("RAIDA" + raida_ID + StringHolder.frackfixer_2); //" unfracked successfully."); Console.Out.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; return("RAIDA" + raida_ID + " unfracked successfully."); } else { Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(""); Console.Out.WriteLine(StringHolder.frackfixer_3 + corner);//"RAIDA failed to accept tickets on corner " + corner); Console.Out.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; return("RAIDA failed to accept tickets on corner " + corner); }//end if fix respons was success or fail } else { Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(""); Console.Out.WriteLine(StringHolder.frackfixer_4 + corner);//"Trusted servers failed to provide tickets for corner " + corner); Console.Out.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; return("Trusted servers failed to provide tickets for corner " + corner);//no three good tickets }//end if all good }//end if trused triad will echo and detect (Detect is used to get ticket) Console.ForegroundColor = ConsoleColor.Red; Console.Out.WriteLine(""); Console.Out.WriteLine(StringHolder.frackfixer_5); //"One or more of the trusted triad will not echo and detect.So not trying."); Console.Out.WriteLine(""); Console.ForegroundColor = ConsoleColor.White; return("One or more of the trusted triad will not echo and detect. So not trying."); }//end if RAIDA fails to fix. } //end fix one
} //end fix one /* PUBLIC METHODS */ public int[] fixAll() { int[] results = new int[3]; String[] frackedFileNames = new DirectoryInfo(this.fileUtils.frackedFolder).GetFiles().Select(o => o.Name).ToArray(); CloudCoin frackedCC; if (frackedFileNames.Length < 0) { Console.ForegroundColor = ConsoleColor.Green; Console.Out.WriteLine(StringHolder.frackfixer_6); // "You have no fracked coins."); Console.ForegroundColor = ConsoleColor.White; }//no coins to unfrack for (int i = 0; i < frackedFileNames.Length; i++) { Console.WriteLine(StringHolder.frackfixer_unfracking + (i + 1) + " of " + frackedFileNames.Length); try { frackedCC = fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.frackedFolder + frackedFileNames[i]); String value = frackedCC.aoid["fracked"]; // Console.WriteLine("Fracked Coin: "); frackedCC.consoleReport(); CloudCoin fixedCC = fixCoin(frackedCC); // Will attempt to unfrack the coin. fixedCC.consoleReport(); switch (fixedCC.getFolder().ToLower()) { case "bank": this.totalValueToBank++; this.fileUtils.overWrite(this.fileUtils.bankFolder, fixedCC); this.deleteCoin(this.fileUtils.frackedFolder + frackedFileNames[i]); Console.WriteLine(StringHolder.frackfixer_8); //"CloudCoin was moved to Bank."); break; case "counterfeit": this.totalValueToCounterfeit++; this.fileUtils.overWrite(this.fileUtils.counterfeitFolder, fixedCC); this.deleteCoin(this.fileUtils.frackedFolder + frackedFileNames[i]); Console.WriteLine(StringHolder.frackfixer_9); //"CloudCoin was moved to Trash."); break; default: //Move back to fracked folder this.totalValueToFractured++; this.deleteCoin(this.fileUtils.frackedFolder + frackedFileNames[i]); this.fileUtils.overWrite(this.fileUtils.frackedFolder, fixedCC); Console.WriteLine(StringHolder.frackfixer_10); //"CloudCoin was moved back to Fraked folder."); break; } // end switch on the place the coin will go } catch (FileNotFoundException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex); Console.ForegroundColor = ConsoleColor.White; } catch (IOException ioex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ioex); Console.ForegroundColor = ConsoleColor.White; } // end try catch } // end for each file name that is fracked results[0] = this.totalValueToBank; results[1] = this.totalValueToCounterfeit; // System.out.println("Counterfeit and Moved to trash: "+totalValueToCounterfeit); results[2] = this.totalValueToFractured; // System.out.println("Fracked and Moved to Fracked: "+ totalValueToFractured); return(results); }// end fix all
} //end write all jpegs /* Write JSON to .stack File */ public bool writeJSONFile(int m1, int m5, int m25, int m100, int m250, String tag) { bool jsonExported = true; int totalSaved = m1 + (m5 * 5) + (m25 * 25) + (m100 * 100) + (m250 * 250); // Track the total coins int coinCount = m1 + m5 + m25 + m100 + m250; String[] coinsToDelete = new String[coinCount]; String[] bankedFileNames = new DirectoryInfo(this.fileUtils.bankFolder).GetFiles().Select(o => o.Name).ToArray();//Get all names in bank folder String[] frackedFileNames = new DirectoryInfo(this.fileUtils.frackedFolder).GetFiles().Select(o => o.Name).ToArray();; // Add the two arrays together var list = new List <String>(); list.AddRange(bankedFileNames); list.AddRange(frackedFileNames); // Program will spend fracked files like perfect files bankedFileNames = list.ToArray(); // Check to see the denomination by looking at the file start int c = 0; // c= counter String json = "{" + Environment.NewLine; json = json + "\t\"cloudcoin\": [" + Environment.NewLine; String bankFileName; String frackedFileName; string denomination; // Put all the JSON together and add header and footer for (int i = 0; (i < bankedFileNames.Length); i++) { denomination = bankedFileNames[i].Split('.')[0]; bankFileName = this.fileUtils.bankFolder + bankedFileNames[i]; //File name in bank folder frackedFileName = this.fileUtils.frackedFolder + bankedFileNames[i]; //File name in fracked folder if (denomination == "1" && m1 > 0) { if (c != 0)//This is the json seperator between each coin. It is not needed on the first coin { json += ",\n"; } if (File.Exists(bankFileName)) // Is it a bank file { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName); coinNote.aoid = null;//Clear all owner data json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = bankFileName; c++; } else { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName); coinNote.aoid = null; json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = frackedFileName; c++; } m1--; // Get the clean JSON of the coin }// end if coin is a 1 if (denomination == "5" && m5 > 0) { if ((c != 0)) { json += ",\n"; } if (File.Exists(bankFileName)) { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName); coinNote.aoid = null;//Clear all owner data json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = bankFileName; c++; } else { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName); coinNote.aoid = null; json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = frackedFileName; c++; } m5--; } // end if coin is a 5 if (denomination == "25" && m25 > 0) { if ((c != 0)) { json += ",\n"; } if (File.Exists(bankFileName)) { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName); coinNote.aoid = null;//Clear all owner data json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = bankFileName; c++; } else { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName); coinNote.aoid = null; json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = frackedFileName; c++; } m25--; }// end if coin is a 25 if (denomination == "100" && m100 > 0) { if ((c != 0)) { json += ",\n"; } if (File.Exists(bankFileName)) { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName); coinNote.aoid = null;//Clear all owner data json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = bankFileName; c++; } else { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName); coinNote.aoid = null; json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = frackedFileName; c++; } m100--; } // end if coin is a 100 if (denomination == "250" && m250 > 0) { if ((c != 0)) { json += ",\n"; } if (File.Exists(bankFileName)) { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName); coinNote.aoid = null;//Clear all owner data json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = bankFileName; c++; } else { CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName); coinNote.aoid = null; json = json + this.fileUtils.setJSON(coinNote); coinsToDelete[c] = frackedFileName; c++; } m250--; }// end if coin is a 250 if (m1 == 0 && m5 == 0 && m25 == 0 && m100 == 0 && m250 == 0) { break; } // Break if all the coins have been called for. } // end for each coin needed /*WRITE JSON TO FILE*/ json = json + "\t] " + Environment.NewLine; json += "}"; String filename = (this.fileUtils.exportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ".stack"); if (File.Exists(filename)) { // tack on a random number if a file already exists with the same tag // Add random Random rnd = new Random(); int tagrand = rnd.Next(999); filename = (this.fileUtils.exportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ".stack"); }//end if file exists // end if file exists /*Add Saying*/ //json = json.Replace("[]", @""["We The Cloud People"]""); File.WriteAllText(filename, json); Console.Out.WriteLine("Writing to : "); Console.Out.WriteLine(filename); /*DELETE FILES THAT HAVE BEEN EXPORTED*/ for (int cc = 0; cc < coinsToDelete.Length; cc++) { // Console.Out.WriteLine("Deleting " + coinsToDelete[cc]); if (coinsToDelete[cc] != null) { File.Delete(coinsToDelete[cc]); } }//end for all coins to delete // end if write was good return(jsonExported); }//end write json to file
}// 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
} //end load one CloudCoin from JSON /* * 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) * { * * //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 * SimpleCoin cc = JsonConvert.DeserializeObject<SimpleCoin>(incomeJson); * //Make Coin * String[] strAoid = cc.aoid.ToArray(); * Dictionary<string, string> aoid_dictionary = new Dictionary<string, string>(); * for (int j = 0; j < strAoid.Length; j++) * { //"fracked=ppppppppppppppppppppppppp" * if (strAoid[j].Contains("=")) * {//see if the string contains an equals sign * String[] keyvalue = strAoid[j].Split('='); * aoid_dictionary.Add(keyvalue[0], keyvalue[1]);//index 0 is the key index 1 is the value. * } * else * { //There is something there but not a key value pair. Treak it like a memo * aoid_dictionary.Add("memo", strAoid[j]); * }//end if cointains an = * }//end for each aoid * * * CloudCoin returnCC = new CloudCoin(cc.nn, cc.sn, cc.an.ToArray(), cc.ed, aoid_dictionary, "suspect"); * for (int i = 0; (i < 25); i++) * {//All newly created loaded coins get new PANs. * returnCC.pans[i] = returnCC.generatePan(); * //returnCC.pastStatus[i] = "undetected"; * } // end for each pan * //Return Coin * * returnCC.fileName = (returnCC.getDenomination() + (".CloudCoin." + (returnCC.nn + ("." + (returnCC.sn + "."))))); * returnCC.json = ""; * returnCC.jpeg = null; * * return returnCC; * }//end load one CloudCoin from JSON * */ public CloudCoin[] loadManyCloudCoinFromJsonFile(String loadFilePath, string incomeJson) { CloudCoin[] returnCoins; //Remove "{ "cloudcoin": [" int secondCurlyBracket = ordinalIndexOf(incomeJson, "{", 2) - 1; incomeJson = incomeJson.Substring(secondCurlyBracket); //remove the last instance of "]}" incomeJson = incomeJson.Remove(incomeJson.LastIndexOf("}"), 1); incomeJson = incomeJson.Remove(incomeJson.LastIndexOf("]"), 1); // Console.Out.WriteLine(incomeJson); String[] pieces = incomeJson.Split('}'); //split json file into coins returnCoins = new CloudCoin[pieces.Length - 1]; //last piece is not a coin for (int j = 0; j < pieces.Length - 1; j++) //for each cloudcoin segment in the chest or stack file. -1 allows for last runt segment { String currentCoin = pieces[j]; String[] jsonArray = currentCoin.Split('"'); // for (int i = 0; i < jsonArray.Length; i++ ) // { // Console.Out.WriteLine( i + " = " + jsonArray[i]); // } int nn = Convert.ToInt32(jsonArray[3]); int sn = Convert.ToInt32(jsonArray[7]); String[] ans = new String[25]; int count = 0; for (int i = 11; i < 60; i = i + 2) { ans[count] = jsonArray[i]; count++; } String ed = jsonArray[63]; String aoid = ""; // Console.Out.WriteLine(jsonArray.Length); if (jsonArray.Length > 67) {//If there is an aoid aoid = jsonArray[67]; } Dictionary <string, string> aoid_dictionary = new Dictionary <string, string>(); if (aoid.Contains("=")) { //see if the string contains an equals sign String[] keyvalue = aoid.Split('='); aoid_dictionary.Add(keyvalue[0], keyvalue[1]); //index 0 is the key index 1 is the value. } else { //There is something there but not a key value pair. Treak it like a memo aoid_dictionary.Add("memo", aoid); }//end if cointains an = CloudCoin returnCC = new CloudCoin(nn, sn, ans, ed, aoid_dictionary, "suspect"); for (int i = 0; (i < 25); i++) {//All newly created loaded coins get new PANs. returnCC.pans[i] = returnCC.generatePan(); returnCC.setPastStatus("undetected", i); } // end for each pan //Return Coin returnCC.fileName = (returnCC.getDenomination() + (".CloudCoin." + (returnCC.nn + ("." + (returnCC.sn + "."))))); returnCC.json = ""; returnCC.jpeg = null; returnCoins[j] = returnCC; }//end for each cloudcoin in the json file return(returnCoins); }//end load one CloudCoin from JSON