Пример #1
0
 public static void Load()
 {
     lock (queues)
     {
         var queueFile = Path.Combine(Config.DataDir, "queues.db");
         if (File.Exists(queueFile))
         {
             using var reader = new BinaryReader(new FileStream(queueFile, FileMode.Open));
             try
             {
                 QueueAutoNumber = reader.ReadInt32();
                 var count = reader.ReadInt32();
                 if (count > 0)
                 {
                     queues.Clear();
                 }
                 for (var i = 0; i < count; i++)
                 {
                     var version = reader.ReadInt32();
                     var queue   = DownloadQueue.Deserialize(version, reader);
                     queues.Add(queue);
                 }
             }
             catch (Exception ex)
             {
                 Log.Debug(ex, ex.Message);
             }
             if (queues.Count == 0)
             {
                 queues.Add(new DownloadQueue(Guid.NewGuid().ToString(), "Default queue"));
             }
         }
     }
 }
Пример #2
0
        private void ProcessScheduledItem(DownloadQueue queue)
        {
            if (queue.Schedule != null)
            {
                //Log.Debug("Queue " + queue + " has schedule: " + queue.Schedule.HasValue);
                var day = queue.Schedule.Value.Days;

                if ((DateTime.Now.DayOfWeek == DayOfWeek.Sunday && HasFlag(day, WeekDays.Sun)) ||
                    (DateTime.Now.DayOfWeek == DayOfWeek.Monday && HasFlag(day, WeekDays.Mon)) ||
                    (DateTime.Now.DayOfWeek == DayOfWeek.Tuesday && HasFlag(day, WeekDays.Tue)) ||
                    (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday && HasFlag(day, WeekDays.Wed)) ||
                    (DateTime.Now.DayOfWeek == DayOfWeek.Thursday && HasFlag(day, WeekDays.Thu)) ||
                    (DateTime.Now.DayOfWeek == DayOfWeek.Friday && HasFlag(day, WeekDays.Fri)) ||
                    (DateTime.Now.DayOfWeek == DayOfWeek.Saturday && HasFlag(day, WeekDays.Sat)))
                {
                    StartOrStopItem(queue);
                }
            }
        }
Пример #3
0
        private void StartOrStopItem(DownloadQueue item)
        {
            var h1 = DateTime.Now.TimeOfDay.Hours;
            var m1 = DateTime.Now.TimeOfDay.Minutes;
            var h2 = item.Schedule !.Value.EndTime.Hours;
            var m2 = item.Schedule !.Value.EndTime.Minutes;
            var h3 = item.Schedule !.Value.StartTime.Hours;
            var m3 = item.Schedule !.Value.StartTime.Minutes;

            //Log.Debug("DateTime.Now.TimeOfDay: " + DateTime.Now.TimeOfDay
            //    + "\nitem.Schedule!.Value.StartTime: "
            //    + item.Schedule!.Value.StartTime
            //    + "\nitem.Schedule!.Value.EndTime: "
            //    + item.Schedule!.Value.EndTime);

            if (h1 == h2 && m1 == m2)
            {
                ApplicationContext.CoreService.StopDownloads(new List <string>(item.DownloadIds), true);
                this.activeSchedules.Remove(item.ID);
                return;
            }

            if (h1 == h3 && m1 == m3)
            {
                if (this.activeSchedules.Contains(item.ID))
                {
                    return;
                }
                this.activeSchedules.Add(item.ID);
                var dict = new Dictionary <string, DownloadItemBase>();
                foreach (var id in item.DownloadIds)
                {
                    var ent = AppDB.Instance.Downloads.GetDownloadById(id);// ApplicationContext.Core.AppUI.GetInProgressDownloadEntry(id);
                    if (ent != null)
                    {
                        dict[id] = ent;
                    }
                }
                ApplicationContext.CoreService.ResumeDownload(dict, nonInteractive: true);
            }
        }