Esempio n. 1
0
        }//Constructor

        /* PUBLIC METHODS */
        public bool importAll()
        {
            var ext = new List <string> {
                ".jpg", ".stack", ".jpeg"
            };
            var fnamesRaw = Directory.GetFiles(this.fileUtils.importFolder, "*.*", SearchOption.TopDirectoryOnly).Where(s => ext.Contains(Path.GetExtension(s)));

            string[] fnames = new string[fnamesRaw.Count()];
            for (int i = 0; i < fnamesRaw.Count(); i++)
            {
                fnames[i] = Path.GetFileName(fnamesRaw.ElementAt(i));
            }
            ;

            //String[] fnames = new DirectoryInfo(this.fileUtils.importFolder).GetFiles().Select(o => o.Name).ToArray();//Get a list of all in the folder except the directory "imported"

            if (fnames.Length == 0)//   Console.Out.WriteLine("There were no CloudCoins to import. Please place our CloudCoin .jpg and .stack files in your imports" + " folder at " + this.fileUtils.importFolder );
            {
                return(false);
            }
            else
            {
                //  Console.ForegroundColor = ConsoleColor.Green;
                //  Console.Out.WriteLine("Importing the following files: ");
                CoreLogger.Log("Importing the following files: ");
                //  Console.ForegroundColor = ConsoleColor.White;
                for (int i = 0; i < fnames.Length; i++)// Loop through each file.
                {
                    Console.Out.WriteLine(fnames[i]);
                    CoreLogger.Log(fnames[i]);
                    this.importOneFile(fnames[i]);
                } // end for each file name
                return(true);
            }     //end if no files
        }         // End Import All
Esempio n. 2
0
        }//import stack

        public bool seemsValidJSON(string json)
        {
            /*This does some simple tests to see if the JSON is valid. It is not precise.*/


            if (json.Count(f => f == '{') != json.Count(f => f == '}'))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("The stack file did not have a matching number of { }. There were " + json.Count(f => f == '{') + " {, and " + json.Count(f => f == '}') + " }");
                CoreLogger.Log("The stack file did not have a matching number of { }. There were " + json.Count(f => f == '{') + " {, and " + json.Count(f => f == '}') + " }");
                Console.ForegroundColor = ConsoleColor.White;
                return(false);
            }//Check if number of currly brackets open are the same as closed
            if (json.Count(f => f == '[') != json.Count(f => f == ']'))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("The stack file did not have a matching number of []. There were " + json.Count(f => f == '[') + " [, and " + json.Count(f => f == ']') + " ]");
                CoreLogger.Log("The stack file did not have a matching number of []. There were " + json.Count(f => f == '[') + " [, and " + json.Count(f => f == ']') + " ]");
                Console.ForegroundColor = ConsoleColor.White;
                return(false);
            }//Check if number of  brackets open are the same as closed
            if (IsOdd(json.Count(f => f == '\"')))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("The stack file did not have a matching number of double quotations");
                CoreLogger.Log("The stack file did not have a matching number of double quotations");
                Console.ForegroundColor = ConsoleColor.White;
                return(false);
            } //Check if number of
            return(true);
        }     //end seems valid
Esempio n. 3
0
        }//end load one CloudCoin from JSON

        public CloudCoin loadOneCloudCoinFromJPEGFile(String loadFilePath)
        {
            /* GET the first 455 bytes of he jpeg where the coin is located */
            String wholeString = "";

            byte[] jpegHeader = new byte[455];
            Console.Out.WriteLine("Load file path " + loadFilePath);
            CoreLogger.Log("Load file path " + loadFilePath);
            FileStream fileStream = new FileStream(loadFilePath, FileMode.Open, FileAccess.Read);

            try
            {
                int count;                            // actual number of bytes read
                int sum = 0;                          // total number of bytes read

                // read until Read method returns 0 (end of the stream has been reached)
                while ((count = fileStream.Read(jpegHeader, sum, 455 - sum)) > 0)
                {
                    sum += count;  // sum is a buffer offset for next reading
                }
            }
            finally
            {
                fileStream.Close();
            }
            wholeString = bytesToHexString(jpegHeader);
            CloudCoin returnCC = this.parseJpeg(wholeString);

            // Console.Out.WriteLine("From FileUtils returnCC.fileName " + returnCC.fileName);
            return(returnCC);
        }//end load one CloudCoin from JSON
Esempio n. 4
0
        }// end parse Jpeg

        public void moveFile(string fromPath, string tooPath)
        {
            string path  = fromPath;
            string path2 = tooPath;

            try
            {
                if (!File.Exists(path))
                {
                    // This statement ensures that the file is created,
                    // but the handle is not kept.
                    using (FileStream fs = File.Create(path)) { }
                }

                // Ensure that the target does not exist.
                if (File.Exists(path2))
                {
                    File.Delete(path2);
                }

                // Move the file.
                File.Move(path, path2);
                //Console.WriteLine("{0} was moved to {1}.", path, path2);
            }
            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
                CoreLogger.Log(e.ToString());
            }
        }
Esempio n. 5
0
        public int readInt()
        {
            string inputString = "";
            int    number      = 0;
            bool   done        = false;

            while (!done)
            {
                try
                {
                    inputString = this.readString();
                    inputString = inputString.Trim();
                    number      = Convert.ToInt32(inputString);
                    done        = true;
                }
                catch (FormatException e)
                {
                    Console.Out.WriteLine("Input is not an integer. " + this.errorMessages[INT_MESSAGE]);// "Input is not an integer. ";
                    CoreLogger.Log("Input is not an integer. " + this.errorMessages[INT_MESSAGE]);
                    CoreLogger.Log(e.ToString());
                    Console.Out.Write(this.prompt);
                }
            }

            return(number);
        }
Esempio n. 6
0
        }  // End constructor

        /* PUBLIC METHODS */

        // 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)
        {
            CloudCoin returnCC = new CloudCoin();

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

            try
            {
                returnCC = JsonConvert.DeserializeObject <CloudCoin>(incomeJson);
            }
            catch (JsonReaderException)
            {
                Console.WriteLine("There was an error reading files in your bank.");
                CoreLogger.Log("There was an error reading files in your bank.");
                Console.WriteLine("You may have the aoid memo bug that uses too many double quote marks.");
                Console.WriteLine("Your bank files are stored using and older version that did not use properly formed JSON.");
                Console.WriteLine("Would you like to upgrade these files to the newer standard?");
                Console.WriteLine("Your files will be edited.");
                Console.WriteLine("1 for yes, 2 for no.");
                KeyboardReader reader = new KeyboardReader();
                int            answer = reader.readInt(1, 2);
                if (answer == 1)
                {
                    //Get rid of ed and aoid
                    //Get file names in bank folder
                    String[] fileNames = new DirectoryInfo(bankFolder).GetFiles().Select(o => o.Name).ToArray();
                    for (int i = 0; i < fileNames.Length; i++)
                    {
                        Console.WriteLine("Fixing " + bankFolder + "\\" + fileNames[i]);
                        CoreLogger.Log("Fixing " + bankFolder + "\\" + fileNames[i]);
                        string text = File.ReadAllText(bankFolder + "\\" + fileNames[i]);
                        text = text.Replace("\"aoid\": [\"memo\"=\"\"]", "");
                        File.WriteAllText(bankFolder + "\\" + fileNames[i], text);
                    }//End for all files in bank
                    CoreLogger.Log("Done Fixing. The program will now exit. Please restart. Press any key.");
                    Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key.");
                    Console.Read();
                    Environment.Exit(0);
                }
                else
                {
                    CoreLogger.Log("Leaving files as is. You maybe able to fix the manually by editing the files.");
                    Console.WriteLine("Leaving files as is. You maybe able to fix the manually by editing the files.");
                    Console.WriteLine("Done Fixing. The program will now exit. Please restart. Press any key.");
                    Console.Read();
                    Environment.Exit(0);
                }
            }

            return(returnCC);
        }//end load one CloudCoin from JSON
Esempio n. 7
0
        public int readInt(int min, int max)
        {
            string inputString = "";
            int    number      = 0;
            bool   done        = false;

            while (!done)
            {
                try
                {
                    inputString = this.readString();
                    inputString = inputString.Trim();
                    number      = Convert.ToInt32(inputString);
                    if (((number < min) || (number > max)))
                    {
                        Console.Out.WriteLine("Please enter an integer between " + min + " & " + max);//"Please enter an integer between "
                    }
                    else
                    {
                        done = true;
                    }
                }
                catch (FormatException e)
                {
                    Console.Out.WriteLine("Input is not an integer. Please enter an integer between " + min + " & " + max);//"Input is not an integer. Please enter an integer between "
                    CoreLogger.Log("Input is not an integer. Please enter an integer between " + min + " & " + max);
                    CoreLogger.Log(e.ToString());
                    Console.Out.Write(this.prompt);
                }
            }

            return(number);
        }
Esempio n. 8
0
        }//end load one CloudCoin from JSON

        public String importJSON(String jsonfile)
        {
            String jsonData = "";
            String line;

            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.

                using (var sr = File.OpenText(jsonfile))
                {
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while (true)
                    {
                        line = sr.ReadLine();
                        if (line == null)
                        {
                            break;
                        } //End if line is null
                        jsonData = (jsonData + line + "\n");
                    }     //end while true
                }         //end using
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file " + jsonfile + " could not be read:");
                CoreLogger.Log("The file " + jsonfile + " could not be read:");
                Console.WriteLine(e.Message);
                CoreLogger.Log(e.Message);
            }
            return(jsonData);
        }//end importJSON
