/// <summary>
        /// 解析请求
        /// </summary>
        /// <param name="client"></param>
        /// <param name="xml"></param>
        /// <param name="useAes"></param>
        /// <returns></returns>
        public static BaseRequest Parse(this ApiClient client, string xml, bool useAes)
        {
            try {
                //如果启用AES加密, 返回的XML中, Encrypt 元素的内容是加密后的结果
                if (useAes)
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(xml);

                    xml = doc.DocumentElement.SelectSingleNode("Encrypt").FirstChild.Value;

                    var appID = "";
                    //使用的是AES加密,但是处理方式可能和你写的逻辑不一样,所以,请使用TX提供的AES处理程序
                    xml = Cryptography.AESDecrypt(xml, client.Config.AesKey, ref appID);
                }

                //EventType 是事件推送的结果中的.
                //普通消息是没有这个字段的
                EventTypes?eventType = null;
                var        ma        = EventTypeRx.Match(xml);
                if (ma.Success)
                {
                    eventType = ma.Groups["eventType"].Value.ToEnum <EventTypes>();
                }

                //消息类型, 事件推送的结果全是 event
                ma = MsgTypeRx.Match(xml);
                if (ma.Success)
                {
                    var msgType = ma.Groups["msgType"].Value.ToEnum <RequestTypes>();

                    Type targetType = BaseRequest.GetMessageType(msgType, eventType);
                    if (targetType != null)
                    {
                        var bytes = Encoding.UTF8.GetBytes(xml);
                        var ser   = new XmlSerializer(targetType);
                        using (var msm = new MemoryStream(bytes)) {
                            return(ser.Deserialize(msm) as BaseRequest);
                        }
                    }
                }
            } catch {
            }

            return(null);
        }
        public async Task <EventQueryResult> GetEventsFeedAsync(Timeframe from = null, Timeframe to = null, RelativeTimes?relativeTime = null, EventTypes?eventType = null, string entityId = null,
                                                                string cursor  = null, CancellationToken cancellationToken = default)
        {
            var queryParamValues = new Dictionary <string, object>();

            if (from is not null)
            {
                queryParamValues.Add(nameof(from), from.ToString());
            }

            if (to is not null)
            {
                queryParamValues.Add(nameof(to), to.ToString());
            }

            if (relativeTime is not null)
            {
                queryParamValues.Add(nameof(relativeTime), s_relativeTimesConverter.ConvertToString(relativeTime));
            }

            if (eventType is not null)
            {
                queryParamValues.Add(nameof(eventType), s_eventTypesConverter.ConvertToString(eventType));
            }

            if (entityId is not null)
            {
                queryParamValues.Add(nameof(entityId), entityId);
            }

            if (cursor is not null)
            {
                queryParamValues.Add(nameof(cursor), cursor);
            }

            var response = await GetEventsUrl()
                           .SetQueryParams(queryParamValues)
                           .GetJsonIfNotEmptyAsync(new EventQueryResult(), cancellationToken)
                           .ConfigureAwait(false);

            return(response);
        }
        /// <summary>
        /// Invoked to execute the state machine.
        /// </summary>
        /// <param name="e">Provides an optional event type to post at normal priority before starting execution</param>

        /// <exception cref="System.InvalidOperationException">Thrown if an event is chosen for
        /// execution and no transition from the current state maches the event.
        /// </exception>
        /// <remarks>
        /// The state machine runs until one of the following conditions is met:
        /// - There are no remaining events to process
        /// - A stop or error state is entered
        /// - An event is encountered and no transition matches the event type
        /// - An action raises an exception
        /// For each state, the next event to be processed is chosen from the head of the
        /// internal event queue, and if no event is found, then the external event queue.
        /// </remarks>
        public void Execute(EventTypes?e = null)
        {
            base.Execute(e.HasValue ? (int)e.Value : default(int?));
        }
Beispiel #4
0
 /// <summary>
 /// Invoked to execute the state machine.
 /// </summary>
 /// <param name="e">Provides an optional event type to post at normal priority before starting execution</param>
 /// <returns>A value of type R</returns>
 /// <exception cref="System.InvalidOperationException">Thrown if an event is chosen for
 /// execution and no transition from the current state maches the event.
 /// </exception>
 /// <remarks>
 /// The state machine runs until one of the following conditions is met:
 /// - There are no remaining events to process
 /// - A stop or error state is entered
 /// - An event is encountered and no transition matches the event type
 /// - An action raises an exception
 /// For each state, the next event to be processed is chosen from the head of the
 /// internal event queue, and if no event is found, then the external event queue.
 /// </remarks>
 public Lexeme Execute(EventTypes?e = null)
 {
     return(base.Execute(e.HasValue ? (int)e.Value : default(int?)));
 }
 public RequestTypeAttribute(RequestTypes msgType, EventTypes eventType)
 {
     this.MessageType = msgType;
     this.EventType   = eventType;
 }
Beispiel #6
0
 /// <summary>
 /// 如果没有找到对应的消息类型,返回 null
 /// </summary>
 /// <param name="msgType"></param>
 /// <param name="eventType"></param>
 /// <returns></returns>
 public static Type GetMessageType(RequestTypes msgType, EventTypes?eventType)
 {
     return(Types.Get(string.Format("{0},{1}", msgType, eventType), null));
 }
Beispiel #7
0
 /// <summary>
 /// 注册 Request 的处理程序
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="msgtype"></param>
 /// <param name="eventType"></param>
 public static void Regist <T>(RequestTypes msgtype, EventTypes?eventType = null) where T : RequestHandler
 {
     Regist(msgtype, eventType, typeof(T));
 }
Beispiel #8
0
 private static void Regist(RequestTypes msgType, EventTypes?eventType, Type handlerType)
 {
     HandlerTypes.Set(GetKey(msgType, eventType), handlerType);
 }
Beispiel #9
0
 private static string GetKey(RequestTypes msgType, EventTypes?evtType)
 {
     return(string.Format("{0},{1}", msgType, evtType));
 }