public static ConektaObject ConektaObjectFactory(JObject jsonObject, String attributeName)
        {
            var conektaObject = new ConektaObject();

            if (jsonObject["object"] != null && isPaymentMethod(jsonObject))
            {
                conektaObject = PaymentMethodFactory(jsonObject);
                try
                {
                    conektaObject.LoadFromObject(jsonObject);
                }
                catch (Exception e)
                {
                    throw new Error(e.Message);
                }
            }
            else
            {
                try
                {
                    var handle = Activator.CreateInstance(null,
                                                          "ConektaCSharp." + ConektaObject.toCamelCase(attributeName));
                    conektaObject = (ConektaObject)handle.Unwrap();
                    conektaObject.LoadFromObject(jsonObject);
                }
                catch (Exception e)
                {
                    throw new Error(e.Message);
                }
            }
            return(conektaObject);
        }
Beispiel #2
0
        protected static ConektaObject scpWhere(String className, JObject _params)
        {
            var requestor = new ConektaRequestor();
            var url       = classUrl(className);
            var jsonArray = (JArray)requestor.Request("GET", url, _params);
            var resource  = new ConektaObject();

            resource.LoadFromArray(jsonArray);
            return(resource);
        }
Beispiel #3
0
        protected ConektaObject createMember(String member, JObject _params)
        {
            var           requestor  = new ConektaRequestor();
            var           url        = instanceUrl() + "/" + member;
            var           jsonObject = (JObject)requestor.Request("POST", url, _params);
            FieldInfo     field;
            ConektaObject conektaObject = null;

            field = GetType().GetField(member);
            String className;
            var    parentClassName = GetType().Name.Substring(0, 1).ToLower() + GetType().Name.Substring(1);

            if (field.GetValue(this).GetType().Name.Equals("ConektaObject"))
            {
                className = member.Substring(0, 1).ToUpper() + member.Substring(1, member.Length - 2).ToLower();
                var handle = Activator.CreateInstance(null, "ConektaCSharp." + className);
                conektaObject = (ConektaObject)handle.Unwrap();
                conektaObject.LoadFromObject(jsonObject);

                conektaObject.GetType().GetField(parentClassName).SetValue(conektaObject, this);

                var objects = ((ConektaObject)field.GetValue(this));
                objects.Add(conektaObject);
                field.SetValue(this, objects);
            }
            else
            {
                className = member.Substring(0, 1).ToUpper() + member.Substring(1).ToLower();
                var handle = Activator.CreateInstance(null, "ConektaCSharp." + className);
                conektaObject = (ConektaObject)handle.Unwrap();

                conektaObject.LoadFromObject(jsonObject);
                conektaObject.GetType().GetField(parentClassName).SetValue(conektaObject, this);

                SetVal(member, conektaObject);
                field.SetValue(this, conektaObject);
                LoadFromObject(null);
            }
            return(conektaObject);
        }
Beispiel #4
0
        public virtual void LoadFromObject(JObject jsonObject)
        {
            IEnumerator itr = jsonObject.Properties().GetEnumerator();
            FieldInfo   field;

            while (itr.MoveNext())
            {
                var key = ((JProperty)itr.Current).Name;
                field = GetType().GetField(key);
                // Si el campo no existe, omitir
                if (field == null)
                {
                    continue;
                }
                Object obj = jsonObject[key];
                try
                {
                    var isConektaObject = (field.FieldType.Namespace ?? "").Equals("ConektaCSharp");

                    var objStr = obj.ToString();

                    if (!String.IsNullOrWhiteSpace(objStr))
                    {
                        switch ((int)objStr[0])
                        {
                        // {
                        case 123:
                            var o = JObject.Parse(objStr);
                            if (o["object"] != null)
                            {
                                var conektaObject = ConektaObjectFromJSONFactory.ConektaObjectFactory(o,
                                                                                                      o["object"].ToString());
                                field.SetValue(this, conektaObject);
                                SetVal(key, conektaObject);
                            }
                            else
                            {
                                if (isConektaObject)
                                {
                                    var handle = Activator.CreateInstance(null, field.FieldType.FullName);
                                    var attr   = (ConektaObject)handle.Unwrap();

                                    attr.LoadFromObject((JObject)obj);
                                    field.SetValue(this, attr);
                                    SetVal(key, attr);
                                }
                                else
                                {
                                    var tipoCampo       = Type.GetType(field.FieldType.FullName);
                                    var valorConvertido = Convert.ChangeType(obj, tipoCampo);
                                    field.SetValue(this, valorConvertido);
                                    SetVal(key, valorConvertido);
                                }
                            }

                            break;

                        // [
                        case 91:
                            var jsonArray = JArray.Parse(objStr);
                            if (jsonArray.Count > 0)
                            {
                                var conektaObject = new ConektaObject();
                                if (isConektaObject)
                                {
                                    var handle = Activator.CreateInstance(null, field.FieldType.FullName);
                                    conektaObject = (ConektaObject)handle.Unwrap();
                                }

                                foreach (var jItem in jsonArray)
                                {
                                    if (jsonArray[0]["object"] != null)
                                    {
                                        conektaObject.Add(
                                            ConektaObjectFromJSONFactory.ConektaObjectFactory(
                                                jItem.ToObject <JObject>(),
                                                jItem["object"].ToString()));
                                    }
                                    else
                                    {
                                        conektaObject.Add(
                                            ConektaObjectFromJSONFactory.ConektaObjectFactory(
                                                jItem.ToObject <JObject>(), key));
                                    }
                                }
                                field.SetValue(this, conektaObject);
                                SetVal(key, conektaObject);
                            }
                            break;

                        default:
                            if (isConektaObject)
                            {
                                var handle = Activator.CreateInstance(null, field.FieldType.FullName);
                                var attr   = (ConektaObject)handle.Unwrap();

                                attr.LoadFromObject((JObject)obj);
                                field.SetValue(this, attr);
                                SetVal(key, attr);
                            }
                            else
                            {
                                var tipoCampo       = Type.GetType(field.FieldType.FullName);
                                var valorConvertido = Convert.ChangeType(obj, tipoCampo);
                                field.SetValue(this, valorConvertido);
                                SetVal(key, valorConvertido);
                            }
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    // No field found
                    //System.out.println(e.toString());
                    throw new Error(e.Message);
                }
            }
        }
Beispiel #5
0
 public Customer()
 {
     cards        = new ConektaObject();
     subscription = new Subscription();
 }
Beispiel #6
0
 public Customer(String id = null) : base(id)
 {
     cards        = new ConektaObject();
     subscription = new Subscription();
 }