Esempio n. 9
0
        }//End importOneFile

        /* IMPORT ONE JPEG */
        private bool importJPEG(String fileName)//Move one jpeg to suspect folder.
        {
            bool isSuccessful = false;

            // Console.Out.WriteLine("Trying to load: " + this.fileUtils.importFolder + fileName );
            CoreLogger.Log("Trying to load: " + this.fileUtils.importFolder + fileName);
            try
            {
                //  Console.Out.WriteLine("Loading coin: " + fileUtils.importFolder + fileName);
                //CloudCoin tempCoin = this.fileUtils.loadOneCloudCoinFromJPEGFile( fileUtils.importFolder + fileName );

                /*Begin import from jpeg*/

                /* GET the first 455 bytes of he jpeg where the coin is located */
                String wholeString = "";
                byte[] jpegHeader  = new byte[455];
                // Console.Out.WriteLine("Load file path " + fileUtils.importFolder + fileName);
                using (FileStream fileStream = new FileStream(fileUtils.importFolder + fileName, FileMode.Open, FileAccess.Read))
                {
                    try
                    {
                        int count;                            // actual number of bytes read
                        int sum = 0;                          // total number of bytes read

                        // read until Read method returns 0 (end of the stream has been reached)
                        while ((count = fileStream.Read(jpegHeader, sum, 455 - sum)) > 0)
                        {
                            sum += count;  // sum is a buffer offset for next reading
                        }
                    }
                    finally
                    {
                    }
                }
                wholeString = bytesToHexString(jpegHeader);

                CloudCoin tempCoin = this.parseJpeg(wholeString);
                // Console.Out.WriteLine("From FileUtils returnCC.fileName " + tempCoin.fileName);

                /*end import from jpeg file */



                //   Console.Out.WriteLine("Loaded coin filename: " + tempCoin.fileName);

                this.fileUtils.writeTo(this.fileUtils.suspectFolder, tempCoin);
                return(true);
            }
            catch (FileNotFoundException ex)
            {
                Console.Out.WriteLine("File not found: " + fileName + ex);
                CoreLogger.Log("File not found: " + fileName + ex);
            }
            catch (IOException ioex)
            {
                Console.Out.WriteLine("IO Exception:" + fileName + ioex);
                CoreLogger.Log("IO Exception:" + fileName + ioex);
            }// end try catch
            return(isSuccessful);
        }
Esempio n. 10
0
        }//end detectOne

        public CoinUtils detectCoin(CoinUtils cu, int milliSecondsToTimeOut)
        {
            cu.generatePan();

            var t00 = detectOne(00, cu.cc.nn, cu.cc.sn, cu.cc.an[00], cu.pans[00], cu.getDenomination());
            var t01 = detectOne(01, cu.cc.nn, cu.cc.sn, cu.cc.an[01], cu.pans[01], cu.getDenomination());
            var t02 = detectOne(02, cu.cc.nn, cu.cc.sn, cu.cc.an[02], cu.pans[02], cu.getDenomination());
            var t03 = detectOne(03, cu.cc.nn, cu.cc.sn, cu.cc.an[03], cu.pans[03], cu.getDenomination());
            var t04 = detectOne(04, cu.cc.nn, cu.cc.sn, cu.cc.an[04], cu.pans[04], cu.getDenomination());
            var t05 = detectOne(05, cu.cc.nn, cu.cc.sn, cu.cc.an[05], cu.pans[05], cu.getDenomination());
            var t06 = detectOne(06, cu.cc.nn, cu.cc.sn, cu.cc.an[06], cu.pans[06], cu.getDenomination());
            var t07 = detectOne(07, cu.cc.nn, cu.cc.sn, cu.cc.an[07], cu.pans[07], cu.getDenomination());
            var t08 = detectOne(08, cu.cc.nn, cu.cc.sn, cu.cc.an[08], cu.pans[08], cu.getDenomination());
            var t09 = detectOne(09, cu.cc.nn, cu.cc.sn, cu.cc.an[09], cu.pans[09], cu.getDenomination());
            var t10 = detectOne(10, cu.cc.nn, cu.cc.sn, cu.cc.an[10], cu.pans[10], cu.getDenomination());
            var t11 = detectOne(11, cu.cc.nn, cu.cc.sn, cu.cc.an[11], cu.pans[11], cu.getDenomination());
            var t12 = detectOne(12, cu.cc.nn, cu.cc.sn, cu.cc.an[12], cu.pans[12], cu.getDenomination());
            var t13 = detectOne(13, cu.cc.nn, cu.cc.sn, cu.cc.an[13], cu.pans[13], cu.getDenomination());
            var t14 = detectOne(14, cu.cc.nn, cu.cc.sn, cu.cc.an[14], cu.pans[14], cu.getDenomination());
            var t15 = detectOne(15, cu.cc.nn, cu.cc.sn, cu.cc.an[15], cu.pans[15], cu.getDenomination());
            var t16 = detectOne(16, cu.cc.nn, cu.cc.sn, cu.cc.an[16], cu.pans[16], cu.getDenomination());
            var t17 = detectOne(17, cu.cc.nn, cu.cc.sn, cu.cc.an[17], cu.pans[17], cu.getDenomination());
            var t18 = detectOne(18, cu.cc.nn, cu.cc.sn, cu.cc.an[18], cu.pans[18], cu.getDenomination());
            var t19 = detectOne(19, cu.cc.nn, cu.cc.sn, cu.cc.an[19], cu.pans[19], cu.getDenomination());
            var t20 = detectOne(20, cu.cc.nn, cu.cc.sn, cu.cc.an[20], cu.pans[20], cu.getDenomination());
            var t21 = detectOne(21, cu.cc.nn, cu.cc.sn, cu.cc.an[21], cu.pans[21], cu.getDenomination());
            var t22 = detectOne(22, cu.cc.nn, cu.cc.sn, cu.cc.an[22], cu.pans[22], cu.getDenomination());
            var t23 = detectOne(23, cu.cc.nn, cu.cc.sn, cu.cc.an[23], cu.pans[23], cu.getDenomination());
            var t24 = detectOne(24, cu.cc.nn, cu.cc.sn, cu.cc.an[24], cu.pans[24], cu.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)
                {
                    cu.setPastStatus(responseArray[i].outcome, i);
                    CoreLogger.Log(cu.cc.sn + " detect:" + i + " " + responseArray[i].fullResponse);
                }
                else
                {
                    cu.setPastStatus("undetected", i);
                };// should be pass, fail, error or undetected.
            }//end for each detection agent

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

            return(cu);
        }//end detect coin
 private void coinExists(String suspectFileName)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.Out.WriteLine("  You tried to import a coin that has already been imported: " + suspectFileName);
     CoreLogger.Log("  You tried to import a coin that has already been imported: " + suspectFileName);
     File.Move(this.fileUtils.suspectFolder + suspectFileName, this.fileUtils.trashFolder + suspectFileName);
     Console.Out.WriteLine("  Suspect CloudCoin was moved to Trash folder.");
     CoreLogger.Log("  Suspect CloudCoin was moved to Trash folder.");
     Console.ForegroundColor = ConsoleColor.White;
 }//end coin exists
Esempio n. 12
0
        }// end fix all

        // End select all file names in a folder
        public bool deleteCoin(String path)
        {
            bool deleted = false;

            // System.out.println("Deleteing Coin: "+path + this.fileName + extension);
            try
            {
                File.Delete(path);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                CoreLogger.Log(e.ToString());
            }
            return(deleted);
        }//end delete coin
Esempio n. 13
0
        }//end echo

        public bool[] echoAll(int milliSecondsToTimeOut)
        {
            Response[] results = new Response[25];
            var        t00     = echoOne(00);
            var        t01     = echoOne(01);
            var        t02     = echoOne(02);
            var        t03     = echoOne(03);
            var        t04     = echoOne(04);
            var        t05     = echoOne(05);
            var        t06     = echoOne(06);
            var        t07     = echoOne(07);
            var        t08     = echoOne(08);
            var        t09     = echoOne(09);
            var        t10     = echoOne(10);
            var        t11     = echoOne(11);
            var        t12     = echoOne(12);
            var        t13     = echoOne(13);
            var        t14     = echoOne(14);
            var        t15     = echoOne(15);
            var        t16     = echoOne(16);
            var        t17     = echoOne(17);
            var        t18     = echoOne(18);
            var        t19     = echoOne(19);
            var        t20     = echoOne(20);
            var        t21     = echoOne(21);
            var        t22     = echoOne(22);
            var        t23     = echoOne(23);
            var        t24     = echoOne(24);

            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);
            for (int i = 0; i < 25; i++)
            {
                if (responseArray[i] != null)
                {
                    CoreLogger.Log("echo:" + i + " " + responseArray[i].fullResponse);
                }
            }


            return(RAIDA_Status.failsEcho);
        }//end echo
Esempio n. 14
0
        }//End convert string array to string

        /**
         * Use System.in.read to read the next character from the
         * STDIN stream.
         */
        private char nextChar()
        {
            int charAsInt = -1;

            try
            {
                charAsInt = Console.Read();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e);
                CoreLogger.Log(e.ToString());
                Console.WriteLine("Fatal error. Exiting program.");// "Fatal error. Exiting program.");
                return((char)charAsInt);
            }

            return((char)charAsInt);
        }//end nextChar
