Exemple #1
0
        protected async virtual Task <Stream> OpenStorage(string fileName, PCLStorage.FileAccess mode)
        {
            IFolder store = FileSystem.Current.LocalStorage;
            IFile   file  = await store.GetFileAsync(fileName);

            return(await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite));
        }
Exemple #2
0
        protected override Task <Stream> OpenFileStreamAsyncInternal(string path, PCLStorage.FileAccess accessType)
        {
            if (Path.Equals(path, StringComparison.OrdinalIgnoreCase))
            {
                return(File.OpenAsync(accessType));
            }

            return(Task.FromResult(null as Stream));
        }
        public Task <Stream> OpenFileStreamAsync(string path, PCLStorage.FileAccess accessType)
        {
            if (!EntriesBufferMapping.Keys.Contains(path, StringComparer.OrdinalIgnoreCase))
            {
                return(Task.FromResult(null as Stream));
            }

            var output = new MemoryStream(EntriesBufferMapping[path]);

            return(Task.FromResult(output as Stream));
        }
Exemple #4
0
            public Task <Stream> OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken = new CancellationToken())
            {
                if (fileAccess == FileAccess.Read)
                {
                    using (Stream fs = File.OpenRead(Path))
                    {
                        return(Task.FromResult(fs));
                    }
                }

                using (Stream fs = File.OpenWrite(Path))
                {
                    return(Task.FromResult(fs));
                }
            }
Exemple #5
0
 public Task <Stream> OpenAsync(PCLStorage.FileAccess fileAccess, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (fileAccess == PCLStorage.FileAccess.Read)
     {
         MemoryStream stream = new MemoryStream();
         StreamWriter writer = new StreamWriter(stream);
         writer.Write(this.content);
         writer.Flush();
         stream.Position = 0;
         return(Task.FromResult(stream as Stream));
     }
     else
     {
         return(Task.FromResult(File.OpenWrite("test") as Stream));
     }
 }
Exemple #6
0
        public Stream OpenFile(string fileName, PCLStorage.FileAccess fileAccess)
        {
            IFile file = this.GetFile(fileName, true);

            if (file == null)
            {
                return(null);
            }
            Stream stream;

            try
            {
                Task <Stream> streamTask = Task.Run(async() => await file.OpenAsync(fileAccess));
                stream = streamTask.Result;
            }
            catch (Exception e)
            {
                string message = "exception " + e;
                System.Diagnostics.Debug.WriteLine(message);
                return(null);
            }
            return(stream);
        }
Exemple #7
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously

        public async Task <Stream> OpenAsync(FileAccess fileAccess, CancellationToken cancellationToken = new CancellationToken())
        {
            throw new NotImplementedException();
        }
Exemple #8
0
 private static async Task <Stream> Open(this IFile file, PCLStorage.FileAccess fileAccess)
 {
     return(await Task.Run(() => file.OpenAsync(fileAccess)).ConfigureAwait(false));
 }
Exemple #9
0
        protected override async Task <Stream> OpenFileStreamAsyncInternal(string path, PCLStorage.FileAccess accessType)
        {
            if (!path.StartsWith(HandledScheme, System.StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            path = path.Substring(HandledScheme.Length + 1);

            if (accessType == PCLStorage.FileAccess.Read)
            {
                var existenceCheck = await RootFolder.CheckExistsAsync(path);

                if (existenceCheck != ExistenceCheckResult.FileExists)
                {
                    return(null);
                }
            }

            var file = await RootFolder.CreateFileAsync(path, CreationCollisionOption.OpenIfExists);

            var output = await file.OpenAsync(accessType);

            return(output);
        }