Ejemplo n.º 1
0
 private void listedefichiers_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (listedefichiers.SelectedItem != null)
     {
         RecivedFiles item = (RecivedFiles)listedefichiers.SelectedItem;
         BiBFilesXML  bib  = new BiBFilesXML();
         if (!bib.getFilesToDownload().Contains(item))
         {
             if (System.IO.File.Exists(item.getPathOfSave()))
             {
                 System.Diagnostics.Process proc = new System.Diagnostics.Process();
                 proc.StartInfo.FileName        = item.getPathOfSave();
                 proc.StartInfo.UseShellExecute = true;
                 proc.Start();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("this file is deleted or changed path", "Alert", MessageBoxButton.OK, MessageBoxImage.Information);
                 bib.deleteFile(item);
             }
         }
         else
         {
             MessageBox.Show("this file is not downloaded", "Alert", MessageBoxButton.OK, MessageBoxImage.Information);
         }
     }
 }
Ejemplo n.º 2
0
        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;
                    }
                }
            }
        }