private void OnFilePaste(object sender, EventArgs e)
 {
     try
     {
         if (Clipboard.ContainsData(DataFormats.FileDrop))
         {
             var paths = new StringCollection();
             paths                       = Clipboard.GetFileDropList();
             modelCopy                   = new ModelProcessCopy();
             modelCopy.Source            = paths.Cast <string>().ToList();
             modelCopy.DestPath          = CurrentPath;
             modelCopy.SourceCurrentPath = Directory.GetParent(modelCopy.Source[0]).FullName;
             var cmd = new CommandCopyFiles(modelCopy.Source.Count > 0 && !String.IsNullOrEmpty(modelCopy.DestPath),
                                            strings.noSelectedFiles, true, modelCopy, isMove);
             var presenterProgress = new PresenterProgress();
             if (modelCopy != null)
             {
                 presenterProgress.AddModel(modelCopy);
             }
             presenterProgress.AddCommand(cmd);
             presenterProgress.Show();
             CommandManager.Execute(cmd);
         }
         if (isMove)
         {
             Clipboard.Clear();
         }
     }
     catch (Exception ex)
     {
         MyLog.logger.Error(ex.StackTrace);
         view.MessageShow(ex.Message, strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #2
0
 /// <summary>
 /// копирование файлов
 /// </summary>
 /// <param name="cond"></param>
 /// <param name="res"></param>
 /// <param name="showMsg"></param>
 /// <param name="mod"></param>
 /// <param name="isMove">delete after copy</param>
 public CommandCopyFiles(bool cond, string res, bool showMsg, ModelProcessCopy mod, bool isMove)
 {
     showMessages        = showMsg;
     Condition           = cond;
     errorMessage        = res;
     _isMove             = isMove;
     model               = mod;
     model.TotalProgress = 0;
     source              = new Dictionary <string, string>();
     if (!String.Equals(model.SourceCurrentPath, model.DestPath, StringComparison.CurrentCultureIgnoreCase))
     {
         var fileList = GetAllFiles(model.Source);
         if (fileList != null)
         {
             foreach (string file in fileList)
             {
                 source.Add(file, Path.Combine(model.DestPath, file.Remove(0, model.SourceCurrentPath.Length + 1)));
             }
         }
     }
     else
     {
         ViewMainForm.GetInstance.MessageShow(strings.copyOnItself, strings.Info, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
예제 #3
0
 private ModelProcessCopy CreateModel(ModelProcessCopy m, List <string> files)
 {
     m.Source            = files;;
     m.SourceCurrentPath = "D:\\Temp";
     m.DestPath          = "D:\\Temp\\folder";
     return(m);
 }
예제 #4
0
        public void TestCopyValidFile()
        {
            files.Clear();
            fileName = "D:\\Temp\\copyValid.txt";
            files.Add(fileName);
            ModelProcessCopy model = new ModelProcessCopy();

            model = CreateModel(model, files);
            CreateModel(model, files);
            string newFile = model.DestPath + "\\copyValid.txt";

            if (!File.Exists(fileName))
            {
                File.Create(fileName).Close();
            }
            CommandCopyFiles cmdCopy = new CommandCopyFiles(true, string.Empty, false, model, false);

            try
            {
                CommandManager.Execute(cmdCopy);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                Assert.True(!cmdCopy.HasError && File.Exists(newFile));
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
            }
        }
예제 #5
0
 public void CreateProgressForm(ModelProcessCopy model, CommandCopyFiles cmd)
 {
     _presenterProgress = new PresenterProgress();
     if (model != null)
     {
         _presenterProgress.AddModel(model);
     }
     _presenterProgress.AddCommand(cmd);
     _presenterProgress.Show();
 }
예제 #6
0
        private void OnMovePerformed(object sender, EventArgs e)
        {
            var model = new ModelProcessCopy();

            model = CreateNewModel(model);
            bool condition = model.Source.Count > 0;
            var  cmd       = new CommandCopyFiles(condition, strings.noSelectedFiles, true, model, true);

            if (condition)
            {
                CreateProgressForm(model, cmd);
            }
            CommandManager.Execute(cmd);
        }
예제 #7
0
 //заполнение модели
 private ModelProcessCopy CreateNewModel(ModelProcessCopy m)
 {
     if (PresenterSource.IsSelected)
     {
         m.Source            = PresenterSource.GetSelectedItems;
         m.SourceCurrentPath = PresenterSource.CurrentPath;
         m.DestPath          = PresenterDest.CurrentPath;
     }
     else if (PresenterDest.IsSelected)
     {
         m.Source            = PresenterDest.GetSelectedItems;
         m.SourceCurrentPath = PresenterDest.CurrentPath;
         m.DestPath          = PresenterSource.CurrentPath;
     }
     return(m);
 }
        private void OnDragDropped(object sender, EventArgs e)
        {
            var           items         = view.GetSelectedItems();
            List <string> selectedItems = new List <string>();
            ListViewItem  itemDest      = view.GetItemDest;

            foreach (ListViewItem item in items)
            {
                if (String.Equals(item.Text, prev, StringComparison.CurrentCultureIgnoreCase))
                {
                    selectedItems.Add(fromPath);
                }
                else if (fromPath.Length <= 3)
                {
                    selectedItems.Add(Path.Combine(fromPath, item.Text + item.SubItems[1].Text));
                }
                else
                {
                    selectedItems.Add(Path.Combine(fromPath, item.Text + item.SubItems[1].Text));
                }
            }
            modelCopy        = new ModelProcessCopy();
            modelCopy.Source = selectedItems;
            if (itemDest != null && !File.Exists(Path.Combine(CurrentPath, itemDest.Text + itemDest.SubItems[1].Text)))
            {
                modelCopy.DestPath = Path.Combine(CurrentPath, itemDest.Text);
            }
            else
            {
                modelCopy.DestPath = CurrentPath;
            }
            modelCopy.SourceCurrentPath = Directory.GetParent(modelCopy.Source[0]).FullName;
            var cmd = new CommandCopyFiles(modelCopy.Source.Count > 0 && !String.IsNullOrEmpty(modelCopy.DestPath),
                                           strings.noSelectedFiles, false, modelCopy, false);
            var presenterProgress = new PresenterProgress();

            if (modelCopy != null)
            {
                presenterProgress.AddModel(modelCopy);
            }
            presenterProgress.AddCommand(cmd);
            presenterProgress.Show();

            CommandManager.Execute(cmd);
        }
예제 #9
0
        public void TestReplaceInvalidFile()
        {
            files.Clear();
            fileName = "D:\\Temp\\invalidFile.txt";
            files.Add(fileName);
            ModelProcessCopy model = new ModelProcessCopy();

            model = CreateModel(model, files);
            CreateModel(model, files);
            try
            {
                CommandCopyFiles cmdCopy = new CommandCopyFiles(true, string.Empty, false, model, false);
                CommandManager.Execute(cmdCopy);
                Assert.True(!cmdCopy.HasError);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message + " " + ex.StackTrace);
            }
        }
예제 #10
0
        public void TestCopyInValidFile()
        {
            string        fileName = "D:\\Test\\testInValid.txt";
            List <string> files    = new List <string>();

            files.Add(fileName);
            ModelProcessCopy model = new ModelProcessCopy();

            model = CreateModel(model, files);
            try
            {
                CommandCopyFiles cmdCopy = new CommandCopyFiles(true, string.Empty, false, model, false);
                CommandManager.Execute(cmdCopy);
                Assert.True(!cmdCopy.HasError);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message + " " + ex.StackTrace);
            }
        }