Beispiel #1
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            //IsolatedStorageSettings.ApplicationSettings.Remove("access_token");
            //IsolatedStorageSettings.ApplicationSettings.Remove("user_id");
            db = new VkDataContext("isostore:/DataContext.sdf");
            if (!db.DatabaseExists())
                db.CreateDatabase();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("access_token"))
            {
                VkApi.Authorization.AccessToken = (string)IsolatedStorageSettings.ApplicationSettings["access_token"];
                VkApi.Authorization.UserId = (string)IsolatedStorageSettings.ApplicationSettings["user_id"];
                //VkApi.Authorization.Secret = (string)IsolatedStorageSettings.ApplicationSettings["secret"];
                var mapper = new UriMapper();
                mapper.UriMappings.Add(new UriMapping() { Uri = new Uri("/LoginPage.xaml", UriKind.Relative), MappedUri = new Uri("/MainPage.xaml", UriKind.Relative) });
                this.RootFrame.UriMapper = mapper;

                new Notifications().SetupNotificationChannel();
            }
        }
        // Constructor
        public ConversationPage()
        {
            try
            {
                db = new VkDataContext("isostore:/DataContext.sdf");
                InitializeComponent();
                BuildApplicationBars();
                ApplicationBar = messagesAppBar;
                //friendName.Text = friend.FirstName + " " + friend.LastName;
                //friendName.Text.ToUpperInvariant();

                var dbMessages = (from message in db.Messages where message.ChatId == chat_id select message).ToList();
                //var atMid = (from at in db.Attachments select at.Mid).ToList();
                if (dbMessages.Count != 0)
                {
                    firstTime = false;
                    List<VkResponseData> messagesFromDb = new List<VkResponseData>();
                    lastMid = 0;
                    for (int i = dbMessages.Count - 1; i >= 0; i--)
                    {
                        messagesFromDb.Add(new Messages() { body = dbMessages[i].Body, mid = dbMessages[i].Mid, date = dbMessages[i].Date, from_id = dbMessages[i].FromId });
                        //messageStackpanels.Add(new MessageTemplateItemViewModel() { Message = message.Body, Mid = message.Mid.ToString(), ReceivedTime = new DateTime(1970, 1, 1).AddSeconds(int.Parse(message.Date)) + TimeZoneInfo.Local.BaseUtcOffset, User = false });
                        //messageStackpanels.Add(new MessageTemplateItemViewModel() { Message = currentMessage.body, Mid = currentMessage.mid.ToString(), ReceivedTime = new DateTime(1970, 1, 1).AddSeconds(int.Parse(currentMessage.date)) + TimeZoneInfo.Local.BaseUtcOffset, User = currentMessage.uid == friend.UserId ? false : true, Img = allAttachmentsString, Attachments = attachments_types });
                        //messageListBox.Items.Add(messageStackpanels.Last().CreateMSGBox());
                        //messageListBox.ScrollIntoView(messageListBox.Items[messageListBox.Items.Count - 1]);
                        if (lastMid < int.Parse(dbMessages[i].Mid))
                            lastMid = int.Parse(dbMessages[i].Mid);
                    }
                    apiMethodRequest.SendRequest(VkApi.Authorization.AccessToken, "messages.getHistory", new Dictionary<string, string>() { { "chat_id", chat_id }, { "start_mid", lastMid.ToString() } });

                    LoadingMessagesList(messagesFromDb, false, false);
                }
                else
                    apiMethodRequest.SendRequest(VkApi.Authorization.AccessToken, "messages.getHistory", new Dictionary<string, string>() { { "chat_id", chat_id }, { "count", "20" } });
            }
            catch { }
        }