Beispiel #1
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            synchronizer.LoggingMode = true;
            using (var db = new BloggingContext())
            {
                var blog = new Blog { BlogId = HashStringToIntId(NewBlogUrl.Text), Url=NewBlogUrl.Text };
                db.Blogs.Add(blog);
                db.SaveChanges();

                Blogs.ItemsSource = db.Blogs.ToList();
            }
            synchronizer.LoggingMode = false;
        }
Beispiel #2
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // initialize synchronizer
            await synchronizer.Setup();

            // db context stuff
            List<Blog> blogs;
            using (var db = new BloggingContext())
            {
                db.Database.EnsureCreated();

                blogs = db.Blogs.ToList();
                Blogs.ItemsSource = blogs;
            }

        }
Beispiel #3
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            Register();

            Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
                Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
                Microsoft.ApplicationInsights.WindowsCollectors.Session);
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new BloggingContext())
            {
                db.Database.Migrate();
                db.RegisterLogger();
            }

            Initialize();
        }
Beispiel #4
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            synchronizer.LoggingMode = true;
            using (var db = new BloggingContext())
            {
                db.Blogs.RemoveRange(Blogs.SelectedItems.Cast<Blog>());
                db.SaveChanges();

                Blogs.ItemsSource = db.Blogs.ToList();
            }
            synchronizer.LoggingMode = false;
        }
Beispiel #5
0
        private async void InitializeAll_Click(object sender, RoutedEventArgs e)
        {
            var synchronizer = SimpleIoc.Default.GetInstance<Synchronizer>();
            using (var db = new BloggingContext())
            {
                // clear onedrive
                await synchronizer.InitializeOnedrive();

                // clear local db
                await synchronizer.InitializeDb(db);

                // invalidate
                Blogs.ItemsSource = db.Blogs.ToList();
            }

        }
Beispiel #6
0
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            var synchronizer = SimpleIoc.Default.GetInstance<Synchronizer>();
            using (var db = new BloggingContext())
            {
                // update the database from remote
                await synchronizer.Download(db);

                // invalidate
                Blogs.ItemsSource = db.Blogs.ToList();
            }

        }
Beispiel #7
0
 public async Task InitializeDb(BloggingContext db)
 {
     foreach(var blog in db.Blogs)
     {
         db.Blogs.Remove(blog);
     }
     await db.SaveChangesAsync();
 }