دریافت زمانبندی شده به روز رسانیهای آنتی ویروس Symantec به کمک کتابخانههای Quartz.NET و Html Agility Pack
نویسنده: سیروان عفیفی
تاریخ: ۱۳۹۲/۰۴/۰۳ ۸:۳۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
namespace SymantecUpdateDownloader
{
using System;
using System.IO;
using Quartz;
using Quartz.Impl;
using System.Globalization;
public class TestJob : IJob
{
public void Execute(IJobExecutionContext context)
{
new Download().Scraping();
}
}
public interface ISchedule
{
void Run();
}
public class TestSchedule : ISchedule
{
public void Run()
{
DateTimeOffset startTime = DateBuilder.FutureDate(2, IntervalUnit.Second);
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1")
.StartAt(startTime)
.WithDailyTimeIntervalSchedule(x => x.OnEveryDay().StartingDailyAt(new TimeOfDay(7, 0)).WithRepeatCount(0))
.Build();
ISchedulerFactory sf = new StdSchedulerFactory();
IScheduler sc = sf.GetScheduler();
sc.ScheduleJob(job, trigger);
sc.Start();
}
}
}public class Download
{
static WebClient wc = new WebClient();
static ManualResetEvent handle = new ManualResetEvent(true);
private DateTime myDate = new DateTime();
public void Scraping()
{
using (WebClient client = new WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
var doc = new HtmlAgilityPack.HtmlDocument();
ArrayList result = new ArrayList();
doc.LoadHtml(client.DownloadString("https://www.symantec.com/security_response/definitions/download/detail.jsp?gid=savce"));
var tasks = new List<Task>();
foreach (var href in doc.DocumentNode.Descendants("a").Select(x => x.Attributes["href"]))
{
if (href == null) continue;
string s = href.Value;
Match m = Regex.Match(s, @"http://definitions.symantec.com/defs/(\d{8}-\d{3}-v5i(32|64)\.exe)");
if (m.Success)
{
Match date = Regex.Match(m.Value, @"(\d{4})(\d{2})(\d{2})");
Match filename = Regex.Match(m.Value, @"\d{8}-\d{3}-v5i(32|64)\.exe");
int year = Int32.Parse(date.Groups[0].Value);
int month = Int32.Parse(date.Groups[1].Value);
int day = Int32.Parse(date.Groups[3].Value);
myDate = new DateTime(
Int32.Parse(date.Groups[1].Value),
Int32.Parse(date.Groups[2].Value),
Int32.Parse(date.Groups[3].Value));
if (myDate == DateTime.Today)
{
tasks.Add(DownloadUpdate(m.Value, filename.Value));
}
else
{
MessageBox.Show("امروز آپدیت موجود نیست");
}
}
}
DownloadTask = Task.WhenAll(tasks);
}
}
private static Task DownloadTask;
private Task DownloadUpdate(string url, string fileName)
{
var wc = new WebClient();
return wc.DownloadFileTaskAsync(new Uri(url), @"\\10.1.0.15\SymantecUpdate\\" + fileName);
}
}http://definitions.symantec.com/defs/20130622-007-v5i32.exe
http://definitions.symantec.com/defs/20130622-007-v5i64.exe
(\d{8}-\d{3}-v5i(32|64)\.exe)int year = Int32.Parse(date.Groups[0].Value); int month = Int32.Parse(date.Groups[1].Value); int day = Int32.Parse(date.Groups[3].Value);
IJobDetail job = JobBuilder.Create<HelloJob>()
SmObjectFactory.Container.GetInstance<MyClass>()