コード例 #1
0
        public bool IsDownloading(IDownloadFile File)
        {
            //if(TotalBytewritten== File.TotalBytesWritten && File.TotalBytesWritten!=0)
            //{
            //    return false;
            //}
            //TotalBytewritten = File.TotalBytesWritten;
            if (File == null)
            {
                return(false);
            }

            switch (File.Status)
            {
            case DownloadFileStatus.INITIALIZED:
            case DownloadFileStatus.PAUSED:
            case DownloadFileStatus.PENDING:
            case DownloadFileStatus.RUNNING:
                // DependencyService.Get<IToast>().ShowToast();
                return(true);

            case DownloadFileStatus.COMPLETED:
            case DownloadFileStatus.CANCELED:
            case DownloadFileStatus.FAILED:
                return(false);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #2
0
 protected internal void RemoveFile(IDownloadFile file)
 {
     lock (_queue)
     {
         _queue.Remove(file);
     }
 }
コード例 #3
0
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var downloadFile = (DownloadFileImplementation)i;
            var downloads    = Queue.Cast <DownloadFileImplementation>().ToList();
            var item         = downloads.Where(x => x.Url == downloadFile.Url).FirstOrDefault();

            if (item != null)
            {
                Abort(item);
            }
            else
            {
                if (FileExistenceCheck(i))
                {
                    return;
                }

                AddFile(downloadFile);

                downloadFile.Status = DownloadFileStatus.INITIALIZED;

                if (downloads.Count == 0)
                {
                    StartDownloadManager();
                }
            }
        }
コード例 #4
0
        public async void DownloadFile(string FileRoot, string FileName, string[] _parameters)
        {
            try
            {
                string _downloadStatus = string.Empty;

                await Task.Run(() =>
                {
                    var downloadManager = CrossDownloadManager.Current;
                    File = downloadManager.CreateDownloadFile(FileRoot);
                    downloadManager.Start(File, true);

                    while (isDownloading)
                    {
                        isDownloading = IsDownloading(File, FileName, _parameters).Result;
                    }
                }).ConfigureAwait(true);

                if (!isDownloading)
                {
                    string _title      = "Descarga de documentos";
                    string _body       = string.Format("Archivo {0} Descargado satisfactoriamente, revise su carpeta de descargas", FileName);
                    string _bodyNotify = string.Format("{0} Descargado.", FileName);

                    //CrossLocalNotifications.Current.Show(_title, _bodyNotify, 100, DateTime.Now.AddSeconds(1));
                    _usuarioActivo.IsBusy = false;
                    await DisplayAlert(_title, _body, "OK");
                }
            }
            catch (Exception ex)
            {
                var _message = ex.Message;
                throw ex;
            }
        }
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var file = (DownloadFileImplementation)i;

            file.StartDownload(_session, mobileNetworkAllowed);
            AddFile(file);
        }
コード例 #6
0
 protected internal void AddFile(IDownloadFile file)
 {
     lock (_queue)
     {
         _queue.Add(file);
     }
 }