Esempio n. 15
0
        }     // end set ans to pans if passed

        public void consoleReport()
        {
            // Used only for console apps
            //  System.out.println("Finished detecting coin index " + j);
            // PRINT OUT ALL COIN'S RAIDA STATUS AND SET AN TO NEW PAN
            char[] pownArray = cc.pown.ToCharArray();
            sortToFolder();
            Console.Out.WriteLine("");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Out.WriteLine("                                                        ");
            Console.Out.WriteLine("   Authenticity Report SN #" + string.Format("{0,8}", cc.sn) + ", Denomination: " + string.Format("{0,3}", this.getDenomination()) + "  ");

            CoreLogger.Log("   Authenticity Report SN #" + string.Format("{0,8}", cc.sn) + ", Denomination: " + string.Format("{0,3}", this.getDenomination()) + "  ");
            Console.Out.WriteLine("                                                        ");
            Console.Out.Write("    "); a(pownArray[0]); Console.Out.Write("       "); a(pownArray[1]); Console.Out.Write("       "); a(pownArray[2]); Console.Out.Write("       "); a(pownArray[3]); Console.Out.Write("       "); a(pownArray[4]); Console.Out.WriteLine("    ");
            Console.Out.WriteLine("                                                        ");
            Console.Out.Write("    "); a(pownArray[5]); Console.Out.Write("       "); a(pownArray[6]); Console.Out.Write("       "); a(pownArray[7]); Console.Out.Write("       "); a(pownArray[8]); Console.Out.Write("       "); a(pownArray[9]); Console.Out.WriteLine("    ");
            Console.Out.WriteLine("                                                        ");
            Console.Out.Write("    "); a(pownArray[10]); Console.Out.Write("       "); a(pownArray[11]); Console.Out.Write("       "); a(pownArray[12]); Console.Out.Write("       "); a(pownArray[13]); Console.Out.Write("       "); a(pownArray[14]); Console.Out.WriteLine("    ");
            Console.Out.WriteLine("                                                        ");
            Console.Out.Write("    "); a(pownArray[15]); Console.Out.Write("       "); a(pownArray[16]); Console.Out.Write("       "); a(pownArray[17]); Console.Out.Write("       "); a(pownArray[18]); Console.Out.Write("       "); a(pownArray[19]); Console.Out.WriteLine("    ");
            Console.Out.WriteLine("                                                ");
            Console.Out.Write("    "); a(pownArray[20]); Console.Out.Write("       "); a(pownArray[21]); Console.Out.Write("       "); a(pownArray[22]); Console.Out.Write("       "); a(pownArray[23]); Console.Out.Write("       "); a(pownArray[24]); Console.Out.WriteLine("    ");
            Console.Out.WriteLine("   Status: " + getFolder());
            Console.Out.WriteLine("                                                        ");
            Console.Out.WriteLine("");
            Console.ForegroundColor = ConsoleColor.White;

            // check if failed
            //  string fmt = "00";
            // string fi = i.ToString(fmt); // Pad numbers with two digits
            //    Console.Out.WriteLine("RAIDA" + i + " " + pastStatus[i] + " | ");
            // Console.Out.WriteLine("AN " + i + ans[i]);
            // Console.Out.WriteLine("PAN " + i + pans[i]);
            //  }

            // End for each cloud coin GUID statu
            //  Console.Out.WriteLine("ed " + ed);
            //  Console.Out.WriteLine("edHex " + edHex);
            //  Console.Out.WriteLine("edhp " + hp);
            // Console.Out.WriteLine("fileName " + fileName);
            // Console.Out.WriteLine("YEARSTILEXPIRE " + YEARSTILEXPIRE);
            //   Console.Out.WriteLine("extension " + extension);
        }//Console Report
Esempio n. 16
0
        }//end echo

        public Response[] echoAll(int milliSecondsToTimeOut)
        {
            Response[] results = new Response[25];
            var        t00     = Task.Factory.StartNew(() => echoOne(00));
            var        t01     = Task.Factory.StartNew(() => echoOne(01));
            var        t02     = Task.Factory.StartNew(() => echoOne(02));
            var        t03     = Task.Factory.StartNew(() => echoOne(03));
            var        t04     = Task.Factory.StartNew(() => echoOne(04));
            var        t05     = Task.Factory.StartNew(() => echoOne(05));
            var        t06     = Task.Factory.StartNew(() => echoOne(06));
            var        t07     = Task.Factory.StartNew(() => echoOne(07));
            var        t08     = Task.Factory.StartNew(() => echoOne(08));
            var        t09     = Task.Factory.StartNew(() => echoOne(09));
            var        t10     = Task.Factory.StartNew(() => echoOne(10));
            var        t11     = Task.Factory.StartNew(() => echoOne(11));
            var        t12     = Task.Factory.StartNew(() => echoOne(12));
            var        t13     = Task.Factory.StartNew(() => echoOne(13));
            var        t14     = Task.Factory.StartNew(() => echoOne(14));
            var        t15     = Task.Factory.StartNew(() => echoOne(15));
            var        t16     = Task.Factory.StartNew(() => echoOne(16));
            var        t17     = Task.Factory.StartNew(() => echoOne(17));
            var        t18     = Task.Factory.StartNew(() => echoOne(18));
            var        t19     = Task.Factory.StartNew(() => echoOne(19));
            var        t20     = Task.Factory.StartNew(() => echoOne(20));
            var        t21     = Task.Factory.StartNew(() => echoOne(21));
            var        t22     = Task.Factory.StartNew(() => echoOne(22));
            var        t23     = Task.Factory.StartNew(() => echoOne(23));
            var        t24     = Task.Factory.StartNew(() => echoOne(24));

            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);
            for (int i = 0; i < 25; i++)
            {
                if (responseArray[i] != null)
                {
                    CoreLogger.Log("echo:" + i + " " + responseArray[i].fullResponse);
                }
            }
            return(results);
        }//end echo
Esempio n. 17
0
        }//end read all bytes

        public bool writeTo(String folder, CloudCoin cc)
        {
            CoinUtils    cu            = new CoinUtils(cc);
            const string quote         = "\"";
            const string tab           = "\t";
            String       wholeJson     = "{" + Environment.NewLine; //{
            bool         alreadyExists = true;
            String       json          = this.setJSON(cc);

            if (!File.Exists(folder + cu.fileName + ".stack"))
            {
                wholeJson += tab + quote + "cloudcoin" + quote + ": [" + Environment.NewLine; // "cloudcoin" : [
                wholeJson += json;
                wholeJson += Environment.NewLine + tab + "]" + Environment.NewLine + "}";
                File.WriteAllText(folder + cu.fileName + ".stack", wholeJson);
            }
            else
            {
                if (folder.Contains("Counterfeit") || folder.Contains("Trash"))
                {
                    //Let the program delete it
                    alreadyExists = false;
                    return(alreadyExists);
                }
                else if (folder.Contains("Imported"))
                {
                    File.Delete(folder + cu.fileName + ".stack");
                    File.WriteAllText(folder + cu.fileName + ".stack", wholeJson);
                    alreadyExists = false;
                    return(alreadyExists);
                }
                else
                {
                    Console.WriteLine(cu.fileName + ".stack" + " already exists in the folder " + folder);
                    CoreLogger.Log(cu.fileName + ".stack" + " already exists in the folder " + folder);
                    return(alreadyExists);
                } //end else
            }     //File Exists
            File.WriteAllText(folder + cu.fileName + ".stack", wholeJson);
            alreadyExists = false;
            return(alreadyExists);
        }//End Write To
Esempio n. 18
0
		}//end get ticket


		public void get_Tickets(int[] triad, String[] ans, int nn, int sn, int denomination, int millisecondsToTimeout)
		{
			//Empty the status of any old ticket info. 
			RAIDA_Status.resetTickets();
			//Console.WriteLine("Get Tickets called. ");
			var t00 = get_Ticket(0, triad[00], nn, sn, ans[00], denomination, millisecondsToTimeout);
			var t01 = get_Ticket(1, triad[01], nn, sn, ans[01], denomination, millisecondsToTimeout);
			var t02 = get_Ticket(2, triad[02], nn, sn, ans[02], denomination, millisecondsToTimeout);

			var taskList = new List<Task> { t00, t01, t02 };
			Task.WaitAll(taskList.ToArray(), millisecondsToTimeout);
			try
			{
				CoreLogger.Log(sn + " get ticket:" + triad[00] + " " + responseArray[triad[00]].fullResponse);
				CoreLogger.Log(sn + " get ticket:" + triad[01] + " " + responseArray[triad[01]].fullResponse);
				CoreLogger.Log(sn + " get ticket:" + triad[02] + " " + responseArray[triad[02]].fullResponse);
			}
			catch { }
			//Get data from the detection agents
		}//end detect coin
Esempio n. 19
0
        }//end get ticket

        public void get_Tickets(int[] triad, String[] ans, int nn, int sn, int denomination, int milliSecondsToTimeOut)
        {
            //Console.WriteLine("Get Tickets called. ");
            var t00 = Task.Factory.StartNew(() => get_Ticket(0, triad[00], nn, sn, ans[00], denomination));
            var t01 = Task.Factory.StartNew(() => get_Ticket(1, triad[01], nn, sn, ans[01], denomination));
            var t02 = Task.Factory.StartNew(() => get_Ticket(2, triad[02], nn, sn, ans[02], denomination));

            var taskList = new List <Task> {
                t00, t01, t02
            };

            Task.WaitAll(taskList.ToArray(), milliSecondsToTimeOut);
            try
            {
                CoreLogger.Log(sn + " get ticket:" + triad[00] + " " + responseArray[triad[00]].fullResponse);
                CoreLogger.Log(sn + " get ticket:" + triad[01] + " " + responseArray[triad[01]].fullResponse);
                CoreLogger.Log(sn + " get ticket:" + triad[02] + " " + responseArray[triad[02]].fullResponse);
            }
            catch { }
            //Get data from the detection agents
        } //end detect coin
