Example #1
0
        public IObservable<Unit> addMap(Map map, System.IO.Stream mapContent)
        {
            Func<Task> impl = async () =>
            {
                try
                {
                    using (var iso = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        var filename = fileNameForMap(map);
                        if (iso.FileExists(filename))
                            iso.DeleteFile(filename);

                        using (var file = iso.CreateFile(filename))
                        {
                            await mapContent.CopyToAsync(file, 4 * 1024 * 1024);
                        }
                    }
                }
                catch (IsolatedStorageException)
                {
                    mapContent.Dispose();
                }

                using (var ctx = getContext())
                {
                    ctx.Maps.InsertOnSubmit(map);
                    ctx.SubmitChanges();
                }
            };

            return impl().ToObservable();
        }
 public async Task WriteStreamToFileAsync(System.IO.Stream dataStream, string fileName, string folderName = null)
 {
     var folder = await folderName.GetLocalFolderByNameCreateIfNotExistingAsync();
     var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
     using (var stream = await file.OpenStreamForWriteAsync())
     {
         await dataStream.CopyToAsync(stream);
     }
 }
Example #3
0
        public static async Task<string> SaveStreamAsync(string itemId, string filename, System.IO.Stream sourceStream, string dataFilesPath)
        {
            IFolder localStorage = FileSystem.Current.LocalStorage;

            string targetPath = await GetLocalFilePathAsync(itemId, filename, dataFilesPath);
            var targetFile = await localStorage.CreateFileAsync(targetPath, CreationCollisionOption.ReplaceExisting);

            using (var targetStream = await targetFile.OpenAsync(FileAccess.ReadAndWrite)) {
                await sourceStream.CopyToAsync(targetStream);
            }

            return targetPath;
        }
Example #4
0
        /// <summary>
        /// Stores the provided string with the provided filename.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public async Task<string> StoreAsync(string fileName, System.IO.Stream stream)
        {
            var fileNameAndPath = Path.Combine(_baseFolder, fileName);
            if (!Directory.Exists(_baseFolder))
            {
                Directory.CreateDirectory(_baseFolder);
            }
            using (var file = System.IO.File.OpenWrite(fileNameAndPath))
            {
                await stream.CopyToAsync(file);
            }

            return fileName;
        }
Example #5
0
        public async Task SaveStream(string fileName, System.IO.Stream stream)
        {
            var _lock = XNamedLock.Get(fileName);

            using (var releaser = await _lock.LockAsync())
            {
                var path = _getPath(fileName);

                _createDirForFile(path);

                using (var s = File.Create(path))
                {
                    await stream.CopyToAsync(s);
                }
            }
        }