/// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.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;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // 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;
            }

            // Create the database if it does not exist.
            using (VKDataContext db = new VKDataContext(VKDataContext.DBConnectionString))
            {
                if (db.DatabaseExists() == false)
                {
                    //Create the database
                    db.CreateDatabase();
                    //createTestData();
                }
            }
        }
        public static void LoadMessages(List<Message> dialogs)
        {
            for (int i = 0; i < dialogs.Count; i++)
            {
                Message msg = dialogs[i];
                HttpRequestsHandler.GetUserByID(msg.uid, (x) =>
                {
                    using (VKDataContext context = new VKDataContext(VKDataContext.DBConnectionString))
                    {
                        VKMessage vm = new VKMessage();
                        vm.Body = msg.body;
                        vm.Date = DateConverter.DateTimeFromUnixTimestampSeconds(msg.date);
                        vm.VKMessageID = msg.mid;
                        VKUser user = new VKUser();

                        user.FirstName = x.first_name;
                        user.LastName = x.last_name;
                        user.IsOnline = (x.online == 1);
                        user.VKUserID = x.uid;

                        context.VKUser.InsertOnSubmit(user);
                        context.SubmitChanges();

                        context.VKMessage.InsertOnSubmit(vm);
                        context.SubmitChanges();

                        UserMessage um = new UserMessage();
                        um.VKMessageID = user.VKUserID;
                        um.VKUserID = vm.VKMessageID;

                        context.UserMessage.InsertOnSubmit(um);
                        context.SubmitChanges();
                    }
                }, (error) =>
                {
                });
            }
        }
        private void createTestData()
        {
            using (VKDataContext context = new VKDataContext(VKDataContext.DBConnectionString))
            {
                //context.DeleteDatabase();
                //context.CreateDatabase();

                IList<String> firstnames = new List<String>();
                firstnames.Add("Александр");
                firstnames.Add("Андрей");
                firstnames.Add("Bob");
                firstnames.Add("Willy");
                firstnames.Add("John");
                firstnames.Add("Akakij");

                IList<String> lastnames = new List<String>();
                lastnames.Add("Семирухин");
                lastnames.Add("White");
                lastnames.Add("Green");
                lastnames.Add("Joke");
                lastnames.Add("Smith");
                lastnames.Add("Васильев");

                IList<String> messageBodies = new List<String>();
                messageBodies.Add("Hi! How are you?");
                messageBodies.Add("Привет! Как дела?");
                messageBodies.Add("Merhaba! Nasilsin?");
                messageBodies.Add("What's up?");
                messageBodies.Add("Йоххо!");
                messageBodies.Add("London is capital of Great Britain");

                for (int i = 0; i < 6; i++)
                {
                    VKUser user = new VKUser();
                    user.LastName = lastnames[i];
                    user.FirstName = firstnames[i];
                    user.Photo = "http://photo.jpg";
                    user.IsOnline = true;
                    context.VKUser.InsertOnSubmit(user);
                    context.SubmitChanges();

                    VKMessage message = new VKMessage();
                    message.Body = messageBodies[i];
                    context.VKMessage.InsertOnSubmit(message);
                    context.SubmitChanges();

                    UserMessage um = new UserMessage();
                    um.VKMessageID = user.VKUserID;
                    um.VKUserID = message.VKMessageID;
                    context.UserMessage.InsertOnSubmit(um);
                    context.SubmitChanges();
                }
            }
        }