private void UploadfilesToDropBox() { BiBFilesXML bib = new BiBFilesXML(); List <RecivedFiles> lf = bib.getFilesToUploadToDropbox(); foreach (RecivedFiles rf in lf) { string originalName = rf.getNom(); try { rf.addToDB(); try { ConnectionDropbox.DeposeFile(rf); rf.setNom(originalName); bib.setFilIsInDropbox(rf); } catch { rf.setNom(originalName); rf.supprimerFromDB(); bib.setFilIsNotInDropbox(rf); } } catch { bib.setFilIsNotInDropbox(rf); } if (bib.FilIsInServer(rf) && bib.FilIsInDropbox(rf)) { bib.setEtatSynchronized(rf); } } }
private void listedefichiers_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (listedefichiers.SelectedItem != null) { RecivedFiles item = (RecivedFiles)listedefichiers.SelectedItem; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Save an File"; string extension = System.IO.Path.GetExtension(item.getNom()); saveFileDialog.DefaultExt = extension; saveFileDialog.FileName = item.getNom(); saveFileDialog.Filter = "(*" + extension + ")|*" + extension; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string destFile = saveFileDialog.FileName; string pathOfFile = item.getPathOfSave(); BiBFilesXML bib = new BiBFilesXML(); // Save here switch (webConnectionState) { case WebConnectionState.None: System.Windows.MessageBox.Show("Please connect you"); break; case WebConnectionState.InternetAndLocal: try { if (bib.FilIsInServer(item)) { //if (File.Exists(pathOfFile)) //{ File.Copy(pathOfFile, destFile, true); item.setPathOfSave(destFile); bib.setPathOfSave(item); bib.setEtatSynchronized(item); //} //else //{ // System.Windows.MessageBox.Show("this file is deleted or renamed", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); // bib.deleteFile(item); //} } else if (bib.FilIsInDropbox(item)) { ConnectionDropbox.DownloadFile(item, destFile); item.setPathOfSave(destFile); bib.setPathOfSave(item); bib.setEtatSynchronized(item); } } catch { item.setPathOfSave(pathOfFile); bib.setEtatToDownload(item); } break; case WebConnectionState.LocalNetworkOnly: try { if (bib.FilIsInServer(item)) { //if (File.Exists(pathOfFile)) //{ File.Copy(pathOfFile, destFile, true); item.setPathOfSave(destFile); bib.setPathOfSave(item); bib.setEtatSynchronized(item); //} //else //{ // System.Windows.MessageBox.Show("this file is deleted or renamed", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); // bib.deleteFile(item); //} } else if (bib.FilIsInDropbox(item)) { System.Windows.MessageBox.Show("Connect to Internet please", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); } } catch { item.setPathOfSave(pathOfFile); bib.setEtatToDownload(item); } break; case WebConnectionState.InternetOnly: try { if (bib.FilIsInDropbox(item)) { ConnectionDropbox.DownloadFile(item, destFile); item.setPathOfSave(destFile); bib.setPathOfSave(item); bib.setEtatSynchronized(item); } else if (bib.FilIsInServer(item)) { System.Windows.MessageBox.Show("Connect to Local Network please", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); } } catch { item.setPathOfSave(pathOfFile); bib.setEtatToDownload(item); } break; } } } }