Exemple #1
0
        private bool AskEncryption(FileExtension fileExtension)
        {
            bool isEncrypted         = false;
            bool encryptionSupported = false;
            bool tryAgain            = false;
            bool startOver           = false;

            do
            {
                tryAgain    = false;
                isEncrypted = this.AskYesNo("File encrypted?");
                if (!isEncrypted)
                {
                    break;
                }
                else
                {
                    encryptionSupported = FileValidator.CheckEncryptionSupported(fileExtension);
                    if (encryptionSupported)
                    {
                        break;
                    }
                    else
                    {
                        tryAgain = this.AskErrorTryAgain($"Encryption not supported for files of type {fileExtension}");
                        if (tryAgain)
                        {
                            continue;
                        }
                        else
                        {
                            startOver = this.AskStartOver();
                            if (startOver)
                            {
                                this.startOver = true;
                                return(isEncrypted);
                            }
                            else
                            {
                                this.StopApplication();
                            }
                        }
                    }
                }
            } while (tryAgain);
            return(isEncrypted);
        }
Exemple #2
0
        private string AskFilePath()
        {
            bool   isExistingFile = false;
            bool   tryAgain       = false;
            bool   startOver      = false;
            string filePath       = null;


            do
            {
                System.Console.WriteLine("File path: ");
                string response = System.Console.ReadLine();
                isExistingFile = FileValidator.CheckFileExists(response);

                if (isExistingFile)
                {
                    filePath = response;
                    break;
                }
                else
                {
                    tryAgain = this.AskErrorTryAgain("File does not exist.");
                    if (!tryAgain)
                    {
                        startOver = this.AskStartOver();
                        if (startOver)
                        {
                            this.startOver = true;
                            return(filePath);
                        }
                        else
                        {
                            this.StopApplication();
                        }
                    }
                }
            } while (tryAgain);
            return(filePath);
        }
Exemple #3
0
        private bool AskRoleBasedSecurity(FileExtension fileExtension)
        {
            bool isRoleSecured             = false;
            bool roleBaseSecuritySupported = false;
            bool tryAgain  = false;
            bool startOver = false;

            do
            {
                tryAgain      = false;
                isRoleSecured = this.AskYesNo("Use role base security?");
                if (isRoleSecured)
                {
                    roleBaseSecuritySupported = FileValidator.CheckRoleBasedSecuritySupported(fileExtension);
                    if (roleBaseSecuritySupported)
                    {
                        break;
                    }
                    else
                    {
                        tryAgain = this.AskErrorTryAgain($"Role base security not supported for files of type {fileExtension}");
                        if (tryAgain)
                        {
                            continue;
                        }
                        else
                        {
                            startOver = this.AskStartOver();
                            if (startOver)
                            {
                                this.startOver = true;
                                return(isRoleSecured);
                            }
                        }
                    }
                }
            } while (tryAgain);
            return(isRoleSecured);
        }
Exemple #4
0
        private IRole AskRole(IAuthorizer authorizer, File file)
        {
            bool  tryAgain      = false;
            bool  startOver     = false;
            bool  roleHasAccess = false;
            bool  isValidRole   = false;
            IRole role          = null;

            if (!file.IsRoleBaseSecured)
            {
                return(null);
            }
            do
            {
                System.Console.WriteLine("Choose a role:");
                int i = 0;
                foreach (IRole accessRole in authorizer.AvailableRoles)
                {
                    System.Console.WriteLine($"({i + 1}) {accessRole.RoleName}");
                    i++;
                }
                string response = System.Console.ReadLine();
                short  roleID;
                Int16.TryParse(response, out roleID);
                roleID     -= 1; // index in list container start at 0
                isValidRole = FileValidator.IsValidRole(authorizer, roleID);

                if (isValidRole)
                {
                    role          = authorizer.AvailableRoles[roleID];
                    roleHasAccess = authorizer.HasReadAccess(file.FileName, role);
                    if (roleHasAccess)
                    {
                        break;
                    }
                    else
                    {
                        tryAgain = this.AskErrorTryAgain($"{role.RoleName} does not have read access to file {file.FileName}.");
                        if (tryAgain)
                        {
                            continue;
                        }
                        else
                        {
                            startOver = this.AskStartOver();
                            if (startOver)
                            {
                                this.startOver = true;
                                return(null);
                            }
                            else
                            {
                                this.StopApplication();
                            }
                        }
                    }
                }
                else
                {
                    tryAgain = this.AskErrorTryAgain($"Unknown role chosen.");
                    if (tryAgain)
                    {
                        continue;
                    }
                    else
                    {
                        startOver = this.AskStartOver();
                        if (startOver)
                        {
                            this.startOver = true;
                            return(null);
                        }
                        else
                        {
                            this.StopApplication();
                        }
                    }
                }
            } while (tryAgain);
            return(role);
        }
Exemple #5
0
        private FileExtension AskExtension(string filePath)
        {
            FileExtension extension;
            bool          tryAgain            = false;
            bool          startOver           = false;
            bool          isMatchingExtension = false;
            bool          isValidExtension    = false;

            do
            {
                tryAgain = false;
                System.Console.WriteLine("Select extension: ");
                foreach (FileExtension option in Enum.GetValues(typeof(FileExtension)))
                {
                    System.Console.WriteLine($"({ (int)option }) { option }");
                }
                string response = System.Console.ReadLine();
                Enum.TryParse(response, out extension);

                isValidExtension = FileValidator.IsValidFileExtension(extension);
                if (!isValidExtension)
                {
                    tryAgain = this.AskErrorTryAgain("Unrecognized file extension.");
                    if (tryAgain)
                    {
                        continue;
                    }
                    else
                    {
                        startOver = this.AskStartOver();
                        if (startOver)
                        {
                            this.startOver = true;
                            return(extension);
                        }
                        else
                        {
                            this.StopApplication();
                        }
                    }
                }

                isMatchingExtension = FileValidator.MatchFileFileExtension(filePath, extension);
                if (isMatchingExtension)
                {
                    break;
                }
                else
                {
                    tryAgain = this.AskErrorTryAgain("File extension does not match file.");
                    if (tryAgain)
                    {
                        continue;
                    }
                    else
                    {
                        startOver = this.AskStartOver();
                        if (startOver)
                        {
                            this.startOver = true;
                            return(extension);
                        }
                        else
                        {
                            this.StopApplication();
                        }
                    }
                }
            } while (tryAgain);
            return(extension);
        }