本文整理汇总了C#中System.IO.IsolatedStorage.IsolatedStorageFileStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# IsolatedStorageFileStream.Flush方法的具体用法?C# IsolatedStorageFileStream.Flush怎么用?C# IsolatedStorageFileStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.IsolatedStorage.IsolatedStorageFileStream
的用法示例。
在下文中一共展示了IsolatedStorageFileStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: wc_OpenReadCompleted
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled)
{
string iconPath = "1.txt";
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
var isfs = new IsolatedStorageFileStream(iconPath, FileMode.Create, isf);
int bytesRead;
byte[] bytes = new byte[e.Result.Length];
while ((bytesRead = e.Result.Read(bytes, 0, bytes.Length)) != 0)
{
isfs.Write(bytes, 0, bytesRead);
}
isfs.Flush();
isfs.Close();
}
this.Dispatcher.BeginInvoke(() =>
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
});
}
}
示例2: CopyFile
private static string CopyFile(string filename)
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
Stream input = null;
Stream output = null;
string absoulutePath = Windows.Storage.ApplicationData.Current.LocalFolder.Path + '\\' + filename;
if (!File.Exists(absoulutePath))
{
input = Application.GetResourceStream(new Uri(filename, UriKind.Relative)).Stream;
output = new IsolatedStorageFileStream(filename, FileMode.CreateNew, isoStore);
CopyFile(input, output);
input.Close();
input = null;
output.Flush();
output.Close();
output = null;
}
return absoulutePath;
}
示例3: CopyFromContentToStorage
private void CopyFromContentToStorage(IsolatedStorageFile ISF, String SourceFile, String DestinationFile)
{
Stream Stream = Application.GetResourceStream(new Uri(SourceFile, UriKind.Relative)).Stream;
IsolatedStorageFileStream ISFS = new IsolatedStorageFileStream(DestinationFile, System.IO.FileMode.Create, System.IO.FileAccess.Write, ISF);
CopyStream(Stream, ISFS);
ISFS.Flush();
ISFS.Close();
Stream.Close();
ISFS.Dispose();
}
示例4: CopyToIsolatedStorage
public static void CopyToIsolatedStorage(string packageFilename, string isoFilename)
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
if (!store.FileExists(isoFilename))
using (var stream = System.Windows.Application.GetResourceStream(new Uri(packageFilename, UriKind.Relative)).Stream)
using (IsolatedStorageFileStream dest = new IsolatedStorageFileStream(isoFilename, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, store))
{
stream.Position = 0;
stream.CopyTo(dest);
dest.Flush();
}
}
示例5: SerializeObject
public static void SerializeObject(string filename, object obj)
{
//Stream stream = File.Open(filename, FileMode.Create);
IsolatedStorageFile isof = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(filename, FileMode.Create, isof);
byte[] b = BusinessLib.SilverlightSerializer.Serialize(obj);
isfs.Write(b, 0, b.Length);
isfs.Flush();
isfs.Close();
isof.Dispose();
}
示例6: decode
private void decode(object sender, RoutedEventArgs e)
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
LibmadWrapper Libmad = new LibmadWrapper();
IBuffer buffer = WindowsRuntimeBufferExtensions.AsBuffer(Mp3bytes, 0, Mp3bytes.Length);
PCMStream = isf.CreateFile("decoded_pcm.pcm");
bool init = Libmad.DecodeMp32Pcm_Init(buffer);
if (init)
{
List<short> samples = new List<short>();
RawPCMContent rpcc = null;
try
{
while ((rpcc = Libmad.ReadSample()).count != 0)
{
short[] shortBytes = rpcc.PCMData.ToArray<short>();
byte[] rawbytes = new byte[shortBytes.Length * 2];
for (int i = 0; i < shortBytes.Length; i++)
{
rawbytes[2 * i] = (byte)shortBytes[i];
rawbytes[2 * i + 1] = (byte)(shortBytes[i] >> 8);
}
PCMStream.Write(rawbytes, 0, rawbytes.Length);
}
PCMStream.Flush();
PCMStream.Close();
PCMStream.Dispose();
MessageBox.Show("over");
Libmad.CloseFile();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
isf.Dispose();
}
示例7: SaveScaledBitmap
private static void SaveScaledBitmap(BitmapImage bitmap, string localFileName, IsolatedStorageFile isoStore, double maxWidth, double maxHeight)
{
double scaleWidth = maxWidth / (double)bitmap.PixelWidth;
double scaleHeight = maxHeight / (double)bitmap.PixelHeight;
double scale = Math.Min(scaleWidth, scaleHeight);
int width = (int)Math.Round(scale * (double)bitmap.PixelWidth);
int height = (int)Math.Round(scale * (double)bitmap.PixelHeight);
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(localFileName, FileMode.Create, isoStore))
{
WriteableBitmap writable = new WriteableBitmap(bitmap);
writable.SaveJpeg(isoStream, width, height, 0, 80);
isoStream.Flush();
}
}
示例8: ResizeFile
public void ResizeFile()
{
const int blocks = 10000;
int blockcount = Blocks.Count;
for (int i = 0; i < blocks; i++)
{
Blocks.Add(blockcount + i, true);
}
using (var fs = new IsolatedStorageFileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, isf))
{
fs.SetLength(fs.Length + (blocks * BlockSize));
fs.Flush();
}
}
示例9: StoreState
//protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
//{
// AdRequest adRequest = new AdRequest();
// adRequest.ForceTesting = true;
// interstitialAd.LoadAd(adRequest);
// interstitialAd.ReceivedAd += OnAdReceived;
// if (p == true)
// {
// p = false;
// q = true;
// interstitialAd.ShowAd();
// }
// // NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
// // Application.Current.Terminate();
//}
/// <summary>
/// Store the page state in case application gets tombstoned.
/// </summary>
private void StoreState()
{
// Save the currently filtered image into isolated app storage.
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
myStore.CreateDirectory(TombstoneImageDir);
try
{
using (var isoFileStream = new IsolatedStorageFileStream(
TombstoneImageFile,
FileMode.OpenOrCreate,
myStore))
{
DataContext dataContext = FilterEffects.DataContext.Instance;
dataContext.FullResolutionStream.Position = 0;
dataContext.FullResolutionStream.CopyTo(isoFileStream);
isoFileStream.Flush();
}
}
catch
{
MessageBox.Show("Error while trying to store temporary image.");
}
// Save also the current preview index
State[StateIndexKey] = FilterPreviewPivot.SelectedIndex;
}
示例10: WriteXmlFile
private void WriteXmlFile(string fileName, XDocument xdoc)
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
//init folder
if (!store.DirectoryExists(@"cache"))
{
store.CreateDirectory(@"cache");
}
if (!store.DirectoryExists(@"cache/xml"))
{
store.CreateDirectory(@"cache/xml");
}
//delete existing file
if (store.FileExists(@"cache/xml/" + fileName + ".xml"))
{
store.DeleteFile(@"cache/xml/" + fileName + ".xml");
}
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(@"cache/xml/" + fileName + ".xml", System.IO.FileMode.Create, store))
{
//xdoc.Save(stream);
//convert xdoc to byte array
byte[] bytes = Encoding.UTF8.GetBytes(xdoc.ToString());
//encrypt byte array
byte[] encryptedBytes = ProtectedData.Protect(bytes, XmlOptionalEntropy);
//write encrypted byte array to file
stream.Write(encryptedBytes, 0, encryptedBytes.Length);
stream.Flush();
}
}
}
示例11: SaveFile
private void SaveFile(byte[] p_FileData, String p_FileName)
{
//MemoryStream ms = new MemoryStream(mp3Data);
using (IsolatedStorageFileStream file = new IsolatedStorageFileStream(p_FileName, FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication()))
{
file.Write(p_FileData, 0, p_FileData.Length);
file.Flush();
file.Close();
}
}
示例12: saveAudioBuffer
/// <summary>
/// Saves the audio buffer into isolated storage as a wav-file.
/// </summary>
private void saveAudioBuffer()
{
IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication();
try
{
DateTime dateTime = DateTime.Now;
string fileName = dateTime.ToString("yyyy_MM_dd_HH_mm_ss.wav");
using (var isoFileStream = new IsolatedStorageFileStream(
fileName,
FileMode.OpenOrCreate,
myStore))
{
// Write a header before the actual pcm data
int sampleBits = 16;
int sampleBytes = sampleBits / 8;
int byteRate = App.AudioModel.SampleRate * sampleBytes * App.AudioModel.ChannelCount;
int blockAlign = sampleBytes * App.AudioModel.ChannelCount;
Encoding encoding = Encoding.UTF8;
isoFileStream.Write(encoding.GetBytes("RIFF"), 0, 4); // "RIFF"
isoFileStream.Write(BitConverter.GetBytes(0), 0, 4); // Chunk Size
isoFileStream.Write(encoding.GetBytes("WAVE"), 0, 4); // Format - "Wave"
isoFileStream.Write(encoding.GetBytes("fmt "), 0, 4); // sub chunk - "fmt"
isoFileStream.Write(BitConverter.GetBytes(16), 0, 4); // sub chunk size
isoFileStream.Write(BitConverter.GetBytes((short)1), 0, 2); // audio format
isoFileStream.Write(BitConverter.GetBytes((short)App.AudioModel.ChannelCount), 0, 2); // num of channels
isoFileStream.Write(BitConverter.GetBytes(App.AudioModel.SampleRate), 0, 4); // sample rate
isoFileStream.Write(BitConverter.GetBytes(byteRate), 0, 4); // byte rate
isoFileStream.Write(BitConverter.GetBytes((short)(blockAlign)), 0, 2); // block align
isoFileStream.Write(BitConverter.GetBytes((short)(sampleBits)), 0, 2); // bits per sample
isoFileStream.Write(encoding.GetBytes("data"), 0, 4); // sub chunk - "data"
isoFileStream.Write(BitConverter.GetBytes(0), 0, 4); // sub chunk size
// write the actual pcm data
App.AudioModel.stream.Position = 0;
App.AudioModel.stream.CopyTo(isoFileStream);
// and fill in the blanks
long previousPos = isoFileStream.Position;
isoFileStream.Seek(4, SeekOrigin.Begin);
isoFileStream.Write(BitConverter.GetBytes((int)isoFileStream.Length - 8), 0, 4);
isoFileStream.Seek(40, SeekOrigin.Begin);
isoFileStream.Write(BitConverter.GetBytes((int)isoFileStream.Length - 44), 0, 4);
isoFileStream.Seek(previousPos, SeekOrigin.Begin);
isoFileStream.Flush();
}
}
catch
{
MessageBox.Show("Error while trying to store audio stream.");
}
}
示例13: StopRecordVoice
/// <summary>
/// 停止录音
/// </summary>
private void StopRecordVoice()
{
IsRecord = false;
RecordButton.Content = "Save...";
RecordButton.Foreground = App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush;
RecordButton.Background = App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;
gSpendTime = 0;
if (gMicrophone.State == MicrophoneState.Started)
{
gMicrophone.Stop();
gStream.Close();
}
MemoryStream m = new MemoryStream();
int s = gMicrophone.SampleRate / 2;
WavHeader.WriteWavHeader(m, s);
byte[] b = NormalizeWaveData(gStream.ToArray());
m.Write(b, 0, b.Length);
m.Flush();
WavHeader.UpdateWavHeader(m);
using (var tStore = IsolatedStorageFile.GetUserStoreForApplication())
{
string savepath = DateTime.Now.ToString();
savepath = savepath.Replace('/', '-');
savepath = savepath.Replace(':', ' ');
using (var tFStream = new IsolatedStorageFileStream(savepath + ".wav", FileMode.Create, tStore))
{
byte[] tByteInStream = m.ToArray();
tFStream.Write(tByteInStream, 0, tByteInStream.Length);
tFStream.Flush();
}
}
gStream = new MemoryStream();
UpdataListBox();
RecordButton.Content = "Record";
}
示例14: Write
private void Write (string filename)
{
byte[] buffer = new byte[8];
using (IsolatedStorageFileStream write = new IsolatedStorageFileStream (filename, FileMode.Create, FileAccess.Write)) {
Assert.IsFalse (write.CanRead, "write.CanRead");
Assert.IsTrue (write.CanSeek, "write.CanSeek");
Assert.IsTrue (write.CanWrite, "write.CanWrite");
Assert.IsFalse (write.IsAsync, "write.IsAync");
write.Write (buffer, 0, buffer.Length);
write.Position = 0;
write.WriteByte ((byte)buffer.Length);
write.SetLength (8);
write.Flush ();
write.Close ();
}
}
示例15: Save
/// <summary>
/// Saves all sections. All data merged from other merged sources will
/// be included.
/// </summary>
public override void Save()
{
using ( IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetStore( Scope, null, null ) )
{
using ( var isoStream =
new IsolatedStorageFileStream( _fileName,
FileMode.Truncate,
FileAccess.Write,
FileShare.Read,
isolatedStorageFile ) )
{
string xml = XmlConfigurationSource.ToXml( Sections.Values );
byte[] xmlBytes = Encoding.UTF8.GetBytes( xml );
isoStream.Write( xmlBytes, 0, xmlBytes.Length );
isoStream.Flush();
}
}
}