Exemplo n.º 1
0
        public static void FillEntityWithXml <T>(T entity, XDocument doc) where T : AbstractRequest, new()
        {
            if (entity == null)
            {
            }
            entity = Activator.CreateInstance <T>();
            XElement root = doc.Root;

            PropertyInfo[] properties = entity.GetType().GetProperties();
            foreach (PropertyInfo info in properties)
            {
                string name = info.Name;
                if (root.Element(name) != null)
                {
                    switch (info.PropertyType.Name)
                    {
                    case "DateTime":
                    {
                        info.SetValue(entity, new DateTime(long.Parse(root.Element(name).Value)), null);
                        continue;
                    }

                    case "Boolean":
                    {
                        if (!(name == "FuncFlag"))
                        {
                            break;
                        }
                        info.SetValue(entity, root.Element(name).Value == "1", null);
                        continue;
                    }

                    case "Int64":
                    {
                        info.SetValue(entity, long.Parse(root.Element(name).Value), null);
                        continue;
                    }

                    case "Int32":
                    {
                        info.SetValue(entity, int.Parse(root.Element(name).Value), null);
                        continue;
                    }

                    case "RequestEventType":
                    {
                        info.SetValue(entity, EventTypeHelper.GetEventType(root.Element(name).Value), null);
                        continue;
                    }

                    case "RequestMsgType":
                    {
                        info.SetValue(entity, MsgTypeHelper.GetMsgType(root.Element(name).Value), null);
                        continue;
                    }
                    }
                    info.SetValue(entity, root.Element(name).Value, null);
                }
            }
        }
