Ejemplo n.º 1
0
        protected void Processing()
        {
            while (ProcessorAlive)
            {
                try
                {
                    lock (NewTorrents)
                    {
                        foreach (var torrent in NewTorrents.Where(nt => !ProcessedTorrents.Any(pt => nt.Name == pt.Name)))
                        {
                            try
                            {
                                var uri      = new Uri(torrent.Url);
                                var request  = (HttpWebRequest)WebRequest.Create(uri);
                                var response = (HttpWebResponse)request.GetResponse();
                                using (var rStream = response.GetResponseStream())
                                {
                                    if (rStream != null)
                                    {
                                        var    reader     = new StreamReader(rStream, Encoding.Default);
                                        Stream fileStream = File.OpenWrite(TorrentPath + torrent.Name + ".torrent");
                                        using (var sw = new StreamWriter(fileStream, Encoding.Default))
                                        {
                                            sw.Write(reader.ReadToEnd());
                                            sw.Flush();
                                            sw.Close();
                                        }
                                    }
                                }

                                ProcessedTorrents.AddProcessed(torrent);
                            }
                            catch (Exception ex)
                            {
                                Logger.LogMessage(System.Diagnostics.EventLogEntryType.Error, GlobalResources.EVENTSOURCE, ex.GetMessage("Processing.InForEach"), 0);
                            }
                        }

                        NewTorrents.Clear();
                    }

                    Sleep(10000);
                }
                catch (Exception ex)
                {
                    Logger.LogMessage(System.Diagnostics.EventLogEntryType.Error, GlobalResources.EVENTSOURCE, ex.GetMessage("Processing.OutsideForEach"), 1);
                }
            }
        }
Ejemplo n.º 2
0
        protected void Collection()
        {
            string tempfile = ExecutionPath + "temp.file";

            while (ProcessorAlive)
            {
                try
                {
                    var tempCollection = new TorrentCollection();
                    var uri            = new Uri(Url);
                    var request        = (HttpWebRequest)WebRequest.Create(uri);
                    var response       = (HttpWebResponse)request.GetResponse();
                    var rStream        = response.GetResponseStream();
                    if (rStream != null)
                    {
                        var reader = new StreamReader(rStream, Encoding.Default);
                        using (Stream fileStream = File.OpenWrite(tempfile))
                        {
                            using (var sw = new StreamWriter(fileStream, Encoding.Default))
                            {
                                sw.Write(reader.ReadToEnd());
                                sw.Flush();
                                sw.Close();
                            }
                        }

                        var lines = File.ReadAllLines(tempfile);

                        for (var i = 0; i < lines.Length; i++)
                        {
                            var torrent = new Torrent();

                            if (lines[i].IndexOf("forum_header_border") > -1)
                            {
                                while (lines[i].IndexOf("epinfo") < 0)
                                {
                                    i++;
                                }
                                int startindex = lines[i].IndexOf("title=\"", 0);
                                if (startindex > -1)
                                {
                                    int length = lines[i].IndexOf("\"", startindex + 10) - startindex;
                                    torrent.Name = lines[i].Substring(startindex + 7, length - 7);
                                }
                                while (lines[i].IndexOf("download_1") < 0)
                                {
                                    i++;
                                }

                                var splitlinks = lines[i].Replace("</a>", "|").Split('|');

                                foreach (
                                    var link in
                                    splitlinks.Where(
                                        link => link.IndexOf("download") > -1 && link.IndexOf(".torrent") > -1))
                                {
                                    startindex = link.IndexOf("href=\"", 0);
                                    if (startindex > -1)
                                    {
                                        var length = link.IndexOf("\"", startindex + 8) - startindex;
                                        torrent.Url = link.Substring(startindex + 6, length - 6);
                                        break;
                                    }
                                }
                            }

                            if (torrent.Name != null)
                            {
                                if (SearchCollection.Any(sk => torrent.Name.ContainsSearchKey(sk)))
                                {
                                    tempCollection.Add(torrent);
                                }
                            }
                        }
                    }

                    NewTorrents.AddRange(tempCollection);
                    tempCollection.Clear();
                }
                catch (Exception ex)
                {
                    Logger.LogMessage(System.Diagnostics.EventLogEntryType.Error, GlobalResources.EVENTSOURCE, ex.GetMessage("Collection"), 0);
                }
                Sleep(10000);
            }
        }