Beispiel #1
0
 public ScheduledGrab Clone()
 {
     var clone= new ScheduledGrab()
                {
                    GrabID = this.GrabID,
                    GrabMode = this.GrabMode,
                    GrabParams = this.GrabParams,
                    GrabSchedule = this.GrabSchedule,
                    Interval = this.Interval,
                    IsActive = this.IsActive,
                    Name = this.Name,
                    GrabSource=this.GrabSource
                };
     return clone;
 }
Beispiel #2
0
 public WinAddJob()
 {
     InitializeComponent();
     CurrentGrab = new ScheduledGrab();
 }
Beispiel #3
0
 public WinAddJob(ScheduledGrab url)
     : this()
 {
     this.CurrentGrab = url;
     this.Title = "Edit Job";
 }
Beispiel #4
0
 public void EditScheduledGrab(ScheduledGrab grab)
 {
     Execute(conn =>
     {
         using (SQLiteCommand cmd = conn.CreateCommand())
         {
             cmd.CommandText = "UPDATE ScheduledGrabs SET Interval  = @Interval, Name = @Name, IsActive = @IsActive, Schedule = @Schedule, Mode = @Mode, Source = @Source, Parameters = @Parameters WHERE GrabID = @GrabID";
             cmd.Parameters.AddWithValue("@GrabID", grab.GrabID);
             cmd.Parameters.AddWithValue("@Interval", grab.Interval);
             cmd.Parameters.AddWithValue("@Name", grab.Name);
             cmd.Parameters.AddWithValue("@IsActive", grab.IsActive);
             cmd.Parameters.AddWithValue("@Schedule", grab.GrabSchedule);
             cmd.Parameters.AddWithValue("@Mode", grab.GrabMode);
             cmd.Parameters.AddWithValue("@Source", grab.GrabSource);
             cmd.Parameters.AddWithValue("@Parameters",grab.GrabParams.Serialize());
             cmd.ExecuteNonQuery();
         }
     });
 }
Beispiel #5
0
 private ScheduledGrab GetScheduledGrab(SQLiteDataReader reader)
 {
     ScheduledGrab grab = new ScheduledGrab()
     {
         GrabID = Convert.ToInt32(reader["GrabID"]),
         GrabParams = GrabEventArgs.Deserialize(Convert.ToString(reader["Parameters"])),
         GrabMode = (Constants.GrabModes)Enum.Parse(typeof(Constants.GrabModes), Convert.ToString(reader["Mode"]), true),
         GrabSource = (Constants.GrabSource)Enum.Parse(typeof(Constants.GrabSource), Convert.ToString(reader["Source"]), true),
         GrabSchedule = (Constants.GrabSchedules)Enum.Parse(typeof(Constants.GrabSchedules), Convert.ToString(reader["Schedule"]), true),
         Interval = Convert.ToInt32(reader["Interval"]),
         IsActive = Convert.ToChar(reader["IsActive"]) == '1',
         Name = Convert.ToString(reader["Name"]),
     };
     return grab;
 }
Beispiel #6
0
        /// <summary>
        /// Duplicates grabs for a range of URLs.
        /// </summary>
        /// <param name="grabToDuplicate">The grab to duplicate.</param>
        /// <param name="urls">The urls.</param>
        public void DuplicateGrabs(ScheduledGrab grabToDuplicate, IEnumerable<string> urls)
        {
            List<string> jobNames = new List<string>();
            Execute(conn =>
            {
                using (SQLiteCommand cmd = conn.CreateCommand()) {
                    StringBuilder cmdBuffer = new StringBuilder("SELECT Name FROM ScheduledGrabs ");
                    cmd.CommandText = cmdBuffer.ToString();
                    cmd.ExecuteNonQuery();

                    SQLiteDataReader reader = cmd.ExecuteReader();
                    while (reader.Read()) {
                        try
                        {
                            string name = Convert.ToString(reader[0]);
                            jobNames.Add(name);
                        } catch (Exception ex) {
                            Console.WriteLine("Error loading job name:" + ex.Message);
                        }
                    }
                    reader.Close();
                }
            });
            List<ScheduledGrab> newGrabs = new List<ScheduledGrab>();
            foreach(var urlToGrab in urls)
            {
                if(string.IsNullOrWhiteSpace(urlToGrab))
                    continue;
                var clone = grabToDuplicate.Clone();
                //clone.GrabParams.Url = new GrabbableUrl(urlToGrab);
                clone.GrabParams = new GrabEventArgs(new GrabbableUrl(urlToGrab), string.Empty) { GrabExpression = grabToDuplicate.GrabParams.GrabExpression };
                var newName = Utils.GetNextAvailableName(clone.Name, jobNames);
                clone.Name = newName;
                jobNames.Add(newName);
                newGrabs.Add(clone);
                Console.WriteLine(clone.GrabParams.Url);
            }
            AddScheduledGrabs(newGrabs);
        }
Beispiel #7
0
        public void DeleteScheduledGrab(ScheduledGrab grab)
        {
            Execute(conn =>
            {
                using (SQLiteCommand cmd = conn.CreateCommand())
                {
                    cmd.Parameters.AddWithValue("@GrabID", grab.GrabID);

                    cmd.CommandText = "DELETE FROM GrabHistory WHERE GrabID = @GrabID";
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "DELETE FROM ScheduledGrabs WHERE GrabID = @GrabID";
                    cmd.ExecuteNonQuery();
                }
            });
        }
Beispiel #8
0
 public GrabJob(ScheduledGrab grab)
     : this()
 {
     this.ScheduledGrab = grab;
 }
Beispiel #9
0
 public GrabbedJob(ScheduledGrab grab, GrabResponse response)
     : base(grab)
 {
     GrabDate = DateTime.Now;
         this.Response = response;
 }
Beispiel #10
0
 /// <summary>
 /// Grabs a single url.
 /// </summary>
 /// <param name="scheduledGrab">The scheduled grab.</param>
 public void GrabSingle(ScheduledGrab scheduledGrab)
 {
     GrabUrls(new[]{scheduledGrab});
 }