public void ImportModule(int moduleId, string content, string version, int userId) { var dataSource = new OpenContentDataSource(); var dsContext = new DataSourceContext { ModuleId = moduleId, UserId = userId, }; 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"); dsContext.Collection = collection?.InnerText ?? ""; JToken data = JToken.Parse(json.InnerText); /* * if (!string.IsNullOrEmpty(key?.InnerText)) * { * data["_id"] = new JValue(key.InnerText); * } */ dataSource.Add(dsContext, data); } }
public void ImportModule(int moduleId, string content, string version, int userId) { var module = OpenContentModuleConfig.Create(moduleId, Null.NullInteger, PortalSettings.Current); var dataSource = new OpenContentDataSource(); var dsContext = OpenContentUtils.CreateDataContext(module, userId); XmlNode xml = Globals.GetContent(content, "opencontent"); var items = xml.SelectNodes("item"); if (items != null) { foreach (XmlNode item in items) { XmlNode json = item.SelectSingleNode("json"); XmlNode collection = item.SelectSingleNode("collection"); XmlNode key = item.SelectSingleNode("key"); try { JToken data = JToken.Parse(json.InnerText); dsContext.Collection = collection?.InnerText ?? ""; dataSource.Add(dsContext, data); App.Services.CacheAdapter.SyncronizeCache(module); } catch (Exception e) { App.Services.Logger.Error($"Failed to parse imported json. Item key: {key}. Collection: {collection}. Error: {e.Message}. Stacktrace: {e.StackTrace}"); throw; } } } }
public HttpResponseMessage Add(UpdateRequest req) { try { var module = new OpenContentModuleInfo(req.ModuleId, req.TabId); string editRole = module.Settings.Template.Manifest.GetEditRole(); var dataSource = new OpenContentDataSource(); if (module.IsListMode()) { if (!OpenContentUtils.HasEditPermissions(PortalSettings, module.ViewModule, editRole, -1)) { Log.Logger.Warn($"Failed the HasEditPermissions() check"); return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Failed the HasEditPermissions() check")); } var dsContext = OpenContentUtils.CreateDataContext(module, UserInfo.UserID); dsContext.Collection = req.Collection; JToken data = req.json; data["Title"] = ActiveModule.ModuleTitle; dataSource.Add(dsContext, data); 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)); } }