private async Task<bool> loadData()
        {
            if (curChar == null)
            {
                return true;
            }
            persistSelectedCharacter(curChar.characterID);

            this.SpinningAnimation.Begin();
            ActivityIndicator.Visibility = Visibility.Visible;

            try
            {
                HttpClient httpClient = new HttpClient() { MaxResponseContentBufferSize = 1000000 };
                Uri character_api_url = new Uri("http://eveapi.azurewebsites.net/api/Character/");
                var creds = new CharacterCredentials();
                creds.characterID = "" + curChar.characterID;
                creds.vCode = curChar.vCode;
                creds.keyID = curChar.keyID;
                string jsoncreds = JsonConvert.SerializeObject(creds);
                HttpResponseMessage res = await httpClient.PostAsync(character_api_url, new StringContent(jsoncreds, Encoding.UTF8, "application/json"));
                String character_data = await res.Content.ReadAsStringAsync();
                CharacterSheet sheet = await JsonConvert.DeserializeObjectAsync<CharacterSheet>(character_data);

                ActivityIndicator.Visibility = Visibility.Collapsed;
                this.SpinningAnimation.Stop();

                await SetPivotData(sheet);

                pivot.Visibility = Visibility.Visible;
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
          
        }
示例#2
0
        protected async override void OnInvoke(ScheduledTask task)
        {
            CharacterDataContext db = new CharacterDataContext(CharacterDataContext.DBConnectionString);
            var chars = db.characterItems.ToList();

            foreach (var curChar in chars)
            {
                Debug.WriteLine("name: " + curChar.name);
                Debug.WriteLine("lastUpdate: " + curChar.lastUpdate);
                Debug.WriteLine("snoozeTimer: " + curChar.snoozeTimer);
                Debug.WriteLine("failcount: " + curChar.failureCount);

                if (curChar.updateInterval == 0)
                {
                    // Updating is turned off for this character.
                    Debug.WriteLine("updating is off: " + curChar.name);
                    continue;
                }

                if (curChar.lastUpdate != null && ((TimeSpan)(DateTime.UtcNow - curChar.lastUpdate)).TotalMinutes < curChar.updateInterval)
                {
                    // Hasn't been long enough to update.
                    Debug.WriteLine("Hasn't been long enough to update: " + curChar.name + " min:" + ((TimeSpan)(DateTime.UtcNow - curChar.lastUpdate)).TotalMinutes);
                    continue;
                }

                if (curChar.failureCount > 6)
                {
                    ShellToast popupMessage = new ShellToast()
                    {
                        Title = "" + curChar.name,
                        Content = "API Lookup not authorized",
                        NavigationUri = new Uri("/Views/CharacterDisplay.xaml?char=" + curChar.characterID, UriKind.Relative)
                    };
                    popupMessage.Show();
                }
                try
                {
                    HttpClient httpClient = new HttpClient() { MaxResponseContentBufferSize = 1000000 };
                    httpClient.Timeout = TimeSpan.FromSeconds(8);
                    Uri character_api_url = new Uri("http://eveapi.azurewebsites.net/api/Character/");
                    var creds = new CharacterCredentials();
                    creds.characterID = "" + curChar.characterID;
                    creds.vCode = curChar.vCode;
                    creds.keyID = curChar.keyID;
                    string jsoncreds = JsonConvert.SerializeObject(creds);
                    HttpResponseMessage res = await httpClient.PostAsync(character_api_url, new StringContent(jsoncreds, Encoding.UTF8, "application/json"));
                    String character_data = await res.Content.ReadAsStringAsync();
                    CharacterSheet sheet = await JsonConvert.DeserializeObjectAsync<CharacterSheet>(character_data);

                    if (curChar.failureCount > 0)
                    {
                        curChar.failureCount = 0;
                    }
                    if (!curChar.notificationsOn)
                    {
                        Debug.WriteLine("Notifications are off");
                        continue;
                    }
                    if (curChar.snoozeTimer != null)
                    {
                        if (curChar.snoozeTimer > DateTime.UtcNow)
                        {
                            Debug.WriteLine("Snooze timer is active");
                            continue;
                        }
                        else
                        {
                            curChar.snoozeTimer = null;
                        }
                    }
                    curChar.lastUpdate = DateTime.UtcNow;

                    db.SubmitChanges();

                    string message = null;
                    if (sheet.empty)
                    {
                        message = "Queue Empty";
                    }
                    else if (sheet.paused)
                    {
                        message = "Queue Paused";
                    }
                    else if (sheet.queue_length_hours < 24)
                    {
                        message = "Queue less than " + (Math.Floor(sheet.queue_length_hours) + 1) + "H";
                    }
                    if (message != null)
                    {
                        ShellToast popupMessage = new ShellToast()
                        {
                            Title = "" + curChar.name,
                            Content = message,
                            NavigationUri = new Uri("/Views/CharacterDisplay.xaml?char=" + curChar.characterID, UriKind.Relative)
                        };
                        popupMessage.Show();
                    }
                }
                catch (Exception e)
                {
                }
            }
            NotifyComplete();
           
        }