/// <summary>
        /// Download up to 1000 latest events of type METAGAME from the Historic Events collection
        /// </summary>
        /// <returns>Task-wrapped List of type CompactWorldEvent</returns>
        public async Task <List <CompactWorldEvent> > GetMetagameEventsAsync()
        {
            EventsHelper eventsHelper = new EventsHelper();
            string       pref         = Preferences.Get("globalWorldId", "100", "theWorld");
            int          time         = ((int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds) - 28800; //28800 is last 8 hours
            string       json;

            using (var client = new WebClient())
            {
                string uri = $"https://census.daybreakgames.com/s:trashpanda/get/ps2:v2/world_event/?world_id={pref}&after={time}&type=METAGAME&c:limit=200";
                if (pref == "100") //if we're debugging
                {
                    uri = $"https://census.daybreakgames.com/s:trashpanda/get/ps2:v2/world_event/?after={time}&type=METAGAME&c:limit=200";
                }

                json = await client.DownloadStringTaskAsync(uri);
            }
            Events.WorldEventListResult recentList = Newtonsoft.Json.JsonConvert.DeserializeObject <Events.WorldEventListResult>(json);


            var compactEventList = new List <CompactWorldEvent>();

            foreach (Events.World_Event item in recentList.world_event_list)
            {
                compactEventList.Add(new CompactWorldEvent()
                {
                    eventName         = eventsHelper.MatchEvents(item).event_name,
                    metagame_event_id = item.metagame_event_id,
                    timestamp         = item.timestamp,
                    world_id_int      = int.Parse(item.world_id)
                });
            }

            return(compactEventList);
        }
        public override bool OnStartJob(JobParameters @params)
        {
            double unix = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds;

            Console.WriteLine("-------------------------Job Started-------------------------");

            //Thread thread;
            //thread = new Thread(DoBackgroundWork(@params));
            //thread.Start();


            //make sure to do this on A DIFFERENT THREAD
            Task.Run(async() =>
            {
                //create a timespan


                //while app is not active

                //count down from the Timespan of 30seconds

                //if(timeSpan.timeRemaining == 0)
                string json;

                using (var client = new WebClient())
                {
                    string uri = $"https://census.daybreakgames.com/get/ps2:v2/world_event/?world_id=17&after={unix}&c:limit=50";

                    json = await client.DownloadStringTaskAsync(uri);
                }

                Events.WorldEventListResult missedEvents = Newtonsoft.Json.JsonConvert.DeserializeObject <Events.WorldEventListResult>(json);

                // check if any of the downloaded event types are continent events
                for (int i = 0; i < missedEvents.world_event_list.Count; i++)
                {
                    if (missedEvents.world_event_list[i].event_type == "MetagameEvent")
                    {
                        //make a notification to the user
                        DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        var notifServ  = Xamarin.Forms.DependencyService.Resolve <INotificationService>();
                        //double stamp = Double.Parse(missedEvents.world_event_list[i].timestamp);
                        double stamp = (double)missedEvents.world_event_list[i].timestamp;
                        await notifServ.NotifyAsync("Planetside Alert", $"{missedEvents.world_event_list[i].metagame_event_id} started at " +
                                                    epoch.AddSeconds(stamp).ToLocalTime().ToShortTimeString());
                    }
                }
                JobFinished(@params, false);
            });


            //return true becasue async work
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Download up to 1000 latest events of all types from the Historic Events collection
        /// </summary>
        /// <returns>Task-wrapped Events.WorldEventListResult</returns>
        public async Task <Events.WorldEventListResult> GetRecentEvents()
        {
            string pref = Preferences.Get("globalWorldId", "100", "theWorld");
            int    time = ((int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalSeconds) - 14400;
            string json;

            using (var client = new WebClient())
            {
                string uri = $"https://census.daybreakgames.com/s:trashpanda/get/ps2:v2/world_event/?world_id={pref}&after={time}&c:limit=1000";
                if (pref == "100") //if we're debugging
                {
                    uri = $"https://census.daybreakgames.com/s:trashpanda/get/ps2:v2/world_event/?after={time}&c:limit=1000";
                }
                json = await client.DownloadStringTaskAsync(uri);
            }
            Events.WorldEventListResult recentList = Newtonsoft.Json.JsonConvert.DeserializeObject <Events.WorldEventListResult>(json);
            return(recentList);
        }
Пример #4
0
        /// <summary>
        /// to call:
        ///     WorldEventListResult a = await GetList();
        ///     PopulateList(a.world_event_list);
        /// </summary>
        /// <returns></returns>
        ///
        private async Task <WorldEventListResult> GetList()
        {
            Events.WorldEventListResult worldResult = await pService.GetRecentEvents();

            return(worldResult);
        }
Пример #5
0
 //debug method
 private WorldEventListResult GetOnlyContinentAlerts()
 {
     Events.WorldEventListResult worldResult = pService.GetMetagameEVents().Result;
     return(worldResult);
 }
Пример #6
0
        private async Task <WorldEventListResult> GetOnlyContinentAlertsAsync()
        {
            Events.WorldEventListResult worldResult = await pService.GetMetagameEVents();

            return(worldResult);
        }