コード例 #1
0
ファイル: NntpProvider.cs プロジェクト: kayone/SharpNZB
        private string GetGroup(NzbSegmentModel segment)
        {
            var queue = _nzbQueue.AllItems();

            foreach (var nzb in queue)
            {
                return((from f in nzb.Files where f.Name == segment.NzbFileName select f.Groups[0]).FirstOrDefault());
            }

            throw new NotImplementedException("NntpProvider - GetGroup");
        }
コード例 #2
0
        public void GetArticle(NzbSegmentModel segment)
        {
            _segment          = segment;
            _connectionThread = new Thread(DoGetArticle)
            {
                Name     = "ConnectionThread " + _connectionId,
                Priority = ThreadPriority.Normal
            };

            _start = CurrentMilliseconds;
            _connectionThread.Start();
        }
コード例 #3
0
        private void ServerResponse(NzbSegmentModel segment, string expect = null)
        {
            byte[] buffer = new byte[1024 * 3];
            int    i      = 0;
            var    bytes  = -1;

            segment.Storage = new MemoryStream();

            do
            {
                i    += 1;
                bytes = _stream.Read(buffer, 0, buffer.Length); // read from server with buffer
                segment.Storage.Write(buffer, 0, bytes);        // write network buffer to memorystream

                if (i == 1 && expect != null)
                {
                    if (!Encoding.ASCII.GetString(buffer).StartsWith(expect))
                    {
                        segment.Storage.Close();
                        return;
                    }
                }
                Throttle(buffer.Length);
            } while (StillDownloading(ref bytes, ref buffer));

            if (segment.Storage.Length > 5)
            {
                segment.Storage.SetLength(segment.Storage.Length - 5); //Trim out "\r\n/\r\n" from end of Stream
                segment.Storage.Position = 0;                          //Set Position to 0 before using, or Stream will be incomplete.

                //Testing
                SaveMemoryStream(segment.Storage, "storage\\" + segment.SegmentId);
                segment.Storage.Position = 0; //Set Position to 0 before using, or Stream will be incomplete.
                //End Testing

                segment.Status = NzbSegmentStatus.Downloaded;
                OnArticleFinished(); //Trigger the Event saying this connection is finished with the current segment
            }
        }
コード例 #4
0
        public NzbModel Process(NzbImportModel import)
        {
            XNamespace ns = "http://www.newzbin.com/DTD/2003/nzb";

            import.Stream.Seek(0, SeekOrigin.Begin);
            XDocument xDoc = XDocument.Load(import.Stream);

            var nzb = from n in xDoc.Descendants(ns + "nzb") select n;

            if (nzb.Count() != 1)
            {
                return(null);
            }

            NzbModel newNzb = new NzbModel();

            newNzb.Name           = !String.IsNullOrEmpty(import.NewName) ? import.NewName : import.Name;
            newNzb.Id             = Guid.NewGuid();
            newNzb.Status         = NzbStatus.Queued;
            newNzb.Priority       = (Priority)import.Priority;
            newNzb.Script         = import.Script;
            newNzb.Category       = import.Category;
            newNzb.PostProcessing = GetPostProcessing(import);

            var nzbFileList = new List <NzbFileModel>();

            //Get all the files for this NZB
            var files = from f in nzb.Elements(ns + "file") select f;

            foreach (var file in files)
            {
                var nzbFile = new NzbFileModel();
                nzbFile.Status = NzbFileStatus.Queued;
                nzbFile.NzbId  = newNzb.Id;
                var segmentList = new List <NzbSegmentModel>();

                //Get the Age of the File and Convert to DateTime
                var date = Convert.ToInt64((from d in file.Attributes("date") select d.Value).FirstOrDefault());
                nzbFile.DatePosted = TicksToDateTime(date);

                //Get the Subject and set the NzbFile's Filename
                var subject       = (from s in file.Attributes("subject") select s).FirstOrDefault();
                int fileNameStart = subject.Value.IndexOf("\"") + 1;
                int fileNameEnd   = subject.Value.LastIndexOf("\"") - fileNameStart;
                nzbFile.Filename = subject.Value.Substring(fileNameStart, fileNameEnd);

                //Get the groups for the NzbFile
                nzbFile.Groups = (from g in file.Descendants(ns + "group") select g.Value).ToList();

                //Get the Segments for this file
                var segments = from s in file.Descendants(ns + "segment") select s;
                foreach (var segment in segments)
                {
                    var nzbFileSegment = new NzbSegmentModel();
                    nzbFileSegment.Status      = NzbSegmentStatus.Queued;
                    nzbFileSegment.NzbFileName = nzbFile.Name;
                    nzbFileSegment.Number      = Convert.ToInt32((from n in segment.Attributes("number") select n.Value).FirstOrDefault());
                    nzbFileSegment.Size        = Convert.ToInt64((from n in segment.Attributes("bytes") select n.Value).FirstOrDefault());
                    nzbFileSegment.SegmentId   = segment.Value;
                    segmentList.Add(nzbFileSegment);
                }
                nzbFile.Segments = segmentList;
                nzbFileList.Add(nzbFile);
            }
            newNzb.Files = nzbFileList;
            return(newNzb);
        }