コード例 #7
0
        public bool IsDownloading(IDownloadFile File)
        {
            if (File == null)
            {
                return(false);
            }
            {
                switch (File.Status)
                {
                case DownloadFileStatus.INITIALIZED:
                case DownloadFileStatus.PAUSED:
                case DownloadFileStatus.PENDING:
                case DownloadFileStatus.RUNNING:
                    return(true);

                case DownloadFileStatus.COMPLETED:
                case DownloadFileStatus.CANCELED:
                case DownloadFileStatus.FAILED:
                    return(false);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
コード例 #8
0
        public void Abort(IDownloadFile i)
        {
            var file = (DownloadFileImplementation)i;

            file.Status = DownloadFileStatus.CANCELED;
            _downloadManager.Remove(file.Id);
            RemoveFile(file);
        }
コード例 #9
0
        public void Abort(IDownloadFile i)
        {
            var file = (DownloadFileImplementation)i;

            file.Cancel();

            RemoveFile(file);
        }
コード例 #10
0
        protected internal void RemoveFile(IDownloadFile file)
        {
            lock (_queue) {
                _queue.Remove(file);
            }

            CollectionChanged?.Invoke(Queue, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, file));
        }
コード例 #11
0
        public void Abort(IDownloadFile i)
        {
            var file = (DownloadFileImplementation)i;

            file.PropertyChanged -= UpdateFileProperty;
            file.Cancel();

            RemoveFile(file);
        }
        public void Abort(IDownloadFile i)
        {
            var file = (DownloadFileImplementation)i;

            file.Status = DownloadFileStatus.CANCELED;
            file.Task?.Cancel();

            RemoveFile(file);
        }
コード例 #13
0
 public void Enqueue(IDownloadFile downloadFile)
 {
     downloadFileQueue.Enqueue(downloadFile);
     if (downloadFileQueue.Count == 1 && !isDownloading && !isPaused)
     {
         var newOne = downloadFileQueue.Dequeue();
         newOne.Finsih += OnFileFinish;
         newOne.StartDownload();
     }
 }
コード例 #14
0
 public void InitializeDownload()
 {
     File = CrossDownloadManager.Current.CreateDownloadFile(
         "http://ipv4.download.thinkbroadband.com/10MB.zip"
         // If you need, you can add a dictionary of headers you need.
         //, new Dictionary<string, string> {
         //    { "Cookie", "LetMeDownload=1;" },
         //    { "Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }
         //}
         );
 }
コード例 #15
0
 public void InitializeDownload()
 {
     File = CrossDownloadManager.Current.CreateDownloadFile(
         "http://www.speedtestx.de/testfiles/data_10mb.test"
         // If you need, you can add a dictionary of headers you need.
         //, new Dictionary<string, string> {
         //    { "Cookie", "LetMeDownload=1;" },
         //    { "Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }
         //}
         );
 }
コード例 #16
0
        protected internal void AddFile(IDownloadFile file)
        {
            lock (_queue) {
                _queue.Add(file);
            }

            if (CollectionChanged != null)
            {
                CollectionChanged.Invoke(Queue, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, file));
            }
        }
コード例 #17
0
 public void InitializeDownload(string url)
 {
     File = CrossDownloadManager.Current.CreateDownloadFile(
         url
         // If you need, you can add a dictionary of headers you need.
         //, new Dictionary<string, string> {
         //    { "Cookie", "LetMeDownload=1;" },
         //    { "Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }
         //}
         );
 }
コード例 #18
0
 public void InitializeDownload()
 {
     File = CrossDownloadManager.Current.CreateDownloadFile(
         "http://newlms.magtu.ru/webservice/pluginfile.php/782554/mod_resource/content/1/%D0%97%D0%B0%D1%8F%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5%20%D0%BD%D0%B0%20%D0%BF%D1%80%D0%B0%D0%BA%D1%82%D0%B8%D0%BA%D1%83%20%D0%BF.doc?forcedownload=1&token=05b32f186215d7e3a7de2cc003acfffb"
         //"http://ipv4.download.thinkbroadband.com/10MB.zip"
         // If you need, you can add a dictionary of headers you need.
         //, new Dictionary<string, string> {
         //    { "Cookie", "LetMeDownload=1;" },
         //    { "Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }
         //}
         );
 }
コード例 #19
0
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var file = (DownloadFileImplementation)i;

            string destinationPathName = null;

            if (PathNameForDownloadedFile != null)
            {
                destinationPathName = PathNameForDownloadedFile(file);
            }

            file.StartDownloadAsync(destinationPathName, mobileNetworkAllowed);
        }
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var file = (DownloadFileImplementation)i;

            string destinationPathName = null;

            if (PathNameForDownloadedFile != null)
            {
                destinationPathName = PathNameForDownloadedFile(file);
            }

            file.StartDownload(_downloadManager, destinationPathName, mobileNetworkAllowed, NotificationVisibility, IsVisibleInDownloadsUi);
            AddFile(file);
        }
コード例 #21
0
        public void Download()
        {
            if (IsDownloading())
            {
                AbortDownloading();
                return;
            }

            File = DownloadManager.CreateDownloadFile("http://ipv4.download.thinkbroadband.com/10MB.zip");
            File.PropertyChanged += OnPropertyChanged;

            DownloadManager.Start(File, false);
            Debug.WriteLine($"Download Queue: {DownloadManager.Queue.ToList().Count}");
        }
