Ejemplo n.º 1
0
    }    //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
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            // Specify what is done when a file is changed, created, or deleted.
            Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
            if (e.ChangeType == WatcherChangeTypes.Created || e.ChangeType == WatcherChangeTypes.Renamed)
            {
                Console.WriteLine("\n" + Path.GetFileName(e.FullPath));
                //if (Path.GetFileName(e.FullPath).Contains("backup"))
                {
                    Console.WriteLine("caught grader action");
                    try
                    {
                        string jsonText = File.ReadAllText(e.FullPath);
                        //JObject jObject = new JObject(jsonText);

                        //                    var jo = JObject.Parse(@jsonText);
                        string account = "DefaultUser";// jo.GetValue("account").ToString();
                        //string targetPath = ""; // jo.GetValue("toPath").ToString();

                        string graderSourceLocation = FolderManager.FolderManager.BasePath + System.IO.Path.DirectorySeparatorChar + "accounts" + Path.DirectorySeparatorChar + account;
                        //Console.WriteLine("Started Watching " + graderSourceLocation);

                        string detectedPath = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_DETECTED;
                        string bankPath     = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_BANK;
                        string frackedPath  = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_FRACKED;
                        string lostPath     = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_LOST;
                        string mindPath     = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_MIND;
                        string vaultPath    = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_VAULT;
                        string galleryPath  = graderSourceLocation + Path.DirectorySeparatorChar + Config.TAG_GALLERY;

                        CloudCoin cloudCoin = FS.LoadCoin(e.FullPath);
                        if (cloudCoin != null)
                        {
                            cloudCoin.SortToFolder();
                        }

                        if (cloudCoin.folder == "Bank")
                        {
                            FS.MoveFile(e.FullPath, bankPath + Path.DirectorySeparatorChar + Path.GetFileName(e.FullPath), IFileSystem.FileMoveOptions.Replace);
                        }

                        if (cloudCoin.folder == "Fracked")
                        {
                            FS.MoveFile(e.FullPath, frackedPath + Path.DirectorySeparatorChar + Path.GetFileName(e.FullPath), IFileSystem.FileMoveOptions.Replace);
                        }

                        //  Console.WriteLine(account);
                        //File.WriteAllText(lostFileName, "");
                        //File.Delete(e.FullPath);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }