////////////////////////////////////////////////////////////////////// /// <summary>parses the inner state of the element</summary> /// <param name="e">the Event arguments</param> /// <param name="parser">the atomFeedParser that called this</param> ////////////////////////////////////////////////////////////////////// public override void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { XmlNode eventNode = e.ExtensionElement; Tracing.TraceMsg(eventNode.LocalName); // Ensure that the namespace is correct. if (String.Compare(eventNode.NamespaceURI, GCodeSearchParserNameTable.CSNamespace, true) == 0) { // Parse a File Element if (eventNode.LocalName == GCodeSearchParserNameTable.EVENT_FILE) { file = File.ParseFile(eventNode, parser); e.DiscardEntry = true; } // Parse a Package Element else if ((eventNode.LocalName == GCodeSearchParserNameTable.EVENT_PACKAGE)) { package = Package.ParsePackage(eventNode, parser); e.DiscardEntry = true; } // Parse Match Elements else if (eventNode.LocalName == GCodeSearchParserNameTable.EVENT_MATCH) { matches.Add(Match.ParseMatch(eventNode, parser)); e.DiscardEntry = true; } } }
public void SaveAndReadMultipleTest() { for (int i = 0; i < 256; i++) { ListEntry.Custom element = new ListEntry.Custom(); element.LocalName = "local_name_" + i; element.Value = "value_" + i; StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); element.Save(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); ExtensionElementEventArgs e = new ExtensionElementEventArgs(); e.ExtensionElement = document.FirstChild; entry.Parse(e, new AtomFeedParser()); Assert.AreEqual(i + 1, entry.Elements.Count); Assert.AreEqual(element.LocalName, entry.Elements[i].LocalName); Assert.AreEqual(element.Value, entry.Elements[i].Value); } }
public void SaveAndReadTest() { entry.Properties.Add(new PropertyElement("name", "value")); StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); entry.SaveToXml(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); AdminSettingsEntry newEntry = new AdminSettingsEntry(); foreach (XmlNode node in document.FirstChild.ChildNodes) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = newEntry; newEntry.Parse(args, new AtomFeedParser()); } Assert.AreEqual(entry.Properties[0].Name, newEntry.Properties[0].Name, "Parsed entry should have same name for property[0] as original entry"); Assert.AreEqual(entry.Properties[0].Value, newEntry.Properties[0].Value, "Parsed entry should have same value for property[0] as original entry"); }
public void SaveAndReadTest() { Who recipient = new Who(); recipient.Email = "*****@*****.**"; recipient.Rel = Who.RelType.MESSAGE_TO; entry.Recipient = recipient; StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); entry.SaveToXml(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); EmailListRecipientEntry newEntry = new EmailListRecipientEntry(); foreach (XmlNode node in document.FirstChild.ChildNodes) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = newEntry; newEntry.Parse(args, new AtomFeedParser()); } Assert.AreEqual(recipient.Email, newEntry.Recipient.Email, "Parsed entry should have same recipient as original entry"); }
public void SaveAndReadTest() { EmailListElement emailList = new EmailListElement("foo"); entry.EmailList = emailList; StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); entry.SaveToXml(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); EmailListEntry newEntry = new EmailListEntry(); foreach (XmlNode node in document.FirstChild.ChildNodes) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = newEntry; newEntry.Parse(args, new AtomFeedParser()); } Assert.AreEqual(emailList.Name, newEntry.EmailList.Name, "Parsed entry should have same email list name as original entry"); }
public void SaveAndReadTest() { LoginElement login = new LoginElement("jdoe"); entry.Login = login; NicknameElement nickname = new NicknameElement("john"); entry.Nickname = nickname; StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); entry.SaveToXml(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); NicknameEntry newEntry = new NicknameEntry(); foreach (XmlNode node in document.FirstChild.ChildNodes) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = newEntry; newEntry.Parse(args, new AtomFeedParser()); } Assert.AreEqual(login.UserName, newEntry.Login.UserName, "Parsed entry should have same username as original entry"); Assert.AreEqual(nickname.Name, newEntry.Nickname.Name, "Parsed entry should have same nickname as original entry"); }
protected void OnNewEventExtensionElement(object sender, ExtensionElementEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } if (e.DiscardEntry) { return; } if (String.Compare(e.ExtensionElement.NamespaceURI, GBaseNameTable.NSGBase, true) == 0) { e.DiscardEntry = true; if (e.Base is GBaseAttributeContainer) { GBaseAttributeContainer container = e.Base as GBaseAttributeContainer; container.GBaseAttributes.AddFromXml(e.ExtensionElement); return; } } if (e.Base is GBaseEntry) { GBaseEntry entry = e.Base as GBaseEntry; if (entry.AddFromMetaNamespace(e.ExtensionElement)) { e.DiscardEntry = true; } } }
///////////////////////////////////////////////////////////////////////////// #endregion /// <summary> /// Parses the inner state of the element /// </summary> /// <param name="e">The extension element that should be added to this entry</param> /// <param name="parser">The AtomFeedParser that called this</param> public virtual void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { if (e == null) { throw new ArgumentNullException("e"); } Tracing.TraceMsg("Entering Parse on AbstractEntry"); XmlNode node = e.ExtensionElement; if (this.ExtensionFactories != null && this.ExtensionFactories.Count > 0) { Tracing.TraceMsg("Entring default Parsing for AbstractEntry"); IExtensionElementFactory f = FindExtensionFactory(node.LocalName, node.NamespaceURI); if (f != null) { this.ExtensionElements.Add(f.CreateInstance(node, parser)); e.DiscardEntry = true; } } return; }
public void SaveAndReadTest() { StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); uint row = (uint)rng.Next(); cell.Row = row; uint column = (uint)rng.Next(); cell.Column = column; cell.InputValue = "input string"; cell.NumericValue = "numeric value"; cell.Value = "display value"; cell.Save(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); ExtensionElementEventArgs e = new ExtensionElementEventArgs(); e.ExtensionElement = document.FirstChild; entry.Parse(e, new AtomFeedParser()); Assert.AreEqual(row, entry.Cell.Row, "Rows should be equal"); Assert.AreEqual(column, entry.Cell.Column, "Columns should be equal"); Assert.AreEqual("input string", entry.Cell.InputValue, "Input value should be equal"); Assert.AreEqual("numeric value", entry.Cell.NumericValue, "Numeric value should be equal"); Assert.AreEqual("display value", entry.Cell.Value, "Cell value should be equal"); }
public void ExtensionElementTest() { ExtensionElementEventArgs target = new ExtensionElementEventArgs(); // TODO: Initialize to an appropriate value XmlNode expected = null; // TODO: Initialize to an appropriate value XmlNode actual; target.ExtensionElement = expected; actual = target.ExtensionElement; Assert.AreEqual(expected, actual); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Event chaining. We catch this by the baseFeedParsers, which /// would not do anything with the gathered data. We pass the event up /// to the user; if the user doesn't discard it, we add the entry to our /// collection</summary> /// <param name="sender"> the object which send the event</param> /// <param name="e">FeedParserEventArguments, holds the feed entry</param> /// <returns> </returns> ////////////////////////////////////////////////////////////////////// protected void OnNewExtensionElement(object sender, ExtensionElementEventArgs e) { // by default, if our event chain is not hooked, the underlying parser will add it Tracing.TraceCall("received new extension element notification"); Tracing.Assert(e != null, "e should not be null"); if (e == null) { throw new ArgumentNullException("e"); } if (this.NewExtensionElement != null) { Tracing.TraceMsg("\t calling event dispatcher"); this.NewExtensionElement(sender, e); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>eventfiring helper for new extensions</summary> /// <param name="node"> the new node that was found</param> /// <param name="baseObject"> the object this node should be added to</param> ////////////////////////////////////////////////////////////////////// protected void OnNewExtensionElement(XmlNode node, AtomBase baseObject) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = baseObject; if (this.NewExtensionElement != null) { this.NewExtensionElement(this, args); } if (!args.DiscardEntry) { baseObject.ExtensionElements.Add(new XmlExtension(node)); } }
/// <summary> /// Parses the inner state of the element /// </summary> /// <param name="e">The extension element that should be added to this entry</param> /// <param name="parser">The AtomFeedParser that called this</param> public virtual void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { Tracing.TraceMsg("Entering Parse on AbstractEntry"); XmlNode node = e.ExtensionElement; if (this.ExtensionFactories != null && this.ExtensionFactories.Count > 0) { Tracing.TraceMsg("Entring default Parsing for AbstractEntry"); IExtensionElementFactory f = FindExtensionFactory(node.LocalName, node.NamespaceURI); if (f != null) { this.ExtensionElements.Add(f.CreateInstance(node, parser)); e.DiscardEntry = true; } } return; }
/// <summary>eventhandler - called for event extension element /// </summary> /// <param name="sender">the object which send the event</param> /// <param name="e">FeedParserEventArguments, holds the feedEntry</param> /// <returns> </returns> protected void OnNewExtensionsElement(object sender, ExtensionElementEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } AtomFeedParser parser = sender as AtomFeedParser; if (e.Base.XmlName == AtomParserNameTable.XmlAtomEntryElement) { // the base is the Entry of the feed, let's call our parsing on the Entry AtomEntry entry = e.Base as AtomEntry; if (entry != null) { entry.Parse(e, parser); } } else { HandleExtensionElements(e, parser); } }
/// <summary> /// event on the Feed to handle extension elements during parsing /// </summary> /// <param name="e">the event arguments</param> /// <param name="parser">the parser that caused this</param> protected virtual void HandleExtensionElements(ExtensionElementEventArgs e, AtomFeedParser parser) { Tracing.TraceMsg("Entering HandleExtensionElements on AbstractFeed"); XmlNode node = e.ExtensionElement; if (this.ExtensionFactories != null && this.ExtensionFactories.Count > 0) { Tracing.TraceMsg("Entring default Parsing for AbstractFeed"); foreach (IExtensionElementFactory f in this.ExtensionFactories) { Tracing.TraceMsg("Found extension Factories"); if (String.Compare(node.NamespaceURI, f.XmlNameSpace, true, CultureInfo.InvariantCulture) == 0) { if (String.Compare(node.LocalName, f.XmlName, true, CultureInfo.InvariantCulture) == 0) { e.Base.ExtensionElements.Add(f.CreateInstance(node, parser)); e.DiscardEntry = true; break; } } } } return; }
/// <summary>eventfiring helper for new extensions</summary> /// <param name="node"> the new node that was found</param> /// <param name="baseObject"> the object this node should be added to</param> protected void OnNewExtensionElement(XmlNode node, AtomBase baseObject) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = baseObject; if (this.NewExtensionElement != null) { this.NewExtensionElement(this, args); } if (!args.DiscardEntry) { baseObject.ExtensionElements.Add(new XmlExtension(node)); } }
public void ExtensionElementEventArgsConstructorTest() { ExtensionElementEventArgs target = new ExtensionElementEventArgs(); Assert.IsNotNull(target); Assert.IsNull(target.Base); Assert.IsNull(target.ExtensionElement); Assert.IsFalse(target.DiscardEntry); }
public void BaseTest() { ExtensionElementEventArgs target = new ExtensionElementEventArgs(); // TODO: Initialize to an appropriate value AtomBase expected = new AtomEntry(); AtomBase actual; target.Base = expected; actual = target.Base; Assert.AreEqual(expected, actual); }
public void ParseXmlTest() { string xmlElementText = "<entry xmlns=\"http://www.w3.org/2005/Atom\" " + "xmlns:gd=\"http://schemas.google.com/g/2005\">" + Rfc822MsgTest.xmlElementAsText + LabelTest.xmlElementAsText + LabelTest.xmlElementAsText.Replace("Friends", "Acquaintances") + MailItemPropertyTest.xmlElementAsText + MailItemPropertyTest.xmlElementAsText.Replace("SENT", "STARRED") + "<gd:when startTime=\"2005-10-06\"/></entry>"; // Parse the XML back into a new MigrationEntry XmlDocument document = new XmlDocument(); document.LoadXml(xmlElementText); foreach (XmlNode node in document.FirstChild.ChildNodes) { ExtensionElementEventArgs e = new ExtensionElementEventArgs(); e.ExtensionElement = node; entry.Parse(e, new AtomFeedParser()); } // Verify that the labels are correct Assert.AreEqual(2, entry.Labels.Count, "Parsed MailItemEntry should have exactly two labels"); Assert.AreEqual("Friends", entry.Labels[0].LabelName, "Parsed MailItemEntry does not contain a \"Friends\" label"); Assert.AreEqual("Acquaintances", entry.Labels[1].LabelName, "Parsed MailItemEntry does not contain an \"Acquaintances\" label"); // Verify that the mail item properties are correct Assert.AreEqual(2, entry.MailItemProperties.Count, "Parsed MailItemEntry should have exactly two mail item properties"); Assert.AreEqual("IS_SENT", entry.MailItemProperties[0].Value.ToString(), "Parsed MailItemEntry does not contain a SENT property."); Assert.AreEqual("IS_STARRED", entry.MailItemProperties[1].Value.ToString(), "Parsed MailItemEntry does not contain the STARRED property."); // Verify that the RFC822 message is correct Assert.AreEqual("Hi", entry.Rfc822Msg.ToString(), "Parsed MailItemEntry has incorrect Rfc822Msg"); }
/// <summary> /// get's called after we already handled the custom entry, to handle all /// other potential parsing tasks /// </summary> /// <param name="e">the event arguments</param> /// <param name="parser">the atom feed parser calling</param> protected override void HandleExtensionElements(ExtensionElementEventArgs e, AtomFeedParser parser) { Tracing.TraceMsg("\t HandleExtensionElements for ListFeedcalled"); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>eventchaining. We catch this by the baseFeedParsers, which /// would not do anything with the gathered data. We pass the event up /// to the user, and if he did not dicscard it, we add the entry to our /// collection</summary> /// <param name="sender"> the object which send the event</param> /// <param name="e">FeedParserEventArguments, holds the feedentry</param> /// <returns> </returns> ////////////////////////////////////////////////////////////////////// protected void OnNewExtensionElement(object sender, ExtensionElementEventArgs e) { // by default, if our event chain is not hooked, the underlying parser will add it Tracing.TraceCall("received new extension element notification"); Tracing.Assert(e != null, "e should not be null"); if (e == null) { throw new ArgumentNullException("e"); } if (this.NewExtensionElement != null) { Tracing.TraceMsg("\t calling event dispatcher"); this.NewExtensionElement(this, e); } }
public void DiscardEntryTest() { ExtensionElementEventArgs target = new ExtensionElementEventArgs(); // TODO: Initialize to an appropriate value bool expected = false; // TODO: Initialize to an appropriate value bool actual; target.DiscardEntry = expected; actual = target.DiscardEntry; Assert.AreEqual(expected, actual); }
/// <summary> /// Parses the inner state of the element. TODO. /// </summary> /// <param name="e">The extension element that should be added to this entry</param> /// <param name="parser">The AtomFeedParser that called this</param> public override void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { if (String.Compare(e.ExtensionElement.NamespaceURI, GDataSpreadsheetsNameTable.NSGSpreadsheetsExtended, true) == 0) { Elements.Add(Custom.ParseCustom(e.ExtensionElement, parser)); e.DiscardEntry = true; } }
public void SaveAndReadColTest() { ColCountElement count = new ColCountElement(); count.Count = (uint)new Random().Next(); StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); count.Save(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); ExtensionElementEventArgs e = new ExtensionElementEventArgs(); e.ExtensionElement = document.FirstChild; entry.Parse(e, new AtomFeedParser()); Assert.IsNotNull(entry.ColCount); Assert.AreEqual(entry.ColCount.Count, count.Count); }
////////////////////////////////////////////////////////////////////// /// <summary>parses the inner state of the element</summary> /// <param name="e">the extensionelement during the parsing process, xml node</param> /// <param name="parser">the atomFeedParser that called this</param> ////////////////////////////////////////////////////////////////////// public override void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { Tracing.TraceCall("AclEntry:Parse is called:" + e); XmlNode node = e.ExtensionElement; if (String.Compare(node.NamespaceURI, AclNameTable.gAclNamespace, true) == 0) { // Parse a Role Element if (node.LocalName == AclNameTable.XmlAclRoleElement) { this.Role = AclRole.parse(node); e.DiscardEntry = true; } // Parse a Where Element else if (node.LocalName == AclNameTable.XmlAclScopeElement) { this.Scope = AclScope.parse(node); e.DiscardEntry = true; } } }
////////////////////////////////////////////////////////////////////// /// <summary>parses the inner state of the element</summary> /// <param name="e">evennt arguments</param> /// <param name="parser">the atomFeedParser that called this</param> ////////////////////////////////////////////////////////////////////// public override void Parse(ExtensionElementEventArgs e, AtomFeedParser parser) { XmlNode eventNode = e.ExtensionElement; // Parse a Reminder Element - recurrence event, g:reminder is in top level // reminders are already changed to IExtensionElementFactory, so call base // see addEventEntryExtensions() base.Parse(e, parser); if (String.Compare(eventNode.NamespaceURI, BaseNameTable.gNamespace, true) == 0) { // Parse a Status Element if (eventNode.LocalName == GDataParserNameTable.XmlEventStatusElement) { this.Status = EventStatus.parse(eventNode); e.DiscardEntry = true; } // Parse a Visibility Element else if (eventNode.LocalName == GDataParserNameTable.XmlVisibilityElement) { this.EventVisibility = Visibility.parse(eventNode); e.DiscardEntry = true; } // Parse a Transparency Element else if (eventNode.LocalName == GDataParserNameTable.XmlTransparencyElement) { this.EventTransparency = Transparency.parse(eventNode); e.DiscardEntry = true; } // Parse a Recurrence Element else if (eventNode.LocalName == GDataParserNameTable.XmlRecurrenceElement) { this.Recurrence = Recurrence.ParseRecurrence(eventNode); e.DiscardEntry = true; } else if (eventNode.LocalName == GDataParserNameTable.XmlRecurrenceExceptionElement) { this.RecurrenceException = RecurrenceException.ParseRecurrenceException(eventNode, parser); e.DiscardEntry = true; } // Parse a Comments Element else if (eventNode.LocalName == GDataParserNameTable.XmlCommentsElement) { this.Comments = Comments.ParseComments(eventNode); e.DiscardEntry = true; } else if (eventNode.LocalName == GDataParserNameTable.XmlExtendedPropertyElement) { ExtendedProperty p = ExtendedProperty.Parse(eventNode); if (p != null) { e.DiscardEntry = true; this.ExtensionElements.Add(p); } } } else if (String.Compare(eventNode.NamespaceURI, GDataParserNameTable.NSGCal, true) == 0) { // parse the eventnotification element Tracing.TraceMsg("Parsing in the gCal Namespace"); if (eventNode.LocalName == GDataParserNameTable.XmlSendNotificationsElement) { this.sendNotifications = SendNotifications.parse(eventNode); e.DiscardEntry = true; } } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>Event chaining. We catch this by the baseFeedParsers, which /// would not do anything with the gathered data. We pass the event up /// to the user; if the user doesn't discard it, we add the entry to our /// collection</summary> /// <param name="sender"> the object which send the event</param> /// <param name="e">FeedParserEventArguments, holds the feed entry</param> /// <returns> </returns> ////////////////////////////////////////////////////////////////////// protected void OnNewExtensionElement(object sender, ExtensionElementEventArgs e) { // by default, if our event chain is not hooked, the underlying parser will add it Tracing.TraceCall("received new extension element notification"); Tracing.Assert(e != null, "e should not be null"); if (e == null) { throw new ArgumentNullException("e"); } if (this.NewExtensionElement != null) { Tracing.TraceMsg("\t calling event dispatcher"); this.NewExtensionElement(sender, e); } // now check the return if (e.DiscardEntry != true) { if (e.Base != null && e.ExtensionElement != null) { // add it to the collection Tracing.TraceMsg("\t new AtomEntry found, adding to collection"); e.Base.ExtensionElements.Add(e.ExtensionElement); } } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>eventfiring helper for new extensions</summary> /// <param name="node"> the new node that was found</param> /// <param name="baseObject"> the object this node should be added to</param> ////////////////////////////////////////////////////////////////////// protected void OnNewExtensionElement(XmlNode node, AtomBase baseObject) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = baseObject; if (this.NewExtensionElement != null) { this.NewExtensionElement(this, args); } }
/// <summary>eventhandler - called for new extension element</summary> /// <param name="sender"> the object which send the event</param> /// <param name="e">FeedParserEventArguments, holds the feedentry</param> /// <returns> </returns> protected void OnNewExtensionElement(object sender, ExtensionElementEventArgs e) { // by default, if our event chain is not hooked, the underlying parser will add it Tracing.TraceCall("received new extension element notification"); Tracing.Assert(e != null, "e should not be null"); if (e == null) { throw new ArgumentNullException("e"); } Tracing.TraceMsg("\t top level event = new extension"); if (String.Compare(e.ExtensionElement.NamespaceURI, "http://purl.org/dc/elements/1.1/", true) == 0) { // found DC namespace Tracing.TraceMsg("\t top level event = new DC extension"); if (e.ExtensionElement.LocalName == "date") { MyEntry entry = e.Base as MyEntry; if (entry != null) { entry.DCDate = DateTime.Parse(e.ExtensionElement.InnerText); e.DiscardEntry = true; } } } }
/// <summary>eventhandler - called for event extension element /// </summary> /// <param name="sender">the object which send the event</param> /// <param name="e">FeedParserEventArguments, holds the feedEntry</param> /// <returns> </returns> protected void OnNewExtensionsElement(object sender, ExtensionElementEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } AtomFeedParser parser = sender as AtomFeedParser; if (e.Base.XmlName == AtomParserNameTable.XmlAtomEntryElement) { // the base is the Entry of the feed, let's call our parsing on the Entry AbstractEntry entry = e.Base as AbstractEntry; if (entry != null) { entry.Parse(e, parser); } } else { HandleExtensionElements(e, parser); } }
public void SaveAndReadTest() { LoginElement login = new LoginElement("jdoe"); login.Admin = true; login.HashFunctionName = "SHA-1"; entry.Login = login; QuotaElement quota = new QuotaElement(2048); entry.Quota = quota; NameElement name = new NameElement("Doe", "John"); entry.Name = name; StringBuilder sb = new StringBuilder(); XmlWriter writer = new XmlTextWriter(new StringWriter(sb)); entry.SaveToXml(writer); writer.Close(); XmlDocument document = new XmlDocument(); document.LoadXml(sb.ToString()); UserEntry newEntry = new UserEntry(); foreach (XmlNode node in document.FirstChild.ChildNodes) { ExtensionElementEventArgs args = new ExtensionElementEventArgs(); args.ExtensionElement = node; args.Base = newEntry; newEntry.Parse(args, new AtomFeedParser()); } Assert.AreEqual(login.UserName, newEntry.Login.UserName, "Parsed entry should have same username as original entry"); Assert.IsTrue(newEntry.Login.Admin, "Parsed entry should have admin property set to true"); Assert.AreEqual(login.HashFunctionName, newEntry.Login.HashFunctionName, "Parsed entry should have same hash function name as original entry"); Assert.AreEqual(quota.Limit, newEntry.Quota.Limit, "Parsed entry should have same quota as original entry"); Assert.AreEqual(name.FamilyName, newEntry.Name.FamilyName, "Parsed entry should have same family name as original entry"); Assert.AreEqual(name.GivenName, newEntry.Name.GivenName, "Parsed entry should have same given name as original entry"); }
/// <summary> /// Is called after we already handled the custom entry, to handle all /// other potential parsing tasks /// </summary> /// <param name="e"></param> /// <param name="parser">the atom feed parser used</param> protected override void HandleExtensionElements(ExtensionElementEventArgs e, AtomFeedParser parser) { base.HandleExtensionElements(e, parser); }
/// <summary> /// event on the Feed to handle extension elements during parsing /// </summary> /// <param name="e">the event arguments</param> /// <param name="parser">the parser that caused this</param> protected virtual void HandleExtensionElements(ExtensionElementEventArgs e, AtomFeedParser parser) { Tracing.TraceMsg("Entering HandleExtensionElements on AbstractFeed"); XmlNode node = e.ExtensionElement; if (this.ExtensionFactories != null && this.ExtensionFactories.Count > 0) { Tracing.TraceMsg("Entring default Parsing for AbstractFeed"); foreach (IExtensionElementFactory f in this.ExtensionFactories) { Tracing.TraceMsg("Found extension Factories"); if (String.Compare(node.NamespaceURI, f.XmlNameSpace, true) == 0) { if (String.Compare(node.LocalName, f.XmlName) == 0) { e.Base.ExtensionElements.Add(f.CreateInstance(node, parser)); e.DiscardEntry = true; break; } } } } return;