private void btnCopyTo_Click(object sender, EventArgs e) { if (folderBrowserDialog1.ShowDialog() != DialogResult.OK) { return; } var filesToDownload = GetSelectedFiles(); var disc = DiscoverRepository.GetInstance(); var rep = DiscoverRepository.CurrentRepository; FormProgress.Run(() => { var download = disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Files, filesToDownload); disc.CopyCacheTo(download, folderBrowserDialog1.SelectedPath); }, (ex) => { if (ex == null) { MessageBox.Show("Arquivos copiados com sucesso", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information); Process.Start(folderBrowserDialog1.SelectedPath); } else { MessageBox.Show("Ocorreu a sequinte excessão:\r\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); dgFiles.ClearSelection(); }
private void btnDownload_Click(object sender, EventArgs e) { if (dgFiles.SelectedRows.Count == 0) { MessageBox.Show("Selecione ao menos um arquivo para fazer download!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var filesToDownload = GetSelectedFiles(); var disc = DiscoverRepository.GetInstance(); var rep = DiscoverRepository.CurrentRepository; FormProgress.Run(() => { disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Files, filesToDownload); }, (ex) => { if (ex == null) { MessageBox.Show("Arquivos baixados com sucesso", "Download", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Ocorreu a sequinte excessão:\r\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); dgFiles.ClearSelection(); }
private void dgMiscellaneous_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0) { return; } var disc = DiscoverRepository.GetInstance(); var rep = DiscoverRepository.CurrentRepository; var item = DiscoverRepository.CurrentRepository.Miscellaneous.ToArray()[e.RowIndex]; if (e.ColumnIndex == 0) { string path = ""; FormProgress.Run(() => { path = disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Miscellaneous, new IFTPFile[] { item })?.FirstOrDefault()?.LocalPath; }, (ex) => { if (ex == null) { Process.Start(path); } else { MessageBox.Show("Ocorreu a seguinte falha:\r\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); } }
private void FormViewTable_Load(object sender, EventArgs e) { tabControl1.TabPages.Remove(tabPage1); FormProgress.Run(LoadTables, (ex) => { if (ex != null) { MessageBox.Show("Não possível carregar os dados da tabela!\r\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); }
private void DiscoverRepositories() { tabExplorer.Text = "Explorar"; DiscoverRepository.CurrentRepository = null; //webBrowser.Navigate("about:blank"); FormProgress.Run(() => { DiscoverRepository dr = DiscoverRepository.GetInstance(tbxFTPURL.Text); var repositories = dr.Load(!chkUseCache.Checked); var rep = repositories.FirstOrDefault(); XElement xml = XElement.Parse(rep.ToXML()); this.ThreadSafeExec(() => { dgFTP.DataSource = repositories.Select(r => new { Name = r.Name, FilesCount = r.Files?.Count(), FTPLink = r.URL }).ToArray(); chkUseCache.Checked = true; }); }); }
private void btnQuery_Click(object sender, EventArgs e) { var files = GetSelectedFiles("dbc"); if (files == null || !files.Any()) { MessageBox.Show("Selecione ao menos um arquivo compatível (.dbc)", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IEnumerable <FileInfo> dbfs = null; FormProgress.Run(() => { DiscoverRepository.GetInstance().ExportFiles2DBF(files, f => dbfs = f); }, ShowError); if (dbfs?.Any() == true) { var wk = dbfs.First().Directory.FullName; FormViewTable.ShowTables(wk, dbfs.Select(f => f.Name).ToArray()); } }
/* * private void ExportDBF(Action<IEnumerable<FileInfo>> callBack) * { * var filesToDownload = GetSelectedFiles(); * var disc = DiscoverRepository.GetInstance(); * var rep = DiscoverRepository.CurrentRepository; * var convert = new DBConvert(folderBrowserDialog1.SelectedPath); * var download = disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Files, filesToDownload); * var localFiles = disc.CopyCacheTo(download, folderBrowserDialog1.SelectedPath); * convert.ConvertDBC2DBF(localFiles.ToArray()); * foreach (var lf in localFiles) * lf.Delete(); * callBack?.Invoke( localFiles.Select(f => new FileInfo(f.FullName.ToLower().TrimEnd('c') + "f"))?.ToArray()); * //return convert; * } * * private void ExportLocalDBF(Action<IEnumerable<FileInfo>> callBack) * { * var filesToDownload = GetSelectedFiles(); * var disc = DiscoverRepository.GetInstance(); * var rep = DiscoverRepository.CurrentRepository; * var wk = Path.Combine(@"c:\temp\sus", rep.Name); * if (!Directory.Exists(wk)) * Directory.CreateDirectory(wk); * var convert = new DBConvert(wk); * var download = disc.DownloadCache(rep.Name, DiscoveredRepositoryCache.Files, filesToDownload); * var localFiles = disc.CopyCacheTo(download, wk); * convert.ConvertDBC2DBF(localFiles.ToArray()); * foreach (var lf in localFiles) * lf.Delete(); * callBack?.Invoke(localFiles.Select(f => new FileInfo(f.FullName.ToLower().TrimEnd('c') + "f"))?.ToArray()); * //return convert; * }*/ private void btnExport_Click(object sender, EventArgs e) { folderBrowserDialog1.SelectedPath = @"C:\"; var selected = GetSelectedFiles("dbc"); if ((selected?.Count() ?? 0) == 0) { MessageBox.Show("Selecione ao menos um arquivo compatível (.dbc)!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var files = GetSelectedFiles().Where(f => f.Name.ToLower().EndsWith("dbc")); if (files?.Count() != selected?.Count()) { MessageBox.Show("Apenas arquivos no formato DBC podem ser exportados para outros formatos\r\nOutras extensões serão ignoradas no processo", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string type = ""; FormExport.OpenDialog((format) => { type = format; }); if (string.IsNullOrEmpty(type)) { return; } if (folderBrowserDialog1.ShowDialog() != DialogResult.OK) { return; } var workingFolder = DBConvert.GetWorkingDirectory(); var filesToDownload = GetSelectedFiles(); var disc = DiscoverRepository.GetInstance(); var rep = DiscoverRepository.CurrentRepository; type = Regex.Match(type, @"\w+", RegexOptions.IgnoreCase).Value.ToUpper(); IEnumerable <FileInfo> dbfs = null; Action callbackExport = () => { disc.ExportFiles2DBF(filesToDownload, (d) => dbfs = d, workingFolder); }; var tableManager = new DBFReader(workingFolder, DBVersion.Default); bool tdbf = false; switch (type) { case "DBF": tdbf = true; callbackExport += () => { tdbf = true; }; break; case "XML": callbackExport += () => { if (dbfs?.Any() != true) { return; } foreach (var dbf in dbfs) { tableManager.ToXML(dbf.Name); } }; break; case "CSV": callbackExport += () => { if (dbfs?.Any() != true) { return; } foreach (var dbf in dbfs) { tableManager.ToCSV(dbf.Name); } }; break; case "JSON": callbackExport += () => { if (dbfs?.Any() != true) { return; } foreach (var dbf in dbfs) { tableManager.ToJSON(dbf.Name); } }; break; } if (!tdbf) { callbackExport += () => { if (dbfs?.Any() != true) { return; } foreach (var dbf in dbfs) { dbf.Delete(); } }; } else { callbackExport += () => { if (dbfs?.Any() != true) { return; } foreach (var dbf in dbfs) { dbf.MoveTo(Path.Combine(folderBrowserDialog1.SelectedPath, dbf.Name)); } }; } callbackExport += () => { tableManager.Dispose(); //MessageBox.Show("Arquivos exportados com sucesso", "Conversão", MessageBoxButtons.OK, MessageBoxIcon.Information); Process.Start("explorer", folderBrowserDialog1.SelectedPath); }; FormProgress.Run(callbackExport, (ex) => { if (ex != null) { MessageBox.Show("Ocorreu a sequinte excessão:\r\n" + ex, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }); }