[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase) { UserRole.EditArticles.demand(); if (libraryId == Guid.Empty) // ensure we have a library to put the Article in { "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error(); return(false); } if (article.Content.DataType.lower() == "html") // tidy the html { var cdataContent = article.Content.Data.Value.replace("]]>", "]] >"); // xmlserialization below will break if there is a ]]> in the text var tidiedHtml = cdataContent.tidyHtml(); article.Content.Data.Value = tidiedHtml; if (article.serialize(false).inValid()) // see if the tidied content can be serialized and if not use the original data { article.Content.Data.Value = cdataContent; } } article.Metadata.Library_Id = libraryId; // ensure the LibraryID is correct if (article.serialize(false).notValid()) // make sure the article can be serilialized correctly { return(false); } article.update_Cache_GuidanceItems(tmDatabase); // add it to in Memory cache tmDatabase.Events.Article_Saved.raise(article); // TODO find way to identify save issues (like the return value of the save action) return(true); }
[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase) { if (libraryId == Guid.Empty) // ensure we have a library to put the Article in { "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error(); return(false); } article.sanitize(); article.Metadata.Library_Id = libraryId; // ensure the LibraryID is correct if (article.serialize(false).notValid()) // make sure the article can be serilialized correctly { return(false); } article.update_Cache_GuidanceItems(tmDatabase); // add it to in Memory cache if (tmDatabase.UsingFileStorage) // save to disk { var guidanceXmlPath = tmDatabase.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId); if (guidanceXmlPath.valid()) { "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath); article.saveAs(guidanceXmlPath); return(guidanceXmlPath.fileExists()); } } return(true); }
[EditArticles] public static bool xmlDB_Save_Article(this TeamMentor_Article article, Guid libraryId, TM_Xml_Database tmDatabase) { if (libraryId == Guid.Empty) // ensure we have a library to put the Article in { "[xmlDB_Save_GuidanceItem] no LibraryId was provided".error(); return(false); } if (article.Content.DataType.lower() == "html") // tidy the html { var cdataContent = article.Content.Data.Value.replace("]]>", "]] >"); // xmlserialization below will break if there is a ]]> in the text var tidiedHtml = cdataContent.tidyHtml(); article.Content.Data.Value = tidiedHtml; if (article.serialize(false).inValid()) // see if the tidied content can be serialized and if not use the original data { article.Content.Data.Value = cdataContent; } } article.Metadata.Library_Id = libraryId; // ensure the LibraryID is correct if (article.serialize(false).notValid()) // make sure the article can be serilialized correctly { return(false); } article.update_Cache_GuidanceItems(tmDatabase); // add it to in Memory cache if (tmDatabase.UsingFileStorage) // save to disk { var guidanceXmlPath = tmDatabase.getXmlFilePathForGuidanceId(article.Metadata.Id, libraryId); if (guidanceXmlPath.valid()) { "Saving GuidanceItem {0} to {1}".info(article.Metadata.Id, guidanceXmlPath); article.saveAs(guidanceXmlPath); return(guidanceXmlPath.fileExists()); } } return(true); }