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(); } } }
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(); }