Пример #1
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
            db = new CharacterDataContext(CharacterDataContext.DBConnectionString);
            if (db.DatabaseExists() == false)
            {
                db.CreateDatabase();
                db.SubmitChanges();
            }
            else
            {
                System.Data.Linq.Table<Character> entities = db.characterItems;
                try
                {
                    IEnumerator<Character> enumEntity = entities.GetEnumerator();
                }
                catch (Exception ee)
                {
                    db.DeleteDatabase();
                    db.CreateDatabase();
                    db.SubmitChanges();
                }
            }
        }
Пример #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            App app = (App)Application.Current;
            db = app.db;

            progressIndicator = new ProgressIndicator()
            {
                IsVisible = false,
                IsIndeterminate = true,
                Text = "Looking up characters ..."
            };

            SystemTray.SetProgressIndicator(this, progressIndicator);

            if (app.loadedInfo != null)
            {
                vCode.Text = app.loadedInfo.vCode;
                apiKey.Text = app.loadedInfo.keyID;
                app.loadedInfo = null;
                goButton_Click(null, null);
            }
        }
Пример #3
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();
           
        }