private async Task<string> ReadFileAsync(StorageFolder storageFolder, StorageFile storageFile, FileType fileType)
        {
            var rootFolder = FileSystem.Current.LocalStorage;

            var folder = await rootFolder.GetFolderAsync(storageFolder.ToString());

            if (folder == null)
            {
                return null;
            }

            var file = await folder.GetFileAsync(string.Format(@"{0}.{1}", storageFile, fileType));

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

            var stream = await file.OpenAsync(FileAccess.Read);

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

            using (var streamReader = new StreamReader(stream))
            {
                return streamReader.ReadToEnd();
            }
        }
예제 #2
0
        private async Task EnsureAssemblyEntries( StorageFolder folder )
        {
            Contract.Requires( folder != null );
            Contract.Ensures( Contract.Result<Task>() != null );

            if ( initialized )
                return;

            var temp = new List<AssemblyEntry>();

            foreach ( var file in await folder.GetFilesAsync() )
            {
                if ( file.FileType != ".dll" && file.FileType != ".exe" )
                    continue;

                var name = new AssemblyName( Path.GetFileNameWithoutExtension( file.Name ) );
                var assembly = Assembly.Load( name );
                var entry = new AssemblyEntry( file.Path, assembly );

                temp.Add( entry );
            }

            lock ( entries )
            {
                if ( initialized )
                    return;

                initialized = true;
                entries.ReplaceAll( temp );
            }
        }
 public async Task SaveUrlAsync(StorageFolder folder, HttpClient client, string path)
 {
     var destName = path.Split('/').Last();
     var content = await client.GetByteArrayAsync(path).ConfigureAwait(false);
     var destFile = await folder.CreateFileAsync(destName, CreationCollisionOption.GenerateUniqueName)
         .AsTask()
         .ConfigureAwait(false);
     using (var destStream = await destFile.OpenStreamForWriteAsync().ConfigureAwait(false))
     {
         destStream.Write(content, 0, content.Length);
         await destStream.FlushAsync().ConfigureAwait(false);
     }
 }
        private async Task<bool> SaveFileAsync(StorageFolder storageFolder, StorageFile storageFile, FileType fileType, string content)
        {
            var rootFolder = FileSystem.Current.LocalStorage;

            var folder = await rootFolder.CreateFolderAsync(storageFolder.ToString(), CreationCollisionOption.OpenIfExists);

            if (folder == null)
            {
                return false;
            }

            var file = await folder.CreateFileAsync(string.Format(@"{0}.{1}", storageFile, fileType), CreationCollisionOption.ReplaceExisting);

            if (file == null)
            {
                return false;
            }

            await file.WriteAllTextAsync(content);

            return true;
        }