示例#1
0
        public void Entity_Event_InvalidStateCode()
        {
            var xm        = System.Guid.NewGuid().ToString();
            var infoValue = new KeyValueBuilder(new Dictionary <string, string> {
                { "XM", xm },
                { "ZZJGM", "11011421005" }
            }).ToArray();
            var request = new Message
            {
                MessageId   = System.Guid.NewGuid().ToString(),
                MessageType = "event",
                IsDumb      = true,
                Verb        = "Create",
                Ontology    = "JS",
                TimeStamp   = DateTime.UtcNow.Ticks,
                Version     = "v1",
                Body        = new BodyData(infoValue, infoValue)
                {
                    Event = new EventData
                    {
                        Subject    = "StateCodeChanged",
                        SourceType = "entity"
                    }
                },
            }.JspxToken();
            //var response = request.RequestNode(acDomain.NodeHost.Nodes.CenterNode);
            var response = AnyMessage.Create(HecpRequest.Create(AcDomain, request), AcDomain.NodeHost.Nodes.CenterNode).Response();

            Assert.IsTrue((int)Status.InvalidStatus == response.Body.Event.Status, response.Body.Event.Description);
            request.IsDumb = false;
            response       = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.InvalidStatus == response.Body.Event.Status, response.Body.Event.Description);
        }
示例#2
0
        public void Command_Event_NotExist()
        {
            var xm        = System.Guid.NewGuid().ToString();
            var infoValue = new KeyValueBuilder(new Dictionary <string, string> {
                { "XM", xm },
                { "ZZJGM", "11011421005" }
            }).ToArray();
            var dto = new Message
            {
                MessageId   = System.Guid.NewGuid().ToString(),
                MessageType = "event",
                Verb        = "Create",
                Ontology    = "JS",
                IsDumb      = true,
                TimeStamp   = DateTime.UtcNow.Ticks,
                Version     = "v1",
                Body        = new BodyData(infoValue, infoValue)
                {
                    Event = new EventData
                    {
                        Status       = (int)Status.AuditApproved,
                        Subject      = "StateCodeChanged",
                        ReasonPhrase = Status.AuditApproved.ToName(),
                        SourceType   = EventSourceType.Command.ToName()
                    }
                },
            }.JspxToken();
            // var response = dto.RequestNode(acDomain.NodeHost.Nodes.CenterNode);
            var response = AnyMessage.Create(HecpRequest.Create(AcDomain, dto), AcDomain.NodeHost.Nodes.ThisNode).Response();

            Assert.IsTrue((int)Status.NotExist == response.Body.Event.Status, response.Body.Event.Description);
            dto.IsDumb = false;
            response   = dto.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.NotExist == response.Body.Event.Status, response.Body.Event.Description);
        }
示例#3
0
        public void UpdateLoginName()
        {
            var localEntityId = Guid.NewGuid().ToString();
            var xm            = NewXM();
            var infoId        = new KeyValue[] {
                new KeyValue("ZZJGM", "11010621022"),
                new KeyValue("XM", xm)
            };
            var infoValue = infoId;
            var request   = new Message()
            {
                Version     = ApiVersion.V1.ToName(),
                IsDumb      = false,
                MessageType = MessageType.Action.ToName(),
                MessageId   = Guid.NewGuid().ToString(),
                Verb        = "create",
                Ontology    = "JS",
                TimeStamp   = DateTime.UtcNow.Ticks,
                Body        = new BodyData(infoValue, infoValue),
            }.UiaSignature();
            var response = AnyMessage.Create(HecpRequest.Create(AcDomain, request), AcDomain.NodeHost.Nodes.ThisNode).Response();

            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            request.Body.InfoId    = response.Body.InfoValue;
            request.Verb           = "update";
            request.Body.InfoValue = new KeyValue[] { new KeyValue("LoginName", DateTime.Now.Ticks.ToString()) };
            response = AnyMessage.Create(HecpRequest.Create(AcDomain, request), AcDomain.NodeHost.Nodes.ThisNode).Response();
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            request.Verb = "delete";
            response     = AnyMessage.Create(HecpRequest.Create(AcDomain, request), AcDomain.NodeHost.Nodes.ThisNode).Response();
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
        }
示例#4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cmdDto"></param>
 /// <param name="responseNode"></param>
 /// <returns></returns>
 public static AnyMessage ToAnyCommand(this IMessageDto cmdDto, NodeDescriptor responseNode)
 {
     if (cmdDto == null)
     {
         throw new ArgumentNullException("cmdDto");
     }
     if (responseNode == null)
     {
         throw new ArgumentNullException("responseNode");
     }
     return AnyMessage.Create(HecpRequest.Create(responseNode.AcDomain, cmdDto), responseNode);
 }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="acDomain"></param>
        /// <param name="context"></param>
        public static MessageContext Create(IAcDomain acDomain, HecpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            var commandContext = new MessageContext(acDomain, AnyMessage.Create(context.Request, acDomain.NodeHost.Nodes.ThisNode));

            foreach (var act in context)
            {
                commandContext.Trace(act);
            }
            return(commandContext);
        }
