示例#1
0
        public void StartDownloadManager(string title, Get_Movies_Object.Movie video)
        {
            try
            {
                if (video != null && !string.IsNullOrEmpty(title))
                {
                    Video = video;
                    SqLiteDatabase dbDatabase = new SqLiteDatabase();
                    dbDatabase.Insert_WatchOfflineVideos(Video);
                    dbDatabase.Dispose();

                    Request.SetTitle(title);
                    Request.SetAllowedNetworkTypes(DownloadNetwork.Mobile | DownloadNetwork.Wifi);
                    Request.SetDestinationInExternalPublicDir("/" + Settings.Application_Name + "/Video/Movie/", Filename);
                    Request.SetNotificationVisibility(DownloadVisibility.Visible);
                    Request.SetAllowedOverRoaming(true);
                    Request.SetVisibleInDownloadsUi(true);
                    DownloadID = Downloadmanager.Enqueue(Request);

                    OnDownloadComplete onDownloadComplete = new OnDownloadComplete();
                    Application.Context.ApplicationContext.RegisterReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ActionDownloadComplete));
                }
                else
                {
                    Toast.MakeText(ContextActivty, Application.Context.GetText(Resource.String.Lbl_Download_faileds), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
            }
        }
        public void StartDownloadManager(string title, SoundDataObject sound, string fromActivity)
        {
            try
            {
                if (sound != null && !string.IsNullOrEmpty(title))
                {
                    FromActivity = fromActivity;
                    Console.WriteLine(FromActivity);

                    var sqlEntity = new SqLiteDatabase();
                    sqlEntity.InsertOrUpdate_LatestDownloadsSound(sound);
                    sqlEntity.Dispose();

                    Request.SetTitle(title);
                    Request.SetAllowedNetworkTypes(DownloadNetwork.Wifi | DownloadNetwork.Mobile);
                    Request.SetDestinationInExternalPublicDir("/" + AppSettings.ApplicationName + "/Sound/", Filename);
                    Request.SetNotificationVisibility(DownloadVisibility.Visible);
                    Request.SetAllowedOverRoaming(true);
                    DownloadId = DownloadManager.Enqueue(Request);

                    OnDownloadComplete onDownloadComplete = new OnDownloadComplete();
                    onDownloadComplete.SetData(ActivityContext, fromActivity, sound);
                    Application.Context.ApplicationContext.RegisterReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ActionDownloadComplete));
                }
                else
                {
                    Toast.MakeText(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_Download_failed), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
    /// <summary>
    /// 下载文件
    /// </summary>
    /// <param name="downloadList"></param>
    public void DownloadFiles(List <DownloadDataEntity> downloadList, OnDownloadComplete onComplete, OnDownloadProgressChanged onDownloadProgressChanged)
    {
        this.onDownloadProgressChanged = onDownloadProgressChanged;
        onDownloadComplete             = onComplete;
        TotalSize              = 0;
        TotalCount             = 0;
        m_CurrentDownloadSize  = 0;
        m_CurrentDownloadCount = 0;
        for (int i = 0; i < m_Routine.Length; ++i)
        {
            if (m_Routine[i] == null)
            {
                m_Routine[i] = gameObject.AddComponent <AssetBundleDownloadRoutine>();
            }
        }
        TotalCount = downloadList.Count;
        for (int i = 0; i < downloadList.Count; ++i)
        {
            m_nRoutineIndex = i % m_Routine.Length;

            m_Routine[m_nRoutineIndex].AddDownload(downloadList[i]);

            TotalSize += downloadList[i].Size;
        }

        for (int i = 0; i < m_Routine.Length; ++i)
        {
            m_Routine[i].StartDownload();
        }
    }
示例#4
0
 private void _workerProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     if (e.ProgressPercentage == 100)
     {
         OnDownloadComplete?.Invoke(this);
     }
     OnProgressChanged?.Invoke(this, e.ProgressPercentage);
 }
