Esempio n. 1
0
        /// <summary>
        /// Check all given files if they are readable and writable.
        /// </summary>
        private Check CheckFilesAccessible(string[] files)
        {
            var result = Check.Create();

            foreach (var file in files)
            {
                try
                {
                    using (var fileStream = new FileStream(file, FileMode.Open))
                    {
                        if (false == fileStream.CanRead && fileStream.CanWrite)
                        {
                            TerminalWriter.WriteLocation();

                            SetResultNotAccessible(result, file);
                        }
                    }
                }
                catch (DirectoryNotFoundException)
                {
                    TerminalWriter.WriteLocation();

                    result = SetResultNotAccessible(result, file);
                }
                catch (Exception)
                {
                    TerminalWriter.WriteLocation();

                    result = SetResultNotAccessible(result, file);
                }
            }

            return(result);
        }
Esempio n. 2
0
        private bool IsWritable(string file)
        {
            try
            {
                FileStream fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                fs.Close();

                return(true);
            }
            catch (Exception)
            {
                TerminalWriter.WriteLocation();

                return(false);
            }
        }
Esempio n. 3
0
        private Check CheckFilesExist(string[] files)
        {
            var result = Check.Create();

            foreach (var file in files)
            {
                if (false == File.Exists(file))
                {
                    TerminalWriter.WriteLocation();

                    result.CheckResult = CheckResult.Error;
                    result.Messages.Add(new TerminalMessage()
                    {
                        Color = Color.Red, Message = $"{file} is not a file."
                    });
                }
            }

            return(result);
        }