Example #1
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);

            CoinUtils cu = new CoinUtils(cc);

            bool fileSavedSuccessfully = true;

            /* BUILD THE CLOUDCOIN STRING */
            String cloudCoinStr = "01C34A46494600010101006000601D05"; //THUMBNAIL HEADER BYTES

            for (int i = 0; (i < 25); i++)
            {
                cloudCoinStr = cloudCoinStr + cc.an[i];
            } // end for each an

            //cloudCoinStr += "204f42455920474f4420262044454645415420545952414e545320";// Hex for " OBEY GOD & DEFEAT TYRANTS "
            //cloudCoinStr += "20466f756e6465727320372d352d3137";// Founders 7-5-17
            cloudCoinStr += "4c6976652046726565204f7220446965"; // Live Free or Die
            cloudCoinStr += "00000000000000000000000000";       //Set to unknown so program does not export user data
                                                                // for (int i =0; i < 25; i++) {
                                                                //     switch () { }//end switch pown char
                                                                // }//end for each pown
            cloudCoinStr += "00";                               // HC: Has comments. 00 = No
            cu.calcExpirationDate();
            cloudCoinStr += cu.edHex;                           // 01;//Expiration date Sep 2016 (one month after zero month)
            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 (cu.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;
            SKBitmap bitmapimage;
            //using (var ms = new MemoryStream(jpegBytes))
            {
                //bitmapimage = new Bitmap(ms);
                bitmapimage = SKBitmap.Decode(jpegBytes);
            }
            SKCanvas canvas = new SKCanvas(bitmapimage);
            //Graphics graphics = Graphics.FromImage(bitmapimage);
            //graphics.SmoothingMode = SmoothingMode.AntiAlias;
            //graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            SKPaint textPaint = new SKPaint()
            {
                IsAntialias = true,
                Color       = SKColors.White,
                TextSize    = 14,
                Typeface    = SKTypeface.FromFamilyName("Arial")
            };

            //PointF drawPointAddress = new PointF(30.0F, 25.0F);

            canvas.DrawText(String.Format("{0:N0}", cc.sn) + " of 16,777,216 on Network: 1", 30, 40, textPaint);
            //graphics.DrawString(String.Format("{0:N0}", cc.sn) + " of 16,777,216 on Network: 1", new Font("Arial", 10), Brushes.White, drawPointAddress);

            //ImageConverter converter = new ImageConverter();
            //byte[] snBytes = (byte[])converter.ConvertTo(bitmapimage, typeof(byte[]));
            SKImage image = SKImage.FromBitmap(bitmapimage);
            SKData  data  = image.Encode(SKEncodedImageFormat.Jpeg, 100);

            byte[] snBytes = data.ToArray();

            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 + cu.fileName + tag + ".jpg";

            File.WriteAllBytes(fileName, b1.ToArray());
            Console.Out.WriteLine("Writing to " + fileName);
            CoreLogger.Log("Writing to " + fileName);
            return(fileSavedSuccessfully);
        }//end write JPEG
        }         //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();;
            String[] partialFileNames = new DirectoryInfo(this.fileUtils.partialFolder).GetFiles().Select(o => o.Name).ToArray();
            // Add the two arrays together
            var list = new List <String>();

            list.AddRange(bankedFileNames);
            list.AddRange(frackedFileNames);
            list.AddRange(partialFileNames);

            // 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;
            json = json + "\t[" + Environment.NewLine;
            String bankFileName;
            String frackedFileName;
            String partialFileName;
            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
                partialFileName = this.fileUtils.partialFolder + bankedFileNames[i];
                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 = fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        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 if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        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 if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        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 if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        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 if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        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
                Random rnd     = new Random();
                int    tagrand = rnd.Next(999);
                filename = (this.fileUtils.exportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ".stack");
            }//end if file exists

            File.WriteAllText(filename, json);
            Console.Out.WriteLine("Writing to : ");
            CoreLogger.Log("Writing to : " + filename);
            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
