示例#1
0
        public async Task <IActionResult> Download()
        {
            FakeConsole.Init();
            const string basePath = "Leagues";

            using (var dropboxClient = new DropboxClient(_configuration["Dropbox:AccessToken"]))
            {
                if (!Directory.Exists(basePath))
                {
                    CreateDirectory(basePath);
                }

                var list = await dropboxClient.Files.ListFolderAsync(string.Empty);

                foreach (var item in list.Entries.Where(i => i.IsFile))
                {
                    await CreateFile(dropboxClient, item, basePath);
                }

                foreach (var folder in list.Entries.Where(i => i.IsFolder))
                {
                    if (!Directory.Exists($"{basePath}{folder.PathDisplay}"))
                    {
                        CreateDirectory($"{basePath}{folder.PathDisplay}");
                    }

                    var folderFiles = await dropboxClient.Files.ListFolderAsync(folder.PathDisplay);

                    foreach (var subFolder in folderFiles.Entries.Where(i => i.IsFolder))
                    {
                        if (!Directory.Exists($"{basePath}{subFolder.PathDisplay}"))
                        {
                            CreateDirectory($"{basePath}{subFolder.PathDisplay}");
                        }

                        var subFolderFiles = await dropboxClient.Files.ListFolderAsync(subFolder.PathDisplay);

                        foreach (var item in subFolderFiles.Entries.Where(i => i.IsFile))
                        {
                            if (!System.IO.File.Exists($"{basePath}{item.PathDisplay}"))
                            {
                                await CreateFile(dropboxClient, item, basePath);
                            }
                        }
                    }
                }
            }

            ViewData["Status"] = "All files synced from Dropbox";
            ViewData["Log"]    = FakeConsole.Print();
            return(View("Index"));
        }
示例#2
0
        public void RunCalculation(bool upload)
        {
            FakeConsole.Init();
            var sourceDirectory = "Leagues";

            foreach (var league in Directory.GetDirectories(sourceDirectory))
            {
                FakeConsole.WriteLine($"Processing league {Path.GetFileName(league)}");
                var results = Calculate(sourceDirectory, league);

                if (upload)
                {
                    UploadResults(_configuration["Tournament:Upload"], results, Path.GetFileName(league));
                }
            }

            ViewData["Status"] = "Results updated";
            ViewData["Log"]    = FakeConsole.Print();
        }