Пример #1
0
 public static bool SetFileAttributes(FileInfo fileInfo, FileAttributes attributes, LoggerBase logger = null)
 {
     try
     {
         fileInfo.Attributes = attributes;
         return(true);
     }
     catch (FileNotFoundException fileNotFoundEx)
     {
         ConditionalLogging.LogExceptionOrThrowIt(logger, LogLevel.Debug, fileNotFoundEx, string.Format("Can't change dirAttributes for file \"{0}\" to \"{1}\"", fileInfo, attributes));
     }
     catch (Exception attrException)
     {
         ConditionalLogging.LogExceptionOrThrowIt(logger, LogLevel.Error, attrException, string.Format("Can't change dirAttributes for file \"{0}\" to \"{1}\"", fileInfo, attributes));
     }
     return(false);
 }
Пример #2
0
 public static bool SetDirectoryAttributes(string dirName, FileAttributes attributes, LoggerBase logger = null)
 {
     try
     {
         DirectoryInfo di = new DirectoryInfo(dirName);
         di.Attributes = attributes;
         return(true);
     }
     catch (FileNotFoundException fileNotFoundEx)
     {
         ConditionalLogging.LogExceptionOrThrowIt(logger, LogLevel.Debug, fileNotFoundEx, string.Format("Can't change dirAttributes for folder \"{0}\" to \"{1}\"", dirName, attributes));
     }
     catch (Exception attrException)
     {
         ConditionalLogging.LogExceptionOrThrowIt(logger, LogLevel.Error, attrException, string.Format("Can't change dirAttributes for folder \"{0}\" to \"{1}\"", dirName, attributes));
     }
     return(false);
 }
Пример #3
0
 public static bool SetFileAttributes(string fileName, FileAttributes attributes, out FileInfo fileInfo, LoggerBase logger = null, LogLevel errorLogLevel = LogLevel.Error)
 {
     try
     {
         fileInfo            = new FileInfo(fileName);
         fileInfo.Attributes = attributes;
         return(true);
     }
     catch (FileNotFoundException fileNotFoundEx)
     {
         ConditionalLogging.LogExceptionOrThrowIt(logger, errorLogLevel, fileNotFoundEx, string.Format("Can't change dirAttributes for file \"{0}\" to \"{1}\"", fileName, attributes));
     }
     catch (Exception attrException)
     {
         ConditionalLogging.LogExceptionOrThrowIt(logger, errorLogLevel, attrException, string.Format("Can't change dirAttributes for file \"{0}\" to \"{1}\"", fileName, attributes));
     }
     fileInfo = null;
     return(false);
 }
Пример #4
0
        //private const string CLASS_NAME = "FilesArchiver.";

        /// </summary>
        ///
        /// <param name="action"></param>
        /// <returns>True if directory was created</returns>
        public static bool CreateDirectoryForFile(string fileName, FileAttributes dirAttributes = FileAttributes.Normal, LoggerBase logger = null, bool checkExistense = true)
        {
            string dir = null;

            try
            {
                dir = Path.GetDirectoryName(fileName);
                if (!checkExistense || !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                if (dirAttributes != FileAttributes.Normal)
                {
                    SetDirectoryAttributes(dir, dirAttributes);
                }
                return(true);
            }
            catch (Exception e)
            {
                ConditionalLogging.LogExceptionOrThrowIt(logger, LogLevel.Error, e, string.Format(Resources.CantCreateDirectory0ForFile1, dir, fileName));
                return(false);
            }
        }