Esempio n. 1
0
 private episode_need_update_to_live findEpisodeNeedUpdateToLive()
 {
     try
     {
         using (var context = new NTVideoEntities())
         {
             var victimUpdateQuery = from enutl in context.episode_need_update_to_live
                                     where enutl.status == 0 && enutl.victim.victimTypeNo == 0 //lifeOfVictimStatus = 0(not ok), 1(ok)
                                     select enutl;
             var episodeNeedUpdateToLive = victimUpdateQuery.FirstOrDefault();
             return(episodeNeedUpdateToLive);
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         return(null);
     }
 }
Esempio n. 2
0
 private void deleteAllEpisodeThatOldDate()
 {
     try
     {
         using (var context = new NTVideoEntities())
         {
             var episodesNeedDeleteQuery = from enutl in context.episode_need_update_to_live
                                           where enutl.dateCreate < DateTime.Today
                                           select enutl;
             var a = episodesNeedDeleteQuery.ToArray();
             context.episode_need_update_to_live.RemoveRange(episodesNeedDeleteQuery.ToArray());
             context.SaveChanges();
         }
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
     }
 }
Esempio n. 3
0
 public bool beginDownLoad()
 {
     while (!CMDUtil.checkPort(85))
     {
         if (!doStartApache)
         {
             doStartApache = true;
             CMDUtil.startApache();
         }
     }
     while (isDownloading || stopDownloadFlag)
     {
         Thread.Sleep(1000);
     }
     using (var context = new NTVideoEntities())
     {
         var infoDownloadQuery = from m in context.movies
                                 from v in context.victims
                                 where m.movieId == v.movieId && v.downloadStatus != "completed" && v.downloadStatus != "pending" && m.countries.Any(c => c.alias != "my")
                                 orderby m.publishYear descending, m.isMultiEpisode ascending
             select new { m, v };
         var movieInfo = infoDownloadQuery.FirstOrDefault();
         if (movieInfo.m != null)
         {
             string movieAlias     = movieInfo.m.alias;
             var    episodes       = BaseVictim.instance().getEpisodes(movieInfo.v.movieHref, true);
             var    totalEpisode   = episodes.Count();
             var    downloadedInfo = getEpisodesDownloadedInfo(movieInfo.v.victimId);
             var    episodeIndex   = 0;
             foreach (var episode in episodes)
             {
                 var typeDownload = getTypeDownload(episode, downloadedInfo);
                 if (typeDownload == "none")
                 {
                     episodeIndex++;
                     continue;
                 }
                 var typeMovieFolder = (movieInfo.m.isMultiEpisode == 1) ? "multi-episode" : "one-episode";
                 var countryFolder   = movieInfo.m.countries.ToList <country>()[0].alias;
                 var savePath        = rootSavePath + "/" + typeMovieFolder + "/" + countryFolder + "/" + movieAlias;
                 if (!Directory.Exists(savePath))
                 {
                     Directory.CreateDirectory(savePath);
                 }
                 fileName      = episode.alias + ".mp4";
                 isDownloading = true;
                 string status = downLoad(movieAlias, episodeIndex, savePath, fileName);
                 if (episodeIndex == (totalEpisode - 1) && status != "error" && status != "pending")
                 {
                     status = "completed";
                 }
                 saveDownloadInfoToDB((typeDownload == "update") ? getDownloadedByName(episode.name, downloadedInfo) : null, episode.alias, savePath, status, movieInfo.m, movieInfo.v, context);
                 episodeIndex++;
                 isDownloading = false;
             }
         }
     }
     return(true);
 }
Esempio n. 4
0
 public category findCategoryByName(string categoryName)
 {
     using (var context = new NTVideoEntities())
     {
         var categories = from m in context.categories
                          where m.name == categoryName
                          select m;
         return(categories.FirstOrDefault());
     }
 }
Esempio n. 5
0
 public director findDirectorByName(string directorName)
 {
     using (var context = new NTVideoEntities())
     {
         var directors = from m in context.directors
                         where m.name == directorName
                         select m;
         return(directors.FirstOrDefault());
     }
 }
Esempio n. 6
0
 public actor findActorByName(string actorName)
 {
     using (var context = new NTVideoEntities())
     {
         var actors = from m in context.actors
                      where m.name == actorName
                      select m;
         return(actors.FirstOrDefault());
     }
 }
Esempio n. 7
0
 public movie findMovieByCheckFields(string name1CheckField, string name2CheckField)
 {
     using (var context = new NTVideoEntities())
     {
         var movies = from m in context.movies
                      where m.name1CheckField == name1CheckField && m.name2CheckField == name2CheckField
                      select m;
         return(movies.FirstOrDefault());
     }
 }
Esempio n. 8
0
 public List <string> findCheckFieldAllMovies()
 {
     using (var context = new NTVideoEntities())
     {
         var checkFields = from m in context.movies
                           select new { checkField = m.name1CheckField + "-" + m.name2CheckField };
         var listCheckFields = checkFields.Select(o => o.checkField).ToList();
         return(listCheckFields);
     }
 }
Esempio n. 9
0
 private void InitializeTimerUpdatingVictimThread()
 {
     threadUpdatingVictim = new Thread(() =>
     {
         while (threadUpdatingVictim.IsAlive)
         {
             try
             {
                 Console.WriteLine("victimsNeedUpdate length: " + episodesNeedUpdateToLive.Count);
                 while (isUpating || episodesNeedUpdateToLive.Count == 0)
                 {
                     Thread.Sleep(1000);
                 }
                 var enutl = episodesNeedUpdateToLive[0];
                 using (var context = new NTVideoEntities())
                 {
                     var episodeNeedUpdateQuery = from e in context.episode_need_update_to_live
                                                  where e.status == 0 && e.episodeUpdateToLiveId == enutl.episodeUpdateToLiveId //status = 0(not ok), 1(ok)
                                                  select e;
                     var episodeNeedUpdateToLive = episodeNeedUpdateQuery.FirstOrDefault();
                     if (episodeNeedUpdateToLive != null)
                     {
                         isUpating             = true;
                         victimServiceInstance = (BaseVictim)VICTIM_INSTANCE[episodeNeedUpdateToLive.victim.victimTypeNo.ToString()];
                         episodeNeedUpdateToLive.victim.playListHtml = getEpisodePlayerInfoByIndexAndRebuildPlayListHtml(Int32.Parse(episodeNeedUpdateToLive.serverIndex.ToString()), Int32.Parse(episodeNeedUpdateToLive.episodeIndex.ToString()), episodeNeedUpdateToLive.victim.playListHtml);
                         episodeNeedUpdateToLive.status = 1;
                         context.Entry(episodeNeedUpdateToLive.victim).State = System.Data.Entity.EntityState.Modified;
                         context.SaveChanges();
                         episodesNeedUpdateToLive.RemoveAt(0);
                         isUpating = false;
                     }
                 }
             }
             catch (DbEntityValidationException e)
             {
                 foreach (var eve in e.EntityValidationErrors)
                 {
                     Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                     foreach (var ve in eve.ValidationErrors)
                     {
                         Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                           ve.PropertyName, ve.ErrorMessage);
                     }
                 }
                 episodesNeedUpdateToLive.RemoveAt(0);
                 isUpating = false;
             }
         }
     });
     threadUpdatingVictim.IsBackground = true;
     threadUpdatingVictim.SetApartmentState(ApartmentState.STA);
     threadUpdatingVictim.Start();
 }