Esempio n. 20
0
        // end get JSON

        /* Writes a JPEG To the Export Folder */
        public bool writeJpeg(CloudCoin cc, string tag)
        {
            // Console.Out.WriteLine("Writing jpeg " + cc.sn);

            CoinUtils cu = new CoinUtils(cc);

            bool fileSavedSuccessfully = true;

            /* BUILD THE CLOUDCOIN STRING */
            String cloudCoinStr = "01C34A46494600010101006000601D05"; //THUMBNAIL HEADER BYTES

            for (int i = 0; (i < 25); i++)
            {
                cloudCoinStr = cloudCoinStr + cc.an[i];
            } // end for each an

            //cloudCoinStr += "204f42455920474f4420262044454645415420545952414e545320";// Hex for " OBEY GOD & DEFEAT TYRANTS "
            //cloudCoinStr += "20466f756e6465727320372d352d3137";// Founders 7-5-17
            cloudCoinStr += "4c6976652046726565204f7220446965"; // Live Free or Die
            cloudCoinStr += "00000000000000000000000000";       //Set to unknown so program does not export user data
                                                                // for (int i =0; i < 25; i++) {
                                                                //     switch () { }//end switch pown char
                                                                // }//end for each pown
            cloudCoinStr += "00";                               // HC: Has comments. 00 = No
            cu.calcExpirationDate();
            cloudCoinStr += cu.edHex;                           // 01;//Expiration date Sep 2016 (one month after zero month)
            cloudCoinStr += "01";                               //  cc.nn;//network number
            String hexSN     = cc.sn.ToString("X6");
            String fullHexSN = "";

            switch (hexSN.Length)
            {
            case 1: fullHexSN = ("00000" + hexSN); break;

            case 2: fullHexSN = ("0000" + hexSN); break;

            case 3: fullHexSN = ("000" + hexSN); break;

            case 4: fullHexSN = ("00" + hexSN); break;

            case 5: fullHexSN = ("0" + hexSN); break;

            case 6: fullHexSN = hexSN; break;
            }
            cloudCoinStr = (cloudCoinStr + fullHexSN);
            /* BYTES THAT WILL GO FROM 04 to 454 (Inclusive)*/
            byte[] ccArray = this.hexStringToByteArray(cloudCoinStr);


            /* READ JPEG TEMPLATE*/
            byte[] jpegBytes = null;
            switch (cu.getDenomination())
            {
            case 1: jpegBytes = readAllBytes(this.templateFolder + "jpeg1.jpg"); break;

            case 5: jpegBytes = readAllBytes(this.templateFolder + "jpeg5.jpg"); break;

            case 25: jpegBytes = readAllBytes(this.templateFolder + "jpeg25.jpg"); break;

            case 100: jpegBytes = readAllBytes(this.templateFolder + "jpeg100.jpg"); break;

            case 250: jpegBytes = readAllBytes(this.templateFolder + "jpeg250.jpg"); break;
            }// end switch


            /* WRITE THE SERIAL NUMBER ON THE JPEG */

            //Bitmap bitmapimage;

            SKBitmap bitmapimage;
            //using (var ms = new MemoryStream(jpegBytes))
            {
                //bitmapimage = new Bitmap(ms);
                bitmapimage = SKBitmap.Decode(jpegBytes);
            }
            SKCanvas canvas = new SKCanvas(bitmapimage);
            //Graphics graphics = Graphics.FromImage(bitmapimage);
            //graphics.SmoothingMode = SmoothingMode.AntiAlias;
            //graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            SKPaint textPaint = new SKPaint()
            {
                IsAntialias = true,
                Color       = SKColors.White,
                TextSize    = 14,
                Typeface    = SKTypeface.FromFamilyName("Arial")
            };

            //PointF drawPointAddress = new PointF(30.0F, 25.0F);

            canvas.DrawText(String.Format("{0:N0}", cc.sn) + " of 16,777,216 on Network: 1", 30, 40, textPaint);
            //graphics.DrawString(String.Format("{0:N0}", cc.sn) + " of 16,777,216 on Network: 1", new Font("Arial", 10), Brushes.White, drawPointAddress);

            //ImageConverter converter = new ImageConverter();
            //byte[] snBytes = (byte[])converter.ConvertTo(bitmapimage, typeof(byte[]));
            SKImage image = SKImage.FromBitmap(bitmapimage);
            SKData  data  = image.Encode(SKEncodedImageFormat.Jpeg, 100);

            byte[] snBytes = data.ToArray();

            List <byte> b1 = new List <byte>(snBytes);
            List <byte> b2 = new List <byte>(ccArray);

            b1.InsertRange(4, b2);

            if (tag == "random")
            {
                Random r    = new Random();
                int    rInt = r.Next(100000, 1000000); //for ints
                tag = rInt.ToString();
            }

            string fileName = exportFolder + cu.fileName + tag + ".jpg";

            File.WriteAllBytes(fileName, b1.ToArray());
            Console.Out.WriteLine("Writing to " + fileName);
            CoreLogger.Log("Writing to " + fileName);
            return(fileSavedSuccessfully);
        }//end write JPEG
Esempio n. 21
0
        }//constructor

        public string fixOneGuidCorner(int raida_ID, CloudCoin cc, int corner, int[] trustedTriad, int millisecondsToTimeout)
        {
            CoinUtils cu = new CoinUtils(cc);

            /*1. WILL THE BROKEN RAIDA FIX? check to see if it has problems echo, detect, or fix. */
            if (RAIDA_Status.failsFix[raida_ID] || RAIDA_Status.failsEcho[raida_ID] || RAIDA_Status.failsEcho[raida_ID])
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("");
                Console.Out.WriteLine("  RAIDA Fails Echo or Fix. Try again when RAIDA online.");
                CoreLogger.Log("  RAIDA Fails Echo or Fix. Try again when RAIDA online.");
                Console.Out.WriteLine("");
                Console.ForegroundColor = ConsoleColor.White;
                return("RAIDA Fails Echo or Fix. Try again when RAIDA online.");
            }
            else
            {
                /*2. ARE ALL TRUSTED RAIDA IN THE CORNER READY TO HELP?*/
                Console.WriteLine("Pown is " + cc.pown);
                char[] pown_chars = cc.pown.ToCharArray();


                //See if First Trusted RAIDA can help
                if (!pown_chars[trustedTriad[0]].Equals('p'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("  RAIDA " + trustedTriad[0] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("  RAIDA " + trustedTriad[0] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("");
                    Console.ForegroundColor = ConsoleColor.White;
                    return("RAIDA " + trustedTriad[0] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                }
                //See if Second Trusted RAIDA can help
                if (!pown_chars[trustedTriad[1]].Equals('p'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("  RAIDA " + trustedTriad[1] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("  RAIDA " + trustedTriad[1] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("");
                    Console.ForegroundColor = ConsoleColor.White;
                    return("RAIDA " + trustedTriad[1] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                }

                //See if Third Trusted RAIDA can help
                if (!pown_chars[trustedTriad[2]].Equals('p'))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("");
                    Console.Out.WriteLine("  RAIDA " + trustedTriad[2] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("  RAIDA " + trustedTriad[2] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                    CoreLogger.Log("");
                    Console.ForegroundColor = ConsoleColor.White;
                    return("RAIDA " + trustedTriad[2] + " can't help RAIDA " + raida_ID + " fix corner  " + corner);
                }

                if (!RAIDA_Status.failsEcho[trustedTriad[0]] || !RAIDA_Status.failsDetect[trustedTriad[0]] || !RAIDA_Status.failsEcho[trustedTriad[1]] || !RAIDA_Status.failsDetect[trustedTriad[1]] || !RAIDA_Status.failsEcho[trustedTriad[2]] || !RAIDA_Status.failsDetect[trustedTriad[2]])
                {
                    /*3. GET TICKETS AND UPDATE RAIDA STATUS TICKETS*/
                    string[] ans = { cc.an[trustedTriad[0]], cc.an[trustedTriad[1]], cc.an[trustedTriad[2]] };
                    raida.get_Tickets(trustedTriad, ans, cc.nn, cc.sn, cu.getDenomination(), 3000);


                    //Check to see if the coin actully is counterfeits and all the so called "p"s are actually "f"s.
                    if (raida.responseArray[trustedTriad[0]].fullResponse.Contains("fail") &&
                        raida.responseArray[trustedTriad[1]].fullResponse.Contains("fail") &&
                        raida.responseArray[trustedTriad[2]].fullResponse.Contains("fail")
                        )
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("The coin is actually counterfeit. RAIDA marked 'passed' turned out to be fails.");
                        Console.Out.WriteLine("");
                        Console.ForegroundColor = ConsoleColor.White;
                        return("counterfeit " + corner);
                    }//end if p's are actully fs.

                    /*4. ARE ALL TICKETS GOOD?*/
                    if (RAIDA_Status.hasTicket[trustedTriad[0]] && RAIDA_Status.hasTicket[trustedTriad[1]] && RAIDA_Status.hasTicket[trustedTriad[2]])
                    {
                        /*5.T YES, so REQUEST FIX*/
                        DetectionAgent da          = new DetectionAgent(raida_ID);
                        Response       fixResponse = da.fix(trustedTriad, RAIDA_Status.tickets[trustedTriad[0]], RAIDA_Status.tickets[trustedTriad[1]], RAIDA_Status.tickets[trustedTriad[2]], cc.an[raida_ID]).Result;
                        /*6. DID THE FIX WORK?*/
                        if (fixResponse.success)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Out.WriteLine("");
                            Console.Out.WriteLine("  RAIDA" + raida_ID + " unfracked successfully.");
                            CoreLogger.Log("  RAIDA" + raida_ID + " unfracked successfully.");
                            Console.Out.WriteLine("");
                            Console.ForegroundColor = ConsoleColor.White;
                            return("RAIDA" + raida_ID + " unfracked successfully.");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Out.WriteLine("");
                            Console.Out.WriteLine("  RAIDA " + raida_ID + " failed to accept tickets on corner " + corner);
                            CoreLogger.Log("  RAIDA failed to accept tickets on corner " + corner);
                            Console.Out.WriteLine("");
                            Console.ForegroundColor = ConsoleColor.White;
                            return("RAIDA failed to accept tickets on corner " + corner);
                        }//end if fix respons was success or fail
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("");
                        Console.Out.WriteLine("  Trusted servers failed to provide tickets for corner " + corner);
                        Console.Out.WriteLine("RAIDa" + trustedTriad[0] + " " + RAIDA_Status.tickets[trustedTriad[0]] + ", RAIDa" + trustedTriad[1] + " " + RAIDA_Status.tickets[trustedTriad[1]] + ", RAIDa" + trustedTriad[2] + " " + RAIDA_Status.tickets[trustedTriad[2]]);
                        CoreLogger.Log("  Trusted servers failed to provide tickets for corner " + corner);
                        Console.Out.WriteLine("");
                        Console.ForegroundColor = ConsoleColor.White;

                        return("  Trusted servers failed to provide tickets for corner " + corner);//no three good tickets
                    }//end if all good
                }//end if trused triad will echo and detect (Detect is used to get ticket)

                Console.ForegroundColor = ConsoleColor.Red;
                Console.Out.WriteLine("");
                Console.Out.WriteLine("  One or more of the trusted triad will not echo and detect.So not trying.");
                CoreLogger.Log("  One or more of the trusted triad will not echo and detect.So not trying.");
                Console.Out.WriteLine("");
                Console.ForegroundColor = ConsoleColor.White;
                return("  One or more of the trusted triad will not echo and detect. So not trying.");
            } //end if RAIDA fails to fix.
        }     //end fix one
Esempio n. 22
0
		}//end detectOneMulti

		public CoinUtils[] detectMultiCoin(CoinUtils[] cu, int milliSecondsToTimeOut)
		{
            //Make arrays to stripe the coins
            milliSecondsToTimeOut = 60000;
			responseArrayMulti = new Response[25, cu.Length];

			int[] nns = new int[cu.Length];
			int[] sns = new int[cu.Length];
			String[] ans_0 = new String[cu.Length];
			String[] ans_1 = new String[cu.Length];
			String[] ans_2 = new String[cu.Length];
			String[] ans_3 = new String[cu.Length];
			String[] ans_4 = new String[cu.Length];
			String[] ans_5 = new String[cu.Length];
			String[] ans_6 = new String[cu.Length];
			String[] ans_7 = new String[cu.Length];
			String[] ans_8 = new String[cu.Length];
			String[] ans_9 = new String[cu.Length];
			String[] ans_10 = new String[cu.Length];
			String[] ans_11 = new String[cu.Length];
			String[] ans_12 = new String[cu.Length];
			String[] ans_13 = new String[cu.Length];
			String[] ans_14 = new String[cu.Length];
			String[] ans_15 = new String[cu.Length];
			String[] ans_16 = new String[cu.Length];
			String[] ans_17 = new String[cu.Length];
			String[] ans_18 = new String[cu.Length];
			String[] ans_19 = new String[cu.Length];
			String[] ans_20 = new String[cu.Length];
			String[] ans_21 = new String[cu.Length];
			String[] ans_22 = new String[cu.Length];
			String[] ans_23 = new String[cu.Length];
			String[] ans_24 = new String[cu.Length];
			String[] pans_0 = new String[cu.Length];
			String[] pans_1 = new String[cu.Length];
			String[] pans_2 = new String[cu.Length];
			String[] pans_3 = new String[cu.Length];
			String[] pans_4 = new String[cu.Length];
			String[] pans_5 = new String[cu.Length];
			String[] pans_6 = new String[cu.Length];
			String[] pans_7 = new String[cu.Length];
			String[] pans_8 = new String[cu.Length];
			String[] pans_9 = new String[cu.Length];
			String[] pans_10 = new String[cu.Length];
			String[] pans_11 = new String[cu.Length];
			String[] pans_12 = new String[cu.Length];
			String[] pans_13 = new String[cu.Length];
			String[] pans_14 = new String[cu.Length];
			String[] pans_15 = new String[cu.Length];
			String[] pans_16 = new String[cu.Length];
			String[] pans_17 = new String[cu.Length];
			String[] pans_18 = new String[cu.Length];
			String[] pans_19 = new String[cu.Length];
			String[] pans_20 = new String[cu.Length];
			String[] pans_21 = new String[cu.Length];
			String[] pans_22 = new String[cu.Length];
			String[] pans_23 = new String[cu.Length];
			String[] pans_24 = new String[cu.Length];

			int[] dens = new int[cu.Length];//Denominations
											//Stripe the coins

			for (int i = 0; i < cu.Length; i++)//For every coin
			{
				cu[i].generatePan();
				nns[i] = cu[i].cc.nn;
				sns[i] = cu[i].cc.sn;
				ans_0[i] = cu[i].cc.an[0];
				ans_1[i] = cu[i].cc.an[1];
				ans_2[i] = cu[i].cc.an[2];
				ans_3[i] = cu[i].cc.an[3];
				ans_4[i] = cu[i].cc.an[4];
				ans_5[i] = cu[i].cc.an[5];
				ans_6[i] = cu[i].cc.an[6];
				ans_7[i] = cu[i].cc.an[7];
				ans_8[i] = cu[i].cc.an[8];
				ans_9[i] = cu[i].cc.an[9];
				ans_10[i] = cu[i].cc.an[10];
				ans_11[i] = cu[i].cc.an[11];
				ans_12[i] = cu[i].cc.an[12];
				ans_13[i] = cu[i].cc.an[13];
				ans_14[i] = cu[i].cc.an[14];
				ans_15[i] = cu[i].cc.an[15];
				ans_16[i] = cu[i].cc.an[16];
				ans_17[i] = cu[i].cc.an[17];
				ans_18[i] = cu[i].cc.an[18];
				ans_19[i] = cu[i].cc.an[19];
				ans_20[i] = cu[i].cc.an[20];
				ans_21[i] = cu[i].cc.an[21];
				ans_22[i] = cu[i].cc.an[22];
				ans_23[i] = cu[i].cc.an[23];
				ans_24[i] = cu[i].cc.an[24];

				pans_0[i] = cu[i].pans[0];
				pans_1[i] = cu[i].pans[1];
				pans_2[i] = cu[i].pans[2];
				pans_3[i] = cu[i].pans[3];
				pans_4[i] = cu[i].pans[4];
				pans_5[i] = cu[i].pans[5];
				pans_6[i] = cu[i].pans[6];
				pans_7[i] = cu[i].pans[7];
				pans_8[i] = cu[i].pans[8];
				pans_9[i] = cu[i].pans[9];
				pans_10[i] = cu[i].pans[10];
				pans_11[i] = cu[i].pans[11];
				pans_12[i] = cu[i].pans[12];
				pans_13[i] = cu[i].pans[13];
				pans_14[i] = cu[i].pans[14];
				pans_15[i] = cu[i].pans[15];
				pans_16[i] = cu[i].pans[16];
				pans_17[i] = cu[i].pans[17];
				pans_18[i] = cu[i].pans[18];
				pans_19[i] = cu[i].pans[19];
				pans_20[i] = cu[i].pans[20];
				pans_21[i] = cu[i].pans[21];
				pans_22[i] = cu[i].pans[22];
				pans_23[i] = cu[i].pans[23];
				pans_24[i] = cu[i].pans[24];

				dens[i] = cu[i].getDenomination();
			}//end for every coin put in an array

			var t00 = detectOneMulti(00, nns, sns, ans_0, pans_0, dens, milliSecondsToTimeOut);
			var t01 = detectOneMulti(01, nns, sns, ans_1, pans_1, dens, milliSecondsToTimeOut);
			var t02 = detectOneMulti(02, nns, sns, ans_2, pans_2, dens, milliSecondsToTimeOut);
			var t03 = detectOneMulti(03, nns, sns, ans_3, pans_3, dens, milliSecondsToTimeOut);
			var t04 = detectOneMulti(04, nns, sns, ans_4, pans_4, dens, milliSecondsToTimeOut);
			var t05 = detectOneMulti(05, nns, sns, ans_5, pans_5, dens, milliSecondsToTimeOut);
			var t06 = detectOneMulti(06, nns, sns, ans_6, pans_6, dens, milliSecondsToTimeOut);
			var t07 = detectOneMulti(07, nns, sns, ans_7, pans_7, dens, milliSecondsToTimeOut);
			var t08 = detectOneMulti(08, nns, sns, ans_8, pans_8, dens, milliSecondsToTimeOut);
			var t09 = detectOneMulti(09, nns, sns, ans_9, pans_9, dens, milliSecondsToTimeOut);
			var t10 = detectOneMulti(10, nns, sns, ans_10, pans_10, dens, milliSecondsToTimeOut);
			var t11 = detectOneMulti(11, nns, sns, ans_11, pans_11, dens, milliSecondsToTimeOut);
			var t12 = detectOneMulti(12, nns, sns, ans_12, pans_12, dens, milliSecondsToTimeOut);
			var t13 = detectOneMulti(13, nns, sns, ans_13, pans_13, dens, milliSecondsToTimeOut);
			var t14 = detectOneMulti(14, nns, sns, ans_14, pans_14, dens, milliSecondsToTimeOut);
			var t15 = detectOneMulti(15, nns, sns, ans_15, pans_15, dens, milliSecondsToTimeOut);
			var t16 = detectOneMulti(16, nns, sns, ans_16, pans_16, dens, milliSecondsToTimeOut);
			var t17 = detectOneMulti(17, nns, sns, ans_17, pans_17, dens, milliSecondsToTimeOut);
			var t18 = detectOneMulti(18, nns, sns, ans_18, pans_18, dens, milliSecondsToTimeOut);
			var t19 = detectOneMulti(19, nns, sns, ans_19, pans_19, dens, milliSecondsToTimeOut);
			var t20 = detectOneMulti(20, nns, sns, ans_20, pans_20, dens, milliSecondsToTimeOut);
			var t21 = detectOneMulti(21, nns, sns, ans_21, pans_21, dens, milliSecondsToTimeOut);
			var t22 = detectOneMulti(22, nns, sns, ans_22, pans_22, dens, milliSecondsToTimeOut);
			var t23 = detectOneMulti(23, nns, sns, ans_23, pans_23, dens, milliSecondsToTimeOut);
			var t24 = detectOneMulti(24, nns, sns, ans_24, pans_24, dens, milliSecondsToTimeOut);


			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 < nns.Length; i++)
			{
				for (int j = 0; j < 25; j++)
				{//For each coin
					if (responseArrayMulti[j, i] != null)
					{
						cu[i].setPastStatus(responseArrayMulti[j, i].outcome, j);
                        Console.WriteLine(cu[i].cc.sn + " detect:" + j + " " + responseArrayMulti[j, i].fullResponse);
						CoreLogger.Log(cu[i].cc.sn + " detect:" + j + " " + responseArrayMulti[j, i].fullResponse);
					}
					else
					{
						cu[i].setPastStatus("undetected", j);
					};// should be pass, fail, error or undetected, or No response. 
				}//end for each coin checked

				cu[i].setAnsToPansIfPassed();
				cu[i].calculateHP();
				cu[i].calcExpirationDate();
				cu[i].grade();
			}//end for each detection agent

			return cu;//Return the array of coins detected
		}//end detect coin
        }// end Detect constructor

        /*  PUBLIC METHODS */
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public int[] detectAll()
        {
            // LOAD THE .suspect COINS ONE AT A TIME AND TEST THEM
            int[]     results                   = new int[4];                                                                                        // [0] Coins to bank, [1] Coins to fracked [2] Coins to Counterfeit
            String[]  suspectFileNames          = new DirectoryInfo(this.fileUtils.suspectFolder).GetFiles("*.stack").Select(o => o.Name).ToArray(); //Get all files in suspect folder
            int       totalValueToBank          = 0;
            int       totalValueToCounterfeit   = 0;
            int       totalValueToFractured     = 0;
            int       totalValueToKeptInSuspect = 0;
            bool      coinSupect                = false;
            CloudCoin newCC;

            for (int j = 0; j < suspectFileNames.Length; j++)
            {
                try
                {
                    if (File.Exists(this.fileUtils.bankFolder + suspectFileNames[j]))
                    {//Coin has already been imported. Delete it from import folder move to trash.
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("You tried to import a coin that has already been imported.");
                        CoreLogger.Log("You tried to import a coin that has already been imported.");
                        File.Move(this.fileUtils.suspectFolder + suspectFileNames[j], this.fileUtils.trashFolder + suspectFileNames[j]);
                        Console.Out.WriteLine("Suspect CloudCoin was moved to Trash folder.");
                        CoreLogger.Log("Suspect CloudCoin was moved to Trash folder.");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        newCC = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.suspectFolder + suspectFileNames[j]);
                        CoinUtils cu = new CoinUtils(newCC);
                        Console.Out.WriteLine("Now scanning coin " + (j + 1) + " of " + suspectFileNames.Length + " for counterfeit. SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination());
                        CoreLogger.Log("Now scanning coin " + (j + 1) + " of " + suspectFileNames.Length + " for counterfeit. SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination());
                        Console.Out.WriteLine("");

                        CoinUtils detectedCC = this.raida.detectCoin(cu, detectTime);
                        cu.calcExpirationDate();

                        if (j == 0)                      //If we are detecting the first coin, note if the RAIDA are working
                        {
                            for (int i = 0; i < 25; i++) // Checks any servers are down so we don't try to check them again.
                            {
                                if (cu.getPastStatus(i) != "pass" && cu.getPastStatus(i) != "fail")
                                {
                                    raida.raidaIsDetecting[i] = false;//Server is not working correctly, don't try it agian
                                }
                            }
                        }//end if it is the first coin we are detecting

                        cu.consoleReport();

                        bool alreadyExists = false;//Does the file already been imported?
                        switch (cu.getFolder().ToLower())
                        {
                        case "bank":
                            totalValueToBank++;
                            alreadyExists = this.fileUtils.writeTo(this.fileUtils.bankFolder, detectedCC.cc);
                            break;

                        case "fracked":
                            totalValueToFractured++;
                            alreadyExists = this.fileUtils.writeTo(this.fileUtils.frackedFolder, detectedCC.cc);
                            break;

                        case "counterfeit":
                            totalValueToCounterfeit++;
                            alreadyExists = this.fileUtils.writeTo(this.fileUtils.counterfeitFolder, detectedCC.cc);
                            break;

                        case "suspect":
                            totalValueToKeptInSuspect++;
                            coinSupect = true;    //Coin will remain in suspect folder
                            break;
                        }//end switch



                        // end switch on the place the coin will go
                        if (!coinSupect)                                                     //Leave coin in the suspect folder if RAIDA is down
                        {
                            File.Delete(this.fileUtils.suspectFolder + suspectFileNames[j]); //Take the coin out of the suspect folder
                        }
                        else
                        {
                            this.fileUtils.writeTo(this.fileUtils.suspectFolder, detectedCC.cc);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Out.WriteLine("Not enough RAIDA were contacted to determine if the coin is authentic.");
                            Console.Out.WriteLine("Try again later.");
                            CoreLogger.Log("Not enough RAIDA were contacted to determine if the coin is authentic. Try again later.");
                            Console.ForegroundColor = ConsoleColor.White;
                        } //end if else
                    }     //end if file exists
                }
                catch (FileNotFoundException ex)
                {
                    Console.Out.WriteLine(ex);
                    CoreLogger.Log(ex.ToString());
                }
                catch (IOException ioex)
                {
                    Console.Out.WriteLine(ioex);
                    CoreLogger.Log(ioex.ToString());
                } // end try catch
            }     // end for each coin to import
            results[0] = totalValueToBank;
            results[1] = totalValueToCounterfeit;
            results[2] = totalValueToFractured;
            results[3] = totalValueToKeptInSuspect;
            return(results);
        }//Detect All
Esempio n. 24
0
        }// 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
Esempio n. 25
0
        }         // End Import All

        /* PRIVATE METHODS */

        /* IMPORT ONE FILE. COULD BE A JPEG, STACK or CHEST */
        private bool importOneFile(String fname)
        {
            String extension = "";
            int    indx      = fname.LastIndexOf('.');//Get file extension

            if (indx > 0)
            {
                extension = fname.Substring(indx + 1);
            }

            extension = extension.ToLower();
            if (extension == "jpeg" || extension == "jpg")//Run if file is a jpeg
            {
                if (!this.importJPEG(fname))
                {
                    if (!File.Exists(this.fileUtils.trashFolder + fname))
                    {
                        File.Move(this.fileUtils.importFolder + fname, this.fileUtils.trashFolder + fname);
                        Console.Out.WriteLine("File moved to trash: " + fname);
                        CoreLogger.Log("File moved to trash: " + fname);
                    }
                    else
                    {
                        File.Delete(this.fileUtils.importedFolder + fname);
                        File.Move(this.fileUtils.importFolder + fname, this.fileUtils.importedFolder + fname);
                    }

                    return(false);//"Failed to load JPEG file");
                }//end if import fails
            }//end if jpeg

            /*
             * else if (extension == "chest" || extension == ".chest")//Run if file is a jpeg
             * {
             *  if (!this.importChest(fname))
             *  {
             *      if (!File.Exists(this.fileUtils.trashFolder + fname))
             *      {
             *          File.Move(this.fileUtils.importFolder + fname, this.fileUtils.trashFolder + fname);
             *          Console.Out.WriteLine("File moved to trash: " +  fname);
             *      }
             *      return false;//"Failed to load JPEG file");
             *  }//end if import fails
             * }//end if jpeg
             */
            else if (!this.importStack(fname))// run if file is a stack
            {
                if (!File.Exists(this.fileUtils.trashFolder + fname))
                {
                    File.Move(this.fileUtils.importFolder + fname, this.fileUtils.trashFolder + fname);
                    Console.Out.WriteLine("File moved to trash: " + fname);
                    CoreLogger.Log("File moved to trash: " + fname);
                }
                return(false);//"Failed to load .stack file");
            }

            if (!File.Exists(this.fileUtils.importedFolder + fname))
            {
                File.Move(this.fileUtils.importFolder + fname, this.fileUtils.importedFolder + fname);
            }
            else
            {
                File.Delete(this.fileUtils.importedFolder + fname);
                File.Move(this.fileUtils.importFolder + fname, this.fileUtils.importedFolder + fname);
            }

            //End if the file is there
            return(true);
        }//End importOneFile
        }// end Detect constructor

        /*  PUBLIC METHODS */
        public int[] gradeAll(int msToFixDangerousFracked, int msToRedetectDangerous)
        {
            String[]  detectedFileNames         = new DirectoryInfo(this.fileUtils.detectedFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder
            int       totalValueToBank          = 0;
            int       totalValueToCounterfeit   = 0;
            int       totalValueToFractured     = 0;
            int       totalValueToKeptInSuspect = 0;
            int       totalValueToLost          = 0;
            CloudCoin newCC;



            for (int j = 0; j < detectedFileNames.Length; j++)//for every coins in the detected folder
            {
                try
                {
                    if (File.Exists(this.fileUtils.bankFolder + detectedFileNames[j]) || File.Exists(this.fileUtils.frackedFolder + detectedFileNames[j]))
                    {//Coin has already been imported. Delete it from import folder move to trash.
                        //THIS SHOULD NOT HAPPEN - THE COIN SHOULD HAVE BEEN CHECKED DURING IMPORT BEFORE DETECTION TO SEE IF IT WAS IN THE BANK FOLDER
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Out.WriteLine("You tried to import a coin that has already been imported.");
                        CoreLogger.Log("You tried to import a coin that has already been imported.");
                        updateLog("You tried to import a coin that has already been imported.");
                        if (File.Exists(this.fileUtils.trashFolder + detectedFileNames[j]))
                        {
                            File.Delete(this.fileUtils.trashFolder + detectedFileNames[j]);
                        }
                        File.Move(this.fileUtils.detectedFolder + detectedFileNames[j], this.fileUtils.trashFolder + detectedFileNames[j]);
                        Console.Out.WriteLine("Suspect CloudCoin was moved to Trash folder.");
                        CoreLogger.Log("Suspect CloudCoin was moved to Trash folder.");
                        updateLog("Suspect CloudCoin was moved to Trash folder.");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        newCC = this.fileUtils.loadOneCloudCoinFromJsonFile(this.fileUtils.detectedFolder + detectedFileNames[j]);
                        CoinUtils cu = new CoinUtils(newCC);

                        //CoinUtils detectedCC = cu;
                        //cu.sortToFolder();//Tells the Coin Utils to set what folder the coins should go to.
                        cu.consoleReport();


                        //Suspect, Counterfeit, Fracked, Bank, Trash, Detected, Lost, Dangerous
                        switch (cu.getFolder().ToLower())
                        {
                        case "bank":
                            totalValueToBank++;
                            fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc);
                            break;

                        case "fracked":
                            totalValueToFractured++;
                            fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc);
                            break;

                        case "counterfeit":
                            totalValueToCounterfeit++;
                            fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc);
                            break;

                        case "lost":
                            totalValueToLost++;
                            fileUtils.writeTo(this.fileUtils.lostFolder, cu.cc);
                            break;

                        case "suspect":
                            totalValueToKeptInSuspect++;
                            fileUtils.writeTo(this.fileUtils.suspectFolder, cu.cc);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Out.WriteLine("  Not enough RAIDA were contacted to determine if the coin is authentic.");
                            Console.Out.WriteLine("  Try again later.");
                            CoreLogger.Log("  Not enough RAIDA were contacted to determine if the coin is authentic. Try again later.");
                            Console.ForegroundColor = ConsoleColor.White;
                            break;

                        case "dangerous":
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("   WARNING: Strings may be attached to this coins");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.Out.WriteLine("  Now fixing fracked for " + (j + 1) + " of " + detectedFileNames.Length + " . SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination());
                            CoreLogger.Log("  Now fixing fracked for " + (j + 1) + " of " + detectedFileNames.Length + " . SN " + string.Format("{0:n0}", newCC.sn) + ", Denomination: " + cu.getDenomination());
                            updateLog("Some of your CloudCoins are still being processed. This should take just a moment.");
                            Frack_Fixer ff = new Frack_Fixer(fileUtils, msToFixDangerousFracked);
                            ff.txtLogs = txtLogs;
                            RAIDA raida = new RAIDA();
                            Console.WriteLine("folder is " + cu.getFolder().ToLower());
                            while (cu.getFolder().ToLower() == "dangerous")
                            {    // keep fracking fixing until all fixed or no more improvments possible.
                                Console.WriteLine("   calling fix Coin");
                                cu = ff.fixCoin(cu.cc, msToFixDangerousFracked).Result;
                                Console.WriteLine("   sorting after fixing");
                                cu.sortFoldersAfterFixingDangerous();
                            }    //while folder still dangerous

                            for (int i = 0; i < 25; i++)
                            {
                                cu.pans[i] = cu.generatePan();
                            }                                                 // end for each pan
                            cu = raida.detectCoin(cu, msToRedetectDangerous); //Detect again to make sure it is powned
                            cu.consoleReport();
                            cu.sortToFolder();                                //Tells the Coin Utils to set what folder the coins should go to.
                            switch (cu.getFolder().ToLower())
                            {
                            case "bank":
                                totalValueToBank++;
                                fileUtils.writeTo(this.fileUtils.bankFolder, cu.cc);
                                break;

                            case "fracked":
                                totalValueToFractured++;
                                fileUtils.writeTo(this.fileUtils.frackedFolder, cu.cc);
                                break;

                            default:
                                totalValueToCounterfeit++;
                                fileUtils.writeTo(this.fileUtils.counterfeitFolder, cu.cc);
                                break;
                            }    //end switch

                            break;
                        }//end switch

                        File.Delete(this.fileUtils.detectedFolder + detectedFileNames[j]);//Take the coin out of the detected folder
                    }//end if file exists
                }
                catch (FileNotFoundException ex)
                {
                    Console.Out.WriteLine(ex);
                    CoreLogger.Log(ex.ToString());
                }
                catch (IOException ioex)
                {
                    Console.Out.WriteLine(ioex);
                    CoreLogger.Log(ioex.ToString());
                } // end try catch
            }     // end for each coin to import

            results[0] = totalValueToBank;
            results[1] = totalValueToFractured;
            results[2] = totalValueToCounterfeit;
            results[3] = totalValueToKeptInSuspect;
            results[4] = totalValueToLost;
            return(results);
        }//Detect All