示例#6
0
        public void Command_Action_Update()
        {
            // 首先使用一个Create型命令准备测试数据。然后测试Command和Action,最后打扫现场删除测试数据。
            var xm        = NewXM();
            var infoValue = new KeyValueBuilder(new Dictionary <string, string> {
                { "XM", xm },
                { "ZZJGM", "11011421004" }
            }).ToArray();
            var request = new Message
            {
                MessageId   = System.Guid.NewGuid().ToString(),
                Version     = "v1",
                MessageType = "action",
                IsDumb      = false,
                Verb        = "Create",
                Ontology    = "JS",
                Body        = new BodyData(infoValue, infoValue),
                TimeStamp   = DateTime.UtcNow.Ticks
            }.JspxToken();
            var response = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);

            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            // 从配置文件中读取或者从数据库表的列名读取
            KeyValue[] infoId = new KeyValueBuilder(new Dictionary <string, string> {
                { "XBM", (DateTime.Now.Ticks % 3).ToString() }
            }).ToArray();
            request.MessageId   = Guid.NewGuid().ToString();
            request.MessageType = "Command";
            request.Body        = new BodyData(infoValue, new KeyValueBuilder(request.Body.InfoValue).Append("XBM", "1").ToArray());
            request.TimeStamp   = DateTime.UtcNow.Ticks;
            request.Verb        = "Update";
            request.IsDumb      = true;
            //response = request.RequestNode(acDomain.NodeHost.Nodes.CenterNode);
            response = AnyMessage.Create(HecpRequest.Create(AcDomain, request), AcDomain.NodeHost.Nodes.CenterNode).Response();
            Assert.IsTrue((int)Status.ReceiveOk == response.Body.Event.Status, response.Body.Event.Description);
            request.MessageType = "action";
            response            = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);

            request.MessageType = "command";
            request.IsDumb      = false;
            response            = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ReceiveOk == response.Body.Event.Status, response.Body.Event.Description);
            request.MessageType = "action";
            response            = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            request.Verb = "delete";
            response     = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
        }
示例#7
0
        public void Permission()
        {
            var infoId = new KeyValueBuilder(new Dictionary <string, string> {
                { "SFZJH", "320113198108242027" },
                { "SFZJLXM", "1" },
                { "GHHM", "85012345" }
            }).ToArray();
            var cmdDto = new Message
            {
                MessageId   = System.Guid.NewGuid().ToString(),
                Version     = "v1",
                Verb        = "Head",
                MessageType = "action",
                IsDumb      = true,
                Ontology    = "JS",
                Body        = new BodyData(infoId, null),
                TimeStamp   = DateTime.UtcNow.Ticks
            }.JspxToken();
            var response = cmdDto.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);

            //var response = AnyMessage.Create(HecpRequest.Create(request, Credential.Create(request))).Response();
            Assert.IsTrue((int)Status.NoPermission == response.Body.Event.Status, response.Body.Event.Description);
            cmdDto.IsDumb = false;
            //response = request.RequestNode(acDomain.NodeHost.Nodes.CenterNode);
            // 使用下面这行可以绕过网络传输从而易于调试,而上面那行需要网络传输
            response = AnyMessage.Create(HecpRequest.Create(AcDomain, cmdDto), AcDomain.NodeHost.Nodes.ThisNode).Response();
            Assert.IsTrue((int)Status.NoPermission == response.Body.Event.Status, response.Body.Event.Description);

            cmdDto.MessageType = "Command";
            response           = cmdDto.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            //var response = AnyMessage.Create(HecpRequest.Create(request, Credential.Create(request))).Response();
            Assert.IsTrue((int)Status.NoPermission == response.Body.Event.Status, response.Body.Event.Description);
            cmdDto.IsDumb = false;
            //response = request.RequestNode(acDomain.NodeHost.Nodes.CenterNode);
            // 使用下面这行可以绕过网络传输从而易于调试,而上面那行需要网络传输
            response = AnyMessage.Create(HecpRequest.Create(AcDomain, cmdDto), AcDomain.NodeHost.Nodes.ThisNode).Response();
            Assert.IsTrue((int)Status.NoPermission == response.Body.Event.Status, response.Body.Event.Description);
        }