示例#5
0
 private void _workerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         OnError?.Invoke(this, e.Error.Message);
         return;
     }
     OnDownloadComplete?.Invoke(this);
 }
 private void M_ftp2_DownloadDataCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     try
     {
         OnDownloadComplete?.Invoke(sender, e);
     }
     catch (Exception ex)
     {
         Log.OutputBox(ex);
         Log.ShowError(m_ftp.ErrorMsg);
     }
 }
    public void Download(string label)
    {
        var index = GetLabelIndex(label);

        if (AsyncOpExists(listOps[index]))
        {
            Debug.Log("Download is allready in progress");
            return;
        }

        listOps[index]            = Addressables.DownloadDependenciesAsync(listLabels[index]);
        listOps[index].Completed += (x) => {
            OnDownloadComplete?.Invoke(GetLabel(index));
        };

        StartCoroutine(CRTDownload(index));
    }
示例#8
0
        public void QueueDownload(UriString url, string targetDirectory, string filename = null, int retryCount = 0)
        {
            var download = new DownloadTask(TaskManager, url, targetDirectory, filename, retryCount, Token);

            download.OnStart += t => OnDownloadStart?.Invoke(((DownloadTask)t).Url);
            download.OnEnd   += (t, res, s, ex) => {
                if (s)
                {
                    OnDownloadComplete?.Invoke(((DownloadTask)t).Url, res);
                }
                else
                {
                    OnDownloadFailed?.Invoke(((DownloadTask)t).Url, ex);
                }
            };
            // queue after hooking up events so OnDownload* gets called first
            Queue(download);
        }
示例#9
0
        public void QueueDownload(UriString url, NPath targetDirectory)
        {
            var download = new DownloadTask(Token, fileSystem, url, targetDirectory);

            download.OnStart += t => OnDownloadStart?.Invoke(((DownloadTask)t).Url);
            download.OnEnd   += (t, res, s, ex) =>
            {
                if (s)
                {
                    OnDownloadComplete?.Invoke(((DownloadTask)t).Url, res);
                }
                else
                {
                    OnDownloadFailed?.Invoke(((DownloadTask)t).Url, ex);
                }
            };
            // queue after hooking up events so OnDownload* gets called first
            Queue(download);
        }
        public void StartDownloadManager(string title, VideoObject video, string fromActivity)
        {
            try
            {
                if (video != null && !string.IsNullOrEmpty(title))
                {
                    Video        = video;
                    FromActivity = fromActivity;

                    var sqlEntity = new SqLiteDatabase();
                    sqlEntity.Insert_WatchOfflineVideos(Video);

                    Request.SetTitle(title);
                    Request.SetAllowedNetworkTypes(DownloadNetwork.Mobile | DownloadNetwork.Wifi);
                    Request.SetDestinationInExternalPublicDir("/" + AppSettings.ApplicationName + "/Video/", Filename);
                    Request.SetNotificationVisibility(DownloadVisibility.Visible);
                    Request.SetAllowedOverRoaming(true);
                    DownloadId = Downloadmanager.Enqueue(Request);

                    var onDownloadComplete = new OnDownloadComplete
                    {
                        ActivityContext = ActivityContext, TypeActivity = fromActivity, Video = Video
                    };

                    ActivityContext.ApplicationContext.RegisterReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ActionDownloadComplete));
                }
                else
                {
                    Toast.MakeText(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_Download_faileds), ToastLength.Short).Show();
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
 /// <summary>
 /// Translate event to high level
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     OnDownloadComplete?.Invoke(this, e);
 }
