Ejemplo n.º 1
0
        }//end detectOne

        public CloudCoin detectCoin(CloudCoin cc, int milliSecondsToTimeOut)
        {
            returnCoin = cc;

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

            Task.WaitAll(taskList.ToArray(), milliSecondsToTimeOut);
            //Get data from the detection agents

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

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

            return(returnCoin);
        }//end detect coin
Ejemplo n.º 2
0
        }//end GetHexValue

        private CloudCoin parseJpeg(String wholeString)
        {
            CloudCoin cc      = new CloudCoin();
            int       startAn = 40;

            for (int i = 0; i < 25; i++)
            {
                cc.ans[i] = wholeString.Substring(startAn, 32);
                // Console.Out.WriteLine(i +": " + cc.ans[i]);
                startAn += 32;
            }

            // end for
            cc.aoid = null;
            // wholeString.substring( 840, 895 );
            cc.hp = 25;
            // Integer.parseInt(wholeString.substring( 896, 896 ), 16);
            cc.ed = wholeString.Substring(898, 4);
            cc.nn = Convert.ToInt32(wholeString.Substring(902, 2), 16);
            cc.sn = Convert.ToInt32(wholeString.Substring(904, 6), 16);
            for (int i = 0; i < 25; i++)
            {
                cc.pans[i] = cc.generatePan();
                cc.setPastStatus("undetected", i);
            }
            cc.fileName = cc.getDenomination() + ".CloudCoin." + cc.nn + "." + cc.sn + ".";
            //Console.Out.WriteLine("parseJpeg cc.fileName " + cc.fileName);
            // end for each pan
            return(cc);
        } // end parse Jpeg
Ejemplo n.º 3
0
        }//end delete coin

        public CloudCoin fixCoin(CloudCoin brokeCoin)
        {
            /*0. RESET TICKETS IN RAIDA STATUS TO EMPTY*/
            RAIDA_Status.resetTickets();
            /*0. RESET THE DETECTION to TRUE if it is a new COIN */
            RAIDA_Status.newCoin();

            brokeCoin.setAnsToPans();// Make sure we set the RAIDA to the cc ans and not new pans.
            DateTime before = DateTime.Now;

            String      fix_result = "";
            FixitHelper fixer;

            /*START*/
            /*1. PICK THE CORNER TO USE TO TRY TO FIX */
            int corner = 1;

            // For every guid, check to see if it is fractured
            for (int raida_ID = 0; raida_ID < 25; raida_ID++)
            {
                //  Console.WriteLine("Past Status for " + raida_ID + ", " + brokeCoin.pastStatus[raida_ID]);

                if (brokeCoin.getPastStatus(raida_ID).ToLower() == "fail")
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Out.WriteLine("");
                    Console.WriteLine(StringHolder.frackfixer_11); //"Attempting to fix RAIDA " + raida_ID);
                    Console.Out.WriteLine("");
                    Console.ForegroundColor = ConsoleColor.White;

                    fixer = new FixitHelper(raida_ID, brokeCoin.ans);

                    //trustedServerAns = new String[] { brokeCoin.ans[fixer.currentTriad[0]], brokeCoin.ans[fixer.currentTriad[1]], brokeCoin.ans[fixer.currentTriad[2]] };
                    corner = 1;
                    while (!fixer.finnished)
                    {
                        Console.WriteLine(StringHolder.frackfixer_12 + corner);  //" Using corner " + corner);
                        fix_result = fixOneGuidCorner(raida_ID, brokeCoin, corner, fixer.currentTriad);
                        // Console.WriteLine(" fix_result: " + fix_result + " for corner " + corner);
                        if (fix_result.Contains("success"))
                        {
                            //Fixed. Do the fixed stuff
                            brokeCoin.setPastStatus("pass", raida_ID);
                            fixer.finnished = true;
                            corner          = 1;
                        }
                        else
                        {
                            //Still broken, do the broken stuff.
                            corner++;
                            fixer.setCornerToCheck(corner);
                        }
                    } //End whild fixer not finnished
                }     //end if RAIDA past status is passed and does not need to be fixed
            }         //end for each AN
            DateTime after = DateTime.Now;
            TimeSpan ts    = after.Subtract(before);

            Console.WriteLine(StringHolder.frackfixer_13); //"Time spent fixing RAIDA in milliseconds: " + ts.Milliseconds);

            brokeCoin.calculateHP();                       //how many fails did it get
            brokeCoin.gradeCoin();
            // sets the grade and figures out what the file extension should be (bank, fracked, counterfeit, lost
            brokeCoin.calcExpirationDate();
            brokeCoin.grade();
            return(brokeCoin);
        } // end fix coin