Exemplo n.º 2
0
        public static void FillEntityWithXml <T>(T entity, XDocument doc) where T : AbstractRequest, new()
        {
            T obj = entity;

            if ((object)obj == null)
            {
                obj = Activator.CreateInstance <T>();
            }
            entity = obj;
            XElement root = doc.Root;

            foreach (PropertyInfo propertyInfo in entity.GetType().GetProperties())
            {
                string name = propertyInfo.Name;
                if (root.Element((XName)name) != null)
                {
                    switch (propertyInfo.PropertyType.Name)
                    {
                    case "DateTime":
                        propertyInfo.SetValue((object)entity, (object)new DateTime(long.Parse(root.Element((XName)name).Value)), (object[])null);
                        break;

                    case "Boolean":
                        if (name == "FuncFlag")
                        {
                            propertyInfo.SetValue((object)entity, (object)(bool)(root.Element((XName)name).Value == "1" ? true : false), (object[])null);
                            break;
                        }
                        else
                        {
                            goto default;
                        }

                    case "Int64":
                        propertyInfo.SetValue((object)entity, (object)long.Parse(root.Element((XName)name).Value), (object[])null);
                        break;

                    case "Int32":
                        propertyInfo.SetValue((object)entity, (object)int.Parse(root.Element((XName)name).Value), (object[])null);
                        break;

                    case "RequestEventType":
                        propertyInfo.SetValue((object)entity, (object)EventTypeHelper.GetEventType(root.Element((XName)name).Value), (object[])null);
                        break;

                    case "RequestMsgType":
                        propertyInfo.SetValue((object)entity, (object)MsgTypeHelper.GetMsgType(root.Element((XName)name).Value), (object[])null);
                        break;

                    default:
                        propertyInfo.SetValue((object)entity, (object)root.Element((XName)name).Value, (object[])null);
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void FillEntityWithXml <T>(T entity, XDocument doc) where T : AbstractRequest, new()
        {
            entity = (entity ?? new T());
            XElement root = doc.Root;

            PropertyInfo[] properties = entity.GetType().GetProperties();
            PropertyInfo[] array      = properties;
            foreach (PropertyInfo propertyInfo in array)
            {
                string name = propertyInfo.Name;
                if (root.Element(name) != null)
                {
                    switch (propertyInfo.PropertyType.Name)
                    {
                    case "DateTime":
                        propertyInfo.SetValue(entity, new DateTime(long.Parse(root.Element(name).Value)), null);
                        break;

                    case "Boolean":
                        if (name == "FuncFlag")
                        {
                            propertyInfo.SetValue(entity, root.Element(name).Value == "1", null);
                            break;
                        }
                        goto default;

                    case "Int64":
                        propertyInfo.SetValue(entity, long.Parse(root.Element(name).Value), null);
                        break;

                    case "RequestEventType":
                        propertyInfo.SetValue(entity, EventTypeHelper.GetEventType(root.Element(name).Value), null);
                        break;

                    case "RequestMsgType":
                        propertyInfo.SetValue(entity, MsgTypeHelper.GetMsgType(root.Element(name).Value), null);
                        break;

                    default:
                        propertyInfo.SetValue(entity, root.Element(name).Value, null);
                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void FillEntityWithXml <T>(T entity, XDocument doc) where T : AbstractRequest, new()
        {
            if (entity == null)
            {
                entity = Activator.CreateInstance <T>();
            }

            XElement root = doc.Root;

            PropertyInfo[] properties = entity.GetType().GetProperties();

            //属性名
            string propName = "";
            //数据类型名
            string dataTypeName = "";

            foreach (PropertyInfo info in properties)
            {
                propName = info.Name;//取出属性名称
                try
                {
                    if (root.Element(propName) != null)
                    {
                        dataTypeName = info.PropertyType.Name;

                        switch (dataTypeName)
                        {
                        case "DateTime":
                        {
                            info.SetValue(entity, new DateTime(long.Parse(root.Element(propName).Value)), null);
                            break;
                        }

                        case "Boolean":
                        {
                            if (propName == "FuncFlag")
                            {
                                info.SetValue(entity, (root.Element(propName).Value == "1"), null);
                            }
                            else
                            {
                                info.SetValue(entity, root.Element(propName).Value, null);
                            }
                            break;
                        }

                        case "Int64":
                        {
                            info.SetValue(entity, long.Parse(root.Element(propName).Value), null);
                            break;
                        }

                        case "RequestEventType":
                        {
                            info.SetValue(entity, EventTypeHelper.GetEventType(root.Element(propName).Value), null);
                            break;
                        }

                        case "RequestMsgType":
                        {
                            info.SetValue(entity, MsgTypeHelper.GetMsgType(root.Element(propName).Value), null);
                            break;
                        }

                        case "Single":
                        {
                            float floatVal = 0f;
                            float.TryParse(root.Element(propName).Value, out floatVal);
                            info.SetValue(entity, floatVal, null);
                            break;
                        }

                        default:
                        {
                            info.SetValue(entity, root.Element(propName).Value, null);
                            break;
                        }
                        }
                    }
                }
                catch //(Exception ex)
                {
                    // System.IO.File.AppendAllText(@"E:\home\LocalUser\580442\www\humowang\api\err.txt", "type:" + entity.GetType().FullName + ";属性名称:" + propName + ";" + ex.Message + "\r\n");
                }
            }

            #region 注释

            /*
             * foreach (PropertyInfo info in properties)
             * {
             *  string name = info.Name;
             *  if (root.Element(name) != null)
             *  {
             *      string str2 = info.PropertyType.Name;
             *      if (str2 == null)
             *      {
             *          goto Label_01CC;
             *      }
             *      if (!(str2 == "DateTime"))
             *      {
             *          if (str2 == "Boolean")
             *          {
             *              goto Label_00FA;
             *          }
             *          if (str2 == "Int64")
             *          {
             *              goto Label_014B;
             *          }
             *          if (str2 == "RequestEventType")
             *          {
             *              goto Label_0176;
             *          }
             *          if (str2 == "RequestMsgType")
             *          {
             *              goto Label_01A1;
             *          }
             *          goto Label_01CC;
             *      }
             *      // info.SetValue(entity, new DateTime(long.Parse(root.Element(name).Value)), null);
             *  }
             *  continue;
             * Label_00FA:
             *  if (name == "FuncFlag")
             *  {
             *      //info.SetValue(entity, root.Element(name).Value == "1", null);
             *      continue;
             *  }
             *  goto Label_01CC;
             * Label_014B:
             *  //info.SetValue(entity, long.Parse(root.Element(name).Value), null);
             *  continue;
             * Label_0176:
             *  //info.SetValue(entity, EventTypeHelper.GetEventType(root.Element(name).Value), null);
             *  continue;
             * Label_01A1:
             *  info.SetValue(entity, MsgTypeHelper.GetMsgType(root.Element(name).Value), null);
             *  continue;
             * Label_01CC:
             *  info.SetValue(entity, root.Element(name).Value, null);
             *
             * }*/
            #endregion
        }
Exemplo n.º 5
0
        public static RequestEventType GetEventType(XDocument doc)
        {
            RequestEventType eventType = EventTypeHelper.GetEventType(doc.Root.Element("Event").Value);

            return(eventType);
        }
Exemplo n.º 6
0
        // Token: 0x06000138 RID: 312 RVA: 0x000057AC File Offset: 0x000039AC
        public static void FillEntityWithXml <T>(T entity, XDocument doc) where T : AbstractRequest, new()
        {
            if (entity == null)
            {
                entity = Activator.CreateInstance <T>();
            }
            XElement root = doc.Root;

            PropertyInfo[] properties = entity.GetType().GetProperties();
            string         name       = "";

            foreach (PropertyInfo info in properties)
            {
                name = info.Name;
                try
                {
                    if (root.Element(name) == null)
                    {
                        continue;
                    }
                    switch (info.PropertyType.Name)
                    {
                    case "DateTime":
                    {
                        info.SetValue(entity, new DateTime(long.Parse(root.Element(name).Value)), null);
                        continue;
                    }

                    case "Boolean":
                    {
                        if (name != "FuncFlag")
                        {
                            break;
                        }
                        info.SetValue(entity, root.Element(name).Value == "1", null);
                        continue;
                    }

                    case "Int64":
                    {
                        info.SetValue(entity, long.Parse(root.Element(name).Value), null);
                        continue;
                    }

                    case "RequestEventType":
                    {
                        info.SetValue(entity, EventTypeHelper.GetEventType(root.Element(name).Value), null);
                        continue;
                    }

                    case "RequestMsgType":
                    {
                        info.SetValue(entity, MsgTypeHelper.GetMsgType(root.Element(name).Value), null);
                        continue;
                    }

                    case "Single":
                    {
                        float result = 0f;
                        float.TryParse(root.Element(name).Value, out result);
                        info.SetValue(entity, result, null);
                        continue;
                    }

                    default:
                        info.SetValue(entity, root.Element(name).Value, null);
                        continue;
                    }
                    info.SetValue(entity, root.Element(name).Value, null);
                    continue;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 7
0
        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))
                {
                case RequestEventType.Subscribe:
                    entity = new SubscribeEventRequest();
                    goto Label_00D7;

                case RequestEventType.UnSubscribe:
                    entity = new UnSubscribeEventRequest();
                    goto Label_00D7;

                case RequestEventType.Scan:
                    entity = new ScanEventRequest();
                    goto Label_00D7;

                case RequestEventType.Location:
                    entity = new LocationEventRequest();
                    goto Label_00D7;

                case RequestEventType.Click:
                    entity = new ClickEventRequest();
                    goto Label_00D7;

                case RequestEventType.MASSSENDJOBFINISH:
                    entity = new MassendJobFinishEventRequest();
                    goto Label_00D7;
                }
                throw new ArgumentOutOfRangeException();

            default:
                throw new ArgumentOutOfRangeException();
            }
Label_00D7:
            EntityHelper.FillEntityWithXml <AbstractRequest>(entity, doc);
            Regex regex = 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);
        }
        public static AbstractRequest GetRequestEntity(XDocument doc)
        {
            RequestMsgType  msgType     = MsgTypeHelper.GetMsgType(doc);
            AbstractRequest textRequest = null;

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

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

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

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

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

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

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

                case RequestEventType.UnSubscribe:
                {
                    textRequest = new UnSubscribeEventRequest();
                    break;
                }

                case RequestEventType.Scan:
                {
                    textRequest = new ScanEventRequest();
                    break;
                }

                case RequestEventType.Location:
                {
                    textRequest = new LocationEventRequest();
                    break;
                }

                case RequestEventType.Click:
                {
                    textRequest = new ClickEventRequest();
                    break;
                }

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

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
            EntityHelper.FillEntityWithXml <AbstractRequest>(textRequest, doc);
            return(textRequest);

            throw new ArgumentOutOfRangeException();
        }
Exemplo n.º 9
0
        public static void FillEntityWithXml <T>(T entity, XDocument doc) where T : AbstractRequest, new()
        {
            if (entity == null)
            {
            }
            entity = Activator.CreateInstance <T>();
            XElement root = doc.Root;

            PropertyInfo[] properties = entity.GetType().GetProperties();
            foreach (PropertyInfo info in properties)
            {
                string name = info.Name;
                if (root.Element(name) != null)
                {
                    string str2 = info.PropertyType.Name;
                    if (str2 == null)
                    {
                        goto Label_01CC;
                    }
                    if (!(str2 == "DateTime"))
                    {
                        if (str2 == "Boolean")
                        {
                            goto Label_00FA;
                        }
                        if (str2 == "Int64")
                        {
                            goto Label_014B;
                        }
                        if (str2 == "RequestEventType")
                        {
                            goto Label_0176;
                        }
                        if (str2 == "RequestMsgType")
                        {
                            goto Label_01A1;
                        }
                        goto Label_01CC;
                    }
                    info.SetValue(entity, new DateTime(long.Parse(root.Element(name).Value)), null);
                }
                continue;
Label_00FA:
                if (name == "FuncFlag")
                {
                    info.SetValue(entity, root.Element(name).Value == "1", null);
                    continue;
                }
                goto Label_01CC;
Label_014B:
                info.SetValue(entity, long.Parse(root.Element(name).Value), null);
                continue;
Label_0176:
                info.SetValue(entity, EventTypeHelper.GetEventType(root.Element(name).Value), null);
                continue;
Label_01A1:
                info.SetValue(entity, MsgTypeHelper.GetMsgType(root.Element(name).Value), null);
                continue;
Label_01CC:
                info.SetValue(entity, root.Element(name).Value, null);
            }
        }
Exemplo n.º 10
0
        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))
                {
                case RequestEventType.Subscribe:
                    entity = new SubscribeEventRequest();
                    goto Label_00C5;

                case RequestEventType.UnSubscribe:
                    entity = new UnSubscribeEventRequest();
                    goto Label_00C5;

                case RequestEventType.Scan:
                    entity = new ScanEventRequest();
                    goto Label_00C5;

                case RequestEventType.Location:
                    entity = new LocationEventRequest();
                    goto Label_00C5;

                case RequestEventType.Click:
                    entity = new ClickEventRequest();
                    goto Label_00C5;
                }
                throw new ArgumentOutOfRangeException();

            default:
                throw new ArgumentOutOfRangeException();
            }
Label_00C5:
            EntityHelper.FillEntityWithXml <AbstractRequest>(entity, doc);
            return(entity);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }