Example #1
0
        }//end GetHexValue

        private CloudCoin parseJpeg(String wholeString)
        {
            CloudCoin cc      = new CloudCoin();
            int       startAn = 40;

            for (int i = 0; i < 25; i++)
            {
                cc.ans[i] = wholeString.Substring(startAn, 32);
                // Console.Out.WriteLine(i +": " + cc.ans[i]);
                startAn += 32;
            }

            // end for
            cc.aoid = null;
            // wholeString.substring( 840, 895 );
            cc.hp = 25;
            // Integer.parseInt(wholeString.substring( 896, 896 ), 16);
            cc.ed = wholeString.Substring(898, 4);
            cc.nn = Convert.ToInt32(wholeString.Substring(902, 2), 16);
            cc.sn = Convert.ToInt32(wholeString.Substring(904, 6), 16);
            for (int i = 0; i < 25; i++)
            {
                cc.pans[i] = cc.generatePan();
                cc.setPastStatus("undetected", i);
            }
            cc.fileName = cc.getDenomination() + ".CloudCoin." + cc.nn + "." + cc.sn + ".";
            //Console.Out.WriteLine("parseJpeg cc.fileName " + cc.fileName);
            // end for each pan
            return(cc);
        } // end parse Jpeg
Example #2
0
        }//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
Example #3
0
        }//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
Example #4
0
        }     //end dump all

        /* Write JSON to .stack File  */
        public bool dumpSome(int m1, int m5, int m25, int m100, int m250)
        {
            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  = "";
            String start = "{" + Environment.NewLine;

            start = start + "\t\"cloudcoin\": [" + Environment.NewLine;
            String end = "\t]" + Environment.NewLine + "}";

            String bankFileName;
            String frackedFileName;
            string denomination;

            // Put all the JSON together and add header and footer
            String filename = "";

            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          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid = null;
                        json          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        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          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid = null;
                        json          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        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          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid = null;
                        json          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        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          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid = null;
                        json          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        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          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid = null;
                        json          = start + this.fileUtils.setJSON(coinNote) + end;
                        int randInt = random.Next(100000, 10000000);
                        filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
                        File.WriteAllText(filename, json);
                        Console.Out.WriteLine("Writing to " + filename);
                        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

            /*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
Example #5
0
        // 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
Example #6
0
        }        //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