public async static Task ProcessNetworkCoins(int NetworkNumber, bool ChangeANS = true) { IFileSystem FS = FileSystem; FileSystem.LoadFileSystem(); FileSystem.DetectPreProcessing(); var predetectCoins = FS.LoadFolderCoins(FS.PreDetectFolder); predetectCoins = (from x in predetectCoins where x.nn == NetworkNumber select x).ToList(); IFileSystem.predetectCoins = predetectCoins; #region Check Existing coins and skip them IEnumerable <CloudCoin> bankCoins = IFileSystem.bankCoins; IEnumerable <CloudCoin> frackedCoins1 = IFileSystem.frackedCoins; var bCoins = bankCoins.ToList(); bCoins.AddRange(frackedCoins1); //bankCoins.ToList().AddRange(frackedCoins1); var totalBankCoins = bCoins; var snList = (from x in totalBankCoins where x.nn == NetworkNumber select x.sn).ToList(); var newCoins = from x in predetectCoins where !snList.Contains(x.sn) select x; var existingCoins = from x in predetectCoins where snList.Contains(x.sn) select x; foreach (var coin in existingCoins) { updateLog("Found coin SN:" + coin.sn + " in folders. Skipping detection of the coin SN:" + coin.sn); FS.MoveFile(FS.PreDetectFolder + coin.FileName + ".stack", FS.TrashFolder + coin.FileName + ".stack", IFileSystem.FileMoveOptions.Replace); } predetectCoins = newCoins.ToList(); #endregion RAIDA raida = (from x in networks where x.NetworkNumber == NetworkNumber select x).FirstOrDefault(); if (raida == null) { return; } // Process Coins in Lots of 200. Can be changed from Config File int LotCount = predetectCoins.Count() / Config.MultiDetectLoad; if (predetectCoins.Count() % Config.MultiDetectLoad > 0) { LotCount++; } ProgressChangedEventArgs pge = new ProgressChangedEventArgs(); int CoinCount = 0; int totalCoinCount = predetectCoins.Count(); for (int i = 0; i < LotCount; i++) { //Pick up 200 Coins and send them to RAIDA var coins = predetectCoins.Skip(i * Config.MultiDetectLoad).Take(Config.MultiDetectLoad); try { raida.coins = coins; } catch (Exception e) { Console.WriteLine(e.Message); } var tasks = raida.GetMultiDetectTasks(coins.ToArray(), Config.milliSecondsToTimeOut, ChangeANS); try { string requestFileName = Utils.RandomString(16).ToLower() + DateTime.Now.ToString("yyyyMMddHHmmss") + ".stack"; // Write Request To file before detect FS.WriteCoinsToFile(coins, FS.RequestsFolder + requestFileName); logger.Info("Request: " + FS.RequestsFolder + requestFileName); await Task.WhenAll(tasks.AsParallel().Select(async task => await task())); int j = 0; foreach (var coin in coins) { coin.pown = ""; for (int k = 0; k < CloudCoinCore.Config.NodeCount; k++) { coin.response[k] = raida.nodes[k].MultiResponse.responses[j]; coin.pown += coin.response[k].outcome.Substring(0, 1); } int countp = coin.response.Where(x => x.outcome == "pass").Count(); int countf = coin.response.Where(x => x.outcome == "fail").Count(); coin.PassCount = countp; coin.FailCount = countf; CoinCount++; logger.Info("No. " + CoinCount + ". Coin Deteced. S. No. - " + coin.sn + ". Pass Count - " + coin.PassCount + ". Fail Count - " + coin.FailCount + ". Result - " + coin.DetectionResult + "." + coin.pown); Debug.WriteLine("Coin Deteced. S. No. - " + coin.sn + ". Pass Count - " + coin.PassCount + ". Fail Count - " + coin.FailCount + ". Result - " + coin.DetectionResult); //coin.sortToFolder(); pge.MinorProgress = (CoinCount) * 100 / totalCoinCount; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); coin.doPostProcessing(); j++; } pge.MinorProgress = (CoinCount - 1) * 100 / totalCoinCount; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); FS.WriteCoin(coins, FS.DetectedFolder, false); FS.RemoveCoins(coins, FS.PreDetectFolder); updateLog(pge.MinorProgress + " % of Coins on Network " + NetworkNumber + " processed."); //FS.WriteCoin(coins, FS.DetectedFolder); } catch (Exception ex) { logger.Error(ex.Message); Debug.WriteLine(ex.Message); } } pge.MinorProgress = 100; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); var detectedCoins = FS.LoadFolderCoins(FS.DetectedFolder); //detectedCoins.ForEach(x => x.pown= "ppppppppppppppppppppppppp"); updateLog(" Detection finished."); printStarLine(); // Apply Sort to Folder to all detected coins at once. updateLog(" Starting Grading Coins.."); //detectedCoins.ForEach(x => x.doPostProcessing()); detectedCoins.ForEach(x => x.SortToFolder()); updateLog(" Grading Coins Completed."); var passedCoins = (from x in detectedCoins where x.folder == FS.BankFolder select x).ToList(); var frackedCoins = (from x in detectedCoins where x.folder == FS.FrackedFolder select x).ToList(); var failedCoins = (from x in detectedCoins where x.folder == FS.CounterfeitFolder select x).ToList(); var lostCoins = (from x in detectedCoins where x.folder == FS.LostFolder select x).ToList(); var suspectCoins = (from x in detectedCoins where x.folder == FS.SuspectFolder select x).ToList(); var dangerousCoins = (from x in detectedCoins where x.folder == FS.DangerousFolder select x).ToList(); Debug.WriteLine("Total Passed Coins - " + (passedCoins.Count() + frackedCoins.Count())); Debug.WriteLine("Total Failed Coins - " + failedCoins.Count()); updateLog("Detection and Import of the EOS Stealth completed."); updateLog("Coin Detection finished."); updateLog(" Total Passed Coins - " + (passedCoins.Count() + frackedCoins.Count()) + ""); updateLog(" Total Counterfeit Coins - " + failedCoins.Count() + ""); updateLog(" Total Lost Coins - " + lostCoins.Count() + ""); updateLog(" Total Suspect Coins - " + suspectCoins.Count() + ""); updateLog(" Total Dangerous Coins - " + dangerousCoins.Count() + ""); //Remove existing duplicate coins in Bank / Fracked var ExistingGoodCoins = FS.LoadFolderCoins(FS.BankFolder); ExistingGoodCoins.Concat(FS.LoadFolderCoins(FS.FrackedFolder)); foreach (CloudCoin cc in ExistingGoodCoins) { var duplicateCoin = (from x in detectedCoins where x.sn == cc.sn select x).ToList(); FS.RemoveCoins(duplicateCoin, FS.BankFolder); FS.RemoveCoins(duplicateCoin, FS.FrackedFolder); } // Move Coins to their respective folders after sort FS.MoveCoins(passedCoins, FS.DetectedFolder, FS.BankFolder, true); FS.MoveCoins(frackedCoins, FS.DetectedFolder, FS.FrackedFolder, true); FS.MoveCoins(failedCoins, FS.DetectedFolder, FS.CounterfeitFolder); FS.MoveCoins(lostCoins, FS.DetectedFolder, FS.LostFolder); FS.MoveCoins(suspectCoins, FS.DetectedFolder, FS.SuspectFolder); // Clean up Detected Folder FS.RemoveCoins(failedCoins, FS.DetectedFolder); FS.RemoveCoins(lostCoins, FS.DetectedFolder); FS.RemoveCoins(suspectCoins, FS.DetectedFolder); FS.MoveImportedFiles(); //after = DateTime.Now; //ts = after.Subtract(before); //Debug.WriteLine("Detection Completed in - " + ts.TotalMilliseconds / 1000); //updateLog("Detection Completed in - " + ts.TotalMilliseconds / 1000); pge.MinorProgress = 100; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); }
public async static Task ProcessNetworkCoins(int NetworkNumber, bool ChangeANS = true) { IFileSystem FS = FileSystem; FileSystem.LoadFileSystem(); FileSystem.DetectPreProcessing(); var predetectCoins = FS.LoadFolderCoins(FS.PreDetectFolder); predetectCoins = (from x in predetectCoins where x.nn == NetworkNumber select x).ToList(); IFileSystem.predetectCoins = predetectCoins; RAIDA raida = (from x in networks where x.NetworkNumber == NetworkNumber select x).FirstOrDefault(); if (raida == null) { return; } // Process Coins in Lots of 200. Can be changed from Config File int LotCount = predetectCoins.Count() / Config.MultiDetectLoad; if (predetectCoins.Count() % Config.MultiDetectLoad > 0) { LotCount++; } ProgressChangedEventArgs pge = new ProgressChangedEventArgs(); int CoinCount = 0; int totalCoinCount = predetectCoins.Count(); for (int i = 0; i < LotCount; i++) { //Pick up 200 Coins and send them to RAIDA var coins = predetectCoins.Skip(i * Config.MultiDetectLoad).Take(Config.MultiDetectLoad); try { raida.coins = coins; } catch (Exception e) { Console.WriteLine(e.Message); } if (i == LotCount - 1) { updateLog("\tDetecting Coins " + (i * CloudCoinCore.Config.MultiDetectLoad + 1) + " to " + totalCoinCount); } else { updateLog("\tDetecting Coins " + (i * CloudCoinCore.Config.MultiDetectLoad + 1) + " to " + (i + 1) * CloudCoinCore.Config.MultiDetectLoad); } var tasks = raida.GetMultiDetectTasks(coins.ToArray(), Config.milliSecondsToTimeOut, ChangeANS); try { string requestFileName = Utils.RandomString(16).ToLower() + DateTime.Now.ToString("yyyyMMddHHmmss") + ".stack"; // Write Request To file before detect FS.WriteCoinsToFile(coins, FS.RequestsFolder + requestFileName); await Task.WhenAll(tasks.AsParallel().Select(async task => await task())); int j = 0; foreach (var coin in coins) { coin.pown = ""; for (int k = 0; k < CloudCoinCore.Config.NodeCount; k++) { coin.response[k] = raida.nodes[k].MultiResponse.responses[j]; coin.pown += coin.response[k].outcome.Substring(0, 1); } int countp = coin.response.Where(x => x.outcome == "pass").Count(); int countf = coin.response.Where(x => x.outcome == "fail").Count(); coin.PassCount = countp; coin.FailCount = countf; CoinCount++; MainWindow.UpdateCELog("No. " + CoinCount + ". Coin Deteced. S. No. - " + coin.sn + ". Pass Count - " + coin.PassCount + ". Fail Count - " + coin.FailCount + ". Result - " + coin.DetectionResult + "." + coin.pown); pge.MinorProgress = (CoinCount) * 100 / totalCoinCount; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); coin.doPostProcessing(); j++; } pge.MinorProgress = (CoinCount - 1) * 100 / totalCoinCount; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); FS.WriteCoin(coins, FS.DetectedFolder, false); FS.RemoveCoins(coins, FS.PreDetectFolder); MainWindow.UpdateCELog(pge.MinorProgress + " % of Coins on Network " + NetworkNumber + " processed."); //FS.WriteCoin(coins, FS.DetectedFolder); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } pge.MinorProgress = 100; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); var detectedCoins = FS.LoadFolderCoins(FS.DetectedFolder); //detectedCoins.ForEach(x => x.pown= "ppppppppppppppppppppppppp"); // Apply Sort to Folder to all detected coins at once. updateLog("Starting Grading Coins.."); //detectedCoins.ForEach(x => x.doPostProcessing()); detectedCoins.ForEach(x => x.SortToFolder()); updateLog("Grading Coins Completed."); var passedCoins = (from x in detectedCoins where x.folder == FS.BankFolder select x).ToList(); var frackedCoins = (from x in detectedCoins where x.folder == FS.FrackedFolder select x).ToList(); var failedCoins = (from x in detectedCoins where x.folder == FS.CounterfeitFolder select x).ToList(); var lostCoins = (from x in detectedCoins where x.folder == FS.LostFolder select x).ToList(); var suspectCoins = (from x in detectedCoins where x.folder == FS.SuspectFolder select x).ToList(); var dangerousCoins = (from x in detectedCoins where x.folder == FS.DangerousFolder select x).ToList(); Debug.WriteLine("Total Passed Coins - " + (passedCoins.Count() + frackedCoins.Count())); Debug.WriteLine("Total Failed Coins - " + failedCoins.Count()); // Move Coins to their respective folders after sort FS.MoveCoins(passedCoins, FS.DetectedFolder, FS.BankFolder); FS.MoveCoins(frackedCoins, FS.DetectedFolder, FS.FrackedFolder); if (failedCoins.Count() > 0) { FS.WriteCoin(failedCoins, FS.CounterfeitFolder, false, true); } FS.MoveCoins(lostCoins, FS.DetectedFolder, FS.LostFolder); FS.MoveCoins(suspectCoins, FS.DetectedFolder, FS.SuspectFolder); // Clean up Detected Folder FS.RemoveCoins(failedCoins, FS.DetectedFolder); FS.RemoveCoins(lostCoins, FS.DetectedFolder); FS.RemoveCoins(suspectCoins, FS.DetectedFolder); FS.MoveImportedFiles(); //after = DateTime.Now; //ts = after.Subtract(before); //Debug.WriteLine("Detection Completed in - " + ts.TotalMilliseconds / 1000); //updateLog("Detection Completed in - " + ts.TotalMilliseconds / 1000); updateLog("Detection and Import of the CloudCoins completed."); updateLog("Coin Detection finished."); updateLog("Total Passed Coins - " + (passedCoins.Count() + frackedCoins.Count()) + ""); updateLog("Total Counterfeit Coins - " + failedCoins.Count() + ""); updateLog("Total Lost Coins - " + lostCoins.Count() + ""); updateLog("Total Suspect Coins - " + suspectCoins.Count() + ""); updateLog("Total Dangerous Coins - " + dangerousCoins.Count() + ""); pge.MinorProgress = 100; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); }
public async static Task ProcessCoins(int NetworkNumber) { IFileSystem FS = FileSystem; FileSystem.LoadFileSystem(); FileSystem.DetectPreProcessing(); var predetectCoins = FS.LoadFolderCoins(FS.PreDetectFolder); predetectCoins = (from x in predetectCoins where x.nn == NetworkNumber select x).ToList(); IFileSystem.predetectCoins = predetectCoins; RAIDA raida = (from x in networks where x.NetworkNumber == NetworkNumber select x).FirstOrDefault(); // Process Coins in Lots of 200. Can be changed from Config File int LotCount = predetectCoins.Count() / Config.MultiDetectLoad; if (predetectCoins.Count() % Config.MultiDetectLoad > 0) LotCount++; ProgressChangedEventArgs pge = new ProgressChangedEventArgs(); int CoinCount = 0; int totalCoinCount = predetectCoins.Count(); for (int i = 0; i < LotCount; i++) { //Pick up 200 Coins and send them to RAIDA var coins = predetectCoins.Skip(i * Config.MultiDetectLoad).Take(200); raida.coins = coins; var tasks = raida.GetMultiDetectTasks(coins.ToArray(), Config.milliSecondsToTimeOut); try { string requestFileName = Utils.RandomString(16).ToLower() + DateTime.Now.ToString("yyyyMMddHHmmss") + ".stack"; // Write Request To file before detect FS.WriteCoinsToFile(coins, FS.RequestsFolder + requestFileName); await Task.WhenAll(tasks.AsParallel().Select(async task => await task())); int j = 0; foreach (var coin in coins) { coin.pown = ""; for (int k = 0; k < CloudCoinCore.Config.NodeCount; k++) { coin.response[k] = raida.nodes[k].MultiResponse.responses[j]; coin.pown += coin.response[k].outcome.Substring(0, 1); } int countp = coin.response.Where(x => x.outcome == "pass").Count(); int countf = coin.response.Where(x => x.outcome == "fail").Count(); coin.PassCount = countp; coin.FailCount = countf; CoinCount++; updateLog("No. " + CoinCount + ". Coin Deteced. S. No. - " + coin.sn + ". Pass Count - " + coin.PassCount + ". Fail Count - " + coin.FailCount + ". Result - " + coin.DetectionResult + "." + coin.pown); Debug.WriteLine("Coin Deteced. S. No. - " + coin.sn + ". Pass Count - " + coin.PassCount + ". Fail Count - " + coin.FailCount + ". Result - " + coin.DetectionResult); //coin.sortToFolder(); pge.MinorProgress = (CoinCount) * 100 / totalCoinCount; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); j++; } pge.MinorProgress = (CoinCount - 1) * 100 / totalCoinCount; Debug.WriteLine("Minor Progress- " + pge.MinorProgress); raida.OnProgressChanged(pge); FS.WriteCoin(coins, FS.DetectedFolder); FS.RemoveCoins(coins, FS.PreDetectFolder); //FS.WriteCoin(coins, FS.DetectedFolder); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }