Exemplo n.º 1
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType msgType = MsgTypeHelper.GetMsgType(doc);

            AbstractRequest entity = null;

            // System.IO.File.AppendAllText(@"E:\home\LocalUser\580442\www\humowang\api\type.txt", "msgType:" + msgType + "\r\n");
            switch (msgType)
            {
            case RequestMsgType.Text:
            {
                entity = new TextRequest();
                break;
            }

            case RequestMsgType.Image:
            {
                entity = new ImageRequest();
                break;
            }

            case RequestMsgType.Voice:
            {
                entity = new VoiceRequest();
                break;
            }

            case RequestMsgType.Video:
            {
                entity = new VideoRequest();
                break;
            }

            case RequestMsgType.Location:
            {
                entity = new LocationRequest();
                break;
            }

            case RequestMsgType.Link:
            {
                entity = new LinkRequest();
                break;
            }

            case RequestMsgType.Event:
            {
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                {
                    entity = new SubscribeEventRequest();
                    //goto Label_00C5;
                    break;
                }

                case RequestEventType.UnSubscribe:
                {
                    entity = new UnSubscribeEventRequest();
                    //goto Label_00C5;
                    break;
                }

                case RequestEventType.Scan:
                {
                    entity = new ScanEventRequest();
                    // goto Label_00C5;
                    break;
                }

                case RequestEventType.Location:
                {
                    entity = new LocationEventRequest();
                    // goto Label_00C5;
                    break;
                }

                case RequestEventType.Click:
                {
                    entity = new ClickEventRequest();
                    // goto Label_00C5;
                    break;
                }

                case RequestEventType.VIEW:
                {
                    entity = new ViewEventRequest();
                    break;
                }

                default:
                {
                    throw new ArgumentOutOfRangeException();
                    // break;
                }
                }
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }

            //Label_00C5:
            EntityHelper.FillEntityWithXml <AbstractRequest>(entity, doc);

            return(entity);
        }
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType  msgType         = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest abstractRequest = null;

            switch (msgType)
            {
            case RequestMsgType.Text:
                abstractRequest = new TextRequest();
                break;

            case RequestMsgType.Video:
                abstractRequest = new VideoRequest();
                break;

            case RequestMsgType.Voice:
                abstractRequest = new VoiceRequest();
                break;

            case RequestMsgType.Location:
                abstractRequest = new LocationRequest();
                break;

            case RequestMsgType.Image:
                abstractRequest = new ImageRequest();
                break;

            case RequestMsgType.Link:
                abstractRequest = new LinkRequest();
                break;

            case RequestMsgType.Event:
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                    abstractRequest = new SubscribeEventRequest();
                    break;

                case RequestEventType.UnSubscribe:
                    abstractRequest = new UnSubscribeEventRequest();
                    break;

                case RequestEventType.Scan:
                    abstractRequest = new ScanEventRequest();
                    break;

                case RequestEventType.Location:
                    abstractRequest = new LocationEventRequest();
                    break;

                case RequestEventType.Click:
                    abstractRequest = new ClickEventRequest();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            EntityHelper.FillEntityWithXml(abstractRequest, doc);
            return(abstractRequest);
        }
Exemplo n.º 3
0
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            AbstractRequest abstractRequest;

            switch (MsgTypeHelper.GetMsgType(doc))
            {
            case RequestMsgType.Text:
                abstractRequest = new TextRequest();
                break;

            case RequestMsgType.Image:
                abstractRequest = new ImageRequest();
                break;

            case RequestMsgType.Voice:
                abstractRequest = new VoiceRequest();
                break;

            case RequestMsgType.Video:
                abstractRequest = new VideoRequest();
                break;

            case RequestMsgType.Location:
                abstractRequest = new LocationRequest();
                break;

            case RequestMsgType.Link:
                abstractRequest = new LinkRequest();
                break;

            case RequestMsgType.Event:
                switch (EventTypeHelper.GetEventType(doc))
                {
                case RequestEventType.Subscribe:
                    abstractRequest = new SubscribeEventRequest();
                    break;

                case RequestEventType.UnSubscribe:
                    abstractRequest = new UnSubscribeEventRequest();
                    break;

                case RequestEventType.Scan:
                    abstractRequest = new ScanEventRequest();
                    break;

                case RequestEventType.Location:
                    abstractRequest = new LocationEventRequest();
                    break;

                case RequestEventType.Click:
                    abstractRequest = new ClickEventRequest();
                    break;

                case RequestEventType.MASSSENDJOBFINISH:
                    abstractRequest = new MassendJobFinishEventRequest();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            EntityHelper.FillEntityWithXml <AbstractRequest>(abstractRequest, doc);
            Regex regex = new Regex("<MsgID>(?<url>\\d+)</MsgID>");

            if (abstractRequest.MsgId == 0L)
            {
                Match match = Regex.Match(doc.Root.ToString(), "<MsgID>(?<msgid>\\d+)</MsgID>", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    abstractRequest.MsgId      = long.Parse(match.Groups["msgid"].Value);
                    abstractRequest.CreateTime = DateTime.Now;
                }
            }
            return(abstractRequest);
        }
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType msgType = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest entity = null;
            switch (msgType)
            {
                case RequestMsgType.Text:
                    entity = new TextRequest();
                    break;

                case RequestMsgType.Image:
                    entity = new ImageRequest();
                    break;

                case RequestMsgType.Voice:
                    entity = new VoiceRequest();
                    break;

                case RequestMsgType.Video:
                    entity = new VideoRequest();
                    break;

                case RequestMsgType.Location:
                    entity = new LocationRequest();
                    break;

                case RequestMsgType.Link:
                    entity = new LinkRequest();
                    break;

                case RequestMsgType.Event:
                    //switch (EventTypeHelper.GetEventType(doc))
                    switch (doc.Root.Element("Event").Value.ToUpper())
                    {
                        //case RequestEventType.Subscribe:
                        case "SUBSCRIBE"://订阅(关注)
                            entity = new SubscribeEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.UnSubscribe:
                        case "UNSUBSCRIBE"://取消订阅(关注)
                            entity = new UnSubscribeEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.Scan:
                        case "SCAN"://二维码扫描
                            entity = new ScanEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.Location:
                        case "LOCATION"://地理位置
                            entity = new LocationEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.Click:
                        case "CLICK"://菜单点击
                            entity = new ClickEventRequest();
                            goto Label_00D1;

                        //case RequestEventType.MASSSENDJOBFINISH:
                        case "MASSSENDJOBFINISH":
                            entity = new MassendJobFinishEventRequest();
                            goto Label_00D1;

                        case "VIEW":
                            entity = new ViewEventRequest();
                            goto Label_00D1;

                        //default://其他意外类型(也可以选择抛出异常)
                        //    entity = new AbstractRequest();
                        //    goto Label_00D1;

                    }
                    throw new ArgumentOutOfRangeException();

                default:
                    throw new ArgumentOutOfRangeException();
            }
        Label_00D1:
            //EntityHelper.FillEntityWithXml<AbstractRequest>(entity, doc);
            //修改无法解析完整数据 2017.7.4
            EntityHelper.FillEntityWithXml(entity, doc);
            new Regex(@"<MsgID>(?<url>\d+)</MsgID>");
            if (entity.MsgId == 0L)
            {
                Match match = Regex.Match(doc.Root.ToString(), @"<MsgID>(?<msgid>\d+)</MsgID>", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    entity.MsgId = long.Parse(match.Groups["msgid"].Value);
                    entity.CreateTime = DateTime.Now;
                }
            }
            return entity;
        }