Ejemplo n.º 1
0
            public void MoveSelectedFile(WorkWindow leftWorkWindow, WorkWindow rightWorkWindow)
            {
                FileSystemInfo selectedFile = GetSelectedFile(leftWorkWindow, rightWorkWindow);

                if (selectedFile != null)
                {
                    Console.WriteLine("Was found file : " + selectedFile.Name);
                    // input new name for file or directory

                    InputDataMessage inputDataMessage = new InputDataMessage("Input new path for " + selectedFile.Name);
                    inputDataMessage.ShowDialog();
                    string inputData = inputDataMessage.answer;

                    if (inputData == selectedFile.Name || inputData == "" || inputData == null)
                    {
                        return;
                    }


                    if (inputData.StartsWith(selectedFile.FullName))
                    {
                        Director            director = new Director();
                        EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                        director.SetEventManagerBuilder(errorEventManagerBuilder);
                        director.ConstructEventManager(selectedFile.FullName + " doesn't move to " + inputData + ". The final folder is the source or child folder for it");
                        EventManager eventManager = director.GetEventManager();
                        AddEventManager(eventManager.ToString());

                        ErrorMessage errorMessage = new ErrorMessage("The final folder is the source or child folder for it");
                        errorMessage.ShowDialog();
                        return;
                    }
                    try
                    {
                        if (Directory.Exists(selectedFile.FullName))
                        {
                            Directory.Move(selectedFile.FullName, inputData + "\\" + selectedFile.Name);
                        }
                        else
                        if (File.Exists(selectedFile.FullName))
                        {
                            File.Move(selectedFile.FullName, inputData + "\\" + selectedFile.Name);
                        }

                        Director            director = new Director();
                        EventManagerBuilder changeEventManagerBuilder = new ChangeEventManagerBuilder();
                        director.SetEventManagerBuilder(changeEventManagerBuilder);
                        director.ConstructEventManager("Was moved " + selectedFile.FullName + " to " + inputData + "\\" + selectedFile.Name);
                        EventManager eventManager = director.GetEventManager();
                        AddEventManager(eventManager.ToString());
                    }
                    catch (Exception e)
                    {
                        Director            director = new Director();
                        EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                        director.SetEventManagerBuilder(errorEventManagerBuilder);
                        director.ConstructEventManager(e.Message);
                        EventManager eventManager = director.GetEventManager();
                        AddEventManager(eventManager.ToString());
                        ErrorMessage errorMessage = new ErrorMessage(e.Message);
                        errorMessage.ShowDialog();
                    }

                    OpenDirectory(leftWorkWindow);
                    OpenDirectory(rightWorkWindow);
                }
                else
                {
                    ErrorMessage errorMessage = new ErrorMessage("No files selected");
                    errorMessage.ShowDialog();
                    Console.WriteLine("Was not selected files");
                }
                return;
            }
Ejemplo n.º 2
0
            public void RenameSelectedFile(WorkWindow leftWorkWindow, WorkWindow rightWorkWindow)
            {
                FileSystemInfo selectedFile = GetSelectedFile(leftWorkWindow, rightWorkWindow);

                if (selectedFile != null)
                {
                    Console.WriteLine("Was found file : " + selectedFile.Name);
                    // input new name for file or directory

                    InputDataMessage inputDataMessage = new InputDataMessage("Input new name for file " + selectedFile.Name);
                    inputDataMessage.ShowDialog();
                    string inputData = inputDataMessage.answer;


                    if (inputData == selectedFile.Name || inputData == "" || inputData == null)
                    {
                        return;
                    }


                    try
                    {
                        if (Directory.Exists(selectedFile.FullName))
                        {
                            ((DirectoryInfo)(selectedFile)).MoveTo(Directory.GetParent(selectedFile.FullName) + "\\" + inputData);
                        }
                        else
                        if (File.Exists(selectedFile.FullName))
                        {
                            ((FileInfo)(selectedFile)).MoveTo(Directory.GetParent(selectedFile.FullName) + "\\" + inputData);
                        }

                        Director            director = new Director();
                        EventManagerBuilder changeEventManagerBuilder = new ChangeEventManagerBuilder();
                        director.SetEventManagerBuilder(changeEventManagerBuilder);
                        director.ConstructEventManager("Was rename " + selectedFile.FullName + " to " + Directory.GetParent(selectedFile.FullName) + "\\" + inputData);
                        EventManager eventManager = director.GetEventManager();
                        AddEventManager(eventManager.ToString());
                    }
                    catch (Exception e)
                    {
                        Director            director = new Director();
                        EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                        director.SetEventManagerBuilder(errorEventManagerBuilder);
                        director.ConstructEventManager(e.Message);
                        EventManager eventManager = director.GetEventManager();
                        AddEventManager(eventManager.ToString());

                        ErrorMessage errorMessage = new ErrorMessage(e.Message);
                        errorMessage.ShowDialog();
                    }

                    OpenDirectory(leftWorkWindow);
                    OpenDirectory(rightWorkWindow);
                }
                else
                {
                    ErrorMessage errorMessage = new ErrorMessage("No files selected");
                    errorMessage.ShowDialog();
                    Console.WriteLine("Was not selected files");
                }
                return;
            }