public async Task fixCoin(CloudCoin brokeCoin, int coinindex) { ObservableStatus[] result = new ObservableStatus[NODEQNTY]; for (int i = 0; i < NODEQNTY; i++) //initializing Array of coin statuses { result[i] = new ObservableStatus(CloudCoin.raidaNodeResponse.unknown); } for (int index = 0; index < NODEQNTY; index++) { if (brokeCoin.detectStatus[index] != CloudCoin.raidaNodeResponse.pass) { // This guid has failed, get tickets onCoinFixStarted(new CoinFixStartedEventArgs(coinindex, index)); //fire event that particular RAIDA key on particular coin has begun to be fixed result[index] = await ProcessFixingGUID(index, brokeCoin, coinindex); // onCoinFixFinished(new CoinFixFinishedEventArgs(coinindex, index, result[index].Status)); }// end for failed guid else { result[index].Status = brokeCoin.detectStatus[index]; } }//end for all the guids bool isGood = result.All <ObservableStatus>(x => x.Status == CloudCoin.raidaNodeResponse.pass); if (isGood) { Logger.Write(String.Format("Fixed Coin Sn {0}", brokeCoin.sn), Logger.Level.Normal); } else { Logger.Write(String.Format("Not Fixed Coin Sn {0}", brokeCoin.sn), Logger.Level.Normal); } }
private async Task <ObservableStatus> ProcessFixingGUID(int guid_id, CloudCoin returnCoin, int coinindex) { fixer = new FixitHelper(guid_id, returnCoin.an); GetTicketResponse[] ticketStatus = new GetTicketResponse[3]; ObservableStatus result = new ObservableStatus(); int corner = 1; while (!fixer.finnished) { onCoinFixProcessing(new CoinFixProcessingEventArgs(coinindex, guid_id, corner)); Logger.Write("Fixing coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ".", Logger.Level.Normal); string[] trustedServerAns = new string[] { returnCoin.an[fixer.currentTriad[0].Number], returnCoin.an[fixer.currentTriad[1].Number], returnCoin.an[fixer.currentTriad[2].Number] }; ticketStatus = await get_tickets(fixer.currentTriad, trustedServerAns, returnCoin.nn, returnCoin.sn, returnCoin.denomination); // See if there are errors in the tickets if (ticketStatus[0].status != "ticket" || ticketStatus[1].status != "ticket" || ticketStatus[2].status != "ticket") {// No tickets, go to next triad corner Logger.Write("Fixing coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ". There is no three tickets from triad", Logger.Level.Normal); corner++; fixer.setCornerToCheck(corner); } else {// Has three good tickets Logger.Write("Fixing coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ". We have three tickets. Going to fix.", Logger.Level.Normal); var fff = await Instance.NodesArray[guid_id].fix(fixer.currentTriad, ticketStatus[0].message, ticketStatus[1].message, ticketStatus[2].message, returnCoin.pans[guid_id], returnCoin.sn); if (fff.status == "success") // the guid IS recovered!!! { Logger.Write("Coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ". Fixed!.", Logger.Level.Normal); returnCoin.detectStatus[guid_id] = result.Status = CloudCoin.raidaNodeResponse.pass; onCoinFixFinished(new CoinFixFinishedEventArgs(coinindex, guid_id, result.Status)); returnCoin.an[guid_id] = returnCoin.pans[guid_id]; fixer.finnished = true; return(result); } else if (fff.status == "fail") { // command failed, need to try another corner Logger.Write("Coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ". Failed, trying another corner...", Logger.Level.Normal); corner++; fixer.setCornerToCheck(corner); returnCoin.detectStatus[guid_id] = CloudCoin.raidaNodeResponse.fail; } else if (fff.status == "error") { Logger.Write("Coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ". Error, trying another corner....", Logger.Level.Normal); corner++; fixer.setCornerToCheck(corner); returnCoin.detectStatus[guid_id] = CloudCoin.raidaNodeResponse.error; } else { Logger.Write("Coin " + returnCoin.sn + ", node " + guid_id + ", corner " + corner + ". Error, trying another corner....", Logger.Level.Normal); corner++; fixer.setCornerToCheck(corner); returnCoin.detectStatus[guid_id] = CloudCoin.raidaNodeResponse.error; } //end if else fix was successful } //end if else one of the tickts has an error. } //end while fixer not finnihsed. // the guid cannot be recovered! all corners checked Logger.Write("Coin " + returnCoin.sn + ", node " + guid_id + " was not fixed!", Logger.Level.Normal); result.Status = returnCoin.detectStatus[guid_id]; onCoinFixFinished(new CoinFixFinishedEventArgs(coinindex, guid_id, result.Status)); return(result); }