Example #1
0
        //public static void QueueDownloadFile(string[] filePartLinks, string file = null)
        public static void QueueDownloadFile(MongoCollectionManager<QueueDownloadFile> mongoQueueDownloadFileManager, string[] filePartLinks, string directory = null, string filename = null)
        {
            //ServerKey key = null;

            //key = new ServerKey { };

            //Uri uri = new Uri(url);
            //string file = uri.Segments[uri.Segments.Length - 1];
            //IRequestDownloadLinks downloadLinks = null;
            //DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks);

            //string[] downloadLinks2 = null;
            //PostDownloadLinks postDownloadLinks = PostDownloadLinks.Create(downloadLinks2);
            //DownloadItemLink[] downloadItemLinks2 = DownloadItemLink.CreateDownloadItemLinkArray(postDownloadLinks);

            DownloadItemLink itemLink = DownloadItemLink.CreateDownloadItemLink(filePartLinks);

            // Key (ServerKey) of QueueDownloadFile is null, no save to _mongoDownloadedFileManager in DownloadManager
            QueueDownloadFile downloadFile = new QueueDownloadFile
            {
                DownloadItemLinks = new DownloadItemLink[] { itemLink },
                RequestTime = DateTime.Now,
                Directory = directory,
                Filename = filename
                //Directory = file != null ? zPath.GetDirectoryName(file) : null,
                //Filename = file != null ? zPath.GetFileName(file) : null
            };
            downloadFile.Id = mongoQueueDownloadFileManager.GetNewId();
            mongoQueueDownloadFileManager.Save(downloadFile.Id, downloadFile);
        }
Example #2
0
        //public static void QueueDownloadFile(string[] filePartLinks, string file = null)
        public static void QueueDownloadFile(MongoCollectionManager <QueueDownloadFile> mongoQueueDownloadFileManager, string[] filePartLinks, string directory = null, string filename = null)
        {
            //ServerKey key = null;

            //key = new ServerKey { };

            //Uri uri = new Uri(url);
            //string file = uri.Segments[uri.Segments.Length - 1];
            //IRequestDownloadLinks downloadLinks = null;
            //DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks);

            //string[] downloadLinks2 = null;
            //PostDownloadLinks postDownloadLinks = PostDownloadLinks.Create(downloadLinks2);
            //DownloadItemLink[] downloadItemLinks2 = DownloadItemLink.CreateDownloadItemLinkArray(postDownloadLinks);

            DownloadItemLink itemLink = DownloadItemLink.CreateDownloadItemLink(filePartLinks);

            // Key (ServerKey) of QueueDownloadFile is null, no save to _mongoDownloadedFileManager in DownloadManager
            QueueDownloadFile downloadFile = new QueueDownloadFile
            {
                DownloadItemLinks = new DownloadItemLink[] { itemLink },
                RequestTime       = DateTime.Now,
                Directory         = directory,
                Filename          = filename
                                    //Directory = file != null ? zPath.GetDirectoryName(file) : null,
                                    //Filename = file != null ? zPath.GetFileName(file) : null
            };

            downloadFile.Id = mongoQueueDownloadFileManager.GetNewId();
            mongoQueueDownloadFileManager.Save(downloadFile.Id, downloadFile);
        }
Example #3
0
        public void AddFileToDownload(ServerKey key, IRequestDownloadLinks downloadLinks, string file = null)
        {
            DownloadItemLink[] downloadItemLinks = DownloadItemLink.CreateDownloadItemLinkArray(downloadLinks);

            QueueDownloadFile downloadFile = new QueueDownloadFile
            {
                Key = key,
                DownloadItemLinks                       = downloadItemLinks,
                RequestTime                             = DateTime.Now,
                Directory                               = file != null?zPath.GetDirectoryName(file) : null,
                                               Filename = file != null?zPath.GetFileName(file) : null
            };

            downloadFile.Id       = _mongoQueueDownloadFileManager.GetNewId();
            downloadFile.Modified = true;
            SaveQueueDownloadFile(downloadFile);
        }
