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