Esempio n. 10
0
 public bool movieExistedWithVictim(movie mv, string victimName)
 {
     using (var context = new NTVideoEntities())
     {
         var movies = from m in context.movies
                      from vtm in context.victims
                      where m.movieId == vtm.movieId && vtm.victimTypeNo == victimTypeNo && (m.name1CheckField == mv.name1CheckField && m.name2CheckField == mv.name2CheckField)
                      select m;
         return((movies.Count() > 0) ? true : false);
     }
 }
Esempio n. 11
0
 public bool beginUpLoad()
 {
     while (!CMDUtil.checkPort(85))
     {
         if (!doStartApache)
         {
             doStartApache = true;
             CMDUtil.startApache();
         }
     }
     while (isUploading || stopUploadFlag)
     {
         Thread.Sleep(1000);
     }
     using (var context = new NTVideoEntities())
     {
         var infoUploadQuery = from m in context.movies
                               from v in context.victims
                               from d in context.downloads
                               where m.movieId == v.movieId && d.victimId == v.victimId &&
                               m.countries.Any(c => c.alias != "my") &&
                               v.downloadStatus == "completed" &&
                               v.uploadStatus != "completed"
                               orderby m.publishYear, m.isMultiEpisode
             select new { m, v, d };
         var movieInfo = infoUploadQuery.FirstOrDefault();
         if (movieInfo.m != null)
         {
             string movieAlias         = movieInfo.m.alias;
             var    episodesDownloaded = movieInfo.v.downloads;
             var    episodeUploaded    = movieInfo.v.uploads;
             var    episodeIndex       = 0;
             foreach (var episodeDownloaded in episodesDownloaded)
             {
                 isUploading = true;
                 var    title       = movieInfo.m.name1 + "-" + movieInfo.m.name2 + ((movieInfo.m.isMultiEpisode == 1) ? (" - Tập " + episodeDownloaded.name) : "");
                 var    description = HtmlUtil.StripHTML(movieInfo.v.description);
                 var    file        = episodeDownloaded.name + ".mp4";
                 string status      = upLoad(title, description, episodeDownloaded.savePath, file);
                 if (episodeIndex == (episodesDownloaded.Count() - 1) && status != "error" && status != "pending")
                 {
                     status = "completed";
                 }
                 //saveDownloadInfoToDB(episodeDownloaded.alias, savePath, status, movieInfo.m, movieInfo.v, context);
                 episodeIndex++;
                 isUploading = false;
             }
         }
     }
     return(true);
 }
