Exemple #1
0
 protected LazyListProxy(string uri, IPomonaClient clientBase)
 {
     if (uri == null)
         throw new ArgumentNullException("uri");
     this.uri = uri;
     this.clientBase = clientBase;
 }
 public static T Get <T>(this IPomonaClient client, string uri)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     return((T)client.Get(uri, typeof(T), null));
 }
 public static object Get(this IPomonaClient client, string uri, Type type)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     return(client.Get(uri, type, null));
 }
 internal ClientSerializationContextProvider(ClientTypeMapper clientTypeMapper, IPomonaClient client)
 {
     if (clientTypeMapper == null)
         throw new ArgumentNullException("clientTypeMapper");
     if (client == null)
         throw new ArgumentNullException("client");
     this.clientTypeMapper = clientTypeMapper;
     this.client = client;
 }
Exemple #5
0
        internal RestQueryProvider(IPomonaClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            Client = client;
        }
Exemple #6
0
 public ClientRepository(IPomonaClient client, string uri, IEnumerable results, IClientResource parent)
 {
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     Client       = client;
     Uri          = uri;
     this.results = results as IEnumerable <TResource> ?? (results != null ? results.Cast <TResource>() : null);
 }
        internal static Task <object> PostAsync <T>(this IPomonaClient client, string uri, Action <T> postAction, RequestOptions options)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            var postForm = client.TypeMapper.CreatePostForm(typeof(T));

            postAction((T)postForm);
            return(client.PostAsync(uri, postForm, options));
        }
Exemple #8
0
        internal static object CreateForType(Type collectionType, string uri, IPomonaClient clientBase)
        {
            Type[] genArgs;
            if (collectionType.TryExtractTypeArguments(typeof(ISet<>), out genArgs))
                return Activator.CreateInstance(typeof(LazySetProxy<>).MakeGenericType(genArgs), uri, clientBase);

            if (collectionType.TryExtractTypeArguments(typeof(IEnumerable<>), out genArgs))
                return Activator.CreateInstance(typeof(LazyListProxy<>).MakeGenericType(genArgs), uri, clientBase);

            throw new NotSupportedException("Unable to create lazy list proxy for collection type " + collectionType);
        }
        public static T GetLazy <T>(this IPomonaClient client, string uri)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            var typeInfo = client.GetResourceInfoForType(typeof(T));
            var proxy    = (LazyProxyBase)Activator.CreateInstance(typeInfo.LazyProxyType);

            proxy.Initialize(uri, client, typeInfo.PocoType);
            return((T)((object)proxy));
        }
        internal ClientSerializationContextProvider(ClientTypeMapper clientTypeMapper, IPomonaClient client, IResourceLoader resourceLoader)
        {
            if (clientTypeMapper == null)
                throw new ArgumentNullException(nameof(clientTypeMapper));

            if (client == null)
                throw new ArgumentNullException(nameof(client));

            if (resourceLoader == null)
                throw new ArgumentNullException(nameof(resourceLoader));

            this.clientTypeMapper = clientTypeMapper;
            this.client = client;
            this.resourceLoader = resourceLoader;
        }
        internal static object CreateForType(Type collectionType, string uri, IPomonaClient clientBase)
        {
            Type[] genArgs;
            if (collectionType.TryExtractTypeArguments(typeof(ISet <>), out genArgs))
            {
                return(Activator.CreateInstance(typeof(LazySetProxy <>).MakeGenericType(genArgs), uri, clientBase));
            }

            if (collectionType.TryExtractTypeArguments(typeof(IEnumerable <>), out genArgs))
            {
                return(Activator.CreateInstance(typeof(LazyListProxy <>).MakeGenericType(genArgs), uri, clientBase));
            }

            throw new NotSupportedException("Unable to create lazy list proxy for collection type " + collectionType);
        }
        public static async Task <T> GetAsync <T>(this IPomonaClient client, string uri, RequestOptions requestOptions)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            var type     = typeof(T);
            var resource = await client.GetAsync(uri, type, requestOptions);

            if (resource == null && type.IsValueType && !type.IsNullable())
            {
                throw new InvalidCastException($"The response from {uri} was null, which can't be cast to {type}.");
            }

            return((T)resource);
        }
        public ClientDeserializationContext(ITypeResolver typeMapper,
                                            IPomonaClient client,
                                            IResourceLoader resourceLoader)
        {
            if (typeMapper == null)
            {
                throw new ArgumentNullException(nameof(typeMapper));
            }

            if (resourceLoader == null)
            {
                throw new ArgumentNullException(nameof(resourceLoader));
            }

            this.typeMapper     = typeMapper;
            this.client         = client;
            this.resourceLoader = resourceLoader;
        }
        internal static async Task <T> PatchAsync <T>(this IPomonaClient client,
                                                      T target,
                                                      Action <T> updateAction,
                                                      Action <IRequestOptions <T> > options = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            var patchForm = (T)client.TypeMapper.CreatePatchForm(typeof(T), target);

            updateAction(patchForm);

            var requestOptions = new RequestOptions <T>();

            options?.Invoke(requestOptions);

            return((T)await client.PatchAsync(patchForm, requestOptions));
        }
        public static T Patch <T>(this IPomonaClient client, T target, Action <T> updateAction, Action <IRequestOptions <T> > options = null)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            var patchForm = (T)client.TypeMapper.CreatePatchForm(typeof(T), target);

            updateAction(patchForm);

            var requestOptions = new RequestOptions <T>();

            if (options != null)
            {
                options(requestOptions);
            }

            return((T)client.Patch(patchForm, requestOptions));
        }
Exemple #16
0
        internal ClientSerializationContextProvider(ClientTypeMapper clientTypeMapper, IPomonaClient client, IResourceLoader resourceLoader)
        {
            if (clientTypeMapper == null)
            {
                throw new ArgumentNullException(nameof(clientTypeMapper));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (resourceLoader == null)
            {
                throw new ArgumentNullException(nameof(resourceLoader));
            }

            this.clientTypeMapper = clientTypeMapper;
            this.client           = client;
            this.resourceLoader   = resourceLoader;
        }
Exemple #17
0
 public ChildResourceRepository(IPomonaClient client, string uri, IEnumerable results, IClientResource parent)
     : base(client, uri, results, parent)
 {
     this.parent = parent;
 }
Exemple #18
0
 protected RootResource(string baseUri, IRequestDispatcher dispatcher)
 {
     BaseUri     = baseUri;
     this.client = new PomonaClient(ClientTypeMapper, dispatcher);
     InstantiateClientRepositories();
 }
Exemple #19
0
 protected RootResource(string baseUri, IWebClient webClient)
 {
     BaseUri     = baseUri;
     this.client = new PomonaClient(ClientTypeMapper, webClient);
     InstantiateClientRepositories();
 }
Exemple #20
0
 internal static object CreateForType(Type elementType, string uri, IPomonaClient clientBase)
 {
     return Activator.CreateInstance(typeof(LazyListProxy<>).MakeGenericType(elementType), uri, clientBase);
 }
Exemple #21
0
 public LazyListProxy(string uri, IPomonaClient clientBase)
     : base(uri, clientBase)
 {
 }