Example #1
0
        public void RemoveFromDatabase(Database.CustomDbContext db)
        {
            if (db == null)
            {
                return;
            }

            foreach (FavShowData favShowData in TvShows)
            {
                favShowData.RemoveFromDatabase(db);
            }
        }
Example #2
0
        public static void SaveToDatabase(Settings settings)
        {
            dbMutex.WaitOne();
            //mutexName = "savetodb";

            try
            {
                string path = GetDBPath();

                if (db == null)
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    db = new CustomDbContext();
                }

                if (File.Exists(path))
                {
                    // If we have an existing db, we should already have some pending changes to save - Calvin 13-Feb-2016

                    db.SaveChanges();
                }
                else
                {
                    // If we do not have an existing db, create a new one and add everything - Calvin 13-Feb-2016
                    db.Database.Create();

                    db.FavShowData.AddRange(settings.TvShows);
                    db.SaveChanges();

                    foreach (FavShowData favShowData in settings.TvShows)
                    {
                        favShowData.InDatabase = true;
                    }
                }
            }
            catch (Exception ex)
            {
                db = null;
                throw new Exception("Fehler beim Schreiben zu Datenbank", ex);
            }
            finally
            {
                dbMutex.ReleaseMutex();
            }
        }
Example #3
0
        public static bool LoadFromDatabase(Settings settings)
        {
            bool result = false;

            dbMutex.WaitOne();
            //mutexName = "savetodb";

            try
            {
                string path = GetDBPath();

                if (File.Exists(path))
                {
                    db = new CustomDbContext();

                    System.Data.Entity.Database.SetInitializer <CustomDbContext>(null);

                    db.Database.Initialize(false);

                    // No longer needed since we now go through the lists to set InDatabase
                    //db.FavShowData.Load();
                    //db.FavSeasonData.Load();
                    //db.FavEpisodeData.Load();
                    //db.ShowInformation.Load(); // Not currently used - Calvin 13-Feb-2016
                    //db.SeasonInformation.Load(); // Not currently used - Calvin 13-Feb-2016
                    //db.EpisodeInformation.Load();
                    //db.DownloadData.Load();
                    //db.UploadData.Load();
                    //db.SeasonData.Load();
                    //db.ShowData.Load();

                    settings.TvShows.Clear();

                    foreach (FavShowData favShowData in db.FavShowData.ToList())
                    {
                        favShowData.InDatabase = true;
                        settings.TvShows.Add(favShowData);
                    }

                    foreach (FavSeasonData favSeasonData in db.FavSeasonData.ToList())
                    {
                        favSeasonData.InDatabase = true;
                    }

                    foreach (FavEpisodeData favEpisodeData in db.FavEpisodeData.ToList())
                    {
                        favEpisodeData.InDatabase = true;
                    }

                    foreach (Provider.EpisodeInformation episodeInformation in db.EpisodeInformation.ToList())
                    {
                        episodeInformation.InDatabase = true;
                    }

                    foreach (DownloadData downloadData in db.DownloadData.ToList())
                    {
                        downloadData.InDatabase = true;
                    }

                    foreach (UploadData uploadData in db.UploadData.ToList())
                    {
                        uploadData.InDatabase = true;
                    }

                    foreach (SeasonData seasonData in db.SeasonData.ToList())
                    {
                        seasonData.InDatabase = true;
                    }

                    foreach (ShowData showData in db.ShowData.ToList())
                    {
                        showData.InDatabase = true;
                    }
                }
            }
            catch (Exception ex)
            {
                db = null;
                throw new Exception("Fehler beim Lesen von Datenbank", ex);
            }

            dbMutex.ReleaseMutex();

            return(result);
        }