Esempio n. 12
0
 public static bool checkConnection()
 {
     try
     {
         using (var context = new NTVideoEntities())
         {
             return(context.Database.Exists());
         }
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
         return(false);
     }
 }
Esempio n. 13
0
 public ICollection <download> getEpisodesDownloadedInfo(int victimId)
 {
     try
     {
         using (var context = new NTVideoEntities())
         {
             var downloadInfoQuery = from d in context.downloads
                                     where d.victimId == victimId
                                     select d;
             return(downloadInfoQuery.ToList());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(new HashSet <download>());
     }
 }
Esempio n. 14
0
 private bool saveDownloadInfoToDB(download updateDownload, string name, string savePath, string status, dynamic movie, dynamic victim, NTVideoEntities context)
 {
     victim.downloadStatus = status;
     if (updateDownload == null)
     {
         var download = new download()
         {
             victimId = victim.victimId,
             name     = name,
             savePath = savePath,
             status   = status
         };
         victim.downloads.Add(download);
         context.Entry(victim).State = System.Data.Entity.EntityState.Modified;
     }
     else
     {
         updateDownload.status = status;
         context.Entry(updateDownload).State = System.Data.Entity.EntityState.Modified;
     }
     context.SaveChanges();
     return(true);
 }
Esempio n. 15
0
        public bool beginUpdateContent()
        {
            try
            {
                using (var context = new NTVideoEntities())
                {
                    var victimUpdateQuery = from m in context.movies
                                            from v in context.victims
                                            where m.movieId == v.movieId && m.isPublic == 1 && v.victimTypeNo == victimTypeNo && !(movieUpdatedTemp.Contains(v.movieDetailHref))
                                            orderby v.isContinue descending, m.publishYear descending, v.priority descending, v.viewed descending
                        select new { m, v };
                    var updateInfo = victimUpdateQuery.FirstOrDefault();
                    if (updateInfo != null)
                    {
                        updatePositionTypeOnHomePage(updateInfo.m);
                        context.Entry(updateInfo.m).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();
                        var victim       = updateInfo.v;
                        var victimUpdate = getVictim(getRootNode(victim.movieDetailHref.Replace("http://", "http://www.")));
                        if (victimUpdate != null)
                        {
                            if (victim.currentEpisode < victimUpdate.currentEpisode ||
                                victim.schedule != victimUpdate.schedule ||
                                victim.viewed < victimUpdate.viewed ||
                                victim.priority < victimUpdate.priority ||
                                victim.isTrailer != victimUpdate.isTrailer ||
                                victim.playListHtml != victim.playListHtml)
                            {
                                logForm.append("=====================   Begin update: " + victim.movieHref);
                                victim.dateUpdate     = victimUpdate.dateUpdate;
                                victim.currentEpisode = victimUpdate.currentEpisode;
                                victim.totalEpisode   = victimUpdate.totalEpisode;
                                victim.isContinue     = victimUpdate.isContinue;
                                victim.hasTrans       = victimUpdate.hasTrans;
                                victim.hasDubbing     = victimUpdate.hasDubbing;
                                victim.hasSub         = victimUpdate.hasSub;
                                victim.hasTrans       = victimUpdate.hasTrans;
                                victim.quality        = victimUpdate.quality;
                                victim.updateState    = victim.updateState + 1;
                                victim.viewed         = victimUpdate.viewed;
                                victim.rating         = victimUpdate.rating;
                                victim.schedule       = victimUpdate.schedule;
                                victim.isTrailer      = victimUpdate.isTrailer;
                                victim.playListHtml   = victimUpdate.playListHtml;

                                context.Entry(victim).State = System.Data.Entity.EntityState.Modified;
                                context.SaveChanges();
                            }
                        }
                        else
                        {
                            updateInfo.m.isPublic             = 0;
                            context.Entry(updateInfo.m).State = System.Data.Entity.EntityState.Modified;
                            context.SaveChanges();
                        }
                        movieUpdatedTemp.Add(victim.movieDetailHref);
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    logForm.append(String.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                 eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        logForm.append(String.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                     ve.PropertyName, ve.ErrorMessage));
                    }
                }
            }

            return(true);
        }