public ActionResult GrantOrDenyRoles()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    bool isAssigned = bool.Parse(row["IsAssigned"].ToString());
                    var  entity     = GetRequiredService <IRepository <Privilege, Guid> >().GetByKey(id);
                    if (entity != null)
                    {
                        if (!isAssigned)
                        {
                            AcDomain.Handle(new RemovePrivilegeCommand(AcSession, entity.Id));
                        }
                        else
                        {
                            if (row.ContainsKey("AcContent"))
                            {
                                AcDomain.Handle(new PrivilegeUpdateIo
                                {
                                    Id        = id,
                                    AcContent = row["AcContent"].ToString()
                                }.ToCommand(AcSession));
                            }
                        }
                    }
                    else if (isAssigned)
                    {
                        var createInput = new PrivilegeCreateIo()
                        {
                            Id                = new Guid(row["Id"].ToString()),
                            SubjectType       = UserAcSubjectType.Role.ToName(),
                            SubjectInstanceId = new Guid(row["RoleId"].ToString()),
                            ObjectInstanceId  = new Guid(row["GroupId"].ToString()),
                            ObjectType        = AcElementType.Group.ToName(),
                            AcContent         = null,
                            AcContentType     = null
                        };
                        if (row.ContainsKey("AcContent"))
                        {
                            createInput.AcContent = row["AcContent"].ToString();
                        }
                        AcDomain.Handle(createInput.ToCommand(AcSession));
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #2
0
        public ActionResult UpdateNodes()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";
                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    var  id = new Guid(row["Id"].ToString());
                    var  isExecuteEnabled  = bool.Parse(row["IsExecuteEnabled"].ToString());
                    var  isProduceEnabled  = bool.Parse(row["IsProduceEnabled"].ToString());
                    var  isReceiveEnabled  = bool.Parse(row["IsReceiveEnabled"].ToString());
                    var  isTransferEnabled = bool.Parse(row["IsDistributeEnabled"].ToString());
                    Node entity            = GetRequiredService <IRepository <Node> >().GetByKey(id);
                    if (entity != null)
                    {
                        entity.IsExecuteEnabled    = isExecuteEnabled;
                        entity.IsProduceEnabled    = isProduceEnabled;
                        entity.IsReceiveEnabled    = isReceiveEnabled;
                        entity.IsDistributeEnabled = isTransferEnabled;
                        AcDomain.Handle(new UpdateNodeCommand(AcSession, new NodeUpdateInput
                        {
                            Abstract         = entity.Abstract,
                            AnycmdApiAddress = entity.AnycmdApiAddress,
                            AnycmdWsAddress  = entity.AnycmdWsAddress,
                            BeatPeriod       = entity.BeatPeriod,
                            Code             = entity.Code,
                            Description      = entity.Description,
                            Email            = entity.Email,
                            IsEnabled        = entity.IsEnabled,
                            Icon             = entity.Icon,
                            Id         = entity.Id,
                            Mobile     = entity.Mobile,
                            Name       = entity.Name,
                            Catalog    = entity.Catalog,
                            PublicKey  = entity.PublicKey,
                            Qq         = entity.Qq,
                            SecretKey  = entity.SecretKey,
                            SortCode   = entity.SortCode,
                            Steward    = entity.Steward,
                            Telephone  = entity.Telephone,
                            TransferId = entity.TransferId
                        }));
                    }
                    else
                    {
                        throw new AnycmdException("意外的节点");
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #3
0
        public ActionResult AddOrUpdateNodeActions()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";
                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    var inputModel = new NodeAction()
                    {
                        Id        = new Guid(row["Id"].ToString()),
                        NodeId    = new Guid(row["NodeId"].ToString()),
                        ActionId  = new Guid(row["ActionId"].ToString()),
                        IsAllowed = row["IsAllowed"].ToString(),
                        IsAudit   = row["IsAudit"].ToString()
                    };
                    NodeDescriptor nodeDescriptor;
                    if (!AcDomain.NodeHost.Nodes.TryGetNodeById(inputModel.NodeId.ToString(), out nodeDescriptor))
                    {
                        throw new ValidationException("意外的节点标识" + inputModel.NodeId);
                    }
                    NodeAction entity = null;
                    if (nodeDescriptor != null)
                    {
                        entity = new NodeAction
                        {
                            Id        = inputModel.Id,
                            ActionId  = inputModel.ActionId,
                            IsAllowed = inputModel.IsAllowed,
                            IsAudit   = inputModel.IsAudit,
                            NodeId    = inputModel.NodeId
                        };
                        AcDomain.PublishEvent(new NodeActionUpdatedEvent(AcSession, entity));
                    }
                    else
                    {
                        entity = new NodeAction
                        {
                            Id        = inputModel.Id,
                            NodeId    = inputModel.NodeId,
                            ActionId  = inputModel.ActionId,
                            IsAudit   = inputModel.IsAudit,
                            IsAllowed = inputModel.IsAllowed
                        };
                        AcDomain.PublishEvent(new NodeActionAddedEvent(AcSession, entity));
                    }
                    AcDomain.CommitEventBus();
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #4
0
        public ActionResult AddOrUpdateElementActions()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                if (state == "modified" || state == "") //更新:_state为空或modified
                {
                    var inputModel = new ElementAction()
                    {
                        Id        = new Guid(row["Id"].ToString()),
                        ElementId = new Guid(row["ElementId"].ToString()),
                        ActionId  = new Guid(row["ActionId"].ToString()),
                        IsAudit   = row["IsAudit"].ToString(),
                        IsAllowed = row["IsAllowed"].ToString()
                    };
                    ElementDescriptor element;
                    AcDomain.NodeHost.Ontologies.TryGetElement(inputModel.ElementId, out element);
                    ElementAction entity = null;
                    if (element != null)
                    {
                        entity = new ElementAction
                        {
                            ActionId  = inputModel.ActionId,
                            IsAllowed = inputModel.IsAllowed,
                            IsAudit   = inputModel.IsAudit,
                            ElementId = element.Element.Id,
                            Id        = inputModel.Id
                        };
                        AcDomain.PublishEvent(new ElementActionUpdatedEvent(AcSession, entity));
                    }
                    else
                    {
                        entity = new ElementAction
                        {
                            Id        = inputModel.Id,
                            ElementId = inputModel.ElementId,
                            ActionId  = inputModel.ActionId,
                            IsAudit   = inputModel.IsAudit,
                            IsAllowed = inputModel.IsAllowed
                        };
                        AcDomain.PublishEvent(new ElementActionAddedEvent(AcSession, entity));
                    }
                    AcDomain.CommitEventBus();
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #5
0
        public ActionResult AddOrUpdateNodeElementActions()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";
                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    var inputModel = new NodeElementAction()
                    {
                        Id        = new Guid(row["Id"].ToString()),
                        NodeId    = new Guid(row["NodeId"].ToString()),
                        ElementId = new Guid(row["ElementId"].ToString()),
                        ActionId  = new Guid(row["ActionId"].ToString()),
                        IsAllowed = bool.Parse(row["IsAllowed"].ToString()),
                        IsAudit   = bool.Parse(row["IsAudit"].ToString())
                    };
                    NodeElementAction entity = GetRequiredService <IRepository <NodeElementAction> >().GetByKey(inputModel.Id);
                    if (entity != null)
                    {
                        entity.IsAudit   = inputModel.IsAudit;
                        entity.IsAllowed = inputModel.IsAllowed;
                        GetRequiredService <IRepository <NodeElementAction> >().Update(entity);
                    }
                    else
                    {
                        entity           = new NodeElementAction();
                        entity.Id        = inputModel.Id;
                        entity.NodeId    = inputModel.NodeId;
                        entity.ElementId = inputModel.ElementId;
                        entity.ActionId  = inputModel.ActionId;
                        entity.IsAudit   = inputModel.IsAudit;
                        entity.IsAllowed = inputModel.IsAllowed;
                        var count = GetRequiredService <IRepository <NodeElementAction> >().AsQueryable().Count(a => a.NodeId == entity.NodeId &&
                                                                                                                a.ElementId == entity.ElementId &&
                                                                                                                a.ActionId == entity.ActionId);
                        if (count > 0)
                        {
                            throw new ValidationException("给定的节点已拥有给定的动作,无需重复关联");
                        }
                        GetRequiredService <IRepository <NodeElementAction> >().Add(entity);
                    }
                    GetRequiredService <IRepository <NodeElementAction> >().Context.Commit();
                    AcDomain.CommitEventBus();
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #6
0
        public ActionResult AddOrRemoveElementCares()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";
                var    id    = new Guid(row["Id"].ToString());
                if (state == "modified" || state == "") //更新:_state为空或modified
                {
                    bool            isAssigned = bool.Parse(row["IsAssigned"].ToString());
                    NodeElementCare entity     = GetRequiredService <IRepository <NodeElementCare> >().GetByKey(id);
                    if (entity != null)
                    {
                        if (!isAssigned)
                        {
                            AcDomain.RemoveNodeElementCare(AcSession, id);
                        }
                        else
                        {
                            // TODO:IsInfoIDItem字段需要update
                        }
                    }
                    else if (isAssigned)
                    {
                        AcDomain.Handle(new NodeElementCareCreateInput
                        {
                            Id           = id,
                            NodeId       = new Guid(row["NodeId"].ToString()),
                            ElementId    = new Guid(row["ElementId"].ToString()),
                            IsInfoIdItem = bool.Parse(row["IsInfoIDItem"].ToString())
                        }.ToCommand(AcSession));
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #7
0
        public ActionResult AddOrDeleteRoleMembers()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    bool isAssigned = bool.Parse(row["IsAssigned"].ToString());
                    var  entity     = GetRequiredService <IRepository <DsdRole, Guid> >().GetByKey(id);
                    if (entity != null)
                    {
                        if (!isAssigned)
                        {
                            AcDomain.Handle(new RemoveDsdRoleCommand(AcSession, id));
                        }
                    }
                    else if (isAssigned)
                    {
                        var createInput = new DsdRoleCreateIo
                        {
                            Id       = new Guid(row["Id"].ToString()),
                            RoleId   = new Guid(row["RoleId"].ToString()),
                            DsdSetId = new Guid(row["DsdSetId"].ToString())
                        };
                        AcDomain.Handle(createInput.ToCommand(AcSession));
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #8
0
        public ActionResult UpdateOntologies()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";
                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    var inputModel = new Ontology()
                    {
                        Id = new Guid(row["Id"].ToString()),
                        IsCataloguedEntity      = bool.Parse(row["IsCataloguedEntity"].ToString()),
                        IsLogicalDeletionEntity = bool.Parse(row["IsLogicalDeletionEntity"].ToString())
                    };
                    Ontology entity = GetRequiredService <IRepository <Ontology> >().GetByKey(inputModel.Id);
                    if (entity != null)
                    {
                        entity.IsCataloguedEntity      = inputModel.IsCataloguedEntity;
                        entity.IsLogicalDeletionEntity = inputModel.IsLogicalDeletionEntity;
                        GetRequiredService <IRepository <Ontology> >().Update(entity);
                        GetRequiredService <IRepository <Ontology> >().Context.Commit();
                        AcDomain.CommitEventBus();
                    }
                    else
                    {
                        throw new AnycmdException("意外的本体");
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #9
0
        public ActionResult ManageOrUnManageFunction()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改功能
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    bool isManaged = bool.Parse(row["IsManaged"].ToString());
                    var  entity    = GetRequiredService <IRepository <Function> >().GetByKey(id);
                    if (entity != null)
                    {
                        var input = new FunctionUpdateInput
                        {
                            Description = entity.Description,
                            DeveloperId = entity.DeveloperId,
                            IsEnabled   = entity.IsEnabled,
                            IsManaged   = entity.IsManaged,
                            SortCode    = entity.SortCode,
                            Code        = entity.Code,
                            Id          = entity.Id
                        };
                        input.IsManaged = isManaged;
                        AcDomain.Handle(input.ToCommand(AcSession));
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
Beispiel #10
0
        public ActionResult AddOrRemoveNodes()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                var id = new Guid(row["Id"].ToString());
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                if (state == "modified" || state == "") //更新:_state为空或modified
                {
                    var inputModel = new NodeElementCare()
                    {
                        Id        = new Guid(row["Id"].ToString()),
                        NodeId    = new Guid(row["NodeId"].ToString()),
                        ElementId = new Guid(row["ElementId"].ToString())
                    };
                    bool            isAssigned = bool.Parse(row["IsAssigned"].ToString());
                    NodeElementCare entity     = GetRequiredService <IRepository <NodeElementCare> >().GetByKey(inputModel.Id);
                    bool            isNew      = true;
                    if (entity != null)
                    {
                        isNew = false;
                        if (!isAssigned)
                        {
                            GetRequiredService <IRepository <NodeElementCare> >().Remove(entity);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        entity = new NodeElementCare {
                            Id = inputModel.Id
                        };
                    }
                    if (isAssigned)
                    {
                        entity.NodeId    = inputModel.NodeId;
                        entity.ElementId = inputModel.ElementId;
                        if (isNew)
                        {
                            var count = GetRequiredService <IRepository <NodeElementCare> >().AsQueryable().Count(a => a.ElementId == entity.ElementId &&
                                                                                                                  a.NodeId == entity.NodeId);
                            if (count > 0)
                            {
                                throw new ValidationException("给定的节点已关心给定的本体元素,无需重复关心");
                            }
                            GetRequiredService <IRepository <NodeElementCare> >().Add(entity);
                        }
                        else
                        {
                            GetRequiredService <IRepository <NodeElementCare> >().Update(entity);
                        }
                    }
                    GetRequiredService <IRepository <NodeElementCare> >().Context.Commit();
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
        public ActionResult AddOrRemoveButtons()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                //更新:_state为空或modified
                if (state == "modified" || state == "")
                {
                    string functionIdStr = row["FunctionId"] == null ? null : row["FunctionId"].ToString();
                    Guid?  functionId    = string.IsNullOrEmpty(functionIdStr) ? null : new Guid?(new Guid(functionIdStr));
                    if (functionId.HasValue)
                    {
                        FunctionState function;
                        if (!AcDomain.FunctionSet.TryGetFunction(functionId.Value, out function))
                        {
                            throw new ValidationException("意外的托管功能标识" + functionId.Value);
                        }
                    }
                    var inputModel = new UiViewButton(new Guid(row["Id"].ToString()))
                    {
                        IsEnabled  = int.Parse(row["IsEnabled"].ToString()),
                        ButtonId   = new Guid(row["ButtonId"].ToString()),
                        UiViewId   = new Guid(row["UiViewId"].ToString()),
                        FunctionId = functionId
                    };

                    if (bool.Parse(row["IsAssigned"].ToString()))
                    {
                        if (AcDomain.RetrieveRequiredService <IRepository <UiViewButton, Guid> >().AsQueryable().Any(a => a.Id == inputModel.Id))
                        {
                            var updateModel = new UiViewButtonUpdateInput()
                            {
                                Id         = inputModel.Id,
                                IsEnabled  = inputModel.IsEnabled,
                                FunctionId = inputModel.FunctionId
                            };
                            AcDomain.Handle(updateModel.ToCommand(AcSession));
                        }
                        else
                        {
                            var input = new UiViewButtonCreateInput()
                            {
                                Id         = inputModel.Id,
                                ButtonId   = inputModel.ButtonId,
                                IsEnabled  = inputModel.IsEnabled,
                                FunctionId = inputModel.FunctionId,
                                UiViewId   = inputModel.UiViewId
                            };
                            AcDomain.Handle(input.ToCommand(AcSession));
                        }
                    }
                    else
                    {
                        AcDomain.Handle(new RemoveUiViewButtonCommand(AcSession, inputModel.Id));
                    }
                    if (functionId.HasValue)
                    {
                        int           functionIsEnabled = int.Parse(row["FunctionIsEnabled"].ToString());
                        FunctionState function;
                        if (!AcDomain.FunctionSet.TryGetFunction(functionId.Value, out function))
                        {
                            throw new GeneralException("意外的功能标识" + functionId.Value);
                        }
                        var input = new FunctionUpdateInput
                        {
                            Id          = function.Id,
                            Code        = function.Code,
                            SortCode    = function.SortCode,
                            IsManaged   = function.IsManaged,
                            IsEnabled   = function.IsEnabled,
                            DeveloperId = function.DeveloperId,
                            Description = function.Description
                        };
                        input.IsEnabled = functionIsEnabled;
                        AcDomain.Handle(input.ToCommand(AcSession));
                    }
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }
        public ActionResult AddOrUpdateCatalogActions()
        {
            String json = Request["data"];
            var    rows = (ArrayList)MiniJSON.Decode(json);

            foreach (Hashtable row in rows)
            {
                //根据记录状态,进行不同的增加、删除、修改操作
                String state = row["_state"] != null ? row["_state"].ToString() : "";

                if (state == "modified" || state == "") //更新:_state为空或modified
                {
                    var inputModel = new CatalogAction(new Guid(row["Id"].ToString()))
                    {
                        CatalogId = new Guid(row["CatalogId"].ToString()),
                        ActionId  = new Guid(row["ActionId"].ToString()),
                        IsAudit   = row["IsAudit"].ToString(),
                        IsAllowed = row["IsAllowed"].ToString()
                    };
                    var action = AcDomain.NodeHost.Ontologies.GetAction(inputModel.ActionId);
                    if (action == null)
                    {
                        throw new ValidationException("意外的本体动作标识" + action.Id);
                    }
                    OntologyDescriptor ontology;
                    if (!AcDomain.NodeHost.Ontologies.TryGetOntology(action.Id, out ontology))
                    {
                        throw new ValidationException("意外的动作本体标识" + action.OntologyId);
                    }
                    CatalogState catalog;
                    if (!AcDomain.CatalogSet.TryGetCatalog(inputModel.CatalogId, out catalog))
                    {
                        throw new ValidationException("意外的目录标识");
                    }
                    var           ontologyOrgDic = AcDomain.NodeHost.Ontologies.GetOntologyCatalogs(ontology);
                    CatalogAction entity         = null;
                    if (ontologyOrgDic.ContainsKey(catalog))
                    {
                        entity = new CatalogAction(inputModel.Id)
                        {
                            ActionId  = inputModel.ActionId,
                            IsAllowed = inputModel.IsAllowed,
                            IsAudit   = inputModel.IsAudit,
                            CatalogId = inputModel.CatalogId
                        };
                        AcDomain.PublishEvent(new CatalogActionUpdatedEvent(AcSession, entity));
                    }
                    else
                    {
                        entity           = new CatalogAction(inputModel.Id);
                        entity.CatalogId = inputModel.CatalogId;
                        entity.ActionId  = inputModel.ActionId;
                        entity.IsAudit   = inputModel.IsAudit;
                        entity.IsAllowed = inputModel.IsAllowed;
                        AcDomain.PublishEvent(new CatalogActionAddedEvent(AcSession, entity));
                    }
                    AcDomain.CommitEventBus();
                }
            }

            return(this.JsonResult(new ResponseData {
                success = true
            }));
        }