Exemple #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void AddPicture()
        {
            if (!TmpPicture.Any())
            {
                return;
            }
            List <PostPictures> posts = TmpPicture;

            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Началась работа метода записи картинок в БД.");
            }
            Sem.Release();
            Models.MyDBEntities1       db    = new Models.MyDBEntities1();
            List <Models.TablePicture> table = (from t in db.TablePicture select t).ToList();

            int count = db.TablePicture.Count();

            for (int i = 0; i < count; i++)
            {
                Models.TablePicture tableItem = (from t in db.TablePicture select t).First();
                db.TablePicture.Remove(tableItem);
                db.SaveChanges();
            }
            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Очистка картинок в БД выполнена.");
            }
            Sem.Release();

            int id = 0;

            foreach (PostPictures item in posts)
            {
                List <string> pictures = item.PictureURLs.ToList();
                foreach (string p in pictures)
                {
                    Models.TablePicture t1 = new Models.TablePicture()
                    {
                        Picture = p,
                        Post_Id = item.ID,
                        Id      = id
                    };
                    db.TablePicture.Add(t1);
                    id++;
                    db.SaveChanges();
                }
            }
            db.Dispose();
            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Метод закончил загружать картинки в БД.");
            }
            Sem.Release();
        }
Exemple #2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void AddText()
        {
            if (!TmpText.Any())
            {
                return;
            }
            List <PostText> posts = TmpText;

            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Началась работа метода записи текста в БД.");
            }
            Sem.Release();
            Models.MyDBEntities1    db    = new Models.MyDBEntities1();
            List <Models.TableText> table = (from t in db.TableText select t).ToList();

            int count = db.TableText.Count();

            for (int i = 0; i < count; i++)
            {
                Models.TableText tableItem = (from t in db.TableText select t).First();
                db.TableText.Remove(tableItem);
                db.SaveChanges();
            }
            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Очистка текста в БД выполнена.");
            }
            Sem.Release();

            int id = 0;

            foreach (PostText item in posts)
            {
                Models.TableText t1 = new Models.TableText()
                {
                    Text    = item.Text,
                    Post_Id = item.ID,
                    Id      = id
                };
                db.TableText.Add(t1);
                db.SaveChanges();
                id++;
            }
            db.Dispose();
            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Метод закончил загружать текст в БД.");
            }
            Sem.Release();
        }
Exemple #3
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void AddUrl()
        {
            if (!TmpURL.Any())
            {
                return;
            }
            List <PostURLs> posts = TmpURL;

            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Началась работа метода записи ссылок в БД.");
            }
            Sem.Release();
            Models.MyDBEntities1   db    = new Models.MyDBEntities1();
            List <Models.TableUrl> table = (from t in db.TableUrl select t).ToList();

            int count = db.TableUrl.Count();

            for (int i = 0; i < count; i++)
            {
                Models.TableUrl tableItem = (from t in db.TableUrl select t).First();
                db.TableUrl.Remove(tableItem);
                db.SaveChanges();
            }
            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Очистка ссылок в БД выполнена.");
            }
            Sem.Release();

            int id = 0;

            foreach (PostURLs item in posts)
            {
                List <string> urls = item.TextURLs.ToList();
                foreach (string u in urls)
                {
                    if (!u.Equals(""))
                    {
                        Models.TableUrl t1 = new Models.TableUrl()
                        {
                            Url     = u,
                            Post_Id = item.ID,
                            Id      = id
                        };
                        db.TableUrl.Add(t1);
                        id++;
                        db.SaveChanges();
                    }
                }
            }
            db.Dispose();
            Sem.WaitOne();
            using (StreamWriter sw = new StreamWriter(pathLog, true, System.Text.Encoding.Default))
            {
                sw.WriteLine("[" + DateTime.Now.ToString() + "] Метод закончил загружать ссылки в БД.");
            }
            Sem.Release();
        }