コード例 #22
0
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var file = (DownloadFileImplementation)i;

            file.PropertyChanged += UpdateFileProperty;
            AddFile(file);

            string destinationPathName = null;

            if (PathNameForDownloadedFile != null)
            {
                destinationPathName = PathNameForDownloadedFile(file);
            }

            //Do not await here otherwise it will never return
            file.StartDownloadAsync(destinationPathName, mobileNetworkAllowed);
        }
コード例 #23
0
        private bool FileExistenceCheck(IDownloadFile i)
        {
            var downloadFile        = (DownloadFileImplementation)i;
            var fileManager         = NSFileManager.DefaultManager;
            var destinationPathName = downloadFile.DestinationPathName;

            string nameFile           = destinationPathName.Split('/').Last();
            var    URLs               = fileManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
            NSUrl  documentsDictionry = URLs.First();
            NSUrl  destinationURL     = documentsDictionry.Append(nameFile, false);

            if (fileManager.FileExists(destinationURL.Path))
            {
                downloadFile.DestinationPathName = destinationURL.Path;
                downloadFile.StatusDetails       = default(string);
                downloadFile.Status = DownloadFileStatus.COMPLETED;
                return(true);
            }
            return(false);
        }
コード例 #24
0
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var downloadFile = (DownloadFileImplementation)i;

            //if(FileExistenceCheck(i))
            //    return;

            var downloads = Queue.Cast <DownloadFileImplementation>();
            var item      = downloads.Where(x => x.Url == downloadFile.Url).FirstOrDefault();

            if (item != null)
            {
                Abort(item);
            }
            else
            {
                downloadFile.Status = DownloadFileStatus.INITIALIZED;

                AddFile(downloadFile);

                StartDownloadWatcher();
            }
        }
コード例 #25
0
        private bool FileExistenceCheck(IDownloadFile i)
        {
            var downloadFile = (DownloadFileImplementation)i;

            var destinationPathName = PathNameForDownloadedFile(downloadFile);
            var file = new Java.IO.File(destinationPathName);

            if (file.Exists())
            {
                string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(destinationPathName.ToLower()));
                if (mimeType == null)
                {
                    mimeType = "*/*";
                }

                downloadFile.DestinationPathName = destinationPathName;
                downloadFile.MimeType            = mimeType;
                downloadFile.StatusDetails       = default(string);
                downloadFile.Status = DownloadFileStatus.COMPLETED;
                return(true);
            }
            return(false);
        }
コード例 #26
0
        public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
        {
            var file = (DownloadFileImplementation)i;

            AddFile(file);

            NSOperationQueue.MainQueue.BeginInvokeOnMainThread(() =>
            {
                NSUrlSession session;

                var inBackground = UIApplication.SharedApplication.ApplicationState == UIApplicationState.Background;

                if (_avoidDiscretionaryDownloadInBackground && inBackground)
                {
                    session = _session;
                }
                else
                {
                    session = _backgroundSession;
                }

                file.StartDownload(session, mobileNetworkAllowed);
            });
        }
 public void Abort(IDownloadFile i)
 {
     throw new NotImplementedException();
 }
 public void Start(IDownloadFile i, bool mobileNetworkAllowed = true)
 {
     throw new NotImplementedException();
 }
