Exemplo n.º 1
0
        public void DoTask(string path)
        {
            try
            {
                var filename = path.Substring(path.LastIndexOf(@"\") + 1);
                var sp       = filename.Split('_');
                var feedId   = Convert.ToInt32(sp[0]);
                var content  = File.ReadAllText(path);

                var feed = JsonConvert.DeserializeObject <FeedSnapshot>(content);
                var url  = feed.Url;

                var urls = ExtractAddress(feed);

                var hisFile     = AppDomain.CurrentDomain.BaseDirectory + @"history\" + feedId + ".txt";
                var urlsHistory = new string[0];
                if (File.Exists(hisFile))
                {
                    urlsHistory = File.ReadAllLines(hisFile, Encoding.UTF8);
                }

                File.WriteAllLines(hisFile, urls, Encoding.UTF8);

                urls.RemoveAll(m => urlsHistory.Contains(m));
                urls.RemoveAll(m => string.IsNullOrEmpty(m));
                urls.RemoveAll(m => !Uri.IsWellFormedUriString(m, UriKind.Absolute));

                foreach (var u in urls)
                {
                    var qm = new QueueModel();
                    qm.FeedId = feedId;
                    qm.Url    = u;

                    ContentQueue.Instance.Enqueue(qm);
                }

                var destFile = path.Replace("snapshot", "pre").Replace(filename, feedId + ".txt");
                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }

                File.Move(path, destFile);
            }
            catch { }
        }
Exemplo n.º 2
0
 internal void Enqueue(QueueModel v)
 {
     queue.Enqueue(v);
 }