Ejemplo n.º 4
0
        }        //end load one CloudCoin from JSON

        /*
         * This loads a JSON file (.stack) from the hard drive that contains only one CloudCoin and turns it into an object.
         * This uses Newton soft but causes a enrror System.IO.FileNotFoundException. Could not load file 'Newtonsoft.Json'
         * public CloudCoin loadOneCloudCoinFromJsonFile(String loadFilePath)
         * {
         *
         *  //Load file as JSON
         *  String incomeJson = this.importJSON(loadFilePath);
         *  //STRIP UNESSARY test
         *  int secondCurlyBracket = ordinalIndexOf(incomeJson, "{", 2) - 1;
         *  int firstCloseCurlyBracket = ordinalIndexOf(incomeJson, "}", 0) - secondCurlyBracket;
         *  // incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket);
         *  incomeJson = incomeJson.Substring(secondCurlyBracket, firstCloseCurlyBracket + 1);
         *  // Console.Out.WriteLine(incomeJson);
         *  //Deserial JSON
         *  SimpleCoin cc = JsonConvert.DeserializeObject<SimpleCoin>(incomeJson);
         *  //Make Coin
         *  String[] strAoid = cc.aoid.ToArray();
         *  Dictionary<string, string> aoid_dictionary = new Dictionary<string, string>();
         *  for (int j = 0; j < strAoid.Length; j++)
         *  { //"fracked=ppppppppppppppppppppppppp"
         *      if (strAoid[j].Contains("="))
         *      {//see if the string contains an equals sign
         *          String[] keyvalue = strAoid[j].Split('=');
         *          aoid_dictionary.Add(keyvalue[0], keyvalue[1]);//index 0 is the key index 1 is the value.
         *      }
         *      else
         *      { //There is something there but not a key value pair. Treak it like a memo
         *          aoid_dictionary.Add("memo", strAoid[j]);
         *      }//end if cointains an =
         *  }//end for each aoid
         *
         *
         *  CloudCoin returnCC = new CloudCoin(cc.nn, cc.sn, cc.an.ToArray(), cc.ed, aoid_dictionary, "suspect");
         *  for (int i = 0; (i < 25); i++)
         *  {//All newly created loaded coins get new PANs.
         *      returnCC.pans[i] = returnCC.generatePan();
         *      //returnCC.pastStatus[i] = "undetected";
         *  } // end for each pan
         *    //Return Coin
         *
         *  returnCC.fileName = (returnCC.getDenomination() + (".CloudCoin." + (returnCC.nn + ("." + (returnCC.sn + ".")))));
         *  returnCC.json = "";
         *  returnCC.jpeg = null;
         *
         *  return returnCC;
         * }//end load one CloudCoin from JSON
         *
         */


        public CloudCoin[] loadManyCloudCoinFromJsonFile(String loadFilePath, string incomeJson)
        {
            CloudCoin[] returnCoins;


            //Remove "{ "cloudcoin": ["
            int secondCurlyBracket = ordinalIndexOf(incomeJson, "{", 2) - 1;

            incomeJson = incomeJson.Substring(secondCurlyBracket);
            //remove the last instance of "]}"
            incomeJson = incomeJson.Remove(incomeJson.LastIndexOf("}"), 1);
            incomeJson = incomeJson.Remove(incomeJson.LastIndexOf("]"), 1);
            // Console.Out.WriteLine(incomeJson);

            String[] pieces = incomeJson.Split('}');        //split json file into coins
            returnCoins = new CloudCoin[pieces.Length - 1]; //last piece is not a coin

            for (int j = 0; j < pieces.Length - 1; j++)     //for each cloudcoin segment in the chest or stack file. -1 allows for last runt segment
            {
                String   currentCoin = pieces[j];
                String[] jsonArray   = currentCoin.Split('"');

                //  for (int i = 0; i < jsonArray.Length; i++ )
                //  {
                //      Console.Out.WriteLine( i  + " = " + jsonArray[i]);
                //  }

                int      nn    = Convert.ToInt32(jsonArray[3]);
                int      sn    = Convert.ToInt32(jsonArray[7]);
                String[] ans   = new String[25];
                int      count = 0;
                for (int i = 11; i < 60; i = i + 2)
                {
                    ans[count] = jsonArray[i];
                    count++;
                }

                String ed   = jsonArray[63];
                String aoid = "";
                // Console.Out.WriteLine(jsonArray.Length);


                if (jsonArray.Length > 67)
                {//If there is an aoid
                    aoid = jsonArray[67];
                }


                Dictionary <string, string> aoid_dictionary = new Dictionary <string, string>();

                if (aoid.Contains("="))
                {                                                  //see if the string contains an equals sign
                    String[] keyvalue = aoid.Split('=');
                    aoid_dictionary.Add(keyvalue[0], keyvalue[1]); //index 0 is the key index 1 is the value.
                }
                else
                { //There is something there but not a key value pair. Treak it like a memo
                    aoid_dictionary.Add("memo", aoid);
                }//end if cointains an =


                CloudCoin returnCC = new CloudCoin(nn, sn, ans, ed, aoid_dictionary, "suspect");
                for (int i = 0; (i < 25); i++)
                {//All newly created loaded coins get new PANs.
                    returnCC.pans[i] = returnCC.generatePan();
                    returnCC.setPastStatus("undetected", i);
                } // end for each pan
                  //Return Coin

                returnCC.fileName = (returnCC.getDenomination() + (".CloudCoin." + (returnCC.nn + ("." + (returnCC.sn + ".")))));
                returnCC.json     = "";
                returnCC.jpeg     = null;
                returnCoins[j]    = returnCC;
            }//end for each cloudcoin in the json file

            return(returnCoins);
        }//end load one CloudCoin from JSON