コード例 #1
0
        }// end Detect constructor



        public async Task<int> detectMulti(int detectTime, string receiptFile)
        {
            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());
                    }
                    catch (IOException ioex)
                    {
                        Console.Out.WriteLine(ioex);
                        CoreLogger.Log(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
                FoundersCloudCoin[] cloudCoin = new FoundersCloudCoin[coinNames];
                CoinUtils[] cu = new CoinUtils[coinNames];
                Receipt receipt = createReceipt(coinNames, receiptFile);

                    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;
                    }
                    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


                //ALL COINS IN THE ARRAY, NOW DETECT

                CoinUtils[] detectedCC = await raida.detectMultiCoin(cu, detectTime);

                //create receits
                using (StreamWriter sw = File.CreateText(fileUtils.receiptsFolder + receiptFile + ".json"))
                {
                    sw.WriteLine(JsonConvert.SerializeObject(receipt));
                }


                    //Write the coins to the detected folder delete from the suspect
                    for (int c = 0; c < detectedCC.Length; c++)
                    {
                        fileUtils.writeTo(fileUtils.detectedFolder, detectedCC[c].cc);
                        File.Delete(fileUtils.suspectFolder + suspectFileNames[c]);//Delete the coin out of the suspect folder
                    }
            }//end while still have suspect
            return coinNames;
        }//End detectMulti All
コード例 #2
0
    }    //Detect All

    public int[] gradeAll(int msToFixDangerousFracked, int msToRedetectDangerous, string receiptFileName)
    {
        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;
        Receipt           receipt;

        using (StreamReader sr = new StreamReader(fileUtils.receiptsFolder + receiptFileName + ".json")) {
            string json = sr.ReadLine();
            receipt = JsonConvert.DeserializeObject <Receipt>(json);
        }
        receipt.rd = new ReceitDetail[detectedFileNames.Length];

        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);
                    ReceitDetail detail = new ReceitDetail();
                    detail.nn   = newCC.nn;
                    detail.sn   = newCC.sn;
                    detail.pown = newCC.pown;
                    //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++;
                        receipt.total_authentic++;
                        detail.status = "authentic";
                        detail.note   = "Moved to Bank";
                        fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc);
                        break;

                    case "fracked":
                        totalValueToFractured++;
                        receipt.total_fracked++;
                        detail.status = "authentic";
                        detail.note   = "Moved to Fracked";
                        fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc);
                        break;

                    case "counterfeit":
                        totalValueToCounterfeit++;
                        receipt.total_counterfeit++;
                        detail.status = "counterfeit";
                        detail.note   = "Sent to trash";
                        fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc);
                        break;

                    case "lost":
                        totalValueToLost++;
                        receipt.total_lost++;
                        detail.status = "lost";
                        detail.note   = "Moved to lost";
                        fileUtils.writeTo(this.fileUtils.lostFolder, cu.cc);
                        break;

                    case "suspect":
                        totalValueToKeptInSuspect++;
                        detail.status = "suspect";
                        detail.note   = "Stayed in Suspect";
                        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":
 *
 *                              detail.status = "lost";
 *                              detail.note = "STRINGS ATTACHED!";
 *                              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++;
 *                                      receipt.total_authentic++;
 *                                      detail.status = "authentic";
 *                                      detail.note = "Moved to Bank";
 *                                      fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc);
 *                                      break;
 *
 *                                  case "fracked":
 *                                      totalValueToFractured++;
 *                                      receipt.total_fracked++;
 *                                      detail.status = "authentic";
 *                                      detail.note = "Moved to Fracked";
 *                                      fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc);
 *                                      break;
 *
 *                                  default:
 *                                      totalValueToCounterfeit++;
 *                                      receipt.total_lost++;
 *                                      fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc);
 *                                      break;
 *
 *                              }//end switch
 *
 *                              break;
 */
                    }                                                                  //end switch
                    receipt.rd[j] = detail;
                    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

        JsonSerializer serializer = new JsonSerializer();

        using (StreamWriter sw = File.CreateText(fileUtils.receiptsFolder + receipt.receipt_id + ".json"))
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.Indented;
                serializer.Serialize(writer, receipt);
            }

        results[0] = totalValueToBank;
        results[1] = totalValueToFractured;
        results[2] = totalValueToCounterfeit;
        results[3] = totalValueToKeptInSuspect;
        results[4] = totalValueToLost;
        return(results);
    } //Detect All