public static void WriteToJson()
 {
     WebClient myWebClient = new WebClient();
     output1 = outputFilePath + "\\Batch" + currBatch;
     reloutput1 = "\\Batch" + currBatch;
     Stream data = myWebClient.OpenRead(batchurl);
     StreamReader reader = new StreamReader(data);
     string s = reader.ReadToEnd();
     JObject jobj = JObject.Parse(s);
     RootObject ro = new RootObject();
     if ((String)jobj["next"] != null)
     {
         ro.next = (String)jobj["next"];
         ro.local_next = "\\Batch" + (currBatch + 1) + ".json";
     }
     if ((String)jobj["previous"] != null)
     {
         ro.previous = (String)jobj["previous"];
         ro.local_previous = "\\Batch" + (currBatch - 1) + ".json";
     }
     ro.batches = new List<Batch>();
     JArray parseArray = (JArray)jobj["batches"];
     foreach (JObject bobj in parseArray) //parsing only necessary fields here to avoid redundancy in data
     {
         Batch b = new Batch();
         Awardee a = new Awardee();
         JObject temp = (JObject)bobj["awardee"];
         a.name = (String)temp["name"];
         a.url = (String)temp["url"];
         b.awardee = a;
         b.ingested = (String)bobj["ingested"];
         JArray temp2 = (JArray)bobj["lccns"];
         b.lccns = temp2.Select(jv => (string)jv).ToList();
         b.name = (String)bobj["name"];
         b.page_count = (int)bobj["page_count"];
         b.url = (String)bobj["url"];
         b.local_url = reloutput1 + "." + (b.name) + ".json";
         ro.batches.Add(b);
     }
     String output = JsonConvert.SerializeObject(ro, Formatting.Indented);
     file = new System.IO.StreamWriter(outputFilePath + "\\Batch" + currBatch + ".json");
     file.WriteLine(output);
     file.Close();
     ParseJBatch(parseArray); //parsing all the information in a batch
 }
示例#2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            ShowWindow(ThisConsole, MAXIMIZE);
            Console.Title = "Battlefield 4 Player Stats and Team Manager";

            List <string> NewStats = new List <string>();

            string[]      splitted   = new string[2];
            List <String> Stats      = new List <string>();
            List <string> GuiID      = new List <string>();
            List <string> PlayerName = new List <string>();
            FileStream    IDInFile   = new FileStream("PlayerID.txt", FileMode.Open, FileAccess.Read);
            StreamReader  Read       = new StreamReader(IDInFile);
            string        Lines      = " ";

            while ((Lines = Read.ReadLine()) != null)
            {
                splitted = Lines.Split(',');
                GuiID.Add(splitted[0]);
                PlayerName.Add(splitted[1]);
            }
            Read.Close();

            #region Process JSON
            Console.WriteLine();
            Console.Write("Do want the new updated stats or old Stats (NEW/OLD) : ");
            string YesNo = Console.ReadLine().ToUpper();
            if (YesNo == "NEW")
            {
                for (int i = 0; i < GuiID.Count; i++)
                {
                    Console.Clear();
                    string URLPrefix = "http://";
                    string URL       = string.Format("{0}battlelog.battlefield.com/bf4/warsawdetailedstatspopulate/{1}/1/", URLPrefix, GuiID[i]);
                    using (var webClient = new System.Net.WebClient())
                    {
                        Console.WriteLine(" Downloading player {0} Data", i + 1);
                        string json = webClient.DownloadString(URL);
                        Console.WriteLine(" Serializing Player {0} Data", i + 1);
                        JavaScriptSerializer ser = new JavaScriptSerializer();
                        Console.WriteLine(" Processing Player {0} Data", i + 1);
                        RootObject ObjRoot = ser.Deserialize <RootObject>(json);
                        System.Threading.Thread.Sleep(500);

                        double CalculationForTeam = Math.Round((((double.Parse(ObjRoot.data.generalStats.timePlayed) / 3600) / int.Parse(ObjRoot.data.generalStats.rank)) * ObjRoot.data.generalStats.scorePerMinute), 2);

                        string BestClass      = "";
                        double ScorePerMinute = ObjRoot.data.generalStats.scorePerMinute;
                        int    Deaths         = int.Parse(ObjRoot.data.generalStats.deaths);

                        double assaultAccuracy         = ObjRoot.data.generalStats.assaultRifleAccuracy;
                        int    Assaultkills            = int.Parse(ObjRoot.data.generalStats.assaultRifleKills);
                        double AssaultClassCalculation = (ScorePerMinute * assaultAccuracy * Assaultkills / (Deaths));

                        double Reconaccuracy         = ObjRoot.data.generalStats.sniperRifleAccuracy;
                        int    Reconkills            = int.Parse(ObjRoot.data.generalStats.sniperRifleKills);
                        double ReconClassCalculation = (ScorePerMinute * Reconaccuracy * Reconkills / (Deaths));

                        double LMGAccuracy             = ObjRoot.data.generalStats.LMGAccuracy;
                        int    LMGkills                = int.Parse(ObjRoot.data.generalStats.LMGKills);
                        double CarbineClassCalculation = (ScorePerMinute * LMGAccuracy * LMGkills / (Deaths));
                        if ((AssaultClassCalculation > ReconClassCalculation) && (AssaultClassCalculation > CarbineClassCalculation))
                        {
                            BestClass = "Assault";
                        }
                        else if ((ReconClassCalculation > AssaultClassCalculation) && (ReconClassCalculation > CarbineClassCalculation))
                        {
                            BestClass = "Recon";
                        }
                        else if ((CarbineClassCalculation > AssaultClassCalculation) && (CarbineClassCalculation > ReconClassCalculation))
                        {
                            BestClass = "Carbine";
                        }
                        else
                        {
                            BestClass = "Any Class";
                        }

                        string Name  = PlayerName[i];
                        string Skill = ObjRoot.data.generalStats.skill;
                        string Rank  = ObjRoot.data.generalStats.rank;
                        string KD    = ObjRoot.data.generalStats.kdRatio.ToString();
                        string SPM   = ObjRoot.data.generalStats.scorePerMinute.ToString();
                        string Time  = Math.Round((double.Parse(ObjRoot.data.generalStats.timePlayed) / 3600), 1).ToString();
                        //calculationForTeam
                        string KPM      = ObjRoot.data.generalStats.killsPerMinute.ToString();
                        string LongShot = ObjRoot.data.generalStats.longestHeadshot.ToString();
                        string DogTags  = ObjRoot.data.generalStats.dogtagsTaken;
                        string Score    = ObjRoot.data.generalStats.score;
                        //BestClass
                        string PID = GuiID[i];
                        //  0     1      2     3   4    5     6                   7    8         9        10     11   12
                        Stats.Add(string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}", Name, Skill, Rank, KD, SPM, Time, CalculationForTeam, KPM, LongShot, DogTags, Score, PID, BestClass));

                        NewStats = Stats;
                    }
                }
            }
            else
            {
                Stats    = PreRun();
                NewStats = Stats;
                if (GuiID.Count != Stats.Count)
                {
                    Console.WriteLine("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-");
                    Console.WriteLine("The amount of players have been changed.");
                    Console.WriteLine("Please retrieve the new stats.");
                    Console.WriteLine("The application will now exit.");
                    System.Threading.Thread.Sleep(6000);
                    Environment.Exit(0);
                }
                Read.Close();
            }

            #endregion

            #region Menu
