896
896
xmlDoc.LoadXml (foreignNoteXml);
899
StringReader reader = new StringReader (foreignNoteXml);
900
XmlTextReader xml = new XmlTextReader (reader);
901
xml.Namespaces = false;
903
899
// Remove tags now, since a note with no tags has
904
900
// no "tags" element in the XML
905
901
List<Tag> newTags = new List<Tag> ();
908
while (xml.Read ()) {
909
switch (xml.NodeType) {
910
case XmlNodeType.Element:
913
Title = xml.ReadString ();
916
XmlContent = xml.ReadInnerXml ();
918
case "last-change-date":
919
if (DateTime.TryParse (xml.ReadString (), out date))
920
data.Data.ChangeDate = date;
922
data.Data.ChangeDate = DateTime.Now;
924
case "last-metadata-change-date":
925
if (DateTime.TryParse (xml.ReadString (), out date))
926
data.Data.MetadataChangeDate = date;
928
data.Data.MetadataChangeDate = DateTime.Now;
931
if (DateTime.TryParse (xml.ReadString (), out date))
932
data.Data.CreateDate = date;
934
data.Data.CreateDate = DateTime.Now;
937
XmlDocument doc = new XmlDocument ();
938
List<string> tag_strings = ParseTags (doc.ReadNode (xml.ReadSubtree ()));
939
foreach (string tag_str in tag_strings) {
940
Tag tag = TagManager.GetOrCreateTag (tag_str);
903
using (var xml = new XmlTextReader (new StringReader (foreignNoteXml)) {Namespaces = false}) {
906
while (xml.Read ()) {
907
switch (xml.NodeType) {
908
case XmlNodeType.Element:
911
Title = xml.ReadString ();
914
XmlContent = xml.ReadInnerXml ();
916
case "last-change-date":
917
if (DateTime.TryParse (xml.ReadString (), out date))
918
data.Data.ChangeDate = date;
920
data.Data.ChangeDate = DateTime.Now;
922
case "last-metadata-change-date":
923
if (DateTime.TryParse (xml.ReadString (), out date))
924
data.Data.MetadataChangeDate = date;
926
data.Data.MetadataChangeDate = DateTime.Now;
929
if (DateTime.TryParse (xml.ReadString (), out date))
930
data.Data.CreateDate = date;
932
data.Data.CreateDate = DateTime.Now;
935
XmlDocument doc = new XmlDocument ();
936
List<string> tag_strings = ParseTags (doc.ReadNode (xml.ReadSubtree ()));
937
foreach (string tag_str in tag_strings) {
938
Tag tag = TagManager.GetOrCreateTag (tag_str);
942
case "open-on-startup":
944
if (bool.TryParse (xml.ReadString (), out isStartup))
945
IsOpenOnStartup = isStartup;
944
case "open-on-startup":
946
if (bool.TryParse (xml.ReadString (), out isStartup))
947
IsOpenOnStartup = isStartup;
956
953
foreach (Tag oldTag in Tags)
957
954
if (!newTags.Contains (oldTag))
958
955
RemoveTag (oldTag);
1268
1265
public virtual NoteData ReadFile (string read_file, string uri)
1270
StreamReader reader = new StreamReader (read_file,
1271
System.Text.Encoding.UTF8);
1272
XmlTextReader xml = new XmlTextReader (reader);
1273
xml.Namespaces = false;
1275
1268
string version;
1276
NoteData data = Read (xml, uri, out version);
1269
using (var xml = new XmlTextReader (new StreamReader (read_file, System.Text.Encoding.UTF8)) {Namespaces = false})
1270
data = Read (xml, uri, out version);
1278
1272
if (version != NoteArchiver.CURRENT_VERSION) {
1279
1273
// Note has old format, so rewrite it. No need
1379
1370
public static string WriteString(NoteData note)
1381
1372
StringWriter str = new StringWriter ();
1382
XmlWriter xml = XmlWriter.Create (str, XmlEncoder.DocumentSettings);
1383
Instance.Write (xml, note);
1373
using (var xml = XmlWriter.Create (str, XmlEncoder.DocumentSettings))
1374
Instance.Write (xml, note);
1386
1376
return str.ToString ();