Пример #1
0
 protected LazyListProxy(string uri, IPomonaClient clientBase)
 {
     if (uri == null)
         throw new ArgumentNullException("uri");
     this.uri = uri;
     this.clientBase = clientBase;
 }
Пример #2
0
 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));
 }
Пример #3
0
 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;
 }
Пример #5
0
        internal RestQueryProvider(IPomonaClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            Client = client;
        }
Пример #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);
 }
Пример #7
0
        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));
        }
Пример #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);
        }
Пример #9
0
        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;
        }
Пример #11
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);
        }
Пример #12
0
        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;
        }
Пример #14
0
        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));
        }
Пример #15
0
        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));
        }
Пример #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;
        }
Пример #17
0
 public ChildResourceRepository(IPomonaClient client, string uri, IEnumerable results, IClientResource parent)
     : base(client, uri, results, parent)
 {
     this.parent = parent;
 }
Пример #18
0
 protected RootResource(string baseUri, IRequestDispatcher dispatcher)
 {
     BaseUri     = baseUri;
     this.client = new PomonaClient(ClientTypeMapper, dispatcher);
     InstantiateClientRepositories();
 }
Пример #19
0
 protected RootResource(string baseUri, IWebClient webClient)
 {
     BaseUri     = baseUri;
     this.client = new PomonaClient(ClientTypeMapper, webClient);
     InstantiateClientRepositories();
 }
Пример #20
0
 internal static object CreateForType(Type elementType, string uri, IPomonaClient clientBase)
 {
     return Activator.CreateInstance(typeof(LazyListProxy<>).MakeGenericType(elementType), uri, clientBase);
 }
Пример #21
0
 public LazyListProxy(string uri, IPomonaClient clientBase)
     : base(uri, clientBase)
 {
 }