Example #4
0
        private void EndDownload(QueueDownloadFile queueDownloadFile)
        {
            try
            {
                if (_trace)
                {
                    pb.Trace.WriteLine("DownloadManager.EndDownload() 01                              : directory \"{0}\" filename \"{1}\"", queueDownloadFile.Directory, queueDownloadFile.Filename);
                }

                DownloadedFile downloadedFile = new DownloadedFile();
                downloadedFile.Key  = queueDownloadFile.Key;
                downloadedFile.File = zPath.Combine(queueDownloadFile.Directory, queueDownloadFile.Filename);
                if (queueDownloadFile.UncompleteDownload)
                {
                    downloadedFile.State = DownloadState.DownloadFailed;
                }
                else
                {
                    downloadedFile.State = DownloadState.DownloadCompleted;
                }
                downloadedFile.DownloadItemLinks = queueDownloadFile.DownloadItemLinks;
                downloadedFile.DownloadedFiles   = queueDownloadFile.DownloadItemLinks.GetDownloadFilePartLinks().Select(filePartLink => filePartLink.DownloadedFile).ToArray();
                downloadedFile.RequestTime       = queueDownloadFile.RequestTime;
                downloadedFile.StartDownloadTime = queueDownloadFile.StartDownloadTime;
                downloadedFile.EndDownloadTime   = queueDownloadFile.EndDownloadTime;
                downloadedFile.DownloadDuration  = queueDownloadFile.DownloadDuration;

                if (downloadedFile.Key != null)
                {
                    _mongoDownloadedFileManager.RemoveFromKey(downloadedFile.Key);
                    downloadedFile.Id = _mongoDownloadedFileManager.GetNewId();
                    _mongoDownloadedFileManager.Save(downloadedFile.Id, downloadedFile);
                }
                _mongoQueueDownloadFileManager.Remove(queueDownloadFile.Id);

                // _uncompressFile
                if (_uncompressManager != null && ContainsCompressFiles(queueDownloadFile))
                {
                    TaskManager.AddTask(new zTask
                    {
                        name = "Uncompress download file",
                        task = () =>
                        {
                            string[] uncompressFiles = UncompressFiles(queueDownloadFile.DownloadItemLinks.GetDownloadFilePartLinks().Select(filePartLink => filePartLink.DownloadedPath).ToArray());
                            if (queueDownloadFile.Directory != null)
                            {
                                uncompressFiles = SetDirectoryFiles(uncompressFiles, queueDownloadFile.Directory);
                            }
                            downloadedFile.UncompressFiles = uncompressFiles;
                            if (downloadedFile.Id != null)
                            {
                                _mongoDownloadedFileManager.Save(downloadedFile.Id, downloadedFile);
                            }
                        }
                    });
                    if (_onDownloaded != null)
                    {
                        TaskManager.AddTask(new zTask {
                            name = "onDownloaded", task = () => _onDownloaded(downloadedFile)
                        });
                    }
                }
                else if (_onDownloaded != null)
                {
                    _onDownloaded(downloadedFile);
                }

                QueueDownloadFile downloadFile2;
                if (!_queueDownloadFiles.TryRemove(queueDownloadFile.Id, out downloadFile2))
                {
                    pb.Trace.WriteLine("error unable to remove downloadFile with id {0} from ConcurrentDictionary _downloadFiles (DownloadManager<TKey>.ManageEndDownloadFiles())", queueDownloadFile.Id);
                }
                _mongoQueueDownloadFileManager.Remove(queueDownloadFile.Id);
            }
            catch (Exception exception)
            {
                pb.Trace.WriteLine("error in DownloadManager.EndDownload() : {0}", exception.Message);
                pb.Trace.WriteLine(exception.StackTrace);
            }
        }