Example #3
0
        }// end Detect constructor

        public int detectMulti(int detectTime)
        {
            bool stillHaveSuspect = true;
            int  coinNames        = 0;

            while (stillHaveSuspect)
            {
                // LOAD ALL SUSPECT COIN NAMES IN AN ARRAY OF NAMES
                String[] suspectFileNames = new DirectoryInfo(this.fileUtils.suspectFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder

                //CHECK TO SEE IF ANY OF THE FILES ARE ALREADY IN BANK. DELETE IF SO
                for (int i = 0; i < suspectFileNames.Length; i++)//for up to 200 coins in the suspect folder
                {
                    try
                    {
                        if (File.Exists(this.fileUtils.bankFolder + suspectFileNames[i]) || File.Exists(this.fileUtils.detectedFolder + suspectFileNames[i]))
                        {//Coin has already been imported. Delete it from import folder move to trash.
                            coinExists(suspectFileNames[i]);
                        }
                    }
                    catch (FileNotFoundException ex)
                    {
                        Console.Out.WriteLine(ex);
                        CoreLogger.Log(ex.ToString());
                        //updateLog(ex.ToString());
                    }
                    catch (IOException ioex)
                    {
                        Console.Out.WriteLine(ioex);
                        CoreLogger.Log(ioex.ToString());
                        //updateLog(ioex.ToString());
                    } // end try catch
                }     // end for each coin to see if in bank


                //DUPLICATES HAVE BEEN DELETED, NOW DETECT
                suspectFileNames = new DirectoryInfo(this.fileUtils.suspectFolder).
                                   GetFiles().Select(o => o.Name).ToArray();                                               //Get all files in suspect folder


                //HOW MANY COINS WILL WE DETECT? LIMIT IT TO 200

                if (suspectFileNames.Length > 200)
                {
                    coinNames = 200;//do not detect more than 200 coins.
                }
                else
                {
                    coinNames        = suspectFileNames.Length;
                    stillHaveSuspect = false;// No need to get more names
                }

                //BUILD AN ARRAY OF COINS FROM THE FILE NAMES - UPTO 200
                CloudCoin[] cloudCoin = new CloudCoin[coinNames];
                CoinUtils[] cu        = new CoinUtils[coinNames];
                //Receipt receipt = createReceipt(coinNames, receiptFile);

                //raida.txtLogs = txtLogs;
                totalImported = 0;
                for (int i = 0; i < coinNames; i++)//for up to 200 coins in the suspect folder
                {
                    try
                    {
                        cloudCoin[i] = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.suspectFolder + suspectFileNames[i]);
                        cu[i]        = new CoinUtils(cloudCoin[i]);

                        Console.Out.WriteLine("  Now scanning coin " + (i + 1) + " of " + suspectFileNames.Length +
                                              " for counterfeit. SN " + string.Format("{0:n0}",
                                                                                      cloudCoin[i].sn) + ", Denomination: " +
                                              cu[i].getDenomination());

                        //CoreLogger.Log("  Now scanning coin " + (i + 1) + " of " + suspectFileNames.Length + " for counterfeit. SN " + string.Format("{0:n0}", cloudCoin[i].sn) + ", Denomination: " + cu[i].getDenomination());

                        ReceitDetail detail = new ReceitDetail();
                        detail.sn     = cloudCoin[i].sn;
                        detail.nn     = cloudCoin[i].nn;
                        detail.status = "suspect";
                        detail.pown   = "uuuuuuuuuuuuuuuuuuuuuuuuu";
                        detail.note   = "Waiting";
                        // receipt.rd[i] = detail;

                        //updateLog("  Now scanning coin " + (i + 1) + " of " + suspectFileNames.Length + " for counterfeit. SN " + string.Format("{0:n0}", cloudCoin[i].sn) + ", Denomination: " + cu[i].getDenomination());
                        Device.BeginInvokeOnMainThread(() => {
                            importBar.Progress = (i * 100 / coinNames);
                        });
                        updateLog("Authenticating a " + cu[i].getDenomination() +
                                  " CoinCoin note (" + cloudCoin[i].sn + "): " + (i + 1) + " of " + coinNames);
                    }
                    catch (FileNotFoundException ex)
                    {
                        Console.Out.WriteLine(ex);
                        //CoreLogger.Log(ex.ToString());
                        updateLog(ex.ToString());
                    }
                    catch (IOException ioex)
                    {
                        Console.Out.WriteLine(ioex);
                        //CoreLogger.Log(ioex.ToString());
                        updateLog(ioex.ToString());
                    } // end try catch
                }     // end for each coin to import


                //ALL COINS IN THE ARRAY, NOW DETECT

                CoinUtils[] detectedCC       = raida.detectMultiCoin(cu, detectTime);
                var         bankCoins        = detectedCC.Where(o => o.folder == CoinUtils.Folder.Bank);
                var         frackedCoins     = detectedCC.Where(o => o.folder == CoinUtils.Folder.Fracked);
                var         counterfeitCoins = detectedCC.Where(o => o.folder == CoinUtils.Folder.Counterfeit);

                totalImported = 0;
                foreach (CoinUtils ccc in bankCoins)
                {
                    fileUtils.writeTo(fileUtils.bankFolder, ccc.cc);
                    totalImported++;
                }

                foreach (CoinUtils ccf in frackedCoins)
                {
                    fileUtils.writeTo(fileUtils.frackedFolder, ccf.cc);
                    totalImported++;
                }

                //Write the coins to the detected folder delete from the suspect
                for (int c = 0; c < detectedCC.Length; c++)
                {
                    //detectedCC[c].txtLogs = txtLogs;
                    fileUtils.writeTo(fileUtils.detectedFolder, detectedCC[c].cc);
                    File.Delete(fileUtils.suspectFolder + suspectFileNames[c]);//Delete the coin out of the suspect folder
                }

                //Console.WriteLine("Total Imported Coins - " + totalImported);
                //Console.WriteLine("Total Counterfeit detected - " + counterfeitCoins.ToArray().Length);
                updateLog("Total Imported Coins - " + totalImported);
                updateLog("Total Counterfeit detected - " + counterfeitCoins.ToArray().Length);
            } //end while still have suspect
            return(coinNames);
        }     //End detectMulti All
