Ejemplo n.º 1
0
            public void createNewDirectory(WorkWindow leftWorkWindow, WorkWindow rightWorkWindow)
            {
                WorkWindow workWindow = GetPartForNewFile(leftWorkWindow, rightWorkWindow);

                if (workWindow == null)
                {
                    return;
                }
                for (int i = 1; ; i++)
                {
                    string newFileName = workWindow.activePath + "NewDirectory" + i.ToString();


                    if (Directory.Exists(newFileName))
                    {
                        continue;
                    }
                    else
                    {
                        try
                        {
                            DirectoryInfo       di       = Directory.CreateDirectory(newFileName);
                            Director            director = new Director();
                            EventManagerBuilder changeEventManagerBuilder = new ChangeEventManagerBuilder();
                            director.SetEventManagerBuilder(changeEventManagerBuilder);
                            director.ConstructEventManager("Was created directory " + newFileName);
                            EventManager eventManager = director.GetEventManager();

                            AddEventManager(eventManager.ToString());
                        }
                        catch (Exception e)
                        {
                            ErrorMessage errorMessage = new ErrorMessage(e.Message);
                            errorMessage.ShowDialog();

                            Director            director = new Director();
                            EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                            director.SetEventManagerBuilder(errorEventManagerBuilder);
                            director.ConstructEventManager(e.Message);
                            EventManager eventManager = director.GetEventManager();
                            AddEventManager(eventManager.ToString());
                        }

                        break;
                    }
                }

                OpenDirectory(leftWorkWindow);
                OpenDirectory(rightWorkWindow);
            }
Ejemplo n.º 2
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.º 3
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;
            }