Esempio n. 1
0
        public static async void SaveOldHandData()
        {
            StorageFile file = await App.files.CreateFileAsync("handhistory2.txt", CreationCollisionOption.OpenIfExists);
            string handtext = await FileIO.ReadTextAsync(file);
            List<BothHands> history = JsonConvert.DeserializeObject<List<BothHands>>(handtext);
            if (history != null)
            {
                if (history.Count != 0)
                {
                    List<BothHands> historySorted = (from h in history orderby h.TimeStamp descending select h).Take(50).ToList<BothHands>();

                    for (int i = 0; i < history.Count; i++)
                    {
                        if (!history[i].IsOnline)
                        {
                            try
                            {
                                HandHistory h = new HandHistory((string)App.settings.Values["microsoftuserid"], history[i].CreditCount, history[i].OpeningHand, history[i].ClosingHand, history[i].GameType, history[i].TimeStamp, history[i].IsSnapped, "WINDOWS 8");
                                await App.MobileService.GetTable<HandHistory>().InsertAsync(h);
                                history[i].IsOnline = true;
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                    }

                    handtext = JsonConvert.SerializeObject(historySorted);
                    file = await App.files.CreateFileAsync("handhistory2.txt", CreationCollisionOption.ReplaceExisting);
                    await FileIO.WriteTextAsync(file, handtext);

                    try
                    {
                        if (App.settings.Values["microsoftuserid"].ToString().Contains("MicrosoftAccount"))
                        {
                            IMobileServiceTable<HandHistory> table = App.MobileService.GetTable<HandHistory>();
                            MobileServiceTableQuery<HandHistory> query = table.Where(i => i.MicrosoftAccountID == settings.Values["microsoftuserid"].ToString()).OrderByDescending(m => m.DatePlayed).Select(k => k).Take(1);
                            List<HandHistory> credits = await query.ToListAsync();
                            if (credits.Count != 0)
                            {
                                settings.Values["credits"] = credits[0].Credits;
                            }
                        }
                    }
                    catch (Exception ex)
                    {

                    }
                }
                else
                {
                    try
                    {
                        if (App.settings.Values["microsoftuserid"].ToString().Contains("MicrosoftAccount"))
                        {
                            IMobileServiceTable<HandHistory> table = App.MobileService.GetTable<HandHistory>();
                            MobileServiceTableQuery<HandHistory> query = table.Where(i => i.MicrosoftAccountID == settings.Values["microsoftuserid"].ToString()).OrderByDescending(m => m.DatePlayed).Select(k => k).Take(1);
                            List<HandHistory> credits = await query.ToListAsync();
                            if (credits.Count != 0)
                            {
                                settings.Values["credits"] = credits[0].Credits;
                            }
                        }
                    }
                catch (Exception ex)
                {

                }
                }
            }
            else
            {
                try
                {
                    if (App.settings.Values["microsoftuserid"].ToString().Contains("MicrosoftAccount"))
                    {
                        IMobileServiceTable<HandHistory> table = App.MobileService.GetTable<HandHistory>();
                        MobileServiceTableQuery<HandHistory> query = table.Where(i => i.MicrosoftAccountID == settings.Values["microsoftuserid"].ToString()).OrderByDescending(m => m.DatePlayed).Select(k => k).Take(1);
                        List<HandHistory> credits = await query.ToListAsync();
                        if (credits.Count != 0)
                        {
                            settings.Values["credits"] = credits[0].Credits;
                        }
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
Esempio n. 2
0
        public static async void SaveOldHandData()
        {
            IMobileServiceTable<HandHistory> table;
            MobileServiceTableQuery<HandHistory> query;
            List<HandHistory> credits;
            
            List<BothHands> history = (List<BothHands>)settings["handhistory"];
            List<BothHands> historySorted = (from h in history orderby h.TimeStamp descending select h).ToList<BothHands>();

            if (history.Count != 0)
            {
                for (int i = 0; i < history.Count; i++)
                {
                    if (!history[i].IsOnline)
                    {
                        try
                        {
                            HandHistory h = new HandHistory((string)App.settings["microsoftuserid"], history[i].CreditCount, history[i].OpeningHand, history[i].ClosingHand, history[i].GameType, history[i].TimeStamp, history[i].IsSnapped, "WINDOWS PHONE 8");
                            await App.MobileService.GetTable<HandHistory>().InsertAsync(h);
                            history[i].IsOnline = true;
                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }

                settings["handhistory"] = (from h in history orderby h.TimeStamp descending select h).Take(50).ToList<BothHands>();

                if (App.settings["microsoftuserid"].ToString().Contains("MicrosoftAccount"))
                {
                    table = App.MobileService.GetTable<HandHistory>();
                    query = table.Where(i => i.MicrosoftAccountID == settings["microsoftuserid"].ToString()).OrderByDescending(m => m.DatePlayed).Select(k => k).Take(1);
                    credits = await query.ToListAsync();

                    if (credits.Count != 0)
                    {
                        if (credits[0].DatePlayed > historySorted[0].TimeStamp)
                        {
                            settings["credits"] = credits[0].Credits;
                        }
                    }
                }
            }
            else
            {
                if (App.settings["microsoftuserid"].ToString().Contains("MicrosoftAccount"))
                {
                    table = App.MobileService.GetTable<HandHistory>();
                    query = table.Where(i => i.MicrosoftAccountID == settings["microsoftuserid"].ToString()).OrderByDescending(m => m.DatePlayed).Select(k => k).Take(1);
                    credits = await query.ToListAsync();

                    if (credits.Count != 0)
                    {
                        if (credits[0].DatePlayed > historySorted[0].TimeStamp)
                        {
                            settings["credits"] = credits[0].Credits;
                        }
                    }
                }
            }

            

            
        }