/// <summary> /// Parse the xml string into a RssFeed object /// </summary> /// <param name="xml"></param> /// <returns></returns> public static RssFeed LoadFeed(string xml) { XDocument doc; try { doc = XDocument.Parse(xml); } catch (Exception ex) { throw new NotSupportedFeedException("Not Supported", ex); } RssType type = BaseReader.GetFeedType(doc); BaseReader reader; switch (type) { case RssType.Atom: reader = new AtomReader(); break; case RssType.Rdf: reader = new RDFReader(); break; default: reader = new Reader(); break; } return reader.LoadFeed(doc); }
/// <summary> /// Starts loading the feed and initializing the reader for the feed type. /// </summary> /// <returns></returns> public async Task<ObservableCollection<RssSchema>> Load() { string xmlContent = await DownloadAsync(); var doc = XDocument.Parse(xmlContent); var type = BaseRssReader.GetFeedType(doc); BaseRssReader rssReader; if (type == RssType.Rss) rssReader = new RssReader(); else rssReader = new AtomReader(); return rssReader.LoadFeed(doc); }
public static void Main(string[] args) { if (Config == null) { Config = new Config(); } try { string DirPath = Config.ReConfig.ReNameDirPath; DirectoryInfo directory = new DirectoryInfo(DirPath); FileInfo[] files = directory.GetFiles(); List <string> oriNames = new List <string>(); Dictionary <string, string> newNames = new Dictionary <string, string>(); foreach (FileInfo info in files) { using (FileStream stream = info.Open(FileMode.Open)) { bool IsArt = false; bool IsName = false; #region Get Mp4 Info var mp4Reader = new AtomReader(stream); string value = mp4Reader.GetMetaAtomValue(AtomReader.TitleTypeName); string value2 = mp4Reader.GetMetaAtomValue(AtomReader.IlstTypeName); string value3 = mp4Reader.GetMetaAtomValue(AtomReader.MetaTypeName); #endregion string songName = ""; string AuthorName = ""; value3 = value3.Replace("\0", ""); value3 = value3.Replace("\u0001", ""); string[] list = value3.Split("data"); if (list != null) { foreach (string s in list) { string x = s; #region Art Tag if (IsArt) { IsArt = !IsArt; if (hasQuesMarkTag(s)) { if (hasTooTag(s)) { int too = s.ToLower().IndexOf("too"); AuthorName = CheckVaildFileName(s.Substring(0, too - 2)); } else { x = s.Replace("�", "?"); int test = x.IndexOf("?"); AuthorName = CheckVaildFileName(s.Substring(0, test - 1)); } } else { AuthorName = CheckVaildFileName(s); } Console.WriteLine("歌手名 : " + AuthorName); } if (hasArtTag(s)) { IsArt = true; } #endregion #region Nam Tag if (IsName) { IsName = !IsName; if (hasQuesMarkTag(s)) { if (hasArtTag(s)) { int art = s.ToLower().IndexOf("art"); songName = CheckVaildFileName(s.Substring(0, art - 2)); } else { x = s.Replace("�", "?"); int test = x.IndexOf("?"); songName = CheckVaildFileName(s.Substring(0, test - 1)); } } else { songName = CheckVaildFileName(s); } Console.WriteLine("歌曲名 : " + songName); } if (hasNamTag(s)) { IsName = true; } #endregion } Console.WriteLine("========================="); } oriNames.Add(info.FullName); newNames.Add(info.FullName, AuthorName + "-" + songName); } } foreach (string oriName in oriNames) { try { if (File.Exists(oriName)) { string strResult = DirPath + newNames[oriName] + ".mp4"; if (!File.Exists(DirPath + strResult)) { File.Move(oriName, strResult); } } else { Console.WriteLine("oriName ..."); } } catch (Exception ex) { Console.WriteLine("==================================="); Console.WriteLine( "舊檔案檔案名稱 : " + oriName + "\r\n" + "新檔案檔案名稱 : " + newNames[oriName] + "\r\n" + "錯誤訊息 : " + ex.Message); } } } catch (Exception ex) { Console.WriteLine("檔名轉換出錯:" + ex.Message); } Console.WriteLine("========================="); Console.WriteLine("全部執行結束 請按任意鍵退出視窗"); Console.ReadKey(); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="Stream"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="stream">The <see cref="Stream"/> containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(Stream stream) { _reader = new AtomReader(stream); return(Parse(_reader.Navigator)); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="XmlReader"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="reader">The <see cref="XmlReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(XmlReader reader) { _reader = new AtomReader(reader); return(Parse(_reader.Navigator)); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified xml fragment. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="xmlFragment">The string containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry LoadXml(string xmlFragment) { XmlTextReader xmlReader = new XmlTextReader(xmlFragment, XmlNodeType.Element, null); _reader = new AtomReader(xmlReader); return Parse(_reader.Navigator); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="WebRequest"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="request">The <see cref="HttpWebRequest"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(WebRequest request) { _reader = new AtomReader(request.RequestUri.ToString()); return Parse(_reader.Navigator); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="Stream"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="stream">The <see cref="Stream"/> containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(Stream stream) { _reader = new AtomReader(stream); return Parse(_reader.Navigator); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="Stream"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="stream">The <see cref="Stream"/> containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(Stream stream, Uri ns) { _reader = new AtomReader(stream, ns); return Parse(_reader.Navigator, ns); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified URI. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="uri">The URI of the resource containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(string uri, Uri ns) { _reader = new AtomReader(uri, ns); return Parse(_reader.Navigator, ns); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="XmlReader"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="reader">The <see cref="XmlReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(XmlReader reader, Uri ns) { _reader = new AtomReader(reader, ns); return(Parse(_reader.Navigator, ns)); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="HttpWebRequest"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="request">The <see cref="WebRequest"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(WebRequest request, Uri ns) { _reader = new AtomReader(request.RequestUri.ToString(), ns); return(Parse(_reader.Navigator, ns)); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="TextReader"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="tr">The <see cref="TextReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(TextReader tr, Uri ns) { _reader = new AtomReader(tr, ns); return(Parse(_reader.Navigator, ns)); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="Stream"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="stream">The <see cref="Stream"/> containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(Stream stream, Uri ns) { _reader = new AtomReader(stream, ns); return(Parse(_reader.Navigator, ns)); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified URI. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="uri">The URI of the resource containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(string uri, Uri ns) { _reader = new AtomReader(uri, ns); return(Parse(_reader.Navigator, ns)); }
private void AnnounceThreadProc() { Logger.Debug("Thread started"); var host = Uri.DnsSafeHost; var port = Uri.Port; if (port < 0) { port = DefaultPort; } while (!IsStopped) { int next_update = Environment.TickCount; posts.Clear(); try { Logger.Debug("Connecting to YP"); AnnouncingStatus = AnnouncingStatus.Connecting; using (var client = new TcpClient(host, port)) { using (var stream = client.GetStream()) { AtomWriter.Write(stream, new Atom(new ID4("pcp\n"), (int)1)); var helo = new AtomCollection(); Logger.Debug("Sending Handshake"); helo.SetHeloAgent(PeerCast.AgentName); helo.SetHeloVersion(1218); helo.SetHeloSessionID(PeerCast.SessionID); helo.SetHeloBCID(PeerCast.BroadcastID); if (PeerCast.IsFirewalled.HasValue) { if (PeerCast.IsFirewalled.Value) { //Do nothing } else { var listener = PeerCast.FindListener( ((IPEndPoint)client.Client.RemoteEndPoint).Address, OutputStreamType.Relay | OutputStreamType.Metadata); if (listener != null) { helo.SetHeloPort(listener.LocalEndPoint.Port); } } } else { var listener = PeerCast.FindListener( ((IPEndPoint)client.Client.RemoteEndPoint).Address, OutputStreamType.Relay | OutputStreamType.Metadata); if (listener != null) { helo.SetHeloPing(listener.LocalEndPoint.Port); } } AtomWriter.Write(stream, new Atom(Atom.PCP_HELO, helo)); while (!IsStopped) { var atom = AtomReader.Read(stream); if (atom.Name == Atom.PCP_OLEH) { OnPCPOleh(atom); break; } else if (atom.Name == Atom.PCP_QUIT) { Logger.Debug("Handshake aborted by PCP_QUIT ({0})", atom.GetInt32()); throw new QuitException(); } if (restartEvent.WaitOne(10)) { throw new RestartException(); } } Logger.Debug("Handshake succeeded"); AnnouncingStatus = AnnouncingStatus.Connected; while (!IsStopped) { if (next_update - Environment.TickCount <= 0) { Logger.Debug("Sending channel info"); lock (announcingChannels) { foreach (var announcing in announcingChannels) { PostChannelBcst(announcing.Channel, true); } } next_update = Environment.TickCount + 30000; } if (stream.DataAvailable) { Atom atom = AtomReader.Read(stream); ProcessAtom(atom); } lock (posts) { foreach (var atom in posts) { AtomWriter.Write(stream, atom); } posts.Clear(); } if (restartEvent.WaitOne(10)) { throw new RestartException(); } } lock (posts) { foreach (var atom in posts) { AtomWriter.Write(stream, atom); } posts.Clear(); } Logger.Debug("Closing connection"); AtomWriter.Write(stream, new Atom(Atom.PCP_QUIT, Atom.PCP_ERROR_QUIT)); } } } catch (RestartException) { Logger.Debug("Connection retrying"); AnnouncingStatus = AnnouncingStatus.Connecting; } catch (BannedException) { AnnouncingStatus = AnnouncingStatus.Error; Logger.Error("Your BCID is banned"); break; } catch (QuitException) { AnnouncingStatus = AnnouncingStatus.Error; } catch (SocketException e) { AnnouncingStatus = AnnouncingStatus.Error; Logger.Info(e); } catch (IOException e) { AnnouncingStatus = AnnouncingStatus.Error; Logger.Info(e); } Logger.Debug("Connection closed"); if (!IsStopped) { restartEvent.WaitOne(10000); } else { AnnouncingStatus = AnnouncingStatus.Idle; } } Logger.Debug("Thread finished"); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified URI. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="uri">The URI of the resource containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(string uri) { _reader = new AtomReader(uri); return Parse(_reader.Navigator); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="TextReader"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="tr">The <see cref="TextReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(TextReader tr, Uri ns) { _reader = new AtomReader(tr, ns); return Parse(_reader.Navigator, ns); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="TextReader"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="tr">The <see cref="TextReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(TextReader tr) { _reader = new AtomReader(tr); return Parse(_reader.Navigator); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="HttpWebRequest"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="request">The <see cref="WebRequest"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(WebRequest request, Uri ns) { _reader = new AtomReader(request.RequestUri.ToString(), ns); return Parse(_reader.Navigator, ns); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="XmlReader"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="reader">The <see cref="XmlReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(XmlReader reader) { _reader = new AtomReader(reader); return Parse(_reader.Navigator); }
/// <summary> /// Loads the <see cref="AtomFeed"/> from the specified <see cref="XmlReader"/>. /// </summary> /// <returns>An <see cref="AtomFeed"/> instance.</returns> /// <param name="reader">The <see cref="XmlReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomFeed Load(XmlReader reader, Uri ns) { _reader = new AtomReader(reader, ns); return Parse(_reader.Navigator, ns); }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="WebRequest"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="request">The <see cref="HttpWebRequest"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(WebRequest request) { _reader = new AtomReader(request.RequestUri.ToString()); return(Parse(_reader.Navigator)); }
public void SubmitBatch() { bool needToLeave = false; busy = true; try { // used to block the Terminate from BizTalk if (!this.control.Enter()) { needToLeave = false; return; } needToLeave = true; AtomReader atom = new AtomReader(XmlReader.Create(this.properties.Uri), atomState.LastEntryId, atomState.LastUpdated); Stack <Queue <Entry> > stk = atom.Entries(); bool leave = false; while (stk.Count > 0) { Queue <Entry> queueEntry = stk.Pop(); while (queueEntry.Count > 0) { Entry entry = queueEntry.Dequeue(); if (SubmitMessage(entry) == false) { leave = true; } } if (leave == true) { break; } } atomState.LastUpdated = atom.LastUpdate; // no exception in Done so we will be getting a BatchComplete which will do the necessary Leave needToLeave = false; } catch (Exception e) { this.transportProxy.SetErrorInfo(e); } finally { busy = false; // if this is true there must have been some exception in or before Done if (needToLeave) { this.control.Leave(); } } }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified URI. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="uri">The URI of the resource containing the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(string uri) { _reader = new AtomReader(uri); return(Parse(_reader.Navigator)); }
public void ProcessBatch() { bool needToLeave = false; busy = true; try { // used to block the Terminate from BizTalk if (!this.control.Enter()) { needToLeave = false; return; } needToLeave = true; StateSettings stateSettings = new StateSettings(); stateSettings.FindFirst = this.properties.FirdFirst; stateSettings.WorkingFeed = this.properties.FirstFeed; stateSettings.Id = atomState.LastEntryId; AtomReader atom = new AtomReader(this.properties.Uri, stateSettings, this.properties.SecuritySettings, this.properties.FeedMax); Feed feed = null; bool discard = atom.IdFound; string stateId = atomState.LastEntryId; string lastId = String.Empty; while ((feed = atom.NextFeed()) != null && feed.Entries.Count > 0) { ManualResetEvent orderedEvent = null; CommittableTransaction transaction = null; //using (SyncReceiveSubmitBatch batch = new SyncReceiveSubmitBatch(this.transportProxy, this.control, 1)) Entry entry = feed.Entries.PopOrNUll(); while (entry != null) { if (discard == false) { orderedEvent = new ManualResetEvent(false); transaction = new CommittableTransaction(); atomState.LastEntryId = entry.Id; atomState.LastUpdated = feed.Updated; atomState.LastFeed = feed.Uri; SaveState(transaction); using (SingleMessageReceiveTxnBatch batch = new SingleMessageReceiveTxnBatch(this.transportProxy, this.control, transaction, orderedEvent)) { batch.SubmitMessage(CreateMessage(entry)); batch.Done(); orderedEvent.WaitOne(); } } if (stateId == entry.Id) { discard = false; } entry = feed.Entries.PopOrNUll(); } } // no exception in Done so we will be getting a BatchComplete which will do the necessary Leave needToLeave = false; } catch (MaxDeepthException deepth) { this.transportProxy.ReceiverShuttingdown(this.properties.Uri, deepth); } catch (InvalidConfiguration arg) { this.transportProxy.ReceiverShuttingdown(this.properties.Uri, arg); } catch (WebException ex) { this.transportProxy.ReceiverShuttingdown(this.properties.Uri, ex); } catch (Exception e) { this.transportProxy.SetErrorInfo(e); } finally { busy = false; // if this is true there must have been some exception in or before Done if (needToLeave) { this.control.Leave(); } } }
/// <summary> /// Loads the <see cref="AtomEntry"/> from the specified <see cref="TextReader"/>. /// </summary> /// <returns>An <see cref="AtomEntry"/> instance.</returns> /// <param name="tr">The <see cref="TextReader"/> from which read the Atom xml data.</param> /// <exception cref="XmlException">Invalid xml syntax in Atom resource or uri is null.</exception> /// <exception cref="ArgumentException">The resource cannot be find.</exception> /// <exception cref="InvalidOperationException"><see cref="AtomReader"/> has been closed, and can not be read.</exception> /// <exception cref="FileNotFoundException">Atom xml resource not found.</exception> public static AtomEntry Load(TextReader tr) { _reader = new AtomReader(tr); return(Parse(_reader.Navigator)); }
static void Main(string[] args) { string test = null; string root = @"C:\atom\"; //string filename = "recent.xml"; string filename = "state.xml"; Console.WriteLine("START..."); // FileStream stm = new FileStream(root + filename, FileMode.CreateNew); X509Certificate2 ClientCertificate = CertificateStore.GetCertByThumbprint("b6e3448a8d92572cc9273b833f0d08248da681e7"); string Id = "23acff5e-0be0-11e8-8f5b-0f7a53ac4427"; string initFeed = "https://api.mit-integration.ladok.se:443/uppfoljning/feed/276367"; //inner state cannot be the same as stae i reader .... StateSettings state = new StateSettings { Id = Id, WorkingFeed = initFeed, LastUpdated = DateTime.Parse("2018-01-15T08:27:42.873Z") }; AtomReader atom = new AtomReader("https://api.mit-integration.ladok.se/uppfoljning/feed/recent", state, new SecuritySettings { ClientCertificate = CertificateStore.GetCertByThumbprint("b6e3448a8d92572cc9273b833f0d08248da681e7") }, 2); //atom.MoveToFirstFeed(); Feed feed = null; bool discard = atom.IdFound; while ((feed = atom.NextFeed()) != null && feed.Entries.Count > 0) { Console.WriteLine("FEED"); Console.WriteLine(feed.Uri); Entry entry = feed.Entries.PopOrNUll(); while (entry != null) { //atom.IdFound == true discard all until id is found if (discard == true) { Console.WriteLine(String.Format("DISCARD...{0} {1}", entry.Updated, entry.Id)); } else { Console.WriteLine(String.Format("PROCESS...{0} {1}", entry.Updated, entry.Id)); } if (Id == entry.Id) { discard = false; } entry = feed.Entries.PopOrNUll(); } } /* * Stack<Queue<Entry>> stk = atom.Entries(); * * * while (stk.Count > 0) * { * Queue<Entry> queueEntry = stk.Pop(); * * while (queueEntry.Count > 0) * { * Entry entry = queueEntry.Dequeue(); * * File.AppendAllText(String.Format("{0}{1}.xml", root, entry.Id), entry.Content); * * } * * * * } */ /* * BizTalk.Adapter.Atom.AtomState atom = new BizTalk.Adapter.Atom.AtomState(); * atom.LastEntryId = "1234"; * atom.LastUpdated = DateTime.Now; * * XmlSerializer atomstate = new XmlSerializer(typeof(BizTalk.Adapter.Atom.AtomState)); * * atomstate.Serialize(stm, atom); */ Console.WriteLine("...S**T"); Console.ReadKey(); }