예제 #1
0
        public ITransferRequest DownloadAsync(string from, string to)
        {
            var serverUri = new Uri(from, UriKind.Absolute);
            var phoneUri  = new Uri(to, UriKind.Relative);

            try
            {
                var request = new FakeWindowsTransferRequest {
                    RequestId = serverUri.ToString(), RequestUri = serverUri, DownloadLocation = phoneUri, TotalBytesToReceive = 100, BytesReceived = 0, TransferStatus = FileTransferStatus.Transferring
                };
                PersistRequestToStorage(request);
                transfers[request.RequestId] = request;
                new TaskFactory().StartNew(() =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        request.ChangeProgress(i, FileTransferStatus.Transferring);
                        Thread.Sleep(500);
                    }
                    request.ChangeProgress(100, FileTransferStatus.Completed);
                });
                return(request);
            }
            catch (InvalidOperationException)
            {
                return(GetRequest(from));
            }
        }
        public ITransferRequest DownloadAsync(string from, string to)
        {
            var serverUri = new Uri(from, UriKind.Absolute);
            var phoneUri = new Uri(to, UriKind.Relative);

            try
            {
                var request = new FakeWindowsTransferRequest {RequestId = serverUri.ToString(), RequestUri = serverUri, DownloadLocation = phoneUri, TotalBytesToReceive = 100, BytesReceived = 0, TransferStatus = FileTransferStatus.Transferring };
                PersistRequestToStorage(request);
                transfers[request.RequestId] = request;
                new TaskFactory().StartNew(() =>
                {
                    for (int i = 0; i < 100; i++)
                    {
                        request.ChangeProgress(i, FileTransferStatus.Transferring);
                        Thread.Sleep(500);
                    }
                    request.ChangeProgress(100, FileTransferStatus.Completed);
                });
                return request;
            }
            catch (InvalidOperationException)
            {
                return GetRequest(from);
            }   
        }