コード例 #29
0
        public async void DownloadItem(FreeDiscItemDownload freeDiscDownloader)
        {
            if (CurrentDownloadFile != null)
            {
                if (IsDownloadInProgress())
                {
                    Debug.WriteLine("DownloadItem: CurrentDownloadFile is active!");
                    return;
                }
            }

            if (freeDiscDownloader == null)
            {
                Debug.WriteLine("DownloadItem: freeDiscDownloader == null");
                return;
            }

            if (freeDiscDownloader.Url.Length < 6)
            {
                Debug.WriteLine("DownloadItem: freeDiscDownloader.Url.Length < 6");
                return;
            }

            await Task.Yield();

            await Task.Run(async() =>
            {
                Debug.WriteLine("DownloadItem: Downloading file: " + freeDiscDownloader.Url);
                freeDiscDownloader.ItemStatus             = DownloadStatus.DownloadInProgress;
                var downloadManager                       = CrossDownloadManager.Current;
                downloadManager.PathNameForDownloadedFile = new System.Func <IDownloadFile, string>(file => { return(freeDiscDownloader.FilePath); });

                CurrentDownloadFile = downloadManager.CreateDownloadFile(freeDiscDownloader.Url);

                CurrentDownloadFile.Headers.Add("Host", @"stream.freedisc.pl");
                CurrentDownloadFile.Headers.Add("Accept", @"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
                CurrentDownloadFile.Headers.Add("Accept-Language", @"pl,en-US;q=0.7,en;q=0.3");
                CurrentDownloadFile.Headers.Add("Accept-Encoding", @"");
                CurrentDownloadFile.Headers.Add("Connection", @"keep-alive");
                CurrentDownloadFile.Headers.Add("Pragma", @"no-cache");
                CurrentDownloadFile.Headers.Add("DNT", @"1");
                CurrentDownloadFile.Headers.Add("Cache-Control", @"no-cache");
                CurrentDownloadFile.Headers.Add("Referer", @"http://reseton.pl/static/player/v612/jwplayer.flash.swf");
                CurrentDownloadFile.Headers.Add("User-Agent", @"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0");

                downloadManager.Start(CurrentDownloadFile, true);
                var isDownloading = true;
                while (isDownloading)
                {
                    isDownloading = IsDownloadInProgress();
                    if (isDownloading)
                    {
                        if (CurrentDownloadFile.TotalBytesExpected > 0)
                        {
                            freeDiscDownloader.DownloadProgres = CurrentDownloadFile.TotalBytesWritten / CurrentDownloadFile.TotalBytesExpected;
                        }
                    }
                    await Task.Delay(500);
                }
            });

            switch (CurrentDownloadFile.Status)
            {
            case DownloadFileStatus.COMPLETED:
                freeDiscDownloader.ItemStatus = DownloadStatus.DownloadFinish;
                break;

            case DownloadFileStatus.CANCELED:
                freeDiscDownloader.ItemStatus = DownloadStatus.WaitingForDownload;
                break;

            default:
                freeDiscDownloader.ItemStatus = DownloadStatus.DownloadInterrupted;
                break;
            }
        }
コード例 #30
0
ファイル: IProvide.cs プロジェクト: gordonkratz/.NetSamples
 public BasicProvider(IDownloadFile <T> fileDownloader, IParse <T> parser)
 {
     _parser                      = parser;
     _fileDownloader              = fileDownloader;
     _fileDownloader.OnFileReady += OnFileReady;
 }
コード例 #31
0
        public TrancingAsuntoTurnoViewModel(AsuntoNotificacionesViewModel asuntoNotificacionesViewModel, AsuntoModel selectedAsuntoTurno, IConfirmation confirmation, IDownloadFile download)
        {
            this._ParentAsunto = asuntoNotificacionesViewModel;
            this._SelectedAsuntoTurno = selectedAsuntoTurno;
            this._Confirmation = confirmation;
            this._Download = download;
            this.TipoUnidadNormativa = this._ParentAsunto._PantallaInicioViewModel._MainWindowViewModel.Usuario.Rol.Organigrama.TipoUnidadNormativa;
            this._TurnoRepository = new GestorDocument.DAL.Repository.TurnoRepository();
            this._ExpedienteRepository = new GestorDocument.DAL.Repository.ExpedienteRepository();
            this._DestinatarioRepository = new GestorDocument.DAL.Repository.DestinatarioRepository();
            this._DocumentosRepository = new GestorDocument.DAL.Repository.DocumentosRepository();
            this._Turnos = new ObservableCollection<TurnoModel>();
            this._SeguimientoTurnos = new ObservableCollection<TurnoModel>();
            this._SyncDocsRepository = new GestorDocument.DAL.Repository.SyncDocsRepository();
            this._SeguimientoTurnos = new ObservableCollection<TurnoModel>();
            this._SignatarioExternoRepository = new GestorDocument.DAL.Repository.SignatarioExternoRepository();
            this.SignatarioExterno = new ObservableCollection<SignatarioExternoModel>();
            this._SuccessPathServer = ConfigurationManager.AppSettings["ServerDocsFolder"].ToString();

            this.GetRol();

            this.GetUsuario();

            this.LoadInfoGrid();

            this.GetAsunto();

            this.GetTurno();

            this.GetExpediente();
        }