private void ToXml(Stream stream) { XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.CheckCharacters = false; using (XmlWriter xmlWriter = XmlWriter.Create(stream, settings)) { xmlWriter.WriteStartElement("Notifications"); xmlWriter.WriteStartElement("Items"); xmlWriter.WriteStartElement("Notification"); LinkExtensions.Serialise(GetLinks(), xmlWriter); Model.XmlHelper.WriteElement(xmlWriter, "TimeTriggered", _WebhookNotification.TimeTriggered); Model.XmlHelper.WriteElement(xmlWriter, "SubscriptionType", _WebhookNotification.SubscriptionType); if (_WebhookNotification.ObjectDefinition != null) { xmlWriter.WriteStartElement("Value"); ObjectInstance instance = new ObjectInstance(_WebhookNotification.ObjectDefinition, _WebhookNotification.ChangedObject); instance.Links = new List <Link>(); instance.Serialise(xmlWriter); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); // Notification xmlWriter.WriteEndElement(); // Items xmlWriter.WriteEndElement(); // Notifications xmlWriter.Flush(); } stream.Position = 0; }
private void ToJson(Stream stream) { using (JsonWriter jsonWriter = new JsonWriter(stream)) { jsonWriter.WriteObject(); jsonWriter.WriteMember("Items"); jsonWriter.WriteArray(); jsonWriter.WriteObject(); LinkExtensions.Serialise(GetLinks(), jsonWriter); jsonWriter.WriteMember("TimeTriggered"); jsonWriter.WriteValue(_WebhookNotification.TimeTriggered); jsonWriter.WriteMember("SubscriptionType"); jsonWriter.WriteValue(_WebhookNotification.SubscriptionType); if (_WebhookNotification.ObjectDefinition != null) { jsonWriter.WriteMember("Value"); ObjectInstance instance = new ObjectInstance(_WebhookNotification.ObjectDefinition, _WebhookNotification.ChangedObject); instance.Links = new List <Link>(); instance.Serialise(jsonWriter); } jsonWriter.WriteEndObject(); jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); jsonWriter.Flush(); } stream.Position = 0; }