コード例 #1
0
        public static INode MatchRequest(this IContainer cnt, INodeRequest request, INodeTypeFactory typeFactory)
        {
            INode ret = null;

            switch (request.RequestType)
            {
            case RequestTypeEnum.Move:
                return(request.Move(cnt));

            case RequestTypeEnum.Get:
                return(cnt.GetById(request.Data));

            case RequestTypeEnum.Add:
                return(request.GetNewNode(cnt, typeFactory));

            case RequestTypeEnum.Update:
                return(request.GetUpdatedNode(cnt));

            case RequestTypeEnum.Remove:
                return(request.RemoveNode(cnt));

            case RequestTypeEnum.Link:
                var rel = request.GetRelation(cnt);
                if (rel.Item1 != null && rel.Item2 != null)
                {
                    cnt.AddRelation(rel.Item1, rel.Item2);
                    ret = rel.Item1;
                }
                break;
            }
            return(ret);
        }
コード例 #2
0
        public static INode GetUpdatedNode(this INodeRequest request, IContainer container)
        {
            var nodeId = GetId(request.JsonData);

            if (!string.IsNullOrEmpty(nodeId))
            {
                return(container.GetById(nodeId).Apply(request.JsonData));
            }
            return(null);
        }
コード例 #3
0
        public static INode RemoveNode(this INodeRequest request, IContainer container)
        {
            var nodeId = GetId(request.JsonData);

            if (!string.IsNullOrEmpty(nodeId))
            {
                var nodeToRemove = container.GetById(nodeId);
                var parent       = container.GetById(nodeToRemove.ParentId);
                container.RemoveNode(nodeToRemove);
                return(parent);
            }
            return(null);
        }
コード例 #4
0
        public static (INode, INode) GetRelation(this INodeRequest request, IContainer container)
        {
            var   fromId = request.QueryString.GetString("from");
            var   toId   = request.QueryString.GetString("to");
            INode from   = container.GetById(fromId);
            INode to     = container.GetById(toId);

            if (from != null && to != null)
            {
                return(from, to);
            }
            return(null, null);
        }
コード例 #5
0
        public static INode GetNewNode(this INodeRequest request, IContainer container, INodeTypeFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentException("Node type factory is needed to create new nodes", nameof(factory));
            }
            var parent  = request.GetParent(container);
            var type    = request.QueryString.GetString("type", request.JsonData.GetString("type"));
            var newNode = factory.GetNew(type);

            if (request.JsonData != null)
            {
                newNode.Apply(request.JsonData);
            }
            parent.Add(newNode);
            return(newNode);
        }
コード例 #6
0
        public static INode Move(this INodeRequest request, IContainer container)
        {
            var moveData = new MoveData();

            JsonSerializer.CreateDefault().Populate(request.JsonData.CreateReader(), moveData);
            if (!string.IsNullOrEmpty(moveData.ParentId) && !string.IsNullOrEmpty(moveData.OldParentId))
            {
                if (moveData.ParentId.Equals(moveData.OldParentId))
                {
                    return(container.GetById(moveData.OldParentId).SetNodePosition(container.GetById(moveData.Id), moveData.NewIndex));
                }
                else
                {
                    return(container.GetById(moveData.OldParentId).ChangeParent(container.GetById(moveData.Id), container.GetById(moveData.ParentId), moveData.NewIndex));
                }
            }
            return(null);
        }
コード例 #7
0
ファイル: SerializerSettings.cs プロジェクト: matst80/TinyCMS
 public void FromRequest(INodeRequest request)
 {
     FromQueryString(request.QueryString);
 }
コード例 #8
0
        public static INode GetParent(this INodeRequest request, IContainer container)
        {
            var parentId = request.QueryString.GetString("parentId", request.JsonData.GetString("parentId"));

            return(container.GetById(parentId) ?? container.RootNode);
        }