public void CreateFile_RaisesArgumentException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { AssertExtensions.Throws <ArgumentException>("path", null, () => isf.CreateFile("\0bad")); } }
public void CreateFile_IsolatedStorageException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { Assert.Throws <IsolatedStorageException>(() => isf.CreateFile("\0bad")); } }
public void CreateFile_ThrowsArgumentNull() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { Assert.Throws <ArgumentNullException>(() => isf.CreateFile(null)); } }
public void Save() { using (IsolatedStorageFileStream fs = container.CreateFile(LocalSettings)) { DataContractSerializer ser = new DataContractSerializer(settings.GetType()); ser.WriteObject(fs, settings); } }
public Accelerometro() { InitializeComponent(); accelerometer = new Accelerometer(); accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(100); accelerometer.Start(); myFile = IsolatedStorageFile.GetUserStoreForApplication(); if (!myFile.FileExists("Impo.txt")) { IsolatedStorageFileStream dataFile = myFile.CreateFile("Impo.txt"); dataFile.Close(); } Wb = new WebBrowser(); Connesso = false; Carica(); System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); dt.Interval = new TimeSpan(0, 0, 0, 0, 250); // 500 Milliseconds dt.Tick += new EventHandler(dt_Tick); dt.Start(); }
public void CreateFile_ThrowsIsolatedStorageException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Remove(); Assert.Throws <IsolatedStorageException>(() => isf.CreateFile("foo")); } }
public void CreateClosedFile_ThrowsInvalidOperationException() { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { isf.Close(); Assert.Throws <InvalidOperationException>(() => isf.CreateFile("foo")); } }
/// <summary> /// Persist the settings to isolated storage. /// </summary> /// <exception cref="ResolutionException"> /// If an exception occurs while retrieving the binary /// serializer.</exception> /// <exception cref="Exception"> /// If the serialization fails.</exception> public void Save() { var serializer = Dependency.Resolve <IBinarySerializer, BinarySerializer>(); using (var fileStream = container.CreateFile(localSettingsFileName)) { serializer.Serialize(settings, fileStream); } }
public IsolatedStorageFileWrapper_Tests() { storage = IsolatedStorageFile.GetUserStoreForAssembly(); directory = new IsolatedStorageDirectory(storage); using (var stream = storage.CreateFile("exists.js")) { "content".AsStream().CopyTo(stream); stream.Flush(); } }
protected static void WriteTextFile(IsolatedStorageFile isf, string path, string text) { using (var fs = isf.CreateFile(path)) { using (var sw = new StreamWriter(fs)) { sw.Write(text); } } }
/// <summary> /// Simple wrapper to create the given file (and close the handle) /// </summary> public static void CreateTestFile(this IsolatedStorageFile isf, string fileName, string content = null) { using (var stream = isf.CreateFile(fileName)) { if (content != null) { stream.WriteAllText(content); } } }
public async Task DisposeAsync_MultipleInvokes_Idempotent(PresetScopes scope) { TestHelper.WipeStores(); using (IsolatedStorageFile isf = GetPresetScope(scope)) { IsolatedStorageFileStream isfs = isf.CreateFile("DisposeAsyncFile"); await isfs.DisposeAsync(); await isfs.DisposeAsync(); } }
public MainPage() { InitializeComponent(); myFile = IsolatedStorageFile.GetUserStoreForApplication(); if (!myFile.FileExists("Impo.txt")) { IsolatedStorageFileStream dataFile = myFile.CreateFile("Impo.txt"); dataFile.Close(); } }
public string PrepareStartRecordToTempFile() { RecordLevel = 0; useTempFile = true; isf = IsolatedStorageFile.GetUserStoreForApplication(); tempFileKey = Guid.NewGuid().ToString() + ".tmp"; tempFileStream = isf.CreateFile(tempFileKey); _sampleDuration = TimeSpan.FromSeconds(0); FrameworkDispatcher.Update(); //_dispatcherTimer.Start(); return tempFileKey; }
public void Save() { using (IsolatedStorageFileStream fs = container.CreateFile(LocalSettings)) { // note: SL seems to prepend a line with a fully qualified name for System.Object + CRLF byte[] header = System.Text.Encoding.UTF8.GetBytes(typeof(object).AssemblyQualifiedName); fs.Write(header, 0, header.Length); fs.WriteByte(13); fs.WriteByte(10); // and does not seems to need it when reading back... DataContractSerializer ser = new DataContractSerializer(settings.GetType()); ser.WriteObject(fs, settings); } }
public async Task DisposeAsync_FlushesAndCloses(PresetScopes scope) { TestHelper.WipeStores(); using (IsolatedStorageFile isf = GetPresetScope(scope)) { IsolatedStorageFileStream isfs = isf.CreateFile("DisposeAsyncFile"); isfs.Write(new byte[100], 0, 100); await isfs.DisposeAsync(); using (isfs = isf.OpenFile("DisposeAsyncFile", FileMode.Open)) { Assert.Equal(100, isfs.Length); } } }
public void Save() { try { using (IsolatedStorageFileStream fs = container.CreateFile(LocalSettings)) { DataContractSerializer ser = new DataContractSerializer(settings.GetType() #if !SILVERLIGHT , new Type[] { typeof(System.Windows.Point), typeof(System.Windows.Size) } #endif ); ser.WriteObject(fs, settings); } } catch (ObjectDisposedException) //if fs is for some reaosn already closed when "using" tries to return, it fails, so catch and ignore the exception here { //NOP } }
void PhotoTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null) { System.Windows.Media.Imaging.WriteableBitmap bmp = Microsoft.Phone.PictureDecoder.DecodeJpeg(e.ChosenPhoto); System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if (isf.FileExists("abc.jpg")) { isf.DeleteFile("abc.jpg"); } System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.CreateFile("abc.jpg"); System.Windows.Media.Imaging.Extensions.SaveJpeg(bmp, PhotoStream, 432, 645, 0, 100); //这里设置保存后图片的大小、品质 PhotoStream.Close(); //写入完毕,关闭文件流 PhotoStream = isf.OpenFile("abc.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); //读取刚刚保存的图片的文件流 System.Windows.Media.Imaging.BitmapImage bmp1 = new System.Windows.Media.Imaging.BitmapImage(); bmp1.SetSource(PhotoStream); //把文件流转换为图片 PhotoStream.Close(); //读取完毕,关闭文件流 System.Windows.Media.ImageBrush ib = new System.Windows.Media.ImageBrush(); ib.ImageSource = bmp1; tip.Background = ib;//把图片设置为控件的背景图 imageTip.Visibility = System.Windows.Visibility.Collapsed; if (imagePicker.Content.ToString() == txtnote.Resources.StringLibrary.imagename) { if (MessageBox.Show(txtnote.Resources.StringLibrary.imagename, txtnote.Resources.StringLibrary.guanlian, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { NavigationService.Navigate(new Uri("/txtnote;component/Pick.xaml", UriKind.Relative)); } } else { appBar3(); } } }
private void SaveDetails(IsolatedStorageFile store) { using (var fs = store.CreateFile(InfoPath)) { var writer = new StreamWriter(fs); var serializer = new JsonSerializer(); serializer.Serialize(writer, Details); writer.Flush(); } }
private void SaveDetails(IsolatedStorageFile store) { using (var fs = store.CreateFile(InfoPath)) SaveDetails(fs); }
/// <summary> /// Saves user password. /// </summary> /// <param name="store">The store.</param> /// <param name="xml">The XML.</param> private async void Save(IsolatedStorageFile store, DbPersistentData xml) { if (!store.DirectoryExists(Folder)) store.CreateDirectory(Folder); using (var fs = store.CreateFile(ProtectionPath)) { var protect = xml.Protection; fs.Write(protect, 0, protect.Length); } using (var fs = store.CreateFile(ParsedXmlPath)) using (var buffer = new MemoryStream(xml.Xml)) BufferEx.CopyStream(buffer, fs); using (var fs = store.CreateFile(MasterPasswordPath)) { var data = xml.MasterKey; await fs.WriteAsync(data, 0, data.Length); } }
private static void WriteFileToFile(File file, IsolatedStorageFile istorage, string newFilePath) { using (var newFile = istorage.CreateFile(newFilePath)) { using (var newWriteableFile = new StreamWriter(newFile, Encoding.Unicode)) { newWriteableFile.Write(file.Content); newWriteableFile.Flush(); } } }
public override void Store( string url, BitmapSource bitmap ) { Deployment.Current.Dispatcher.BeginInvoke( () => { string fileName = GetFilePath( GetFileName( url ) ); using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) { if ( _storage.FileExists( fileName ) ) { _storage.DeleteFile( fileName ); } using ( IsolatedStorageFileStream fileStream = _storage.CreateFile( fileName ) ) { WriteableBitmap writeableBitmap = new WriteableBitmap( bitmap ); writeableBitmap.SaveJpeg( fileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, IMAGE_QUALITY ); } } } ); }
private async Task SaveMultimedia(IsolatedStorageFile isoStore, string snapshotDir, IProgress<Tuple<BackupStage, int>> Progress) { Progress.Report(Tuple.Create(BackupStage.ExternalData, 0)); var snapshotMultimediaDir = Path.Combine(snapshotDir, MultimediaStorageService.MEDIA_FOLDER); var snapshotDBPath = Path.Combine(snapshotDir, DiversityDataContext.DB_FILENAME); using (var db = new DiversityDataContext(snapshotDBPath)) { var totalCount = db.MultimediaObjects.Count(); if (totalCount > 0) { var reporter = new PercentageReporter<Tuple<BackupStage, int>>( Progress, p => Tuple.Create(BackupStage.ExternalData, p), totalCount); foreach (var mm in db.MultimediaObjects) { var descriptor = StorageDescriptor.FromURI(mm.Uri); if (descriptor.Type == StorageType.CameraRoll) { using (var content = ImageStore.GetMultimedia(mm.Uri)) { var mmFilePath = Path.Combine(snapshotMultimediaDir, descriptor.FileName); using (var targetFile = isoStore.CreateFile(mmFilePath)) { await content.CopyToAsync(targetFile); descriptor.Type = StorageType.IsolatedStorage; mm.Uri = descriptor.ToString(); } } } reporter.Completed++; } db.SubmitChanges(); } } }
private static void ExtractFile(IsolatedStorageFile store, string baseFileName) { if (!store.FileExists(baseFileName)) { using (Stream sourceStream = Application.GetResourceStream(new Uri("Data/" + baseFileName, UriKind.Relative)).Stream) { using (IsolatedStorageFileStream targetStream = store.CreateFile(baseFileName)) { byte[] buffer = new byte[1024]; int length; while ((length = sourceStream.Read(buffer, 0, 1024)) > 0) targetStream.Write(buffer, 0, length); targetStream.Close(); } sourceStream.Close(); } } }
private static void WriteToIsolatedStorage(IsolatedStorageFile storage, System.IO.Stream inputStream, string fileName) { IsolatedStorageFileStream outputStream = null; try { if (!storage.DirectoryExists(imageStorageFolder)) { storage.CreateDirectory(imageStorageFolder); } if (storage.FileExists(fileName)) { storage.DeleteFile(fileName); } outputStream = storage.CreateFile(fileName); byte[] buffer = new byte[32768]; int read; while ((read = inputStream.Read(buffer, 0, buffer.Length)) > 0) { outputStream.Write(buffer, 0, read); } outputStream.Dispose(); } catch { //We cannot do anything here. outputStream?.Dispose(); } }
private void ImportOrMakeSoundsCache(IsolatedStorageFile isf) { _soundFiles = new Dictionary<int, string>(); foreach (var sound in Cartridge.Resources.Where(m => ViewModels.SoundManager.IsPlayableSound(m))) { // Copies the sound file to the cache if it doesn't exist already. string cacheFilename = GetCachePathCore(sound); if (!isf.FileExists(cacheFilename)) { using (IsolatedStorageFileStream fs = isf.CreateFile(cacheFilename)) { if (sound.Type == MediaType.FDL) { // Converts the FDL to WAV and writes it. ConvertAndWriteFDL(fs, sound); } else { // Dumps the bytes out! fs.Write(sound.Data, 0, sound.Data.Length); } } } // Adds the sound filename to the dictionary. _soundFiles.Add(sound.MediaId, cacheFilename); } RaisePropertyChanged("Sounds"); }
private static void SaveCompletedTimeStamp(string snapshotDir, IsolatedStorageFile isoStore) { var completedMarkerPath = Path.Combine(snapshotDir, COMPLETED_MARKER); using (var completedFile = isoStore.CreateFile(completedMarkerPath)) using (var writer = new StreamWriter(completedFile)) { var universalNow = DateTime.Now.ToUniversalTime(); var invariantNowString = universalNow.ToString(CultureInfo.InvariantCulture); writer.WriteLine(invariantNowString); writer.Flush(); } }
private void ImportOrMakeSoundsCache(IsolatedStorageFile isf) { _soundFiles = new Dictionary<int, string>(); foreach (var sound in Cartridge.Resources.Where(m => m.Type == MediaType.MP3 || m.Type == MediaType.WAV)) { // Copies the sound file to the cache if it doesn't exist already. string cacheFilename = GetCachePathCore(sound); if (!isf.FileExists(cacheFilename)) { using (IsolatedStorageFileStream fs = isf.CreateFile(cacheFilename)) { fs.Write(sound.Data, 0, sound.Data.Length); } } // Adds the sound filename to the dictionary. _soundFiles.Add(sound.MediaId, cacheFilename); } RaisePropertyChanged("Sounds"); }