Ejemplo n.º 1
0
        public Response <UIImage> Load(Uri uri, bool localCacheOnly)
        {
            NSUrl url = NSUrl.FromString(uri.AbsoluteUri);

            var cachePolicy = localCacheOnly
                ? NSUrlRequestCachePolicy.ReturnCacheDataDoNotLoad
                : NSUrlRequestCachePolicy.ReturnCacheDataElseLoad;

            var request = new NSUrlRequest(url, cachePolicy, 20);

            NSCachedUrlResponse cachedResponse = NSUrlCache.SharedCache.CachedResponseForRequest(request);

            if (cachedResponse != null)
            {
                return(new Response <UIImage>(cachedResponse.Data.AsStream(), true, cachedResponse.Data.Length));
            }

            NSUrlResponse response;
            NSError       error;
            NSData        data = NSUrlConnection.SendSynchronousRequest(request, out response, out error);

            if (error != null || data == null)
            {
                return(null);
            }

            cachedResponse = new NSCachedUrlResponse(response, data, null, NSUrlCacheStoragePolicy.Allowed);
            NSUrlCache.SharedCache.StoreCachedResponse(cachedResponse, request);

            return(new Response <UIImage>(data.AsStream(), false, data.Length));
        }
 public CoreCustomUrlProtocol(
     NSUrlRequest request,
     NSCachedUrlResponse cachedResponse,
     INSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
 }
Ejemplo n.º 3
0
 public CustomUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
     if (State == 2)
     {
         State++;
     }
 }
        public IPhoneNSUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client)
            : base(request, cachedResponse, client)
        {
            //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneNSUrlProtocol - Init with Request");

            serviceLocator           = IPhoneServiceLocator.GetInstance();
            serviceURIHandler        = new IPhoneServiceURIHandler(serviceLocator);
            resourceURIHandler       = new IPhoneResourceHandler(ApplicationSource.FILE);
            serviceInvocationManager = new ServiceInvocationManager();
        }
Ejemplo n.º 5
0
        public IPhoneNSUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client)
            : base(request, cachedResponse, client)
        {
            //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneNSUrlProtocol - Init with Request");

            serviceLocator = IPhoneServiceLocator.GetInstance ();
            serviceURIHandler = new IPhoneServiceURIHandler (serviceLocator);
            resourceURIHandler = new IPhoneResourceHandler (ApplicationSource.FILE);
            serviceInvocationManager = new ServiceInvocationManager ();
        }
Ejemplo n.º 6
0
        public UrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, NSObject client)
            : base(NSObjectFlag.Empty)
        {
            var h = Selector.GetHandle("initWithRequest:cachedResponse:client:");

            if (base.IsDirectBinding)
            {
                Handle = Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(base.Handle, h, request.Handle, cachedResponse?.Handle ?? IntPtr.Zero, client.Handle);
            }
            else
            {
                Handle = Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr(base.SuperHandle, h, request.Handle, cachedResponse?.Handle ?? IntPtr.Zero, client.Handle);
            }
        }
Ejemplo n.º 7
0
        void HandleCacheItemAdded(object sender, CachedEventArgs e)
        {
            var url = NSUrl.FromString(e.Url);

            if (url == null)
            {
                return;
            }

            var req            = NSUrlRequest.FromUrl(url);
            var data           = NSData.FromStream(e.Item.DataSource());
            var resp           = new NSUrlResponse(url, e.Item.MimeType, (nint)data.Length, "UTF-8");
            var cachedResponse = new NSCachedUrlResponse(resp, data);

            NSUrlCache.SharedCache.StoreCachedResponse(cachedResponse, req);
        }
        public void ConstructorTest()
        {
            // See https://bugzilla.xamarin.com/show_bug.cgi?id=3835
            using (var response = new NSUrlResponse())
                using (var data = new NSData()) {
                    // Test that UserInfo is NullAllowed
                    using (var res1 = new NSCachedUrlResponse(response, data, null, NSUrlCacheStoragePolicy.Allowed)) {
                        Assert.That(res1.StoragePolicy, Is.EqualTo(NSUrlCacheStoragePolicy.Allowed), "StoragePolicy-1");
                        Assert.Null(res1.UserInfo, "UserInfo-1");
                    }

                    using (var res2 = new NSCachedUrlResponse(response, data)) {
                        Assert.That(res2.StoragePolicy, Is.EqualTo(NSUrlCacheStoragePolicy.Allowed), "StoragePolicy-2");
                        Assert.Null(res2.UserInfo, "UserInfo-2");
                    }
                }
        }
