Exemple #1
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
Exemple #2
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