Пример #1
0
        public void Copy(string from, string to)
        {
            try
            {
                IIOContext io     = IOContext.Current;
                string     source = io.TranslateLocalPath(from);
                string     dest   = io.TranslateLocalPath(to);

                if (!io.Exists(source))
                {
                    throw new NonFatalException(D.FILE_NOT_EXISTS + ": " + from);
                }
                if (io.Exists(dest))
                {
                    throw new NonFatalException(D.FILE_ALREADY_EXISTS + ": " + to);
                }

                io.Copy(source, dest);
            }
            catch (CustomException e)
            {
                throw ClientException(e.FriendlyMessage);
            }
            catch (ArgumentException)
            {
                throw ClientException(D.INVALID_PATH + ": " + from + "; " + to);
            }
            catch (Exception e)
            {
                HandleException(e, "Exists");
                throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
            }
        }
Пример #2
0
 private IEnumerable <string> Dir(string name, bool dirFilesNotFolders)
 {
     try
     {
         IIOContext io   = IOContext.Current;
         string     path = io.TranslateLocalPath(name);
         if (io.Exists(path))
         {
             IEnumerable <string> result = dirFilesNotFolders
                 ? Directory.EnumerateFiles(path)
                 : Directory.EnumerateDirectories(path);
             return(result.Select(Path.GetFileName));
         }
         throw new NonFatalException(D.DIRECTORY_NOT_EXISTS + ": " + name);
     }
     catch (CustomException e)
     {
         throw ClientException(e.FriendlyMessage);
     }
     catch (ArgumentException)
     {
         throw ClientException(D.INVALID_PATH + ": " + name);
     }
     catch (Exception e)
     {
         HandleException(e, "Dir");
         throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
     }
 }
Пример #3
0
 public string OpenTextFile(string name)
 {
     try
     {
         IIOContext io   = IOContext.Current;
         string     path = io.TranslateLocalPath(name);
         if (io.Exists(path, FileSystemItem.File))
         {
             using (var stream = io.FileStream(path, FileMode.Open))
                 using (var reader = new StreamReader(stream))
                     return(reader.ReadToEnd());
         }
         throw new NonFatalException(D.FILE_NOT_EXISTS + ": " + name);
     }
     catch (CustomException e)
     {
         throw ClientException(e.FriendlyMessage);
     }
     catch (ArgumentException)
     {
         throw ClientException(D.INVALID_PATH + ": " + name);
     }
     catch (Exception e)
     {
         HandleException(e, "Dir");
         throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
     }
 }
Пример #4
0
 public void CreateTextFile(string name, string text)
 {
     try
     {
         IIOContext io   = IOContext.Current;
         string     path = io.TranslateLocalPath(name);
         if (!io.Exists(path))
         {
             string dir = Path.GetDirectoryName(path);
             io.CreateDirectory(dir);
             using (var stream = io.FileStream(path, FileMode.CreateNew))
                 using (var writer = new StreamWriter(stream))
                     writer.Write(text);
         }
         else
         {
             throw new NonFatalException(D.FILE_ALREADY_EXISTS + ": " + name);
         }
     }
     catch (CustomException e)
     {
         throw ClientException(e.FriendlyMessage);
     }
     catch (ArgumentException)
     {
         throw ClientException(D.INVALID_PATH + ": " + name);
     }
     catch (Exception e)
     {
         HandleException(e, "Dir");
         throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
     }
 }
Пример #5
0
        public bool Exists(string name)
        {
            bool result;

            try
            {
                IIOContext io   = IOContext.Current;
                string     path = io.TranslateLocalPath(name);
                result = io.Exists(path);
            }
            catch (CustomException e)
            {
                throw ClientException(e.FriendlyMessage);
            }
            catch (ArgumentException)
            {
                throw ClientException(D.INVALID_PATH + ": " + name);
            }
            catch (Exception e)
            {
                HandleException(e, "Exists");
                throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
            }
            return(result);
        }
Пример #6
0
        public bool Delete(string name)
        {
            if (name.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries).Length == 1)
            {
                throw ClientException(D.UNABE_TO_DELETE_SYSTEM_DIRECTORY);
            }

            try
            {
                IIOContext io   = IOContext.Current;
                string     path = io.TranslateLocalPath(name);

                return(io.Delete(path));
            }
            catch (CustomException e)
            {
                throw ClientException(e.FriendlyMessage);
            }
            catch (ArgumentException)
            {
                throw ClientException(D.INVALID_PATH + ": " + name);
            }
            catch (Exception e)
            {
                HandleException(e, "Delete");
                throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
            }
        }
Пример #7
0
        public bool CreateDirectory(string name)
        {
            try
            {
                IIOContext io   = IOContext.Current;
                string     path = io.TranslateLocalPath(name);

                return(io.CreateDirectory(path));
            }
            catch (CustomException e)
            {
                throw ClientException(e.FriendlyMessage);
            }
            catch (ArgumentException)
            {
                throw ClientException(D.INVALID_PATH + ": " + name);
            }
            catch (Exception e)
            {
                HandleException(e, "CreateDirectory");
                throw ClientException(D.UNEXPECTED_ERROR_OCCURED);
            }
        }