public string ExportModule(int moduleId) { string xml = ""; OpenContentController ctrl = new OpenContentController(PortalSettings.Current.PortalId); var tabModules = ModuleController.Instance.GetTabModulesByModule(moduleId); Hashtable moduleSettings = tabModules.Any() ? tabModules.First().ModuleSettings : new Hashtable(); var items = ctrl.GetContents(moduleId); xml += "<opencontent>"; foreach (var item in items) { xml += "<item>"; xml += "<json>" + XmlUtils.XMLEncode(item.Json) + "</json>"; xml += "<collection>" + XmlUtils.XMLEncode(item.Collection) + "</collection>"; xml += "<key>" + XmlUtils.XMLEncode(item.Id) + "</key>"; xml += "</item>"; } foreach (DictionaryEntry moduleSetting in moduleSettings) { xml += "<moduleSetting>"; xml += "<settingName>" + XmlUtils.XMLEncode(moduleSetting.Key.ToString()) + "</settingName>"; xml += "<settingValue>" + XmlUtils.XMLEncode(moduleSetting.Value.ToString()) + "</settingValue>"; xml += "</moduleSetting>"; } xml += "</opencontent>"; return(xml); }
public void ImportModule(int moduleId, string Content, string version, int userId) { var module = new OpenContentModuleInfo(moduleId, Null.NullInteger); var index = module.Settings.Template.Manifest.Index; var indexConfig = OpenContentUtils.GetIndexConfig(module.Settings.Template); OpenContentController ctrl = new OpenContentController(); XmlNode xml = Globals.GetContent(Content, "opencontent"); foreach (XmlNode item in xml.SelectNodes("item")) { XmlNode json = item.SelectSingleNode("json"); XmlNode collection = item.SelectSingleNode("collection"); XmlNode key = item.SelectSingleNode("key"); var contentInfo = new OpenContentInfo() { ModuleId = moduleId, Collection = collection?.InnerText ?? "", Key = key?.InnerText ?? "", Json = item.InnerText, CreatedByUserId = userId, CreatedOnDate = DateTime.Now, LastModifiedByUserId = userId, LastModifiedOnDate = DateTime.Now, Title = "" }; ctrl.AddContent(contentInfo, index, indexConfig); } }
public HttpResponseMessage Add(UpdateRequest req) { try { ModuleController mc = new ModuleController(); var requestModule = mc.GetModule(req.ModuleId, req.TabId, false); bool index = false; OpenContentSettings settings = requestModule.OpenContentSettings(); ModuleInfo module = requestModule; if (settings.ModuleId > 0) { module = mc.GetModule(settings.ModuleId, settings.TabId, false); } var manifest = settings.Template.Manifest; TemplateManifest templateManifest = settings.Template; index = settings.Template.Manifest.Index; string editRole = manifest.GetEditRole(); bool listMode = templateManifest != null && templateManifest.IsListTemplate; int createdByUserid = -1; OpenContentController ctrl = new OpenContentController(); if (listMode) { if (!OpenContentUtils.HasEditPermissions(PortalSettings, module, editRole, createdByUserid)) { return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } var indexConfig = OpenContentUtils.GetIndexConfig(settings.Template.Key.TemplateDir); OpenContentInfo content = new OpenContentInfo() { ModuleId = module.ModuleID, Title = ActiveModule.ModuleTitle, Json = req.json.ToString(), JsonAsJToken = req.json, CreatedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserInfo.UserID, LastModifiedOnDate = DateTime.Now, Html = "", }; ctrl.AddContent(content, index, indexConfig); return(Request.CreateResponse(HttpStatusCode.OK, "")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "It's not a list mode module")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
public string ExportModule(int ModuleID) { string xml = ""; OpenContentController ctrl = new OpenContentController(); var content = ctrl.GetFirstContent(ModuleID); if ((content != null)) { xml += "<opencontent>"; xml += "<json>" + XmlUtils.XMLEncode(content.Json) + "</json>"; xml += "</opencontent>"; } return xml; }
public string ExportModule(int moduleId) { string xml = ""; OpenContentController ctrl = new OpenContentController(); var content = ctrl.GetFirstContent(moduleId); if ((content != null)) { xml += "<opencontent>"; xml += "<json>" + XmlUtils.XMLEncode(content.Json) + "</json>"; xml += "</opencontent>"; } return(xml); }
public void ImportModule(int ModuleID, string Content, string Version, int UserID) { OpenContentController ctrl = new OpenContentController(); XmlNode xml = Globals.GetContent(Content, "opencontent"); var content = new OpenContentInfo() { ModuleId = ModuleID, Json = xml.SelectSingleNode("json").InnerText, CreatedByUserId = UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserID, LastModifiedOnDate = DateTime.Now, Html = "" }; ctrl.AddContent(content); }
public string ExportModule(int moduleId) { string xml = ""; OpenContentController ctrl = new OpenContentController(PortalSettings.Current.PortalId); var items = ctrl.GetContents(moduleId); xml += "<opencontent>"; foreach (var item in items) { xml += "<item>"; xml += "<json>" + XmlUtils.XMLEncode(item.Json) + "</json>"; xml += "<collection>" + XmlUtils.XMLEncode(item.Collection) + "</collection>"; xml += "<key>" + XmlUtils.XMLEncode(item.Id) + "</key>"; xml += "</item>"; } xml += "</opencontent>"; return(xml); }
public void ImportModule(int moduleId, string Content, string version, int userId) { OpenContentController ctrl = new OpenContentController(); XmlNode xml = Globals.GetContent(Content, "opencontent"); var content = new OpenContentInfo() { ModuleId = moduleId, Json = xml.SelectSingleNode("json").InnerText, CreatedByUserId = userId, CreatedOnDate = DateTime.Now, LastModifiedByUserId = userId, LastModifiedOnDate = DateTime.Now, Title = "", Html = "" }; ctrl.AddContent(content, false, null); }
public HttpResponseMessage Add(UpdateRequest req) { try { var module = new OpenContentModuleInfo(req.ModuleId, req.TabId); string editRole = module.Settings.Template.Manifest.GetEditRole(); OpenContentController ctrl = new OpenContentController(); if (module.IsListMode()) { if (!OpenContentUtils.HasEditPermissions(PortalSettings, module.ViewModule, editRole, -1)) { Log.Logger.WarnFormat("Failed the HasEditPermissions() check for "); return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Failed the HasEditPermissions() check")); } var index = module.Settings.Template.Manifest.Index; var indexConfig = OpenContentUtils.GetIndexConfig(module.Settings.Template.Key.TemplateDir, "Items"); OpenContentInfo content = new OpenContentInfo() { ModuleId = module.DataModule.ModuleID, Collection = req.Collection, Title = ActiveModule.ModuleTitle, Json = req.json.ToString(), CreatedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserInfo.UserID, LastModifiedOnDate = DateTime.Now }; ctrl.AddContent(content, index, indexConfig); return(Request.CreateResponse(HttpStatusCode.OK, "")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, "It's not a list mode module")); } } catch (Exception exc) { Log.Logger.Error(exc); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } }
private void DisplayFile(string selectedDataType) { string json = string.Empty; switch (selectedDataType) { case cData: OpenContentController ctrl = new OpenContentController(); OpenContentInfo data = ctrl.GetFirstContent(ModuleId); if (data != null) { json = data.Json; } break; case cSettings: json = ModuleContext.Settings["data"] as string; break; } txtSource.Text = json; }
public override IList<SearchDocument> GetModifiedSearchDocuments(ModuleInfo modInfo, DateTime beginDateUtc) { var searchDocuments = new List<SearchDocument>(); OpenContentController ctrl = new OpenContentController(); var content = ctrl.GetFirstContent(modInfo.ModuleID); if (content != null && (content.LastModifiedOnDate.ToUniversalTime() > beginDateUtc && content.LastModifiedOnDate.ToUniversalTime() < DateTime.UtcNow)) { var searchDoc = new SearchDocument { UniqueKey = modInfo.ModuleID.ToString(), PortalId = modInfo.PortalID, Title = modInfo.ModuleTitle, Description = content.Title, Body = content.Json, ModifiedTimeUtc = content.LastModifiedOnDate.ToUniversalTime() }; searchDocuments.Add(searchDoc); } return searchDocuments; }
private bool GetDemoData(string Template, out string dataJson, out string settingsJson) { dataJson = ""; settingsJson = ""; OpenContentController ctrl = new OpenContentController(); var dataFilename = Path.GetDirectoryName(Server.MapPath(Template)) + "\\" + "data.json"; if (File.Exists(dataFilename)) { string fileContent = File.ReadAllText(dataFilename); if (!string.IsNullOrWhiteSpace(fileContent)) { dataJson = fileContent; } } if (Template == (ModuleContext.Settings["template"] as string)) { settingsJson = ModuleContext.Settings["data"] as string; } if (string.IsNullOrEmpty(settingsJson)) { var settingsFilename = Path.GetDirectoryName(Server.MapPath(Template)) + "\\" + Path.GetFileNameWithoutExtension(Template) + "-data.json"; if (File.Exists(settingsFilename)) { string fileContent = File.ReadAllText(settingsFilename); if (!string.IsNullOrWhiteSpace(fileContent)) { settingsJson = fileContent; } } } return !string.IsNullOrWhiteSpace(dataJson); }
private bool GetData(out string dataJson, out string settingsJson) { dataJson = ""; settingsJson = ""; OpenContentController ctrl = new OpenContentController(); var struc = ctrl.GetFirstContent(ModuleContext.ModuleId); if (struc != null) { dataJson = struc.Json; settingsJson = ModuleContext.Settings["data"] as string; return true; } return false; }
public HttpResponseMessage Edit() { string Template = (string)ActiveModule.ModuleSettings["template"]; JObject json = new JObject(); try { string TemplateFilename = HostingEnvironment.MapPath("~/" + Template); // schema string schemaFilename = Path.GetDirectoryName(TemplateFilename) + "\\" + "schema.json"; JObject schemaJson = JObject.Parse(File.ReadAllText(schemaFilename)); json["schema"] = schemaJson; // default options string optionsFilename = Path.GetDirectoryName(TemplateFilename) + "\\" + "options.json"; if (File.Exists(optionsFilename)) { string fileContent = File.ReadAllText(optionsFilename); if (!string.IsNullOrWhiteSpace(fileContent)) { JObject optionsJson = JObject.Parse(fileContent); json["options"] = optionsJson; } } // language options optionsFilename = Path.GetDirectoryName(TemplateFilename) + "\\" + "options." + PortalSettings.CultureCode + ".json"; if (File.Exists(optionsFilename)) { string fileContent = File.ReadAllText(optionsFilename); if (!string.IsNullOrWhiteSpace(fileContent)) { JObject optionsJson = JObject.Parse(fileContent); json["options"] = json["options"].JsonMerge(optionsJson); } } // view string viewFilename = Path.GetDirectoryName(TemplateFilename) + "\\" + "view.json"; if (File.Exists(optionsFilename)) { string fileContent = File.ReadAllText(viewFilename); if (!string.IsNullOrWhiteSpace(fileContent)) { JObject optionsJson = JObject.Parse(fileContent); json["view"] = optionsJson; } } // template options /* optionsFilename = Path.GetDirectoryName(TemplateFilename) + "\\" + "options." + Path.GetFileNameWithoutExtension(TemplateFilename) + ".json"; if (File.Exists(optionsFilename)) { JObject optionsJson = JObject.Parse(File.ReadAllText(optionsFilename)); json["options"] = json["options"].JsonMerge(optionsJson); } */ int ModuleId = ActiveModule.ModuleID; OpenContentController ctrl = new OpenContentController(); var struc = ctrl.GetFirstContent(ModuleId); if (struc != null) { json["data"] = JObject.Parse(struc.Json); } return Request.CreateResponse(HttpStatusCode.OK, json); } catch (Exception exc) { Logger.Error(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }
public HttpResponseMessage Update(JObject json) { try { int ModuleId = ActiveModule.ModuleID; OpenContentController ctrl = new OpenContentController(); var content = ctrl.GetFirstContent(ModuleId); if (content == null) { content = new OpenContentInfo() { ModuleId = ModuleId, Title = json["form"]["Title"] == null ? ActiveModule.ModuleTitle : json["form"]["Title"].ToString(), Json = json["form"].ToString(), CreatedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserInfo.UserID, LastModifiedOnDate = DateTime.Now, Html = "", }; ctrl.AddContent(content); } else { content.Title = json["form"]["Title"] == null ? ActiveModule.ModuleTitle : json["form"]["Title"].ToString(); content.Json = json["form"].ToString(); content.LastModifiedByUserId = UserInfo.UserID; content.LastModifiedOnDate = DateTime.Now; ctrl.UpdateContent(content); } if (json["form"]["ModuleTitle"] != null && json["form"]["ModuleTitle"].Type == JTokenType.String) { string ModuleTitle = json["form"]["ModuleTitle"].ToString(); OpenContentUtils.UpdateModuleTitle(ActiveModule, ModuleTitle); } return Request.CreateResponse(HttpStatusCode.OK, ""); } catch (Exception exc) { Logger.Error(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }
private void SaveData() { OpenContentController ctrl = new OpenContentController(); var data = ctrl.GetFirstContent(ModuleId); if (string.IsNullOrEmpty(txtSource.Text)) { if (data != null) { ctrl.DeleteContent(data); } } else { JObject json = JObject.Parse(txtSource.Text); if (data == null) { data = new OpenContentInfo() { ModuleId = ModuleId, Title = json["Title"] == null ? ModuleContext.Configuration.ModuleTitle : json["Title"].ToString(), CreatedByUserId = UserInfo.UserID, CreatedOnDate = DateTime.Now, LastModifiedByUserId = UserInfo.UserID, LastModifiedOnDate = DateTime.Now, Html = "", Json = txtSource.Text }; ctrl.AddContent(data); } else { data.Title = json["Title"] == null ? ModuleContext.Configuration.ModuleTitle : json["Title"].ToString(); data.LastModifiedByUserId = UserInfo.UserID; data.LastModifiedOnDate = DateTime.Now; data.Json = txtSource.Text; ctrl.UpdateContent(data); } if (json["ModuleTitle"] != null && json["ModuleTitle"].Type == JTokenType.String) { string ModuleTitle = json["ModuleTitle"].ToString(); OpenContentUtils.UpdateModuleTitle(ModuleContext.Configuration, ModuleTitle); } } }