CreateFile() public method

public CreateFile ( string path ) : IsolatedStorageFileStream
path string
return IsolatedStorageFileStream
コード例 #1
0
 public void CreateFile_RaisesArgumentException()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         AssertExtensions.Throws <ArgumentException>("path", null, () => isf.CreateFile("\0bad"));
     }
 }
コード例 #2
0
 public void CreateFile_IsolatedStorageException()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         Assert.Throws <IsolatedStorageException>(() => isf.CreateFile("\0bad"));
     }
 }
コード例 #3
0
 public void CreateFile_ThrowsArgumentNull()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         Assert.Throws <ArgumentNullException>(() => isf.CreateFile(null));
     }
 }
コード例 #4
0
 public void Save()
 {
     using (IsolatedStorageFileStream fs = container.CreateFile(LocalSettings)) {
         DataContractSerializer ser = new DataContractSerializer(settings.GetType());
         ser.WriteObject(fs, settings);
     }
 }
コード例 #5
0
        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();
        }
コード例 #6
0
 public void CreateFile_ThrowsIsolatedStorageException()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         isf.Remove();
         Assert.Throws <IsolatedStorageException>(() => isf.CreateFile("foo"));
     }
 }
コード例 #7
0
 public void CreateClosedFile_ThrowsInvalidOperationException()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly())
     {
         isf.Close();
         Assert.Throws <InvalidOperationException>(() => isf.CreateFile("foo"));
     }
 }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
 public IsolatedStorageFileWrapper_Tests()
 {
     storage = IsolatedStorageFile.GetUserStoreForAssembly();
     directory = new IsolatedStorageDirectory(storage);
     using (var stream = storage.CreateFile("exists.js"))
     {
         "content".AsStream().CopyTo(stream);
         stream.Flush();
     }
 }
コード例 #10
0
ファイル: BaseViewModel.cs プロジェクト: slodge/main
 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);
         }
     }
 }
コード例 #11
0
 /// <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);
         }
     }
 }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        public MainPage()
        {
            InitializeComponent();

            myFile = IsolatedStorageFile.GetUserStoreForApplication();

            if (!myFile.FileExists("Impo.txt"))
            {
                IsolatedStorageFileStream dataFile = myFile.CreateFile("Impo.txt");
                dataFile.Close();
            }
        }
コード例 #14
0
ファイル: RecordHelper.cs プロジェクト: sandcu/wpaudio
 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;
 }
コード例 #15
0
 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);
     }
 }
コード例 #16
0
        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);
                }
            }
        }
コード例 #17
0
        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
            }
        }
コード例 #18
0
ファイル: MainPage.xaml.cs プロジェクト: goumang2010/txtNote
        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();
                }
            }
        }
コード例 #19
0
ファイル: DatabaseInfo.cs プロジェクト: MarioBinder/7Pass
        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();
            }
        }
コード例 #20
0
ファイル: DatabaseInfo.cs プロジェクト: gkardava/WinPass
 private void SaveDetails(IsolatedStorageFile store)
 {
     using (var fs = store.CreateFile(InfoPath))
         SaveDetails(fs);
 }
コード例 #21
0
ファイル: DatabaseInfo.cs プロジェクト: gkardava/WinPass
        /// <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);

            }
        }
コード例 #22
0
 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();
         }
     }
 }
コード例 #23
0
ファイル: FsBitmapCache.cs プロジェクト: arakuma/wp_imagetool
        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 );
                    }
                }
            } );
        }
コード例 #24
0
        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();
                }
            }
        }
コード例 #25
0
 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();
         }
     }
 }
コード例 #26
0
 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();
     }
 }
コード例 #27
0
		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");
		}
コード例 #28
0
        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();
            }
        }
コード例 #29
0
		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");
		}