Menu:
            Console.Clear();
            Console.WriteLine(@"
            
            =========================================
            |                                       |
            |           Battlefield 4 Stats         |
            |                                       |
            -----------------------------------------

            1)  Generate Teams
            2)  Overall Stats
            3)  Detailed Stats
            4)  Add Player
            5)  Compare to previous Save
            6)  Export Stats
            7)  Exit Application
            
");
            Console.Write("             Please Select a Option : ");

            int  Choice = int.Parse(Console.ReadLine());
            Menu Option = (Menu)Choice;
            switch (Option)
            {
            case Menu.Teams:
                Console.Clear();
                Teams(Stats);
                Console.WriteLine();
                Console.WriteLine(" Press ENTER to go back");
                Console.ReadKey();
                goto Menu;

            case Menu.Overall:
                Console.Clear();
                Overall(Stats);
                Console.WriteLine();
                Console.WriteLine(" Press ENTER to go back");
                Console.ReadKey();
                goto Menu;

            case Menu.Details:
                Console.Clear();
                Detail(Stats);
                Console.WriteLine();
                Console.WriteLine(" Press ENTER to go back");
                Console.ReadKey();
                goto Menu;

            case Menu.Add:
                Console.Clear();
                Console.WriteLine();
                AddPlayer();
                Console.WriteLine(" Player added.");
                Console.WriteLine(" Application will now exit.");
                Console.WriteLine(" Please retrieve the new stats.");
                System.Threading.Thread.Sleep(400);
                Environment.Exit(0);
                goto Menu;

            case Menu.Previous:
                Console.Clear();
                Console.WriteLine();
                Compare(PreRun(), NewStats);
                Console.WriteLine();
                Console.WriteLine(" Press ENTER to go back");
                Console.ReadKey();
                goto Menu;

            case Menu.Export:
                Export(Stats);
                Console.WriteLine(" Exporting Stats Completed");
                System.Threading.Thread.Sleep(1200);
                goto Menu;

            case Menu.Exit:
                Environment.Exit(0);
                break;

            default:
                break;
            }

            #endregion

            Console.ReadKey();
        }
示例#3
0
 static void Main(string[] args)
 {
     RootObject myWeather = Task.Run(() => OpenWeatherMapProxy.GetWeather(20.0, 30.0)).Result;
     Console.WriteLine( myWeather.name + " - " + ((int)myWeather.main.temp).ToString()); 
 }
示例#4
0
 static void Main(string[] args)
 {
     string     json = "{  \"took\":31,  \"timed_out\":false,  \"_shards\": {    \"total\":91,    \"successful\":91,    \"skipped\":0,    \"failed\":0  },  \"hits\":{    \"total\":1,    \"max_score\":1.0,    \"hits\":[      {        \"_index\":\"my-index\",        \"_type\":\"doc\",        \"_id\":\"TrxrZGYQRaDom5XaZp23\",        \"_score\":1.0,        \"_source\":{          \"my_id\":\"65a107ed-7325-342d-adab-21fec0a97858\",          \"host\":\"something\",          \"zip\":\"12345\"        }      },    ]  }}";
     RootObject t    = JsonConvert.DeserializeObject <RootObject>(json);
 }