Esempio n. 27
0
        }//end detect coin

        public CoinUtils partialDetectCoin(CoinUtils cu, int milliSecondsToTimeOut)
        {
            cu.generatePan();
            int[] echoes = (int[])RAIDA_Status.echoTime.Clone();
            int[] raidas = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
            Array.Sort(echoes, raidas);
            Console.WriteLine("fastest raida: " + raidas[0] + "," + raidas[1] + "," + raidas[2] + "," + raidas[3] + "," + raidas[4] + "," + raidas[5] + "," + raidas[6] + "," + raidas[7] + "," + raidas[8] + "," + raidas[9] + "," + raidas[10] + "," + raidas[11] + "," + raidas[12] + "," + raidas[13] + "," + raidas[14] + "," + raidas[15]);
            var t00 = detectOne(raidas[00], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[00]], cu.pans[raidas[00]], cu.getDenomination());
            var t01 = detectOne(raidas[01], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[01]], cu.pans[raidas[01]], cu.getDenomination());
            var t02 = detectOne(raidas[02], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[02]], cu.pans[raidas[02]], cu.getDenomination());
            var t03 = detectOne(raidas[03], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[03]], cu.pans[raidas[03]], cu.getDenomination());
            var t04 = detectOne(raidas[04], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[04]], cu.pans[raidas[04]], cu.getDenomination());
            var t05 = detectOne(raidas[05], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[05]], cu.pans[raidas[05]], cu.getDenomination());
            var t06 = detectOne(raidas[06], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[06]], cu.pans[raidas[06]], cu.getDenomination());
            var t07 = detectOne(raidas[07], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[07]], cu.pans[raidas[07]], cu.getDenomination());
            var t08 = detectOne(raidas[08], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[08]], cu.pans[raidas[08]], cu.getDenomination());
            var t09 = detectOne(raidas[09], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[09]], cu.pans[raidas[09]], cu.getDenomination());
            var t10 = detectOne(raidas[10], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[10]], cu.pans[raidas[10]], cu.getDenomination());
            var t11 = detectOne(raidas[11], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[11]], cu.pans[raidas[11]], cu.getDenomination());
            var t12 = detectOne(raidas[12], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[12]], cu.pans[raidas[12]], cu.getDenomination());
            var t13 = detectOne(raidas[13], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[13]], cu.pans[raidas[13]], cu.getDenomination());
            var t14 = detectOne(raidas[14], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[14]], cu.pans[raidas[14]], cu.getDenomination());
            var t15 = detectOne(raidas[15], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[15]], cu.pans[raidas[15]], cu.getDenomination());
            //var t16 = Task.Run(() => detectOne(raidas[16], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[16]], cu.pans[raidas[16]], cu.getDenomination()));



            var taskList = new List <Task> {
                t00, t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15
            };

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

            //nt k = 0;
            //for(int j =0; j<16;j++)
            //{
            //    if(responseArray[raidas[j]] != null && responseArray[raidas[j]].outcome == "error" && k < 9)
            //    {
            //        detectOne(raidas[16+k], cu.cc.nn, cu.cc.sn, cu.cc.an[raidas[16+k]], cu.pans[raidas[16+k]], cu.getDenomination());
            //       k++;
            //   }
            //}

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

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

            return(cu);
        }//end detect coin
