private static void ReadAllElements(XmlElement root, AttributePackage pack) { ReadPack rpack = new ReadPack(root, pack); SafeReadElement(rpack, ReadInformation, "Information"); SafeReadElement(rpack, ReadCaption, "Caption"); SafeReadElement(rpack, ReadHowto, "Howto"); SafeReadElement(rpack, ReadDerivate, "Derivate"); SafeReadElement(rpack, ReadRemark, "Remark"); SafeReadElement(rpack, ReadLicense, "License"); SafeReadElement(rpack, ReadUpdate, "Update"); }
private static void ReadCaption(XmlElement root, AttributePackage pack) { var nodes = root.GetElementsByTagName("Caption"); if (nodes.Count > 0) { pack.Caption = nodes[0].InnerText; } else { pack.Caption = ""; } }
private static void WriteInformation(XmlTextWriter w, AttributePackage pack) { w.WriteStartElement("Information"); { WriteElement(w, "Author", pack.Author); WriteElement(w, "Email", pack.Email); WriteElement(w, "Title", pack.Title); WriteElement(w, "CreatedAt", pack.CreatedAt); WriteElement(w, "Version", pack.Version); WriteElement(w, "Tags", pack.Tags); WriteElement(w, "OpenPass", pack.OpenPass); } w.WriteEndElement(); }
public static AttributePackage Open(Stream stream) { AttributePackage pack = new AttributePackage(); XmlDocument doc = new XmlDocument(); try { doc.Load(stream); var root = doc.DocumentElement; ReadAllElements(root, pack); } catch (XmlException e) { MessageBox.Show(e.Message, "読み込みエラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } return pack; }
public static void Save(AttributePackage pack, Stream stream) { XmlTextWriter w = new XmlTextWriter(stream, Encoding.UTF8); w.Formatting = Formatting.Indented; w.WriteStartDocument(true); { w.WriteStartElement("ReadmeEditor"); { WriteInformation(w, pack); WriteElement(w, "Caption", pack.Caption); WriteHowto(w, pack); WriteDerivate(w, pack); WriteRemark(w, pack); WriteLicense(w, pack); WriteUpdate(w, pack); } w.WriteEndElement(); } w.WriteEndDocument(); w.Close(); }
private static void ReadDerivate(XmlElement root, AttributePackage pack) { pack.Derivate = ReadItemsAsForeach(root, "Derivate", new string[] { "Title", "Link", "Comment" }); }
private static void WriteHowto(XmlTextWriter w, AttributePackage pack) { WriteItems(w, pack.Howto, "Howto", new string[] { "Title", "Section", "Caption" }); }
private static void WriteDerivate(XmlTextWriter w, AttributePackage pack) { WriteItems(w, pack.Derivate, "Derivate", new string[] { "Title", "Link", "Comment" }); }
private static void WriteUpdate(XmlTextWriter w, AttributePackage pack) { WriteItems(w, pack.Update, "Update", new string[] { "Title", "Section", "Caption" }); }
private static void ReadInformation(XmlElement root, AttributePackage pack) { var nodes = root.GetElementsByTagName("Information"); if (nodes.Count > 0) { foreach (XmlElement node in nodes[0]) { switch (node.Name) { case "Title": pack.Title = node.InnerText; break; case "Author": pack.Author = node.InnerText; break; case "CreatedAt": pack.CreatedAt = node.InnerText; break; case "Version": pack.Version = node.InnerText; break; case "Email": pack.Email = node.InnerText; break; case "Tags": pack.Tags = node.InnerText; break; } } } }
private static void ReadHowto(XmlElement root, AttributePackage pack) { pack.Howto = ReadItemsAsForeach(root, "Howto", new string[] { "Title", "Section", "Caption" }); }
private void UnpackingAttributes(AttributePackage pack) { // AttributePackageの中身をフォームへ流し込む author.Text = pack.Author; tags.Text = pack.Tags; developedName.Text = pack.Title; createdAt.Text = pack.CreatedAt; captionTextBox.Text = pack.Caption; version.Text = pack.Version; howtoCaption = Unpacker.UnpackListBoxOnSection(pack.Howto, howtoListBox); updateCaption = Unpacker.UnpackListBoxOnSection(pack.Update, updateListBox); remarkCaption = Unpacker.UnpackListBox(pack.Remark, remarkListBox); derivateCaption = Unpacker.UnpackListBox(pack.Derivate, derivateListBox); Unpacker.UnpackLicense(pack.License, licenseCheckedListBox); }
private static void WriteLicense(XmlTextWriter w, AttributePackage pack) { WriteItems(w, pack.License, "License", new string[] { "Type" }); }
private static void ReadLicense(XmlElement root, AttributePackage pack) { pack.License = ReadItemsAsForeach(root, "License", new string[] { "Type" }); }
public ReadPack(XmlElement root, AttributePackage pack) { this.root = root; this.pack = pack; }
private static void ReadUpdate(XmlElement root, AttributePackage pack) { pack.Update = ReadItemsAsForeach(root, "Update", new string[] { "Title", "Section", "Caption" }); }
private static void ReadRemark(XmlElement root, AttributePackage pack) { pack.Remark = ReadItemsAsForeach(root, "Remark", new string[] { "Title", "Caption" }); }
private static void WriteRemark(XmlTextWriter w, AttributePackage pack) { WriteItems(w, pack.Remark, "Remark", new string[] { "Title", "Caption" }); }
private AttributePackage PackingAttributes() { // パッケージに書き込みを行う AttributePackage pack = new AttributePackage(); pack.Author = author.Text; pack.OpenPass = openPass.Text; pack.Title = developedName.Text; pack.CreatedAt = createdAt.Text; pack.Email = mailAddress.Text; pack.Caption = captionTextBox.Text; pack.Version = version.Text; pack.Tags = tags.Text; pack.Update = updateCaption.ToArray(); pack.Howto = howtoCaption.ToArray(); pack.Derivate = derivateCaption.ToArray(); pack.Remark = remarkCaption.ToArray(); pack.License = CheckedListMethod.GetSelectedItems(licenseCheckedListBox, licenseCaption); return pack; }