Example #4
0
        }//constructor

        public string fixOneGuidCorner(int raida_ID, CloudCoin cc, int corner, int[] trustedTriad, int millisecondsToTimeout)
        {
            CoinUtils cu = new CoinUtils(cc);

            /*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("  RAIDA Fails Echo or Fix. Try again when RAIDA online.");
                CoreLogger.Log("  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.WriteLine("Pown is " + cc.pown);
                char[] pown_chars = cc.pown.ToCharArray();


                //See if First Trusted RAIDA can help
                if (!pown_chars[trustedTriad[0]].Equals('p'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("  RAIDA " + trustedTriad[0] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("  RAIDA " + trustedTriad[0] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("");
                    Console.ForegroundColor = ConsoleColor.White;
                    return("RAIDA " + trustedTriad[0] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                }
                //See if Second Trusted RAIDA can help
                if (!pown_chars[trustedTriad[1]].Equals('p'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("  RAIDA " + trustedTriad[1] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("  RAIDA " + trustedTriad[1] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("");
                    Console.ForegroundColor = ConsoleColor.White;
                    return("RAIDA " + trustedTriad[1] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                }

                //See if Third Trusted RAIDA can help
                if (!pown_chars[trustedTriad[2]].Equals('p'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("  RAIDA " + trustedTriad[2] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("  RAIDA " + trustedTriad[2] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("");
                    Console.ForegroundColor = ConsoleColor.White;
                    return("RAIDA " + trustedTriad[2] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                }

                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.an[trustedTriad[0]], cc.an[trustedTriad[1]], cc.an[trustedTriad[2]] };
                    raida.get_Tickets(trustedTriad, ans, cc.nn, cc.sn, cu.getDenomination(), 3000);


                    //Check to see if the coin actully is counterfeits and all the so called "p"s are actually "f"s.
                    if (raida.responseArray[trustedTriad[0]].fullResponse.Contains("fail") &&
                        raida.responseArray[trustedTriad[1]].fullResponse.Contains("fail") &&
                        raida.responseArray[trustedTriad[2]].fullResponse.Contains("fail")
                        )
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("The coin is actually counterfeit. RAIDA marked 'passed' turned out to be fails.");
                        Console.Out.WriteLine("");
                        Console.ForegroundColor = ConsoleColor.White;
                        return("counterfeit " + corner);
                    }//end if p's are actully fs.

                    /*4. ARE ALL TICKETS GOOD?*/
                    if (RAIDA_Status.hasTicket[trustedTriad[0]] && RAIDA_Status.hasTicket[trustedTriad[1]] && RAIDA_Status.hasTicket[trustedTriad[2]])
                    {
                        /*5.T YES, so REQUEST FIX*/
                        DetectionAgent da          = new DetectionAgent(raida_ID);
                        Response       fixResponse = da.fix(trustedTriad, RAIDA_Status.tickets[trustedTriad[0]], RAIDA_Status.tickets[trustedTriad[1]], RAIDA_Status.tickets[trustedTriad[2]], cc.an[raida_ID]).Result;
                        /*6. DID THE FIX WORK?*/
                        if (fixResponse.success)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Out.WriteLine("");
                            Console.Out.WriteLine("  RAIDA" + raida_ID + " unfracked successfully.");
                            CoreLogger.Log("  RAIDA" + raida_ID + " 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("  RAIDA " + raida_ID + " failed to accept tickets on corner " + corner);
                            CoreLogger.Log("  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("  Trusted servers failed to provide tickets for corner " + corner);
                        Console.Out.WriteLine("RAIDa" + trustedTriad[0] + " " + RAIDA_Status.tickets[trustedTriad[0]] + ", RAIDa" + trustedTriad[1] + " " + RAIDA_Status.tickets[trustedTriad[1]] + ", RAIDa" + trustedTriad[2] + " " + RAIDA_Status.tickets[trustedTriad[2]]);
                        CoreLogger.Log("  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("  One or more of the trusted triad will not echo and detect.So not trying.");
                CoreLogger.Log("  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 #5
0
        }//end delete coin

        public CoinUtils fixCoin(CloudCoin brokeCoin, int millisecondsToTimeout)
        {
            CoinUtils cu = new CoinUtils(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();

            cu.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++)
            {
                //Check to see if the coin has been marked counterfeit and should be moved to trash
                // Console.Out.WriteLine("The folder is " + cu.getFolder().ToLower());
                if (cu.cc.pown == "fffffffffffffffffffffffff")
                {
                    cu.setFolder("counterfeit");
                    return(cu);
                }

                //  Console.WriteLine("Past Status for " + raida_ID + ", " + brokeCoin.pastStatus[raida_ID]);

                if (cu.getPastStatus(raida_ID).ToLower() != "pass") //will try to fix everything that is not perfect pass.
                {
                    cu.cc.an[raida_ID]      = cu.generatePan();     //Assign the AN a new PAN for security.
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Write("  Attempting to fix RAIDA " + raida_ID + " ");
                    CoreLogger.Log("  Attempting to fix RAIDA " + raida_ID);
                    Console.ForegroundColor = ConsoleColor.White;

                    fixer = new FixitHelper(raida_ID, brokeCoin.an.ToArray());

                    //trustedServerAns = new String[] { brokeCoin.ans[fixer.currentTriad[0]], brokeCoin.ans[fixer.currentTriad[1]], brokeCoin.ans[fixer.currentTriad[2]] };
                    corner = 1;
                    while (!fixer.finnished)
                    {
                        Console.Write(" Using corner " + corner + " ");
                        CoreLogger.Log(" Using corner " + corner + " ");
                        fix_result = fixOneGuidCorner(raida_ID, brokeCoin, corner, fixer.currentTriad, millisecondsToTimeout);
                        // Console.WriteLine(" fix_result: " + fix_result + " for corner " + corner);
                        if (fix_result.Contains("success"))
                        {
                            //Fixed. Do the fixed stuff
                            cu.setPastStatus("pass", raida_ID);
                            fixer.finnished = true;
                            corner          = 1;
                        }
                        else if (fix_result.Contains("counterfeit"))
                        {
                            for (int j = 0; j < 25; j++)
                            {
                                cu.setPastStatus("fail", j);
                            }                                                            //Set all status to fail so the coin will be moved to counterfeit.
                            cu.setFolder("counterfeit");
                            fixer.finnished = true;
                            return(cu);
                        }
                        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

            for (int raida_ID = 24; raida_ID > -1; raida_ID--)
            {
                //  Console.WriteLine("Past Status for " + raida_ID + ", " + brokeCoin.pastStatus[raida_ID]);
                // Console.WriteLine("Pown is " + cu.cc.pown);
                if (cu.getPastStatus(raida_ID).ToLower() != "pass") //will try to fix everything that is not perfect pass.
                {
                    cu.cc.an[raida_ID]      = cu.generatePan();     //Assign the AN a new PAN for security.
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Write("  Attempting to fix RAIDA " + raida_ID + " ");
                    CoreLogger.Log("  Attempting to fix RAIDA " + raida_ID);
                    Console.ForegroundColor = ConsoleColor.White;

                    fixer = new FixitHelper(raida_ID, brokeCoin.an.ToArray());

                    //trustedServerAns = new String[] { brokeCoin.ans[fixer.currentTriad[0]], brokeCoin.ans[fixer.currentTriad[1]], brokeCoin.ans[fixer.currentTriad[2]] };
                    corner = 1;
                    while (!fixer.finnished)
                    {
                        Console.Write(" Using corner " + corner + " ");
                        CoreLogger.Log(" Using corner " + corner + " ");
                        fix_result = fixOneGuidCorner(raida_ID, brokeCoin, corner, fixer.currentTriad, millisecondsToTimeout);
                        // Console.WriteLine(" fix_result: " + fix_result + " for corner " + corner);
                        if (fix_result.Contains("success"))
                        {
                            //Fixed. Do the fixed stuff
                            cu.setPastStatus("pass", raida_ID);
                            fixer.finnished = true;
                            corner          = 1;
                        }
                        else if (fix_result.Contains("counterfeit"))
                        {
                            for (int j = 0; j < 25; j++)
                            {
                                cu.setPastStatus("fail", j);
                            }                                                            //Set all status to fail so the coin will be moved to counterfeit.
                            cu.setFolder("counterfeit");
                            fixer.finnished = true;
                            return(cu);
                        }
                        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("  Time spent fixing RAIDA in milliseconds: " + ts.Milliseconds);
            CoreLogger.Log("  Time spent fixing RAIDA in milliseconds: " + ts.Milliseconds);

            cu.calculateHP(); //how many fails did it get
                              //  cu.gradeCoin();// sets the grade and figures out what the file extension should be (bank, fracked, counterfeit, lost

            cu.grade();
            cu.calcExpirationDate();
            return(cu);
        } // end fix coin
Example #6
0
        }//constructor

        public string fixOneGuidCorner(int raida_ID, CloudCoin cc, int corner, int[] trustedTriad)
        {
            CoinUtils cu = new CoinUtils(cc);

            /*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("RAIDA Fails Echo or Fix. Try again when RAIDA online.");
                CoreLogger.Log("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.an[trustedTriad[0]], cc.an[trustedTriad[1]], cc.an[trustedTriad[2]] };
                    raida.get_Tickets(trustedTriad, ans, cc.nn, cc.sn, cu.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.an[raida_ID]).Result;
                        /*6. DID THE FIX WORK?*/
                        if (fixResponse.success)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Out.WriteLine("");
                            Console.Out.WriteLine("RAIDA" + raida_ID + " unfracked successfully.");
                            CoreLogger.Log("RAIDA" + raida_ID + " 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("RAIDA failed to accept tickets on corner " + corner);
                            CoreLogger.Log("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("Trusted servers failed to provide tickets for corner " + corner);
                        CoreLogger.Log("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("One or more of the trusted triad will not echo and detect.So not trying.");
                CoreLogger.Log("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 Detect constructor

        public int detectMulti(int detectTime)
        {
            bool stillHaveSuspect = true;
            int  coinNames        = 0;
            int  total            = 0;
            int  loops            = 0;

            //totalImported = 0;

            while (stillHaveSuspect)
            {
                // LOAD ALL SUSPECT COIN NAMES IN AN ARRAY OF NAMES
                String[] suspectFileNames = new DirectoryInfo(this.fileUtils.suspectFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder
                if (suspectFileNames.Length > total)
                {
                    total = suspectFileNames.Length;
                }
                //CHECK TO SEE IF ANY OF THE FILES ARE ALREADY IN BANK. DELETE IF SO
                for (int i = 0; i < suspectFileNames.Length; i++)//for up to 200 coins in the suspect folder
                {
                    try
                    {
                        if (File.Exists(this.fileUtils.bankFolder + suspectFileNames[i]) || File.Exists(this.fileUtils.frackedFolder + suspectFileNames[i]) || File.Exists(this.fileUtils.detectedFolder + suspectFileNames[i]))
                        {//Coin has already been imported. Delete it from import folder move to trash.
                            coinExists(suspectFileNames[i]);
                        }
                    }
                    catch (FileNotFoundException ex)
                    {
                        Console.Out.WriteLine(ex);
                        CoreLogger.Log(ex.ToString());
                        //updateLog(ex.ToString());
                    }
                    catch (IOException ioex)
                    {
                        Console.Out.WriteLine(ioex);
                        CoreLogger.Log(ioex.ToString());
                        //updateLog(ioex.ToString());
                    } // end try catch
                }     // end for each coin to see if in bank


                //DUPLICATES HAVE BEEN DELETED, NOW DETECT
                //suspectFileNames = new DirectoryInfo(this.fileUtils.suspectFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder
                var ext = new List <string> {
                    ".jpg", ".stack", ".jpeg"
                };
                var fnamesRaw = Directory.GetFiles(this.fileUtils.suspectFolder, "*.*", SearchOption.TopDirectoryOnly).Where(s => ext.Contains(Path.GetExtension(s)));
                suspectFileNames = new string[fnamesRaw.Count()];
                for (int i = 0; i < fnamesRaw.Count(); i++)
                {
                    suspectFileNames[i] = Path.GetFileName(fnamesRaw.ElementAt(i));
                }
                ;

                //HOW MANY COINS WILL WE DETECT? LIMIT IT TO 200

                if (suspectFileNames.Length > 200)
                {
                    coinNames = 200;//do not detect more than 200 coins.
                }
                else
                {
                    coinNames        = suspectFileNames.Length;
                    stillHaveSuspect = false;// No need to get more names
                }

                //BUILD AN ARRAY OF COINS FROM THE FILE NAMES - UPTO 200
                CloudCoin[] cloudCoin = new CloudCoin[coinNames];
                CoinUtils[] cu        = new CoinUtils[coinNames];
                //Receipt receipt = createReceipt(coinNames, receiptFile);

                raida.txtLogs = txtLogs;
                //totalImported = 0;
                for (int i = 0; i < coinNames; i++)//for up to 200 coins in the suspect folder
                {
                    try
                    {
                        cloudCoin[i] = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.suspectFolder + suspectFileNames[i]);
                        cu[i]        = new CoinUtils(cloudCoin[i]);

                        Console.Out.WriteLine("  Now scanning coin " + (i + 1 + loops * 200) + " of " + total + " for counterfeit. SN " + string.Format("{0:n0}", cloudCoin[i].sn) + ", Denomination: " + cu[i].getDenomination());

                        CoreLogger.Log("  Now scanning coin " + (i + 1 + loops * 200) + " of " + total + " for counterfeit. SN " + string.Format("{0:n0}", cloudCoin[i].sn) + ", Denomination: " + cu[i].getDenomination());

                        ReceitDetail detail = new ReceitDetail();
                        detail.sn     = cloudCoin[i].sn;
                        detail.nn     = cloudCoin[i].nn;
                        detail.status = "suspect";
                        detail.pown   = "uuuuuuuuuuuuuuuuuuuuuuuuu";
                        detail.note   = "Waiting";
                        // receipt.rd[i] = detail;

                        //updateLog("  Now scanning coin " + (i + 1) + " of " + suspectFileNames.Length + " for counterfeit. SN " + string.Format("{0:n0}", cloudCoin[i].sn) + ", Denomination: " + cu[i].getDenomination());

                        updateLog("Authenticating a " + cu[i].getDenomination() +
                                  " CloudCoin note (" + cloudCoin[i].sn + "): " + (i + 1 + loops * 200) + " of " + total);
                    }
                    catch (FileNotFoundException ex)
                    {
                        Console.Out.WriteLine(ex);
                        CoreLogger.Log(ex.ToString());
                        updateLog(ex.ToString());
                    }
                    catch (IOException ioex)
                    {
                        Console.Out.WriteLine(ioex);
                        CoreLogger.Log(ioex.ToString());
                        updateLog(ioex.ToString());
                    } // end try catch
                }     // end for each coin to import


                //ALL COINS IN THE ARRAY, NOW DETECT

                CoinUtils[] detectedCC       = raida.detectMultiCoin(cu, detectTime);
                var         bankCoins        = detectedCC.Where(o => o.folder == CoinUtils.Folder.Bank);
                var         frackedCoins     = detectedCC.Where(o => o.folder == CoinUtils.Folder.Fracked);
                var         counterfeitCoins = detectedCC.Where(o => o.folder == CoinUtils.Folder.Counterfeit);

                //totalImported = 0;
                foreach (CoinUtils ccc in bankCoins)
                {
                    //fileUtils.writeTo(fileUtils.bankFolder, ccc.cc);
                    totalImported++;
                }

                foreach (CoinUtils ccf in frackedCoins)
                {
                    //fileUtils.writeTo(fileUtils.frackedFolder, ccf.cc);
                    totalImported++;
                }

                foreach (CoinUtils cccf in counterfeitCoins)
                {
                    totalCounterfeit++;
                }

                //Write the coins to the detected folder delete from the suspect
                for (int c = 0; c < detectedCC.Length; c++)
                {
                    detectedCC[c].txtLogs = txtLogs;
                    fileUtils.writeTo(fileUtils.detectedFolder, detectedCC[c].cc);
                    File.Delete(fileUtils.suspectFolder + suspectFileNames[c]);  //Delete the coin out of the suspect folder
                }


                updateLog("Total Imported Coins : " + totalImported);
                updateLog("Total Counterfeits : " + totalCounterfeit);
                updateLog("Coins still being processed : " + detectedCC.Where(o => o.folder == CoinUtils.Folder.Dangerous).ToArray().Length);
                loops++;
            } //end while still have suspect
            return(coinNames);
        }     //End detectMulti All