示例#1
0
    }               //end detect coin

    public async Task <CoinUtils> detectCoin(CoinUtils cu, int milliSecondsToTimeOut)
    {
        cu.generatePan();

        var t00 = detectOne(00, cu.cc.nn, cu.cc.sn, cu.cc.an[00], cu.pans[00], cu.getDenomination());
        var t01 = detectOne(01, cu.cc.nn, cu.cc.sn, cu.cc.an[01], cu.pans[01], cu.getDenomination());
        var t02 = detectOne(02, cu.cc.nn, cu.cc.sn, cu.cc.an[02], cu.pans[02], cu.getDenomination());
        var t03 = detectOne(03, cu.cc.nn, cu.cc.sn, cu.cc.an[03], cu.pans[03], cu.getDenomination());
        var t04 = detectOne(04, cu.cc.nn, cu.cc.sn, cu.cc.an[04], cu.pans[04], cu.getDenomination());
        var t05 = detectOne(05, cu.cc.nn, cu.cc.sn, cu.cc.an[05], cu.pans[05], cu.getDenomination());
        var t06 = detectOne(06, cu.cc.nn, cu.cc.sn, cu.cc.an[06], cu.pans[06], cu.getDenomination());
        var t07 = detectOne(07, cu.cc.nn, cu.cc.sn, cu.cc.an[07], cu.pans[07], cu.getDenomination());
        var t08 = detectOne(08, cu.cc.nn, cu.cc.sn, cu.cc.an[08], cu.pans[08], cu.getDenomination());
        var t09 = detectOne(09, cu.cc.nn, cu.cc.sn, cu.cc.an[09], cu.pans[09], cu.getDenomination());
        var t10 = detectOne(10, cu.cc.nn, cu.cc.sn, cu.cc.an[10], cu.pans[10], cu.getDenomination());
        var t11 = detectOne(11, cu.cc.nn, cu.cc.sn, cu.cc.an[11], cu.pans[11], cu.getDenomination());
        var t12 = detectOne(12, cu.cc.nn, cu.cc.sn, cu.cc.an[12], cu.pans[12], cu.getDenomination());
        var t13 = detectOne(13, cu.cc.nn, cu.cc.sn, cu.cc.an[13], cu.pans[13], cu.getDenomination());
        var t14 = detectOne(14, cu.cc.nn, cu.cc.sn, cu.cc.an[14], cu.pans[14], cu.getDenomination());
        var t15 = detectOne(15, cu.cc.nn, cu.cc.sn, cu.cc.an[15], cu.pans[15], cu.getDenomination());
        var t16 = detectOne(16, cu.cc.nn, cu.cc.sn, cu.cc.an[16], cu.pans[16], cu.getDenomination());
        var t17 = detectOne(17, cu.cc.nn, cu.cc.sn, cu.cc.an[17], cu.pans[17], cu.getDenomination());
        var t18 = detectOne(18, cu.cc.nn, cu.cc.sn, cu.cc.an[18], cu.pans[18], cu.getDenomination());
        var t19 = detectOne(19, cu.cc.nn, cu.cc.sn, cu.cc.an[19], cu.pans[19], cu.getDenomination());
        var t20 = detectOne(20, cu.cc.nn, cu.cc.sn, cu.cc.an[20], cu.pans[20], cu.getDenomination());
        var t21 = detectOne(21, cu.cc.nn, cu.cc.sn, cu.cc.an[21], cu.pans[21], cu.getDenomination());
        var t22 = detectOne(22, cu.cc.nn, cu.cc.sn, cu.cc.an[22], cu.pans[22], cu.getDenomination());
        var t23 = detectOne(23, cu.cc.nn, cu.cc.sn, cu.cc.an[23], cu.pans[23], cu.getDenomination());
        var t24 = detectOne(24, cu.cc.nn, cu.cc.sn, cu.cc.an[24], cu.pans[24], cu.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
        };
        await Task.WhenAll(taskList.ToArray());

        //Get data from the detection agents

        for (int i = 0; i < 25; i++)
        {
            if (responseArray[i] != null)
            {
                cu.setPastStatus(responseArray[i].outcome, i);
                CoreLogger.Log(cu.cc.sn + " detect:" + i + " " + responseArray[i].fullResponse);
            }
            else
            {
                cu.setPastStatus("undetected", i);
            }; // should be pass, fail, error or undetected.
        }      //end for each detection agent

        cu.setAnsToPansIfPassed();
        cu.calculateHP();
        // cu.gradeCoin(); // sets the grade and figures out what the file extension should be (bank, fracked, counterfeit, lost
        cu.calcExpirationDate();
        cu.grade();

        return(cu);
    }    //end detect coin
示例#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;
        FoundersCloudCoin 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]))
                {    //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.");
                    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.");
                    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());

/*
 *                              Frack_Fixer ff = new Frack_Fixer(fileUtils, msToFixDangerousFracked);
 *                              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);
 *                                  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).Result;//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