}//end get ticket

        public async Task DetectCoin(CloudCoin coin, int milliSecondsToTimeOut)
        {
            //Task.WaitAll(coin.detectTaskList.ToArray(),Config.milliSecondsToTimeOut);
            //Get data from the detection agents
            //Task.WaitAll(coin.detectTaskList.ToArray(), milliSecondsToTimeOut);
            await Task.WhenAll(coin.detectTaskList);

            for (int i = 0; i < Config.NodeCount; i++)
            {
                var resp = coin.response;
            }//end for each detection agent

            var counts = coin.response
                         .GroupBy(item => item.outcome == "pass")
                         .Select(grp => new { Number = grp.Key, Count = grp.Count() });

            var countsf = coin.response
                          .GroupBy(item => item.outcome == "fail")
                          .Select(grp => new { Number = grp.Key, Count = grp.Count() });

            Debug.WriteLine("Pass Count -" + counts.Count());
            Debug.WriteLine("Fail Count -" + countsf.Count());

            coin.SetAnsToPansIfPassed();
            coin.CalculateHP();

            coin.CalcExpirationDate();
            coin.grade();
            coin.SortToFolder();
            DetectEventArgs de = new DetectEventArgs(coin);

            OnCoinDetected(de);
        }//end detect coin
示例#2
0
        // en d json test
        public String setJSON(CloudCoin cc)
        {
            const string quote = "\"";
            const string tab   = "\t";
            String       json  = (tab + tab + "{ " + Environment.NewLine);                                       // {

            json += tab + tab + quote + "nn" + quote + ":" + quote + cc.nn + quote + ", " + Environment.NewLine; // "nn":"1",
            json += tab + tab + quote + "sn" + quote + ":" + quote + cc.sn + quote + ", " + Environment.NewLine; // "sn":"367544",
            json += tab + tab + quote + "an" + quote + ": [" + quote;                                            // "an": ["
            for (int i = 0; (i < 25); i++)
            {
                json += cc.an[i];// 8551995a45457754aaaa44
                if (i == 4 || i == 9 || i == 14 || i == 19)
                {
                    json += quote + "," + Environment.NewLine + tab + tab + tab + quote; //",
                }
                else if (i == 24)
                {
                    // json += "\""; last one do nothing
                }
                else
                { // end if is line break
                    json += quote + ", " + quote;
                }

                // end else
            }// end for 25 ans

            json += quote + "]," + Environment.NewLine;//"],
            // End of ans
            //CoinUtils cu = new CoinUtils(cc);
            //cu.calcExpirationDate();
            cc.CalcExpirationDate();
            json += tab + tab + quote + "ed" + quote + ":" + quote + cc.ed + quote + "," + Environment.NewLine; // "ed":"9-2016",
            if (string.IsNullOrEmpty(cc.pown))
            {
                cc.pown = "uuuuuuuuuuuuuuuuuuuuuuuuu";
            }                                                                                                       //Set pown to unknow if it is not set.
            json += tab + tab + quote + "pown" + quote + ":" + quote + cc.pown + quote + "," + Environment.NewLine; // "pown":"uuupppppffpppppfuuf",
            json += tab + tab + quote + "aoid" + quote + ": []" + Environment.NewLine;
            json += tab + tab + "}" + Environment.NewLine;
            // Keep expiration date when saving (not a truley accurate but good enought )
            return(json);
        }
        public override bool WriteCoinToJpeg(CloudCoin cloudCoin, string TemplateFile, string OutputFile, string tag)
        {
            OutputFile = OutputFile.Replace("\\\\", "\\");
            bool fileSavedSuccessfully = true;

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

            for (int i = 0; (i < 25); i++)
            {
                cloudCoinStr = cloudCoinStr + cloudCoin.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 Withdraw 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
            cloudCoin.CalcExpirationDate();
            cloudCoinStr += cloudCoin.edHex;                    // 01;//Expiration date Sep 2016 (one month after zero month)
            cloudCoinStr += "01";                               //  cc.nn;//network number
            String hexSN     = cloudCoin.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 (cloudCoin.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}", cloudCoin.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 = WithdrawFolder + cloudCoin.FileName + tag + ".jpg";

            File.WriteAllBytes(fileName, b1.ToArray());
            Console.Out.WriteLine("Writing to " + fileName);
            CoreLogger.Log("Writing to " + fileName);
            return(fileSavedSuccessfully);
        }