예제 #1
0
 /// <include file='../../_Doc/mscorlib.xml' path='doc/members/member[@name="M:System.IO.File.Exists(System.String)"]/*' />
 public static bool Exists(string path)
 {
     try
     {
         return Task.Run(async () => await FileHelper.GetStorageFileAsync(path)).Result != null;
     }
     catch
     {
         return false;
     }
 }
예제 #2
0
 /// <include file='../../_Doc/mscorlib.xml' path='doc/members/member[@name="M:System.IO.File.Delete(System.String)"]/*' />
 public static void Delete(string path)
 {
     try
     {
         Task.Run(async () =>
         {
             var file = await FileHelper.GetStorageFileAsync(path);
             await file.DeleteAsync();
         }).Wait();
     }
     catch
     {
     }
 }
예제 #3
0
        /// <include file='../../_Doc/mscorlib.xml' path='doc/members/member[@name="M:System.IO.File.Move(System.String,System.String)"]/*' />
        public static void Move(string sourceFileName, string destFileName)
        {
            try
            {
                Task.Run(async () =>
                {
                    var src = await FileHelper.GetStorageFileAsync(sourceFileName);
                    var dest = await FileHelper.CreateStorageFileAsync(destFileName);
                    await src.MoveAndReplaceAsync(dest);
                }).Wait();

            }
            catch
            {
            }
        }
예제 #4
0
        /// <include file='../../_Doc/mscorlib.xml' path='doc/members/member[@name="M:System.IO.FileStream.#ctor(System.String,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)"]/*' />
        public FileStream(string path, FileMode mode, FileAccess access, FileShare share)
        {
            try
            {
                _internalStream = Task.Run(async() =>
                {
                    StorageFile file;
                    Stream stream;
                    long position;
                    switch (mode)
                    {
                    case FileMode.Create:
                    case FileMode.Truncate:
                        file     = await FileHelper.CreateStorageFileAsync(path);
                        position = 0;
                        break;

                    case FileMode.CreateNew:
                        if (File.Exists(path))
                        {
                            throw new IOException("File mode is CreateNew, but file already exists.");
                        }
                        file     = await FileHelper.CreateStorageFileAsync(path);
                        position = 0;
                        break;

                    case FileMode.OpenOrCreate:
                        if (File.Exists(path))
                        {
                            file = await FileHelper.GetStorageFileAsync(path);
                        }
                        else
                        {
                            file = await FileHelper.CreateStorageFileAsync(path);
                        }
                        position = 0;
                        break;

                    case FileMode.Open:
                        if (!File.Exists(path))
                        {
                            throw new FileNotFoundException("File mode is Open, but file does not exist.");
                        }
                        file     = await FileHelper.GetStorageFileAsync(path);
                        position = 0;
                        break;

                    case FileMode.Append:
                        if (File.Exists(path))
                        {
                            file     = await FileHelper.GetStorageFileAsync(path);
                            position = (long)(await file.GetBasicPropertiesAsync()).Size;
                        }
                        else
                        {
                            file     = await FileHelper.CreateStorageFileAsync(path);
                            position = 0;
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("mode");
                    }
                    switch (access)
                    {
                    case FileAccess.ReadWrite:
                    case FileAccess.Write:
                        stream = await file.OpenStreamForWriteAsync();
                        break;

                    case FileAccess.Read:
                        stream = await file.OpenStreamForReadAsync();
                        break;

                    default:
                        throw new ArgumentException("Unsupported file access type", "access");
                    }
                    stream.Seek(position, SeekOrigin.Begin);
                    return(stream);
                }).Result;

                _disposed = false;
                Name      = path;
            }
            catch
            {
                _internalStream = null;
                _disposed       = true;
                Name            = String.Empty;
            }
        }