示例#12
0
        /// <summary>
        /// From a provided REST API endpoint download a mod.
        /// </summary>
        public async Task DownloadMod(string url)
        {
            Downloading = true;
            string modZipPath;
            string modImagePath;
            string modExtractPath;
            string modString = string.Empty;

            using (WebClient wc = new WebClient()) {
                dynamic Data = new OnDownloadCompleteArgs();
                OnDownloadStart?.Invoke(this, Data);


                wc.DownloadProgressChanged += WCDownloadPercentChanged;
                try {
                    modString = await wc.DownloadStringTaskAsync(url);
                } catch (WebException ex) {
                    Data.ErrorMessage = ex.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                JsonObject json = JsonObject.Parse(modString);
                // Let's make sure the slug doesn't have weird stuff.
                json["slug"] = string.Join(" ", json["slug"].Split(Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToArray()));
                if (json["compatible"] != "Yes")
                {
                    Data.ErrorMessage = Helpers._("Error.NotCompatible");
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                m = new Mod(
                    json["id"],
                    json.ArrayObjects("title") [0]["rendered"],
                    DateTime.ParseExact(json["modified"].Replace("T", " "), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                    json.ArrayObjects("content") [0]["rendered"],
                    json["author_name"],
                    url,
                    json["File"],
                    json["slug"],
                    json["slug"] + ".jpg"
                    );
                modZipPath     = zipPath + m.Slug + ".zip";
                modExtractPath = Mod.InstallPath + m.Slug + "\\";
                modImagePath   = Mod.ImagePath + m.Thumbnail;

                // Cleanup previous versions and files.
                Delete(m.Slug);
                if (File.Exists(modZipPath))
                {
                    File.Delete(modZipPath);
                }
                if (Directory.Exists(modExtractPath))
                {
                    Directory.Delete(modExtractPath, true);
                }
                if (File.Exists(modImagePath))
                {
                    File.Delete(modImagePath);
                }

                // And start downloading stuff.
                try {
                    await wc.DownloadFileTaskAsync(new System.Uri(json["image"]), modImagePath);
                } catch (WebException we) {
                    Data.ErrorMessage = we.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                try {
                    await wc.DownloadFileTaskAsync(new System.Uri(m.File), modZipPath);
                } catch (WebException we) {
                    Data.ErrorMessage = we.Message;
                    OnDownloadComplete?.Invoke(this, Data);
                    return;
                }
                UnpackMod(modZipPath, modExtractPath);
                AvailableMods.Add(m);
                Data.Success = true;
                OnDownloadComplete?.Invoke(this, Data);
                UpdateSettings();
            }
            Downloading = false;
        }
示例#13
0
 void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
 {
     OnDownloadComplete?.Invoke(tempFile);
 }
示例#14
0
 public void SetDownloadComplete(OnDownloadComplete listener)
 {
     _onDownloadComplete = listener;
 }
示例#15
0
        private async void DownloadWithUrl(string _url)
        {
            var _filePath = new Uri(_url).AbsolutePath;
            var _name     = Path.GetFileName(_filePath);
            var _dir      = $"./downloads/{Path.GetDirectoryName(_filePath)}";

            var _path = $"{_dir}/{_name}";

            if (!Directory.Exists(_dir))
            {
                Directory.CreateDirectory(_dir);
            }

            if (File.Exists(_path))
            {
                OnDownloadComplete?.Invoke(this, new DownloadResultEventArg
                {
                    FileName = _name,
                    Success  = true,
                    Url      = _url,
                    Contains = true
                });
            }
            else
            {
                try
                {
                    OnDownloadStart?.Invoke(this, new DownloadResultEventArg
                    {
                        FileName = _name,
                        Success  = true,
                        Url      = _url
                    });

                    HttpWebRequest webRequest = WebRequest.CreateHttp(_url);
                    webRequest.UserAgent = "Half-Life 2";
                    webRequest.Referer   = "hl2://31.186.251.23:27016";

                    using (WebResponse _request = webRequest.GetResponse())
                        using (Stream _stream = _request.GetResponseStream())
                            using (FileStream _file = File.Create(_path))
                                await _stream.CopyToAsync(_file);

                    OnDownloadComplete?.Invoke(this, new DownloadResultEventArg
                    {
                        FileName = _name,
                        Success  = true,
                        Url      = _url
                    });
                }
                catch (Exception ex)
                {
                    //WebException _ex = ex as WebException;

                    if (_retryCount++ < 3)
                    {
                        File.Delete(_path);
                        DownloadWithUrl(_url);
                    }
                    else
                    {
                        _retryCount = 0;

                        OnDownloadComplete?.Invoke(this, new DownloadResultEventArg
                        {
                            FileName  = _name,
                            Success   = false,
                            Url       = _url,
                            Exception = ex
                        });
                    }
                }
            }
        }