Esempio n. 28
0
        /* IMPORT ONE STACK FILE */
        private bool importStack(String fileName)
        {
            bool isSuccessful = false;

            //  System.out.println("Trying to load: " + importFolder + fileName );
            try
            {
                String incomeJson = fileUtils.importJSON(this.fileUtils.importFolder + fileName);//Load file as JSON .stack or .chest
                Stack  tempCoins  = null;
                if (seemsValidJSON(incomeJson))
                {
                    try
                    {
                        tempCoins = this.fileUtils.loadManyCloudCoinFromJsonFile(this.fileUtils.importFolder + fileName, incomeJson);
                    }
                    catch (JsonReaderException e) {
                        //Console.WriteLine("Moving corrupted file to trash: " + fileName);
                        Console.WriteLine("Error reading " + fileName + ". Moving to trash.");
                        CoreLogger.Log("Error reading " + fileName + ". Moving to trash.");
                        Console.WriteLine(e);
                        CoreLogger.Log(e.ToString());
                        moveFile(this.fileUtils.importFolder + fileName, this.fileUtils.trashFolder + fileName);
                    }//end catch json error
                }
                else
                {
                    //Console.WriteLine("Moving corrupted file to trash: " + fileName);
                    moveFile(this.fileUtils.importFolder + fileName, this.fileUtils.trashFolder + fileName);
                }

                if (tempCoins == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Out.WriteLine("  The following file does not appear to be valid JSON. It will be moved to the Trash Folder: ");
                    Console.Out.WriteLine(fileName);
                    CoreLogger.Log("  The following file does not appear to be valid JSON. It will be moved to the Trash Folder: " + fileName);
                    Console.Out.WriteLine("  Paste the text into http://jsonlint.com/ to check for validity.");
                    Console.ForegroundColor = ConsoleColor.White;
                    return(false);//CloudCoin was null so move to trash
                }
                else
                {
                    for (int i = 0; i < tempCoins.cc.Length; i++)
                    {
                        this.fileUtils.writeTo(this.fileUtils.suspectFolder, tempCoins.cc[i]);
                    } //end for each temp Coin
                    return(true);
                }     //end if no coins.
            }
            catch (FileNotFoundException ex)
            {
                Console.Out.WriteLine("File not found: " + fileName + ex);
                CoreLogger.Log("File not found: " + fileName + ex);
            }
            catch (IOException ioex)
            {
                Console.Out.WriteLine("IO Exception:" + fileName + ioex);
                CoreLogger.Log("IO Exception:" + fileName + ioex);
            }

            // end try catch
            return(isSuccessful);
        }//import stack
        }         //end write all jpegs

        /* Write JSON to .stack File  */
        public bool writeJSONFile(int m1, int m5, int m25, int m100, int m250, String tag)
        {
            bool jsonExported = true;
            int  totalSaved   = m1 + (m5 * 5) + (m25 * 25) + (m100 * 100) + (m250 * 250);
            // Track the total coins
            int coinCount = m1 + m5 + m25 + m100 + m250;

            String[] coinsToDelete    = new String[coinCount];
            String[] bankedFileNames  = new DirectoryInfo(this.fileUtils.bankFolder).GetFiles().Select(o => o.Name).ToArray();//Get all names in bank folder
            String[] frackedFileNames = new DirectoryInfo(this.fileUtils.frackedFolder).GetFiles().Select(o => o.Name).ToArray();;
            String[] partialFileNames = new DirectoryInfo(this.fileUtils.partialFolder).GetFiles().Select(o => o.Name).ToArray();
            // Add the two arrays together
            var list = new List <String>();

            list.AddRange(bankedFileNames);
            list.AddRange(frackedFileNames);
            list.AddRange(partialFileNames);

            // Program will spend fracked files like perfect files
            bankedFileNames = list.ToArray();


            // Check to see the denomination by looking at the file start
            int c = 0;
            // c= counter
            String json = "{" + Environment.NewLine;

            json = json + "\t\"cloudcoin\": " + Environment.NewLine;
            json = json + "\t[" + Environment.NewLine;
            String bankFileName;
            String frackedFileName;
            String partialFileName;
            string denomination;

            // Put all the JSON together and add header and footer
            for (int i = 0; (i < bankedFileNames.Length); i++)
            {
                denomination    = bankedFileNames[i].Split('.')[0];
                bankFileName    = this.fileUtils.bankFolder + bankedFileNames[i];    //File name in bank folder
                frackedFileName = this.fileUtils.frackedFolder + bankedFileNames[i]; //File name in fracked folder
                partialFileName = this.fileUtils.partialFolder + bankedFileNames[i];
                if (denomination == "1" && m1 > 0)
                {
                    if (c != 0)//This is the json seperator between each coin. It is not needed on the first coin
                    {
                        json += ",\n";
                    }

                    if (File.Exists(bankFileName)) // Is it a bank file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid    = null;
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = frackedFileName;
                        c++;
                    }

                    m1--;
                    // Get the clean JSON of the coin
                }// end if coin is a 1

                if (denomination == "5" && m5 > 0)
                {
                    if ((c != 0))
                    {
                        json += ",\n";
                    }

                    if (File.Exists(bankFileName))
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid    = null;
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = frackedFileName;
                        c++;
                    }

                    m5--;
                } // end if coin is a 5

                if (denomination == "25" && m25 > 0)
                {
                    if ((c != 0))
                    {
                        json += ",\n";
                    }

                    if (File.Exists(bankFileName))
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid    = null;
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = frackedFileName;
                        c++;
                    }

                    m25--;
                }// end if coin is a 25

                if (denomination == "100" && m100 > 0)
                {
                    if ((c != 0))
                    {
                        json += ",\n";
                    }

                    if (File.Exists(bankFileName))
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid    = null;
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = frackedFileName;
                        c++;
                    }

                    m100--;
                } // end if coin is a 100

                if (denomination == "250" && m250 > 0)
                {
                    if ((c != 0))
                    {
                        json += ",\n";
                    }

                    if (File.Exists(bankFileName))
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = bankFileName;
                        c++;
                    }
                    else if (File.Exists(partialFileName)) // Is it a partial file
                    {
                        CloudCoin coinNote = fileUtils.loadOneCloudCoinFromJsonFile(partialFileName);
                        coinNote.aoid    = null;//Clear all owner data
                        json             = json + fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = partialFileName;
                        c++;
                    }
                    else
                    {
                        CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
                        coinNote.aoid    = null;
                        json             = json + this.fileUtils.setJSON(coinNote);
                        coinsToDelete[c] = frackedFileName;
                        c++;
                    }

                    m250--;
                }// end if coin is a 250

                if (m1 == 0 && m5 == 0 && m25 == 0 && m100 == 0 && m250 == 0)
                {
                    break;
                } // Break if all the coins have been called for.
            }     // end for each coin needed

            /*WRITE JSON TO FILE*/
            json  = json + "\t] " + Environment.NewLine;
            json += "}";
            String filename = (this.fileUtils.exportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + ".stack");

            if (File.Exists(filename))
            {
                // tack on a random number if a file already exists with the same tag
                Random rnd     = new Random();
                int    tagrand = rnd.Next(999);
                filename = (this.fileUtils.exportFolder + Path.DirectorySeparatorChar + totalSaved + ".CloudCoins." + tag + tagrand + ".stack");
            }//end if file exists

            File.WriteAllText(filename, json);
            Console.Out.WriteLine("Writing to : ");
            CoreLogger.Log("Writing to : " + filename);
            Console.Out.WriteLine(filename);
            /*DELETE FILES THAT HAVE BEEN EXPORTED*/
            for (int cc = 0; cc < coinsToDelete.Length; cc++)
            {
                // Console.Out.WriteLine("Deleting " + coinsToDelete[cc]);
                if (coinsToDelete[cc] != null)
                {
                    File.Delete(coinsToDelete[cc]);
                }
            }//end for all coins to delete

            // end if write was good
            return(jsonExported);
        }//end write json to file
        /* PUBLIC METHODS */
        public void writeJPEGFiles(int m1, int m5, int m25, int m100, int m250, String tag)
        {
            int totalSaved = m1 + (m5 * 5) + (m25 * 25) + (m100 * 100) + (m250 * 250); // Total value of all coins
            int coinCount  = m1 + m5 + m25 + m100 + m250;                              // Total number of coins

            String[] coinsToDelete    = new String[coinCount];
            String[] bankedFileNames  = new DirectoryInfo(this.fileUtils.bankFolder).GetFiles().Select(o => o.Name).ToArray();    // list all file names with bank extension
            String[] frackedFileNames = new DirectoryInfo(this.fileUtils.frackedFolder).GetFiles().Select(o => o.Name).ToArray(); // list all file names with bank extension
            String[] partialFileNames = new DirectoryInfo(this.fileUtils.partialFolder).GetFiles().Select(o => o.Name).ToArray();

            var list = new List <string>();

            list.AddRange(bankedFileNames);
            list.AddRange(frackedFileNames);
            list.AddRange(partialFileNames);

            bankedFileNames = list.ToArray();          // Add the two arrays together

            String path = this.fileUtils.exportFolder; //the word path is shorter than other stuff

            // Look at all the money files and choose the ones that are needed.
            for (int i = 0; i < bankedFileNames.Length; i++)
            {
                String bankFileName    = (this.fileUtils.bankFolder + bankedFileNames[i]);
                String frackedFileName = (this.fileUtils.frackedFolder + bankedFileNames[i]);
                String partialFileName = (this.fileUtils.partialFolder + bankedFileNames[i]);

                // Get denominiation
                String denomination = bankedFileNames[i].Split('.')[0];
                try
                {
                    switch (denomination)
                    {
                    case "1":
                        if (m1 > 0)
                        {
                            this.jpegWriteOne(path, tag, bankFileName, frackedFileName, partialFileName); m1--;
                        }
                        break;

                    case "5":
                        if (m5 > 0)
                        {
                            this.jpegWriteOne(path, tag, bankFileName, frackedFileName, partialFileName); m5--;
                        }
                        break;

                    case "25":
                        if (m25 > 0)
                        {
                            this.jpegWriteOne(path, tag, bankFileName, frackedFileName, partialFileName); m25--;
                        }
                        break;

                    case "100":
                        if (m100 > 0)
                        {
                            this.jpegWriteOne(path, tag, bankFileName, frackedFileName, partialFileName); m100--;
                        }
                        break;

                    case "250":
                        if (m250 > 0)
                        {
                            this.jpegWriteOne(path, tag, bankFileName, frackedFileName, partialFileName); m250--;
                        }
                        break;
                    }//end switch

                    if (m1 == 0 && m5 == 0 && m25 == 0 && m100 == 0 && m250 == 0)// end if file is needed to write jpeg
                    {
                        break;// Break if all the coins have been called for.
                    }
                }
                catch (FileNotFoundException ex)
                {
                    Console.Out.WriteLine(ex);
                    CoreLogger.Log(ex.ToString());
                }
                catch (IOException ioex)
                {
                    Console.Out.WriteLine(ioex);
                    CoreLogger.Log(ioex.ToString());
                } //end catch
            }     // for each 1 note
        }         //end write all jpegs