예제 #1
0
        public void CleanupDuplicatedTitles()
        {
            var db    = new NewsObjectContext();
            var count = db.Entries.Count();


            var query = db.Entries.ToList();

            var removal = new List <Entry>();

            for (int i = query.Count - 1; i >= 0; i--)
            {
                var item  = query[i];
                var exist = query.Exists(q => q != item && q.Title == item.Title);
                if (exist)
                {
                    removal.Add(item);
                }
            }

            foreach (var entry in removal)
            {
                db.EntrySources.DeleteObject(entry.EntrySource);
                db.Entries.DeleteObject(entry);
            }

            db.SaveChanges();
        }
예제 #2
0
        public void CreateDatabase()
        {
            var db = new NewsObjectContext();

            db.DeleteDatabase();
            db.CreateDatabase();
        }
예제 #3
0
        public void CleanupDuplication()
        {
            //var db = _voleur.Db;
            var db = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServerRemote"].ConnectionString);



            var entries = db.Entries.ToList();
            var dist    = entries.GroupBy(g => g.Title);
            var keep    = new List <Entry>();

            foreach (var distitem in dist)
            {
                var items  = distitem.ToList();
                var val    = items.FirstOrDefault(i => !string.IsNullOrEmpty(i.Content));
                var keepme = val ?? items[0];
                keep.Add(keepme);
                entries.Remove(keepme);
            }

            foreach (var entry in entries)
            {
                if (entry.EntrySource != null)
                {
                    db.EntrySources.DeleteObject(entry.EntrySource);
                }
                db.Entries.DeleteObject(entry);
            }

            db.SaveChanges();
        }
예제 #4
0
 protected BaseVoleur(NewsObjectContext db = null)
 {
     //_dbVoleur = new VoleurEntities();
     //Db = new NewsObjectContext();
     Db  = db ?? new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServer"].ConnectionString);
     _wc = new WebClient {
         Encoding = Encoding.UTF8
     };
 }
예제 #5
0
        public void CheckNullGroupEntries()
        {
            var db      = new NewsObjectContext();
            var entries = db.Entries.Where(en => en.Group == null).ToList();

            foreach (var entry in entries)
            {
                db.EntrySources.DeleteObject(entry.EntrySource);
                db.Entries.DeleteObject(entry);
            }
            db.SaveChanges();
        }
예제 #6
0
        public void FixGroupEntries()
        {
            var db = new NewsObjectContext();
            var g1 = db.Groups.SingleOrDefault(g => g.Name == "YoungPeople_Love");
            var g2 = db.Groups.SingleOrDefault(g => g.Name == "YoungPeople & Love");

            foreach (var entry in g2.Entries.ToList())
            {
                entry.Group = g1;
            }

            db.Groups.DeleteObject(g2);
            db.SaveChanges();
        }
예제 #7
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public VoleurMainViewModel(NewsObjectContext db = null)
        {
            if (IsInDesignMode)
            {
                return;
            }

            Db = db ?? new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServer"].ConnectionString);

            _voleurs = new Dictionary <string, BaseVoleur>
            {
                { "DanTri", new DanTriVoleur(db) },
                { "TinhTe", new TinhTeVoleur(db) },
            };
        }
예제 #8
0
        public void IndexingEntries()
        {
            var db         = new NewsObjectContext();
            var indexingDb = new CachedDatabaseContainer();

            var formatter = new BinaryFormatter();

            var controller = new NouvelleController();
            var counter    = 0;

            foreach (var id in db.Entries.Select(en => en.Id))
            {
                counter++;
                if (counter % 5 == 0)
                {
                    Debug.WriteLine(">> Indexed: " + counter);
                }
                var chk = indexingDb.EntryViews.SingleOrDefault(e => e.Id == id);
                if (chk != null)
                {
                    continue;
                }

                chk = new EntryView {
                    Id = id
                };
                var stream = new MemoryStream();
                formatter.Serialize(stream, controller.GetEntryViewModel(id));
                chk.Data = stream.ToArray();
                indexingDb.EntryViews.AddObject(chk);
                stream.Close();


                indexingDb.SaveChanges();
            }
        }
예제 #9
0
 protected BaseHtmlParserVoleur(NewsObjectContext db = null)
     : base(db)
 {
 }
예제 #10
0
 public TinhTeVoleur(NewsObjectContext db = null)
     : base(db)
 {
 }
예제 #11
0
 public void CheckSmth()
 {
     var db = new NewsObjectContext();
 }
예제 #12
0
 public void TestDatabaseSqlServer()
 {
     var     db    = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServer"].ConnectionString);
     dynamic count = db.Entries.Count();
 }
예제 #13
0
        public void CreateDatabaseSqlServer()
        {
            var db = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServer"].ConnectionString);

            db.CreateDatabase();
        }
예제 #14
0
        public void SyncData()
        {
            var remote       = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServerRemote"].ConnectionString);
            var remoteGroups = remote.Groups.ToDictionary(a => a.Id, b => b);
            var entrySource  = remote.Sources.ToDictionary(a => a.Id, b => b);

            var entries1 = remote.Entries.Select(e => new
            {
                e.Id,
                e.Title,
                Content = ""
            }).ToList();

            var local = new NewsObjectContext(ConfigurationManager.ConnectionStrings["EnewsSqlServerLocal"].ConnectionString);

            var entries2 = local.Entries.Select(e => e).ToList();
            var query    = (from e in entries2
                            where !entries1.Exists(e1 => e1.Title == e.Title)
                            select e).ToList();

            for (int i = 0; i < query.Count; i++)
            {
                var entry = query[i];
                if (i % 40 == 0)
                {
                    remote.SaveChanges();
                    Debug.WriteLine(string.Format(">> Save {0}/{1}", i, query.Count));
                }

                if (entry.Group == null)
                {
                    continue;
                }
                if (!remoteGroups.ContainsKey(entry.Group.Id))
                {
                    //throw new Exception("Group not exist");
                    continue;
                }

                if (!entrySource.ContainsKey(entry.EntrySource.Source.Id))
                {
                    throw new Exception("EntrySource not exist");
                }
                // clone
                var newEntry = new Entry
                {
                    Content     = entry.Content,
                    Date        = entry.Date,
                    Description = entry.Description,
                    Title       = entry.Title,
                    ImageUrl    = entry.ImageUrl,
                    ViewType    = entry.ViewType,
                    ViewIndex   = entry.ViewIndex,
                    Group       = remoteGroups[entry.Group.Id],
                    Published   = entry.Published,
                    EntrySource =
                        new EntrySource
                    {
                        Url    = entry.EntrySource.Url,
                        Source = entrySource[entry.EntrySource.Source.Id]
                    }
                };
                remote.Entries.AddObject(newEntry);
            }
            remote.SaveChanges();

            // Empty entry
            var entries3 = (from e in remote.Entries
                            where e.Content == null
                            select
                            e).ToList();

            foreach (var entry in entries3)
            {
                var tmp = entries2.SingleOrDefault(e => e.Title == entry.Title);
                if (tmp == null)
                {
                    continue;
                }
                entry.Content = tmp.Content;
            }

            remote.SaveChanges();
        }
예제 #15
0
 public DanTriVoleur(NewsObjectContext db = null) : base(db)
 {
 }