Ejemplo n.º 1
0
 public static void StartDownloadAsync(DownloaderParams downloadInfo)
 {
     var worker = new BackgroundWorker();
     worker.DoWork += DownloadDoWork;
     worker.RunWorkerCompleted += DownloadComplete;
     _activeWorkers.Add(worker);
     worker.RunWorkerAsync(downloadInfo);
 }
Ejemplo n.º 2
0
        private static string GetFile(DownloaderParams info)
        {
            string writePath = info.FullLocalPath;

            if (!IsValidPath(writePath))
            {
                Debug.Fail("Generated invalid paths.");
                return null;
            }

            string directory = Path.GetDirectoryName(writePath);

            //if (WriteAccess(writePath))
            //{
            //    Debug.WriteLine("I have write access");
            //}
            //else
            //{
            //    Debug.WriteLine("I don't have write access");
            //}

            if (!FileSystem.DirectoryExists(directory))
            {
                FileSystem.CreateDirectory(directory);
            }
            //check for existence of local file
            bool localFileExists = FileSystem.FileExists(writePath);
            if (localFileExists)
            {
                return writePath;
            }
            var webRequest = new WebRequest();
            IHttpWebResponse response;
            IHttpWebRequest request = webRequest.Create(new Uri(info.RemoteUrl));
            try
            {
                response = request.GetResponse();
            }
            catch (WebException ex)
            {
                response = ex.Response as System.Net.HttpWebResponse == null
                               ? null
                               : new HttpWebResponse(ex.Response as System.Net.HttpWebResponse);
            }
            if (response == null)
            {
                return null;
            }
            if (response.StatusCode == HttpStatusCode.OK)
            {
                ReadResponseToFileStream(writePath, response);

                return writePath;
            }
            return null;
        }
Ejemplo n.º 3
0
 public static void Download(DownloaderParams downloadInfo)
 {
     string localPath = GetFile(downloadInfo);
 }