示例#8
0
        public void Action_Create()
        {
            var xm        = NewXM();
            var infoValue = new KeyValueBuilder(new Dictionary <string, string> {
                { "XM", xm },
                { "ZZJGM", "11011421004" }
            }).ToArray();
            var request = new Message
            {
                MessageId   = System.Guid.NewGuid().ToString(),
                Version     = "v1",
                MessageType = "action",
                IsDumb      = true,
                Verb        = Verb.Create.Code,
                Ontology    = "JS",
                Body        = new BodyData(infoValue, infoValue)
                {
                    QueryList = new string[] { "Id" }
                },
                TimeStamp = DateTime.UtcNow.Ticks
            }.JspxToken();
            //var response = request.RequestNode(acDomain.NodeHost.Nodes.CenterNode);
            var response = AnyMessage.Create(HecpRequest.Create(AcDomain, request), AcDomain.NodeHost.Nodes.ThisNode).Response();

            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            request.JspxSignature();// 签名
            response = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            request.IsDumb = false;
            request.JspxSignature();// 命令对象有更改则需重新签名
            response = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
            request.Verb = "Delete";
            request.JspxSignature();// 命令对象有更改则需重新签名
            response = request.RequestNode(AcDomain.NodeHost.Nodes.CenterNode);
            Assert.IsTrue((int)Status.ExecuteOk == response.Body.Event.Status, response.Body.Event.Description);
        }
示例#9
0
        public ActionResult AuditUnapproved(string ontologyCode, string id)
        {
            var response = new ResponseData {
                id = id, success = true
            };
            OntologyDescriptor ontology;

            if (!AcDomain.NodeHost.Ontologies.TryGetOntology(ontologyCode, out ontology))
            {
                throw new ValidationException("非法的本体码");
            }
            string[] ids           = id.Split(',');
            var      localEventIDs = new Guid[ids.Length];

            for (int i = 0; i < ids.Length; i++)
            {
                Guid tmp;
                if (Guid.TryParse(ids[i], out tmp))
                {
                    localEventIDs[i] = tmp;
                }
                else
                {
                    throw new ValidationException("意外的本地事件标识" + ids[i]);
                }
            }
            foreach (var localEventId in localEventIDs)
            {
                MessageEntity evnt = ontology.MessageProvider.GetCommand(MessageTypeKind.LocalEvent, ontology, localEventId);
                if (evnt != null)
                {
                    if (evnt.Status == (int)Status.ToAudit &&
                        evnt.EventSourceType.Equals("Command", StringComparison.OrdinalIgnoreCase))
                    {
                        var node  = AcDomain.NodeHost.Nodes.ThisNode;
                        var ticks = DateTime.UtcNow.Ticks;
                        var cmd   = new Message()
                        {
                            Version     = ApiVersion.V1.ToName(),
                            IsDumb      = false,
                            MessageType = MessageType.Event.ToName(),
                            Credential  = new CredentialData
                            {
                                ClientType     = ClientType.Node.ToName(),
                                UserType       = UserType.None.ToName(),
                                CredentialType = CredentialType.Token.ToName(),
                                ClientId       = node.Node.Id.ToString(),
                                UserName       = evnt.UserName,// UserName
                                Password       = TokenObject.Token(node.Node.Id.ToString(), ticks, node.Node.SecretKey),
                                Ticks          = ticks
                            },
                            TimeStamp = DateTime.UtcNow.Ticks,
                            MessageId = evnt.Id.ToString(),
                            Verb      = evnt.Verb.Code,
                            Ontology  = evnt.Ontology,
                            Body      = new BodyData(new KeyValue[] { new KeyValue("Id", evnt.LocalEntityId) }, evnt.DataTuple.ValueItems.Items.ToDto())
                            {
                                Event = new EventData
                                {
                                    Status       = (int)Status.AuditUnapproved,
                                    ReasonPhrase = Status.AuditUnapproved.ToName(),
                                    SourceType   = evnt.EventSourceType,
                                    Subject      = evnt.EventSubjectCode
                                }
                            }
                        };
                        var result = AnyMessage.Create(HecpRequest.Create(AcDomain, cmd), AcDomain.NodeHost.Nodes.ThisNode).Response();
                        if (result.Body.Event.Status == (int)Status.NotExist)
                        {
                            ontology.MessageProvider.DeleteCommand(MessageTypeKind.LocalEvent, ontology, evnt.Id, evnt.IsDumb);
                        }
                        else
                        {
                            if ((result.Body.Event.Status < 200 || result.Body.Event.Status >= 400) && result.Body.Event.Status != (int)Status.AuditUnapproved)
                            {
                                response.success = false;
                                response.msg     = result.Body.Event.Description;
                                response.Warning();
                            }
                        }
                    }
                }
            }

            return(this.JsonResult(response));
        }