Exemple #1
0
        public ThriftObject Invoke(string url, string protocolName)
        {
            TTransport transport = Thrift.GetTransport(url);
            TProtocol  protocol  = Thrift.GetProtocol(protocolName, transport);

            object instance = Activator.CreateInstance(_classAndMethod.ClassType, protocol);

            object[] parameters = _parameters;

            try
            {
                object response = _classAndMethod.Method.Invoke(instance, parameters);
                if (response != null)
                {
                    ThriftObject thriftObjects = ThriftResponseObjectFactory.CreateResponseThriftObjects(response, "Response", null);
                    return(thriftObjects);
                }
            }
            catch (TargetInvocationException target)
            {
                var thriftObjects = ThriftResponseObjectFactory.CreateResponseThriftObjects(target.InnerException, "Response", null);
                return(thriftObjects);
            }

            return(null);
        }
        private static ThriftObject CreateThriftObjects(Type type, string propertyName, ThriftObject parentObj)
        {
            object instance = null;

            if (type != typeof(string))
            {
                instance = Activator.CreateInstance(type);
            }

            var t = new ThriftObject(parentObj, instance, type, propertyName);

            if (parentObj != null)
            {
                parentObj.ChildObjs.Add(t);
            }

            if (type.IsValueType || type == typeof(string))
            {
                t.IsNull = false;
            }
            else
            {
                var props = type.GetProperties();

                CreateThriftObjects(props, t);
            }

            return(t);
        }
Exemple #3
0
        public ThriftObject(ThriftObject parentObj, object obj, Type objType, string propertyName)
        {
            ParentObj    = parentObj;
            Obj          = obj;
            ObjType      = objType;
            PropertyName = propertyName;

            IsNull    = true;
            ChildObjs = new List <ThriftObject>();
        }
Exemple #4
0
        public static ThriftObject CreateResponseThriftObjects(object obj, string propertyName, ThriftObject parentObj)
        {
            if (obj == null)
            {
                return(null);
            }

            if (propertyName == "TargetSite")
            {
                return(null);
            }

            var objType = obj.GetType();

            var t = new ThriftObject(parentObj, obj, objType, string.Format("{0}={1}", propertyName, obj.GetType().Name));

            if (parentObj != null)
            {
                parentObj.ChildObjs.Add(t);
            }

            if (objType.IsGenericType && objType.GetGenericTypeDefinition() == typeof(List <>))
            {
                var list = (IEnumerable)obj;

                foreach (var l in list)
                {
                    var t2 = new ThriftObject(t, l, l.GetType(), string.Format("{0}={1}", propertyName, l.GetType().Name));
                    t.ChildObjs.Add(t2);

                    CreateResponseThriftObjects(l, l.GetType().GetProperties(), t2);
                }

                return(t);
            }

            if (objType.IsValueType || obj is string)
            {
                return(t);
            }

            CreateResponseThriftObjects(obj, objType.GetProperties(), t);

            return(t);
        }
 private static void CreateThriftObjects(IEnumerable <PropertyInfo> getParameters, ThriftObject parentObj)
 {
     foreach (var parameter in getParameters)
     {
         Type type = parameter.PropertyType;
         CreateThriftObjects(type, parameter.Name, parentObj);
     }
 }
Exemple #6
0
        private static void CreateResponseThriftObjects(object obj, IEnumerable <PropertyInfo> getParameters, ThriftObject parentObj)
        {
            if (obj.GetType().Name == "RuntimeModule")
            {
                return;
            }

            foreach (var parameter in getParameters)
            {
                if (parameter.Name == "TargetSite")
                {
                    continue;
                }

                try
                {
                    var newObj = parameter.GetValue(obj, null);

                    CreateResponseThriftObjects(newObj, parameter.Name, parentObj);
                }
                catch {}
            }
        }