internal static IResourceStrategy Create(ResourceStrategyType resourceStrategyType) { IResourceStrategy resourceStrategy = new ResourceStrategyCache(); switch (resourceStrategyType) { case ResourceStrategyType.Cache: resourceStrategy = new ResourceStrategyCache(); break; case ResourceStrategyType.DirectStream: resourceStrategy = new ResourceStrategyDirectStream(); break; case ResourceStrategyType.LocalFile: resourceStrategy = new ResourceStrategyLocalFile(); break; default: // throw exception ? resourceStrategy = null; break; } return(resourceStrategy); }
/// <summary> /// Gets the resource request. /// </summary> /// <param name="uri">The URI.</param> /// <param name="resourceStrategyType">Type of the resource strategy.</param> /// <returns></returns> public ResourceRequest GetResourceRequest(string uri, ResourceStrategyType resourceStrategyType) { NetworkResourceArguments args = new NetworkResourceArguments() { Headers = Device.RequestInjectionHeaders, CacheStaleMethod = CacheStaleMethod.Deferred }; return(GetResourceRequest(uri, resourceStrategyType, args)); }
/// <summary> /// Gets the specified resource. /// </summary> /// <param name="uri">The URI of the resource.</param> /// <param name="type">The strategy type for the resource.</param> /// <param name="format">The serialization format for the request.</param> /// <returns></returns> public static string Get(string uri, ResourceStrategyType type, SerializationFormat format) { NetworkResourceArguments args = new NetworkResourceArguments() { Headers = Device.RequestInjectionHeaders, CacheStaleMethod = CacheStaleMethod.Deferred }; return(Get(uri, args, type, format)); }
/// <summary> /// Returns Resource Request for specified cache and resource strategy /// </summary> /// <returns></returns> public ResourceRequest GetResourceRequest(string uri, ResourceStrategyType resourceStrategyType, NetworkResourceArguments args) { if (string.IsNullOrEmpty(uri)) { throw new ArgumentNullException("uri"); } // return default value ResourceRequest resourceRequest = new ResourceRequest(uri, resourceStrategyType, args); return(resourceRequest); }
/// <summary> /// Gets the specified resource. /// </summary> /// <param name="uri">The URI of the resource.</param> /// <param name="args">The network resource arguments for the request.</param> /// <param name="type">The strategy type for the resource.</param> /// <param name="format">The serialization format for the request.</param> /// <returns></returns> public static string Get(string uri, NetworkResourceArguments args, ResourceStrategyType type, SerializationFormat format) { if (string.IsNullOrEmpty(uri)) { return(string.Empty); } ResourceRequest request = NetworkResourceLibrary.Instance.GetResourceRequest(uri, type, args); ResourceResponse response = request.GetResponse(args.TimeoutMilliseconds); return(response.GetResponseString()); }
/// <summary> /// Gets a resource using the specified URI. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="uri">The URI of the resource.</param> /// <param name="args">The arguments for the request.</param> /// <param name="type">The resource strategy type.</param> /// <param name="format">The serialization format.</param> /// <param name="customSerializerType">Type of the custom serializer.</param> /// <returns></returns> public static T Get <T>(string uri, NetworkResourceArguments args, ResourceStrategyType type, SerializationFormat format, Type customSerializerType) { if (string.IsNullOrEmpty(uri)) { return(default(T)); } ResourceRequest request = NetworkResourceLibrary.Instance.GetResourceRequest(uri, type, args); ResourceResponse response = request.GetResponse(args.TimeoutMilliseconds); ISerializer <T> iSerializer = SerializerFactory.Create <T>(format, customSerializerType); T obj = iSerializer.DeserializeObject(response.GetResponseBytes()); return(obj); }
internal ResourceStrategyController(ResourceStrategyType strategyType) { ResourceStrategy = ResourceStrategyFactory.Create(strategyType); }
/// <summary> /// Gets the specified resource. /// </summary> /// <param name="uri">The URI of the resource.</param> /// <param name="args">The network resource arguments for the request.</param> /// <param name="type">The strategy type for the resource.</param> /// <returns></returns> public static string Get(string uri, NetworkResourceArguments args, ResourceStrategyType type) { return(Get(uri, args, type, SerializationFormat.XML)); }
/// <summary> /// Gets a resource using the specified URI. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="uri">The URI of the resource.</param> /// <param name="args">The arguments for the request.</param> /// <param name="type">The resource strategy type.</param> /// <param name="format">The serialization format.</param> /// <returns></returns> public static T Get <T>(string uri, NetworkResourceArguments args, ResourceStrategyType type, SerializationFormat format) { return(Get <T>(uri, args, type, format, null)); }
internal ResourceRequest(string uri, ResourceStrategyType resourceStrategyType, NetworkResourceArguments args) { Uri = uri; ResourceStrategyType = resourceStrategyType; NetworkResourceArguments = args; }