本文整理汇总了C#中System.IO.IsolatedStorage.IsolatedStorageFileStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# IsolatedStorageFileStream.Seek方法的具体用法?C# IsolatedStorageFileStream.Seek怎么用?C# IsolatedStorageFileStream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.IsolatedStorage.IsolatedStorageFileStream
的用法示例。
在下文中一共展示了IsolatedStorageFileStream.Seek方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenLog
/// <summary>
/// Opens logs file
/// </summary>
private static void OpenLog()
{
try
{
var storageFile = GetIsolatedStorageFile();
_storageFileStream = storageFile.OpenFile(_logFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete);
_storageFileStream.Seek(0, SeekOrigin.End);
_streamWriter = new StreamWriter(_storageFileStream);
_streamWriter.AutoFlush = true;
_isLogFileOpen = true;
}
catch
{
// we fail silently because logging trouble should not affect the end users
}
}
示例2: Open
/// <include file='Doc/Wrappers.xml' path='docs/method[@name="Open"]/*'/>
public override PhpStream Open(ref string path, string mode, StreamOpenOptions options, StreamContext context)
{
Debug.Assert(path != null);
//Debug.Assert(PhpPath.IsLocalFile(path));
// Get the File.Open modes from the mode string
FileMode fileMode;
FileAccess fileAccess;
StreamAccessOptions ao;
if (!ParseMode(mode, options, out fileMode, out fileAccess, out ao)) return null;
// Open the native stream
this.storageFile = IsolatedStorageFile.GetUserStoreForApplication();
FileStream stream = null;
try
{
stream = new IsolatedStorageFileStream(path, fileMode, fileAccess, FileShare.ReadWrite | FileShare.Delete, storageFile);
}
catch (FileNotFoundException)
{
// Note: There may still be an URL in the path here.
PhpException.Throw(PhpError.Warning, CoreResources.GetString("stream_file_not_exists",
FileSystemUtils.StripPassword(path)));
return null;
}
catch (IOException e)
{
if ((ao & StreamAccessOptions.Exclusive) > 0)
{
PhpException.Throw(PhpError.Warning, CoreResources.GetString("stream_file_exists",
FileSystemUtils.StripPassword(path)));
}
else
{
PhpException.Throw(PhpError.Warning, CoreResources.GetString("stream_file_io_error",
FileSystemUtils.StripPassword(path), PhpException.ToErrorMessage(e.Message)));
}
return null;
}
catch (UnauthorizedAccessException)
{
PhpException.Throw(PhpError.Warning, CoreResources.GetString("stream_file_access_denied",
FileSystemUtils.StripPassword(path)));
return null;
}
catch (Exception)
{
PhpException.Throw(PhpError.Warning, CoreResources.GetString("stream_file_invalid",
FileSystemUtils.StripPassword(path)));
return null;
}
if ((ao & StreamAccessOptions.SeekEnd) > 0)
{
// Read/Write Append is not supported. Seek to the end of file manually.
stream.Seek(0, SeekOrigin.End);
}
if ((ao & StreamAccessOptions.Temporary) > 0)
{
// Set the file attributes to Temporary too.
File.SetAttributes(path, FileAttributes.Temporary);
}
return new NativeStream(stream, this, ao, path, context);
}
示例3: DoOPMLExport
private void DoOPMLExport()
{
String dateCreated = DateTime.Now.ToString("r");
String opmlExportFileName = String.Format("PodcatcherSubscriptions_{0}.opml.xml", DateTime.Now.ToString("dd_MM_yyyy"));
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(opmlExportFileName, FileMode.Create, myIsolatedStorage);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(isoStream, settings))
{
/** OPML root */
writer.WriteStartElement("opml");
writer.WriteAttributeString("version", "2.0");
/** Head */
writer.WriteStartElement("head");
// title
writer.WriteStartElement("title");
writer.WriteString("My subscriptions from Podcatcher");
writer.WriteEndElement();
// dateCreated
writer.WriteStartElement("dateCreated");
writer.WriteString(dateCreated);
writer.WriteEndElement();
/** End Head */
writer.WriteEndElement();
/** Body */
writer.WriteStartElement("body");
// Each outline
List<PodcastSubscriptionModel> subscriptions = App.mainViewModels.PodcastSubscriptions.ToList();
foreach (PodcastSubscriptionModel s in subscriptions)
{
writer.WriteStartElement("outline");
writer.WriteAttributeString("title", s.PodcastName);
writer.WriteAttributeString("xmlUrl", s.PodcastRSSUrl);
writer.WriteAttributeString("type", "rss");
writer.WriteAttributeString("text", s.PodcastDescription);
writer.WriteEndElement();
}
/** End Body */
writer.WriteEndElement();
// Finish the document
writer.WriteEndDocument();
writer.Flush();
}
isoStream.Seek(0, SeekOrigin.Begin);
using (var db = new PodcastSqlModel())
{
if (db.settings().SelectedExportIndex == (int)SettingsModel.ExportMode.ExportToOneDrive)
{
SubscriptionManagerArgs args = new SubscriptionManagerArgs();
args.state = SubscriptionsState.StartedOneDriveExport;
OnOPMLExportToOneDriveChanged(this, args);
exportToOneDrive(opmlExportFileName, isoStream);
}
else if (db.settings().SelectedExportIndex == (int)SettingsModel.ExportMode.ExportViaEmail)
{
exportViaEmail(isoStream);
}
}
}
}
示例4: Seek
public void Seek ()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication ();
using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream ("moon", FileMode.Create, isf)) {
fs.Seek (0, SeekOrigin.Begin);
isf.Remove (); // this removed everything
Assert.Throws (delegate { fs.Seek (0, SeekOrigin.Begin); }, typeof (IsolatedStorageException), "Remove/Write"); // Fails in Silverlight 3
isf.Dispose ();
Assert.Throws (delegate { fs.Seek (0, SeekOrigin.Begin); }, typeof (ObjectDisposedException), "Dispose/Write");
}
isf = IsolatedStorageFile.GetUserStoreForApplication ();
Assert.AreEqual (0, isf.GetFileNames ().Length, "Empty");
}
示例5: button1_Click_1
/* private void LayoutRoot_Unloaded(object sender, RoutedEventArgs e)
{
Sender.DetachDuplexOutputChannel();
}*/
private void button1_Click_1(object sender, RoutedEventArgs e)
{
textBox4.Text = "test";
textBox2.Text = "";
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream stream = new IsolatedStorageFileStream("Intro English.jpg", FileMode.Open, fileStorage);
//textBox4.Text = "1 step passed!";
var image = new BitmapImage();
// textBox4.Text = "2 step passed!";
image.SetSource(stream);
//textBox4.Text = "3 step passed!";
image1.Source = image;
//textBox4.Text = "4 step passed!";
//stream.Seek(0,0);
/*for (int i = 0; i < stream.Length; i++)
{
file[i] = stream.Read(
}*/
//string sim = "";
byte[] img = new byte[stream.Length];
long seekPos = stream.Seek(0, SeekOrigin.Begin);
stream.Read(img, 0, img.Length);
seekPos = stream.Seek(0, SeekOrigin.Begin);
/* var cnt = 0;
foreach (byte x in img)
{
textBox4.Text = cnt.ToString() + ":" + x.ToString();
cnt++;
}*/
textBox4.Text = img[3000].ToString();
/* IPAddress ipa = IPAddress.Parse("127.0.0.1");
IPEndPoint end = new IPEndPoint(ipa, 8001);*/
TcpClient to_transmit = new TcpClient("127.0.0.1",8001);
// to_transmit.Connect(textBox1.Text, 8001);
//to_transmit.Connect(end);
NetworkStream trans_stream = to_transmit.GetStream();
trans_stream.Write(img, 0, img.Length);
if (to_transmit.Connected != true) textBox4.Text = "Conn error!";
byte[] resp = new byte[1000000];
int max = trans_stream.Read(resp, 0, 1000000);
for (int i = 0; i < max; i++) textBox2.Text += Convert.ToChar(resp[i]);
trans_stream.Dispose();
to_transmit.Dispose();
//to_transmit.EndConnect();
//textBox4.Text = stream.Length.ToString();
}
示例6: 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.");
}
}
示例7: downloadClient_OpenReadCompleted
void downloadClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try
{
using (var strm = e.Result)
{
using (var isofile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var isoFileStream = new IsolatedStorageFileStream(mp3name,FileMode.Create, isofile))
{
int read;
var buffer = new byte[10000];
while ((read = strm.Read(buffer, 0, buffer.Length)) > 0)
{
isoFileStream.Write(buffer, 0, read);
}
isoFileStream.Seek(0, SeekOrigin.Begin);
player.SetSource(isoFileStream);
player.Play();
//player.Position = TimeSpan.FromSeconds(App.DWModel.DWArtical.ProgressValue * TotalTime.TotalSeconds);
App.DWModel.DWArtical.Visibility = Visibility.Collapsed;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
App.DWModel.DWArtical.Visibility = Visibility.Collapsed;
}
}
示例8: Read
private void Read (string filename)
{
byte[] buffer = new byte[8];
using (IsolatedStorageFileStream read = new IsolatedStorageFileStream (filename, FileMode.Open, FileAccess.Read)) {
Assert.AreEqual (8, read.Length, "Length");
Assert.AreEqual (0, read.Position, "Position");
Assert.IsTrue (read.CanRead, "read.CanRead");
Assert.IsTrue (read.CanSeek, "read.CanSeek");
Assert.IsFalse (read.CanWrite, "read.CanWrite");
Assert.IsFalse (read.IsAsync, "read.IsAync");
Assert.AreEqual (buffer.Length, read.ReadByte (), "ReadByte");
read.Seek (0, SeekOrigin.Begin);
Assert.AreEqual (buffer.Length, read.Read (buffer, 0, buffer.Length), "Read");
read.Close ();
}
}
示例9: ReadSaveJsonFromFile
/// <summary>
/// Read Save File from local file
/// </summary>
/// <param name="filename">Filename</param>
/// <returns>Json String</returns>
public static string ReadSaveJsonFromFile(string filename)
{
string saveJsonStr = string.Empty;
IsolatedStorageFile isolateStorageFile = IsolatedStorageFile.GetUserStoreForApplication();
string filePath = filename + ".txt";
if (CheckFileIsExist(filename))
{
using (IsolatedStorageFileStream readStream = new IsolatedStorageFileStream(filePath, FileMode.Open, isolateStorageFile))
{
readStream.Seek(0, SeekOrigin.Begin);
using (StreamReader streamReader = new StreamReader(readStream))
{
saveJsonStr = streamReader.ReadToEnd();
}
}
}
return saveJsonStr;
}
示例10: button1_Click_1
/* private void LayoutRoot_Unloaded(object sender, RoutedEventArgs e)
{
Sender.DetachDuplexOutputChannel();
}*/
private void button1_Click_1(object sender, RoutedEventArgs e)
{
textBox4.Text = "test";
textBox2.Text = "";
IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream stream = new IsolatedStorageFileStream("Intro English.jpg", FileMode.Open, fileStorage);
//textBox4.Text = "1 step passed!";
var image = new BitmapImage();
// textBox4.Text = "2 step passed!";
image.SetSource(stream);
//textBox4.Text = "3 step passed!";
image1.Source = image;
//textBox4.Text = "4 step passed!";
//stream.Seek(0,0);
/*for (int i = 0; i < stream.Length; i++)
{
file[i] = stream.Read(
}*/
//string sim = "";
byte[] img = new byte[stream.Length];
long seekPos = stream.Seek(0, SeekOrigin.Begin);
stream.Read(img, 0, img.Length);
seekPos = stream.Seek(0, SeekOrigin.Begin);
/* var cnt = 0;
foreach (byte x in img)
{
textBox4.Text = cnt.ToString() + ":" + x.ToString();
cnt++;
}*/
textBox4.Text = img[3000].ToString();
OcrService.RecognizeImageAsync(HawaiiClient.HawaiiApplicationId, img, (output) => { this.Dispatcher.BeginInvoke(() => rozpoznany(output)); });
//textBox4.Text = stream.Length.ToString();
}
示例11: DownloadFile
public void DownloadFile(string url)
{
request = (HttpWebRequest)WebRequest.Create(new Uri(url));
request.AllowReadStreamBuffering = false;
request.Method = "get";
request.Headers["Range"] = "bytes=" + ((int)currentDownVideo.Loadedsize).ToString() + "-";
WebHeaderCollection WebHeaderCollection = new WebHeaderCollection();
string[] headers = WebHeaderCollection.AllKeys;
request.BeginGetResponse(new AsyncCallback(GetVideoData), request);
string fileName = CommonData.videoSavePath + currentDownVideo.VideoId.ToString() + ".mp4";
Debug.WriteLine("文件路径:"+fileName);
if (!WpStorage.isoFile.FileExists(fileName))
{
string strBaseDir = string.Empty;
string delimStr = "\\";
char[] delimiter = delimStr.ToCharArray();
string[] dirsPath = fileName.Split(delimiter);
for (int i = 0; i < dirsPath.Length - 1; i++)
{
strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
WpStorage.isoFile.CreateDirectory(strBaseDir);
}
}
streamToWriteTo = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, WpStorage.isoFile);
if (currentDownVideo.Loadedsize > 0)
{
streamToWriteTo.Seek((long)currentDownVideo.Loadedsize,SeekOrigin.Current);
}
//streamToWriteTo.Position = (long)currentDownVideo.Loadedsize;
}