public XmlContent Store(XmlContent xml) { Contract.Requires <ArgumentNullException>(null != xml); Contract.Requires <ArgumentNullException>(null != xml.Token); Contract.Ensures(Contract.Result <XmlContent>() != null); using (new PerformanceMonitor()) { var id = Guid.Empty; if (Guid.Empty == xml.Id) { var contentId = this.source.InsertXml(xml.Content); var data = xml.Convert(); data.ContentId = contentId; id = this.source.Insert(data); } else { var data = this.source.SelectXml(xml.Token.ApplicationId, xml.Id); data.Active = xml.Active; data.Deleted = xml.Deleted; data.UpdatedOn = DateTime.UtcNow; this.source.UpdateXml(data.ContentId, xml.Content); id = this.source.Update(data); } return(new XmlContent() { Id = id }); } }
/// <summary> /// WCPay notify, placed here due to non-authentic context. /// </summary> public async Task notify(ActionContext ac) { XElem xe = await ac.ReadAsync <XElem>(); long orderid; decimal cash; if (Notified(xe, out orderid, out cash)) { string mgrwx = null; using (var dc = NewDbContext()) { var shopid = (string)dc.Scalar("UPDATE orders SET cash = @1, accepted = localtimestamp, status = @2 WHERE id = @3 AND status <= @2 RETURNING shopid", (p) => p.Set(cash).Set(Order.ACCEPTED).Set(orderid)); if (shopid != null) { mgrwx = (string)dc.Scalar("SELECT mgrwx FROM shops WHERE id = @1", p => p.Set(shopid)); } } // return xml XmlContent cont = new XmlContent(true, 1024); cont.ELEM("xml", null, () => { cont.ELEM("return_code", "SUCCESS"); cont.ELEM("return_msg", "OK"); }); if (mgrwx != null) { await PostSendAsync(mgrwx, "【买家付款】订单编号:" + orderid + ",金额:" + cash + "元"); } ac.Give(200, cont); } else { ac.Give(400); } }
/// <summary> /// Copies the <see cref="HttpResponseMessage"/> and adds the specified object serialized as xml string content. /// </summary> /// <param name="response">The response.</param> /// <param name="obj">The object.</param> /// <param name="mediaType">The media type.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">response</exception> public static HttpResponseMessage WithXmlContent( this HttpResponseMessage response, object obj, string mediaType = null) { if (response == null) { throw new ArgumentNullException(nameof(response)); } var newContent = new XmlContent(obj, mediaType); foreach (var v in response.Content?.Headers ?? EmptyHeader) { newContent.Headers.TryAddWithoutValidation(v.Key, v.Value); } var clone = response.Clone(); clone.Content = newContent; return(clone); }
public void SavePreviewSet() { //make sure the preview folder exists first var dir = new DirectoryInfo(IO.IOHelper.MapPath(IO.SystemDirectories.Preview)); if (!dir.Exists) { dir.Create(); } // check for old preview sets and try to clean foreach (FileInfo file in dir.GetFiles(m_userId + "_*.config")) { try { file.Delete(); } catch { Log.Add(LogTypes.Error, User.GetUser(m_userId), -1, String.Format("Couldn't delete preview set: {0}", file.Name)); } } XmlContent.Save(PreviewsetPath); }
public void PrepareDocument(User user, Document documentObject, bool includeSubs) { _userId = user.Id; // clone xml XmlContent = (XmlDocument)content.Instance.XmlContent.Clone(); var previewNodes = new List <Document>(); var parentId = documentObject.Level == 1 ? -1 : documentObject.Parent.Id; while (parentId > 0 && XmlContent.GetElementById(parentId.ToString(CultureInfo.InvariantCulture)) == null) { var document = new Document(parentId); previewNodes.Insert(0, document); parentId = document.ParentId; } previewNodes.Add(documentObject); foreach (var document in previewNodes) { //Inject preview xml parentId = document.Level == 1 ? -1 : document.Parent.Id; var previewXml = document.ToPreviewXml(XmlContent); content.AppendDocumentXml(document.Id, document.Level, parentId, previewXml, XmlContent); } if (includeSubs) { foreach (var prevNode in documentObject.GetNodesForPreview(true)) { XmlContent = content.AppendDocumentXml(prevNode.NodeId, prevNode.Level, prevNode.ParentId, XmlContent.ReadNode(XmlReader.Create(new StringReader(prevNode.Xml))), XmlContent); } } }
public void PrepareDocument(User user, Document documentObject, bool includeSubs) { _userId = user.Id; // clone xml XmlContent = (XmlDocument)content.Instance.XmlContent.Clone(); // inject current document xml int parentId = documentObject.Level == 1 ? -1 : documentObject.Parent.Id; XmlContent = content.AppendDocumentXml(documentObject.Id, documentObject.Level, parentId, documentObject.ToPreviewXml(XmlContent), XmlContent); if (includeSubs) { foreach (CMSPreviewNode prevNode in documentObject.GetNodesForPreview(true)) { XmlContent = content.AppendDocumentXml(prevNode.NodeId, prevNode.Level, prevNode.ParentId, XmlContent.ReadNode(XmlReader.Create(new StringReader(prevNode.Xml))), XmlContent); } } }
/// <summary> /// Used to generate a response for a "GET" request. /// </summary> public static XmlContent HandleXmlGet(Request request) { XmlContent result; try { string path = Environment.CurrentDirectory + HttpServer.WEB_D + @"\Aufgabe8\database.xml"; XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode node = doc.DocumentElement.SelectSingleNode(@"/users"); string data = node.InnerXml; data = data.Replace("<user>", "-User-<br/>"); data = data.Replace("</user>", "<br/>"); // Format XML data to an easyly-readable form and react to the specified filter. if (!request.Url.Contains("/name") && !request.Url.Contains("/birthdate")) { data = data.Replace("<username>", "User name: \""); data = data.Replace(@"</username>", "\" <br/>"); } else { HideInfo("username", ref data); } if (!request.Url.Contains("/username") && !request.Url.Contains("/birthdate")) { data = data.Replace("<name>", "Name: \""); data = data.Replace(@"</name>", "\" <br/>"); } else { HideInfo("name", ref data); } if (!request.Url.Contains("/username") && !request.Url.Contains("/name")) { data = data.Replace("<birthdate>", "Birthdate: \""); data = data.Replace(@"</birthdate>", "\"<br/>"); } else { HideInfo("birthdate", ref data); } // Return data converted into bytes and the status. result = new XmlContent(); result.ByteData = Encoding.UTF8.GetBytes(data); result.Status = "200"; return(result); } catch { result = new XmlContent(); result.ByteData = Encoding.UTF8.GetBytes("Error: The database or the specified attribute doesn't exist yet, please specify existing attributes or create new users."); result.Status = "200"; return(result); } }
public MTBFXmlBuilder() { XmlContent.Insert(0, "<?xml version=\"1.0\" encoding=\"utf-8\"?>"); }
public void RoundTripXmlContent() { const string Xml = "<xml>{0}</xml>"; Token token = new Token() { ApplicationId = Guid.NewGuid() }; XmlContent data = new XmlContent() { Active = true, Content = string.Format(Xml, Guid.NewGuid()), CreatedOn = DateTime.UtcNow, Deleted = true, UpdatedOn = DateTime.UtcNow, Token = token }; Assert.AreEqual <Guid>(Guid.Empty, data.Id); ContentCore core = new ContentCore(); XmlContent returned = core.Store(data); Assert.IsNotNull(returned); Assert.AreNotEqual <Guid>(Guid.Empty, returned.Id); XmlContent query = new XmlContent() { Token = token, Id = returned.Id }; XmlContent filled = core.Get(query); Assert.IsNotNull(filled); Assert.AreEqual <Guid>(returned.Id, filled.Id); Assert.AreEqual <bool>(data.Active, filled.Active, "Data Mismatch"); Assert.AreEqual <string>(data.Content, filled.Content, "Data Mismatch"); Assert.AreEqual <DateTime>(data.CreatedOn.Date, filled.CreatedOn.Date, "Data Mismatch"); Assert.AreEqual <bool>(data.Deleted, filled.Deleted, "Data Mismatch"); Assert.AreEqual <DateTime>(data.UpdatedOn.Date, filled.UpdatedOn.Date, "Data Mismatch"); filled.Active = false; filled.Content = string.Format(Xml, Guid.NewGuid()); filled.CreatedOn = DateTime.UtcNow; filled.Deleted = false; filled.UpdatedOn = DateTime.UtcNow; filled.Token = token; returned = core.Store(filled); Assert.IsNotNull(returned); Assert.AreEqual <Guid>(filled.Id, returned.Id); returned.Token = token; XmlContent updated = core.Get(returned); Assert.IsNotNull(updated); Assert.AreEqual <Guid>(filled.Id, updated.Id); Assert.AreEqual <bool>(filled.Active, updated.Active, "Data Mismatch"); Assert.AreEqual <string>(filled.Content, updated.Content, "Data Mismatch"); Assert.AreEqual <DateTime>(filled.CreatedOn.Date, updated.CreatedOn.Date, "Data Mismatch"); Assert.AreEqual <bool>(filled.Deleted, updated.Deleted, "Data Mismatch"); Assert.AreEqual <DateTime>(filled.UpdatedOn.Date, updated.UpdatedOn.Date, "Data Mismatch"); }
private void ProcessContent(XmlContent xmlContent, Content businessContent) { if (xmlContent != null) { foreach (IXmlElement dataElement in xmlContent.Elements) { switch (dataElement.GetType().Name.ToLower()) { case "text": var dataText = (Data.Xml.Elements.Text)dataElement; var bText = new Text.Text(businessContent, dataElement.Key, string.IsNullOrEmpty(dataText.Rotation) ? 0 : float.Parse(dataText.Rotation)); bText.LayoutContainer = new LayoutContainer(bText, dataElement.XmlLayoutDefinition); foreach (Paragraph dParagraph in dataText.Paragraphs) { var bParagraph = new Text.Paragraph(bText, dParagraph.Leading, dParagraph.Alignment); bParagraph.Offset = dParagraph.Offset != null ? new Unit(dParagraph.Offset) : null; bParagraph.Symbol = dParagraph.Symbol != null ? dParagraph.Symbol : null; bText.Add(bParagraph); foreach (TextElement dTextElement in dParagraph.TextElements) { var bTextElement = new Text.TextElement(bParagraph, dTextElement .Value, dTextElement .Font, dTextElement .Style, dTextElement . Fontsize, dTextElement .Color); if (!string.IsNullOrEmpty(dTextElement.Charspacing)) { bTextElement.CharSpacing = new Unit(dTextElement.Charspacing); } bParagraph.Add(bTextElement); } } if (!string.IsNullOrEmpty(dataElement.ZOrder)) { bText.ZOrder = Convert.ToUInt16(dataElement.ZOrder); } if (!string.IsNullOrEmpty(dataText.OverflowElement)) { bText.SetOverflowElement(dataText.OverflowElement); } bText.SetTextlines(); businessContent.Elements.Add(bText); break; case "line": var dataLine = (Data.Xml.Elements.Line)dataElement; var bLine = new Line(businessContent, dataElement.Key, dataLine.Width, dataLine.Color); bLine.LayoutContainer = new LayoutContainer(bLine, dataElement.XmlLayoutDefinition); if (!string.IsNullOrEmpty(dataElement.ZOrder)) { bLine.ZOrder = Convert.ToUInt16(dataElement.ZOrder); } businessContent.Elements.Add(bLine); break; case "image": var dataImage = (Data.Xml.Elements.Image)dataElement; var bImage = new Image(businessContent, dataImage.Key, dataImage.Path); bImage.LayoutContainer = new LayoutContainer(bImage, dataElement.XmlLayoutDefinition); bImage.ConvertDPI(); if (!string.IsNullOrEmpty(dataElement.ZOrder)) { bImage.ZOrder = Convert.ToUInt16(dataElement.ZOrder); } businessContent.Elements.Add(bImage); break; case "rectangle": var dataRectangle = (Data.Xml.Elements.Rectangle)dataElement; var bRectangle = new Rectangle(businessContent, dataRectangle.Key, dataRectangle.Bordercolor, dataRectangle.Borderwidth); bRectangle.LayoutContainer = new LayoutContainer(bRectangle, dataElement.XmlLayoutDefinition); bRectangle.Contents = new Content(bRectangle); if (dataRectangle.XmlContent != null) { ProcessContent(dataRectangle.XmlContent, bRectangle.Contents); bRectangle.Contents.UpdateContentHeight(); bRectangle.LayoutContainer.TryResize(bRectangle.Layout.Width, bRectangle.Contents.Height); bRectangle.Relocate(); } if (!string.IsNullOrEmpty(dataRectangle.Fillcolor)) { bRectangle.FillColor = businessContent.Page.Document.Colors[dataRectangle.Fillcolor]; } if (!string.IsNullOrEmpty(dataRectangle.Roundness)) { bRectangle.Roundness = new Unit(dataRectangle.Roundness); } if (!string.IsNullOrEmpty(dataElement.ZOrder)) { bRectangle.ZOrder = Convert.ToUInt16(dataElement.ZOrder); } businessContent.Elements.Add(bRectangle); break; } } } }