Esempio n. 1
0
        public override TPostResponseResource Post(IPostForm form)
        {
            var requestOptions = new RequestOptions();

            AddEtagOptions(requestOptions);
            return((TPostResponseResource)Client.Post(Uri, (TResource)((object)form), requestOptions));
        }
Esempio n. 2
0
        public virtual object SaveResourceFromForm(IPostForm form)
        {
            var formType          = form.GetType();
            var resourceInterface = this.GetMostInheritedResourceInterface(formType);
            ResourceInfoAttribute resInfo;

            if (!TryGetResourceInfoForType(resourceInterface, out resInfo))
            {
                throw new InvalidOperationException("Unable to get resource info for " + formType.FullName);
            }

            var resource = Activator.CreateInstance(resInfo.PocoType);

            foreach (var formProp in formType.GetProperties())
            {
                if (form.PropertyIsSerialized(formProp.Name))
                {
                    var resProp = resInfo.PocoType.GetProperty(formProp.Name);
                    var value   = formProp.GetValue(form, null);

                    if (value != null)
                    {
                        Type valueType = value.GetType();
                        if (value is PostResourceBase)
                        {
                            value = SaveResourceFromForm((PostResourceBase)value);
                        }
                        else if (valueType != typeof(string))
                        {
                            Type elementType;

                            Type[] dictTypeArgs;
                            if (valueType.TryExtractTypeArguments(typeof(IDictionary <,>), out dictTypeArgs))
                            {
                                value = mapFormDictionaryToResourceDictionaryMethod
                                        .MakeGenericMethod(dictTypeArgs)
                                        .Invoke(this, new[] { value });
                            }
                            else if (valueType.TryGetEnumerableElementType(out elementType))
                            {
                                value = mapFormListToResourceListMethod.MakeGenericMethod(elementType)
                                        .Invoke(this, new[] { value });
                            }
                        }
                    }

                    resProp.SetValue(resource, value, null);
                }
            }

            if (!resInfo.IsValueObject)
            {
                Save(resource);
            }
            return(resource);
        }
Esempio n. 3
0
        public virtual object OnPost(IPostForm form)
        {
            var resourceInterface = this.GetMostInheritedResourceInterface(form.GetType());

            Delegate del;

            if (this.postHandlers.TryGetValue(resourceInterface, out del))
            {
                return(del.DynamicInvoke(form));
            }

            return(SaveResourceFromForm(form));
        }
Esempio n. 4
0
        public virtual Task <object> PostAsync(string uri, IPostForm form, RequestOptions options)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            return(this.dispatcher.SendRequestAsync(uri, "POST", form, GetSerializationContextProvider(options), options));
        }
Esempio n. 5
0
 public Task <object> PostAsync(string uri, IPostForm form, RequestOptions options)
 {
     return(this.client.PostAsync(uri, form, options));
 }
Esempio n. 6
0
 public Task <object> PostAsync(string uri, IPostForm form, RequestOptions options)
 {
     throw new NotImplementedException();
 }
Esempio n. 7
0
 public virtual TPostReturnType Post(IPostForm form)
 {
     return((TPostReturnType)Client.OnPost(form));
 }
Esempio n. 8
0
 public virtual TPostResponseResource Post(IPostForm form)
 {
     return((TPostResponseResource)Client.Post(Uri, (TResource)((object)form), null));
 }