Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void CreateUserForItems(int TabId, int ModuleId, int userToChangeId, string passPrefix, string passSuffix, string roleName, string titlePath, string emailPath, string firstName)
        {
            //int ModuleId = 585; // dev 682;
            //int TabId = 160; // dev 210;
            ModuleController mc = new ModuleController();
            var activeModule    = mc.GetModule(ModuleId, TabId, false);

            if (activeModule != null)
            {
                var ocModule = new OpenContentModuleInfo(activeModule);

                //IDataSource ds = DataSourceManager.GetDataSource(module.Settings.Manifest.DataSource);
                var dsContext = OpenContentUtils.CreateDataContext(ocModule);
                var ds        = new OpenContentDataSource();
                var items     = ds.GetAll(dsContext);
                foreach (var item in items.Items)
                {
                    if (item.CreatedByUserId == userToChangeId)
                    {
                        var title = item.Data.SelectToken(titlePath, false)?.ToString();
                        var email = item.Data.SelectToken(emailPath, false)?.ToString();
                        if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(email))
                        {
                            //var name = title.Replace(" ", "").ToLower();
                            //var password = (new Guid()).ToString().Substring(0, 10);
                            try
                            {
                                int userid  = CreateUser(email, passPrefix + item.Id + passSuffix, firstName, title, email, roleName);
                                var content = (OpenContentInfo)item.Item;
                                content.CreatedByUserId = userid;
                                ds.Update(dsContext, item, item.Data);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
        }
        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));
            }
        }