Ejemplo n.º 9
0
 public NSUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, NSUrlProtocolClient client)
     : base(NSObjectFlag.Empty)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (client == null)
     {
         throw new ArgumentNullException("client");
     }
     if (IsDirectBinding)
     {
         InitializeHandle(global::ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr_IntPtr(this.Handle, selInitWithRequest_CachedResponse_Client_Handle, request.Handle, cachedResponse == null ? IntPtr.Zero : cachedResponse.Handle, client.Handle), "initWithRequest:cachedResponse:client:");
     }
     else
     {
         InitializeHandle(global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr_IntPtr(this.SuperHandle, selInitWithRequest_CachedResponse_Client_Handle, request.Handle, cachedResponse == null ? IntPtr.Zero : cachedResponse.Handle, client.Handle), "initWithRequest:cachedResponse:client:");
     }
 }
Ejemplo n.º 10
0
 public CustomUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
     custom_url_protocol_instance = this;
 }
Ejemplo n.º 11
0
 public CustomProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client)
 {
 }
Ejemplo n.º 12
0
 public override void WillCacheResponse(NSUrlSession session, NSUrlSessionDataTask dataTask, NSCachedUrlResponse proposedResponse, Action <NSCachedUrlResponse> completionHandler)
 {
     completionHandler(sessionHandler.DisableCaching ? null : proposedResponse);
 }
Ejemplo n.º 13
0
 public void CachedResponseIsValid(NSUrlProtocol protocol, NSCachedUrlResponse cachedResponse)
 {
     Messaging.void_objc_msgSend_IntPtr_IntPtr(this.Handle, Selector.GetHandle(selUrlProtocolCachedResponseIsValid_), protocol.Handle, cachedResponse.Handle);
 }
Ejemplo n.º 14
0
 public void CachedResponseIsValid(NSUrlProtocol protocol, NSCachedUrlResponse cachedResponse)
 {
 }
Ejemplo n.º 15
0
		public ImageProtocol (NSUrlRequest request, NSCachedUrlResponse cachedResponse, NSUrlProtocolClient client) 
			: base (request, cachedResponse, client)
		{
		}
Ejemplo n.º 16
0
 public PheidiUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
 }
Ejemplo n.º 17
0
 public UrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, NSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
     this.Client = client;
 }
Ejemplo n.º 18
0
 public ImageProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, NSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
 }
Ejemplo n.º 19
0
 public void CachedResponseIsValid(NSUrlProtocol protocol, NSCachedUrlResponse cachedResponse)
 {
     Messaging.void_objc_msgSend_IntPtr_IntPtr (this.Handle, selUrlProtocolCachedResponseIsValid_, protocol.Handle, cachedResponse.Handle);
 }
 public MsalCustomUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse,
     INSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
 }
Ejemplo n.º 21
0
 public override void WillCacheResponse (NSUrlSession session, NSUrlSessionDataTask dataTask,
     NSCachedUrlResponse proposedResponse, Action<NSCachedUrlResponse> completionHandler)
 {
     completionHandler (This.DisableCaching ? null : proposedResponse);
 }
Ejemplo n.º 22
0
 public AppProtocolHandler(NSUrlRequest request, NSCachedUrlResponse cachedResponse, NSUrlProtocolClient client)
     : base(request, cachedResponse, client)
 {
 }