Esempio n. 1
0
        /// <summary>
        ///		Descarga los archivos
        /// </summary>
        public async Task DownloadFilesAsync()
        {
            var webClient = new LibCommonHelper.Communications.HttpWebClient();

            // Descarga los eventos
            foreach (MediaFileModel file in Files)
            {
                string fileName = GetDownloadFileName(file);

                // Descarga el archivo
                if (!string.IsNullOrEmpty(fileName) && !File.Exists(fileName))
                {
                    // Lanza el evento de descarga
                    RaiseEvent(file, Files.IndexOf(file), Files.Count);
                    // Crea el directorio
                    HelperFiles.MakePath(Path.GetDirectoryName(fileName));
                    // Descarga el archivo
                    try
                    {
                        // Descarga el archivo
                        await webClient.DownloadFileAsync(file.Url, fileName);

                        // Asigna el nombre del archivo descargado
                        file.FileName = fileName;
                    }
                    catch {}
                }
            }
            // Lanza el evento de fin
            EndDownload?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 2
0
 private IEnumerator _BeginDownload(string path, EndDownload endDownload, System.Object ud, UpdatePBar upb, int index)
 {
     if (path == null || path == "")
     {
         yield break;
     }
     yield return(StartCoroutine(DoDownload(path, endDownload, ud, upb, index)));
 }
Esempio n. 3
0
        public static IEnumerator BeginDownload(string path, EndDownload endDownload, System.Object ud, UpdatePBar upb)
        {
            if (instance == null)
            {
                yield break;
            }

            yield return(instance.StartCoroutine(instance._BeginDownload(path, endDownload, ud, upb, 0)));
        }
Esempio n. 4
0
        private IEnumerator DoDownload(string path, EndDownload endDownload, System.Object ud, UpdatePBar upb, int index)
        {
            using (UnityWebRequest www = UnityWebRequest.Get(path))
            {
                if (upb != null && updatePBarDic.ContainsKey(www))
                {
                    updatePBarDic.Remove(www);
                }
                updatePBarDic.Add(www, upb);

                yield return(www.Send());

                if (upb != null)
                {
                    upb(1);
                }

                updatePBarDic.Remove(www);

                if ((www.isNetworkError || www.isHttpError) && www.error.Length > 0)
                {
                    Debugger.LogError("Failed to download res: " + path + " Error: " + www.error);
                    www.Dispose();
                    if (index < 5)
                    {
                        StartCoroutine(instance._BeginDownload(path, endDownload, ud, upb, index++));
                    }
                    else
                    {
                        endDownload(www.url, null, ud);
                    }
                    yield break;
                }

                endDownload(www.url, www.downloadHandler.data, ud);
            }
        }
Esempio n. 5
0
 private void _RaiseEndDownload(bool isCanceled) => EndDownload?.Invoke(this, new UpdateDownloadEventArgs(isCanceled));