Exemple #1
0
            public void DeleteFolder(DirectoryInfo folder)
            {
                if (!IsFolderAvailable(folder))
                {
                    Director            director = new Director();
                    EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                    director.SetEventManagerBuilder(errorEventManagerBuilder);
                    director.ConstructEventManager("Directory " + folder.FullName + " is not available for deleting");
                    EventManager eventManager = director.GetEventManager();
                    AddEventManager(eventManager.ToString());

                    ErrorMessage errorMessage = new ErrorMessage("This directory is not available");
                    errorMessage.ShowDialog();
                    return;
                }
                else
                {
                    FileInfo[] childerFile = folder.GetFiles();
                    for (int i = childerFile.Length - 1; i >= 0; i--)
                    {
                        childerFile[i].Delete();
                    }

                    DirectoryInfo[] childrenDirectory = folder.GetDirectories();
                    for (int i = childrenDirectory.Length - 1; i >= 0; i--)
                    {
                        DeleteFolder(childrenDirectory[i]);
                    }


                    folder.Delete();
                }
            }
Exemple #2
0
            public string NextPath(string activePath, string nextPath)
            {
                if (nextPath == null || nextPath == "")
                {
                    return(activePath);
                }
                else
                if (nextPath == "...")
                {
                    return(PrevPath(activePath));
                }
                else
                {
                    string answerPath = activePath + nextPath + "\\";
                    if (IsFolderAvailable(new DirectoryInfo(answerPath)))
                    {
                        return(answerPath);
                    }
                    else
                    {
                        Director            director = new Director();
                        EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                        director.SetEventManagerBuilder(errorEventManagerBuilder);
                        director.ConstructEventManager("Directory " + answerPath + " is not available");
                        EventManager eventManager = director.GetEventManager();
                        AddEventManager(eventManager.ToString());

                        ErrorMessage errorMessage = new ErrorMessage("This directory is not available");
                        errorMessage.ShowDialog();
                        return(activePath);
                    }
                }
            }
Exemple #3
0
            public void OpenFile(string activePath)
            {
                try
                {
                    FileInfo fi = new FileInfo(activePath);

                    Director            director = new Director();
                    EventManagerBuilder movingEventManagerBuilder = new MovingEventManagerBuilder();
                    director.SetEventManagerBuilder(movingEventManagerBuilder);
                    director.ConstructEventManager("Was opened " + activePath);
                    EventManager eventManager = director.GetEventManager();
                    AddEventManager(eventManager.ToString());

                    TextEditor te = new TextEditor(fi);
                    te.ShowDialog();

                    movingEventManagerBuilder = new MovingEventManagerBuilder();
                    director.SetEventManagerBuilder(movingEventManagerBuilder);
                    director.ConstructEventManager("Was  " + activePath);
                    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();
                }
            }
Exemple #4
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);
            }
Exemple #5
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;
            }
Exemple #6
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;
            }
Exemple #7
0
            public void DeleteSelectedFile(WorkWindow leftWorkWindow, WorkWindow rightWorkWindow)
            {
                FileSystemInfo selectedFile = GetSelectedFile(leftWorkWindow, rightWorkWindow);

                if (selectedFile == null)
                {
                    ErrorMessage errorMessage = new ErrorMessage("No files selected");
                    errorMessage.ShowDialog();
                    Console.WriteLine("Was not selected files");
                    return;
                }


                if (File.Exists(selectedFile.FullName))
                {
                    var dlgRes = MessageBox.Show("Delete this item : " + selectedFile.Name, "", MessageBoxButtons.YesNo);

                    if (dlgRes == DialogResult.Yes)
                    {
                        try
                        {
                            selectedFile.Delete();
                        }
                        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
                {
                    var dlgRes = MessageBox.Show("Delete this item : " + selectedFile.Name, "", MessageBoxButtons.YesNo);

                    if (dlgRes == DialogResult.Yes)
                    {
                        if (IsOpenNow(leftWorkWindow, (DirectoryInfo)selectedFile) || IsOpenNow(rightWorkWindow, (DirectoryInfo)selectedFile))
                        {
                            Director            director = new Director();
                            EventManagerBuilder errorEventManagerBuilder = new ErrorEventManagerBuilder();
                            director.SetEventManagerBuilder(errorEventManagerBuilder);
                            director.ConstructEventManager("This folder or children for it is opened in one of the part in FileManager");
                            EventManager eventManager = director.GetEventManager();
                            AddEventManager(eventManager.ToString());

                            ErrorMessage errorMessage = new ErrorMessage("This folder or children for it is opened in one of the part in FileManager");
                            errorMessage.ShowDialog();
                        }
                        else
                        {
                            DeleteFolder((DirectoryInfo)(selectedFile));
                            OpenDirectory(leftWorkWindow);
                            OpenDirectory(rightWorkWindow);
                        }
                    }
                }
            }