internal static List <NNTPInput> Parse(Stream xXML) { NNTPInput nI = null; List <NNTPInput> cList = new List <NNTPInput>(); try { XmlReader xR = XmlReader.Create(xXML, Common.ReaderSettings); while (xR.ReadToFollowing("file")) { nI = ParseSegments(xR.ReadSubtree(), xR.GetAttribute("subject")); if ((nI != null) && (nI.Segments.Count > 0)) { cList.Add(nI); } } } catch { return(null); } if (cList.Count == 0) { return(null); } else { return(cList); } }
private static NNTPInput ParseSegments(XmlReader sR, string Subject) { NNTPInput nI = null; try { nI = new NNTPInput(Subject); while (sR.ReadToFollowing("segment")) { int lBytes = 0; int lNumber = 0; while (sR.MoveToNextAttribute()) { switch (sR.Name.ToLower()) { case "bytes": lBytes = sR.ReadContentAsInt(); break; case "number": lNumber = sR.ReadContentAsInt(); break; } } sR.MoveToContent(); sR.Read(); string sMsgID = sR.Value; if (sMsgID.Length < 1) { return(null); } if ((lNumber > 0) && (lBytes > 0)) { nI.Segments.Add(new NNTPSegment(lNumber, lBytes, sMsgID)); } } } catch { return(null); } if ((nI != null) && (nI.Segments.Count > 0)) { return(nI); } return(null); }
//internal VirtualSlot Get(int ID) { lock (zServers) { return zServers.Slots.Item(ID); } } //public string Add(string Name, Stream NZB) //{ // // Asynchronous, returns the Slot ID // CancellationTokenSource vToken = null; // if (NZB == null) { return ""; } // if (Name == null) { return ""; } // if (Name.Length == 0) { return ""; } // //string SID = Module.RandomString(6); // Action aStart = (Action)(() => ImportNZB(Name, SID, zServers.Slots, NZB, vToken)); // Task zAdd = new Task(aStart, vToken.Token); // zAdd.Start(); // return SID; //} //public string Add(string Name, List<string> Commands) //{ // // Asynchronous, returns the Slot ID // int cI = 1; // if (Commands == null) { return ""; } // if (Commands.Count == 0) { return ""; } // NNTPInput nI = new NNTPInput(Name); // List<NNTPInput> cList = new List<NNTPInput>(); // foreach (string sC in Commands) // { // if (sC == null) { continue; } // if (sC.Length == 0) { continue; } // NNTPSegment nS = new NNTPSegment(); // nS.Index = cI; // nS.Command = sC; // nI.Segments.Add(nS); // } // if (nI.Segments.Count == 0) { return ""; } // cList.Add(nI); // //string SID = Module.RandomString(6); // CancellationTokenSource vToken = new CancellationTokenSource(); // Action aStart = (Action)(() => InternalAdd(nI.Name, SID, zServers.Slots, cList, vToken.Token)); // Task zAdd = new Task(aStart, vToken.Token); // zAdd.Start(); // return SID; //} public string Send(string Newsgroup, List <string> Command, CancellationTokenSource vToken = null) { // Synchronous, returns the last commands response if (Newsgroup == null) { throw new Exception("No group"); } if (Command == null) { throw new Exception("No command"); } if (zServers.Count == 0) { throw new Exception("No server"); } List <string> tList = new List <string>(); tList.Add("GROUP " + Newsgroup.ToLower()); tList.AddRange(Command); NNTPSegment nS = new NNTPSegment(); NNTPInput nI = new NNTPInput(""); List <NNTPInput> cList = new List <NNTPInput>(); nS.Index = 1; nS.Commands = tList; nI.Segments.Add(nS); cList.Add(nI); ManualResetEventSlim wHandle; wHandle = new ManualResetEventSlim(false); if (vToken == null) { vToken = new CancellationTokenSource(); } VirtualSlot vSlot = InternalAdd(nI.Name, zServers.Slots, cList, vToken.Token, wHandle); if (vSlot == null) { throw new Exception("No slot"); } if (vToken.Token.IsCancellationRequested) { throw new Exception("Cancelled"); } List <WaitHandle> wList = new List <WaitHandle>(); wList.Add(vToken.Token.WaitHandle); if (vSlot.WaitHandle == null) { throw new Exception("No waithandle"); } wList.Add(vSlot.WaitHandle.WaitHandle); vSlot.Status = SlotStatus.Downloading; Notify(); WaitHandle wRet = Common.WaitList(wList); if ((wRet == null) || (wRet.Handle == vToken.Token.WaitHandle.Handle)) { throw new Exception("Cancelled"); } if (vToken.Token.IsCancellationRequested) { throw new Exception("Cancelled"); } string zOut = null; if (vSlot.Status != SlotStatus.Completed) { if (vSlot.Status == SlotStatus.Failed) { zOut = vSlot.StatusLine; } else { zOut = Common.TranslateStatus((int)vSlot.Status); } int vId = vSlot.ID; vSlot = null; Remove(vId); if ((zOut == null) || (zOut.Length == 0)) { zOut = "Unknown"; } throw new Exception(zOut); } else { foreach (VirtualFile vFile in vSlot.List()) { if (vFile.Output == null) { continue; } if (vFile.Output.Data == null) { continue; } if (vFile.Output.Data.Length == 0) { continue; } vFile.Output.Data.Position = 0; zOut = Common.GetString(vFile.Output.Data); } int vId = vSlot.ID; vSlot = null; Remove(vId); return(zOut); } }