Ejemplo n.º 1
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
Ejemplo n.º 2
0
        }// end Detect constructor

        /*  PUBLIC METHODS */
        public int[] gradeAll(int msToFixDangerousFracked, int msToRedetectDangerous)
        {
            String[]  detectedFileNames         = new DirectoryInfo(this.fileUtils.detectedFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder
            int       totalValueToBank          = 0;
            int       totalValueToCounterfeit   = 0;
            int       totalValueToFractured     = 0;
            int       totalValueToKeptInSuspect = 0;
            int       totalValueToLost          = 0;
            CloudCoin newCC;



            for (int j = 0; j < detectedFileNames.Length; j++)//for every coins in the detected folder
            {
                try
                {
                    if (File.Exists(this.fileUtils.bankFolder + detectedFileNames[j]) || File.Exists(this.fileUtils.frackedFolder + detectedFileNames[j]))
                    {//Coin has already been imported. Delete it from import folder move to trash.
                        //THIS SHOULD NOT HAPPEN - THE COIN SHOULD HAVE BEEN CHECKED DURING IMPORT BEFORE DETECTION TO SEE IF IT WAS IN THE BANK FOLDER
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("You tried to import a coin that has already been imported.");
                        CoreLogger.Log("You tried to import a coin that has already been imported.");
                        updateLog("You tried to import a coin that has already been imported.");
                        if (File.Exists(this.fileUtils.trashFolder + detectedFileNames[j]))
                        {
                            File.Delete(this.fileUtils.trashFolder + detectedFileNames[j]);
                        }
                        File.Move(this.fileUtils.detectedFolder + detectedFileNames[j], this.fileUtils.trashFolder + detectedFileNames[j]);
                        Console.Out.WriteLine("Suspect CloudCoin was moved to Trash folder.");
                        CoreLogger.Log("Suspect CloudCoin was moved to Trash folder.");
                        updateLog("Suspect CloudCoin was moved to Trash folder.");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        newCC = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.detectedFolder + detectedFileNames[j]);
                        CoinUtils cu = new CoinUtils(newCC);

                        //CoinUtils detectedCC = cu;
                        //cu.sortToFolder();//Tells the Coin Utils to set what folder the coins should go to.
                        cu.consoleReport();


                        //Suspect, Counterfeit, Fracked, Bank, Trash, Detected, Lost, Dangerous
                        switch (cu.getFolder().ToLower())
                        {
                        case "bank":
                            totalValueToBank++;
                            fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc);
                            break;

                        case "fracked":
                            totalValueToFractured++;
                            fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc);
                            break;

                        case "counterfeit":
                            totalValueToCounterfeit++;
                            fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc);
                            break;

                        case "lost":
                            totalValueToLost++;
                            fileUtils.writeTo(this.fileUtils.lostFolder, cu.cc);
                            break;

                        case "suspect":
                            totalValueToKeptInSuspect++;
                            fileUtils.writeTo(this.fileUtils.suspectFolder, cu.cc);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Out.WriteLine("  Not enough RAIDA were contacted to determine if the coin is authentic.");
                            Console.Out.WriteLine("  Try again later.");
                            CoreLogger.Log("  Not enough RAIDA were contacted to determine if the coin is authentic. Try again later.");
                            Console.ForegroundColor = ConsoleColor.White;
                            break;

                        case "dangerous":
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("   WARNING: Strings may be attached to this coins");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.Out.WriteLine("  Now fixing fracked for " + (j + 1) + " of " + detectedFileNames.Length + " . SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination());
                            CoreLogger.Log("  Now fixing fracked for " + (j + 1) + " of " + detectedFileNames.Length + " . SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination());
                            updateLog("Some of your CloudCoins are still being processed. This should take just a moment.");
                            Frack_Fixer ff = new Frack_Fixer(fileUtils, msToFixDangerousFracked);
                            ff.txtLogs = txtLogs;
                            RAIDA raida = new RAIDA();
                            Console.WriteLine("folder is " + cu.getFolder().ToLower());
                            while (cu.getFolder().ToLower() == "dangerous")
                            {    // keep fracking fixing until all fixed or no more improvments possible.
                                Console.WriteLine("   calling fix Coin");
                                cu = ff.fixCoin(cu.cc, msToFixDangerousFracked).Result;
                                Console.WriteLine("   sorting after fixing");
                                cu.sortFoldersAfterFixingDangerous();
                            }    //while folder still dangerous

                            for (int i = 0; i < 25; i++)
                            {
                                cu.pans[i] = cu.generatePan();
                            }                                                 // end for each pan
                            cu = raida.detectCoin(cu, msToRedetectDangerous); //Detect again to make sure it is powned
                            cu.consoleReport();
                            cu.sortToFolder();                                //Tells the Coin Utils to set what folder the coins should go to.
                            switch (cu.getFolder().ToLower())
                            {
                            case "bank":
                                totalValueToBank++;
                                fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc);
                                break;

                            case "fracked":
                                totalValueToFractured++;
                                fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc);
                                break;

                            default:
                                totalValueToCounterfeit++;
                                fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc);
                                break;
                            }    //end switch

                            break;
                        }//end switch

                        File.Delete(this.fileUtils.detectedFolder + detectedFileNames[j]);//Take the coin out of the detected folder
                    }//end if file exists
                }
                catch (FileNotFoundException ex)
                {
                    Console.Out.WriteLine(ex);
                    CoreLogger.Log(ex.ToString());
                }
                catch (IOException ioex)
                {
                    Console.Out.WriteLine(ioex);
                    CoreLogger.Log(ioex.ToString());
                } // end try catch
            }     // end for each coin to import

            results[0] = totalValueToBank;
            results[1] = totalValueToFractured;
            results[2] = totalValueToCounterfeit;
            results[3] = totalValueToKeptInSuspect;
            results[4] = totalValueToLost;
            return(results);
        }//Detect All
        }// 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