예제 #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);
         }
     }
 }
예제 #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;
                    }
                }
            }
        }
예제 #3
0
        //*************************************************

        private void Envoyer_Click(object sender, EventArgs e)
        {
            DateTime           time   = DateTime.Now;
            string             format = "yyyy-MM-dd HH:mm:ss";
            LastUserConnection usr    = new LastUserConnection();

            if (radioButton2.Checked == true)
            {
                List <Utilisateur> onlyMe = new List <Utilisateur>();
                onlyMe.Add(Utilisateur.getUser(new LastUserConnection().getNomUtil()));
                ConfidentialiteFichier conf = new ConfidentialiteFichier(onlyMe, new List <Groupe>());;
                RecivedFiles           f    = new RecivedFiles(nomDuFichier, cibleFichier, textBox2.Text, usr.getNomUtil(), time.ToString(format), conf);
                BiBFilesXML            bib  = new BiBFilesXML();
                bib.ajouter(f);
            }
            else if (radioButton1.Checked == true)
            {
                Groupe        p  = new Groupe("Public", Utilisateur.getAllUsers());
                List <Groupe> lg = new List <Groupe>();
                lg.Add(p);
                ConfidentialiteFichier conf = new ConfidentialiteFichier(new List <Utilisateur>(), lg);
                RecivedFiles           f    = new RecivedFiles(nomDuFichier, cibleFichier, textBox2.Text, usr.getNomUtil(), time.ToString(format), conf);
                BiBFilesXML            bib  = new BiBFilesXML();
                bib.ajouter(f);
                bib.setEtatToUpload(f);
            }
            else if (radioButton3.Checked == true)
            {
                List <Utilisateur> lu = new List <Utilisateur>();
                lu.Add(Utilisateur.getUser(new LastUserConnection().getNomUtil()));
                List <Groupe> lg = new List <Groupe>();
                if (checkBox1.Checked == false && checkedListBox1.CheckedItems.Count >= 1)
                {
                    foreach (var elem in checkedListBox1.CheckedItems)
                    {
                        if (elem is Utilisateur)
                        {
                            lu.Add((Utilisateur)elem);
                        }
                    }
                    foreach (var elem in checkedListBox2.CheckedItems)
                    {
                        if (elem is Groupe)
                        {
                            lg.Add((Groupe)elem);
                        }
                    }
                    ConfidentialiteFichier conf = new ConfidentialiteFichier(lu, lg);
                    RecivedFiles           f    = new RecivedFiles(nomDuFichier, cibleFichier, textBox2.Text, usr.getNomUtil(), time.ToString(format), conf);
                    BiBFilesXML            bib  = new BiBFilesXML();
                    bib.ajouter(f);
                    bib.setEtatToUpload(f);
                }
                else if (checkBox1.Checked == true && TGroupe.Text != "")
                {
                    List <Utilisateur> membres = new List <Utilisateur>();
                    foreach (var u in checkedListBox1.CheckedItems)
                    {
                        if (u is Utilisateur)
                        {
                            membres.Add((Utilisateur)u);
                        }
                    }
                    foreach (var u in checkedListBox2.CheckedItems)
                    {
                        if (u is Groupe)
                        {
                            membres.Concat((((Groupe)u).getMemberOfGroup()));
                        }
                    }
                    Groupe g = new Groupe(TGroupe.Text, membres);
                    lg.Add(g);
                    g.addToXML();
                    ConfidentialiteFichier conf = new ConfidentialiteFichier(lu, lg);
                    RecivedFiles           f    = new RecivedFiles(nomDuFichier, cibleFichier, textBox2.Text, usr.getNomUtil(), time.ToString(format), conf);
                    BiBFilesXML            bib  = new BiBFilesXML();
                    bib.ajouter(f);
                    bib.setEtatToUpload(f);
                }
            }
        }