Ejemplo n.º 1
0
        public void DownloadRebrickableCsvFiles(RbDatabaseFile databaseFiles, string destinationFolder)
        {
            if (DatabaseFileLinks.Count == 0)
            {
                FetchRebrickableDownloadLinks();
            }


            Directory.CreateDirectory(destinationFolder);

            using (var wc = new WebClient())
            {
                foreach (var dbFileInfo in DatabaseFileLinks.Values)
                {
                    if (databaseFiles.HasFlag(dbFileInfo.FileType))
                    {
                        string destinationPath = Path.Combine(destinationFolder, dbFileInfo.FileName);
                        NotifyProgressStatus($"Downloading file {dbFileInfo.FileName}...");
                        var downloadTask = wc.DownloadFileTaskAsync(dbFileInfo.DownloadUrl, destinationPath);
                        downloadTask.Wait(CancellationToken);
                        if (CancellationToken.IsCancellationRequested)
                        {
                            break;
                        }
                        //downloadTasks.Add(downloadTask);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void DownloadRebrickableCsvFiles(RbDatabaseFile databaseFiles, string destinationFolder)
        {
            if (DatabaseFileLinks.Count == 0)
            {
                FetchRebrickableDownloadLinks();
            }

            var downloadTasks = new List <Task>();

            using (var wc = new WebClient())
            {
                foreach (var dbFileInfo in DatabaseFileLinks.Values)
                {
                    if (databaseFiles.HasFlag(dbFileInfo.FileType))
                    {
                        string destinationPath = Path.Combine(destinationFolder, dbFileInfo.FileName);
                        var    downloadTask    = wc.DownloadFileTaskAsync(dbFileInfo.DownloadUrl, destinationPath);
                        downloadTasks.Add(downloadTask);
                    }
                }

                foreach (var downloadTask in downloadTasks)
                {
                    downloadTask.Wait(CancellationToken);
                    if (CancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static string GetDatabaseFileName(RbDatabaseFile databaseFile)
        {
            if (DatabaseFileLinks.Count == 0)
            {
                FetchRebrickableDownloadLinks();
            }

            if (DatabaseFileLinks.ContainsKey(databaseFile))
            {
                return(DatabaseFileLinks[databaseFile].FileName);
            }

            return(string.Empty);
        }
Ejemplo n.º 4
0
        public static string GetDatabaseFileName(RbDatabaseFile databaseFile, string destinationFolder)
        {
            if (DatabaseFileLinks.Count == 0)
            {
                FetchRebrickableDownloadLinks();
            }

            if (DatabaseFileLinks.ContainsKey(databaseFile))
            {
                return(Path.Combine(destinationFolder, DatabaseFileLinks[databaseFile].FileName));
            }

            return(string.Empty);
        }
Ejemplo n.º 5
0
        public CsvFile GetRebrickableCsvFile(RbDatabaseFile csvFile)
        {
            string filename = GetDatabaseFileName(csvFile);

            if (string.IsNullOrEmpty(filename))
            {
                return(null);
            }


            if (!string.IsNullOrEmpty(DownloadDirectory))
            {
                string fullPath = Path.Combine(DownloadDirectory, filename);
                if (!File.Exists(fullPath))
                {
                    DownloadRebrickableCsvFiles(csvFile, DownloadDirectory);
                }

                if (File.Exists(fullPath))
                {
                    return(ReadRebrickableCsvFile(fullPath));
                }
            }
            else
            {
                var tmpFolder = FileHelper.GetTempDirectory();
                try
                {
                    string fullPath = Path.Combine(tmpFolder, filename);
                    DownloadRebrickableCsvFiles(csvFile, tmpFolder);
                    return(ReadRebrickableCsvFile(fullPath));
                }
                finally
                {
                    Task.Factory.StartNew(() => FileHelper.DeleteFileOrFolder(tmpFolder, true, true));
                }
            }

            return(null);
        }