public void TestStreamToTextOtherStream() { var stream1 = new StorageStream(new MemoryStorage()); stream1.Write(Encoding.Default.GetBytes("Hello world"), 0, 11); stream1.Seek(0, SeekOrigin.Begin); Assert.AreEqual("Hello world", stream1.ToText()); }
private void AddImages(IEnumerable <string> files) { if (files.Count() > 0) { if (items == null) { items = new List <ImageInfo>(); } //IsEnabled = false; //ProgressDialog dialog = new ProgressDialog("Progress", "Adding files..."); //dialog.Show(); try { int count = files.Count(); int index = 1; storage.StartTransaction(); foreach (string file in files) { using (StorageStream s = storage.CreateStream(Guid.NewGuid())) { using (FileStream fs = File.OpenRead(file)) { byte[] buf = new byte[65536]; int l = fs.Read(buf, 0, buf.Length); while (l > 0) { s.Write(buf, 0, l); l = fs.Read(buf, 0, buf.Length); } } items.Add(new ImageInfo() { Name = System.IO.Path.GetFileName(file), Size = (int)s.Length, StreamId = s.StreamId }); } //dialog.Progress = (double)index * 100d / (double)count; index++; } SaveImageList(); UpdateUI(); RefreshMap(imageList.SelectedValue as Guid?); storage.CommitTransaction(); } finally { //dialog.Close(); //IsEnabled = true; } } }
public void TestStreamToTextLarage() { var stream1 = new StorageStream(new MemoryStorage()); var builder = new StringBuilder(); for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++) { stream1.Write(Encoding.Default.GetBytes("1234567890"), 0, 10); builder.Append("1234567890"); } stream1.Seek(0, SeekOrigin.Begin); Assert.AreEqual(builder.ToString(), stream1.ToText()); }
public void TestChineseText() { var stream1 = new StorageStream(new MemoryStorage()); var builder = new StringBuilder(); for (var i = 0; i < (ThreadStatic.Buffer.Length / 10) + 1; i++) { var data = Encoding.UTF8.GetBytes("12中文34测试的5这是67890"); stream1.Write(data, 0, data.Length); builder.Append("12中文34测试的5这是67890"); } stream1.Seek(0, SeekOrigin.Begin); Assert.AreEqual(builder.ToString(), stream1.ToText()); }
private void ReplaceImage(string file, Guid streamId) { if (file.Count() > 0) { if (items == null) { items = new List <ImageInfo>(); } using (StorageStream s = storage.OpenStream(streamId)) { using (FileStream fs = File.OpenRead(file)) { byte[] buf = new byte[65536]; int l = fs.Read(buf, 0, buf.Length); while (l > 0) { s.Write(buf, 0, l); l = fs.Read(buf, 0, buf.Length); } } ImageInfo ii = items .Where(i => i.StreamId == streamId) .First(); ii.Name = System.IO.Path.GetFileName(file); ii.Size = (int)s.Length; s.SetLength(s.Position); } SaveImageList(); UpdateUI(); RefreshMap(imageList.SelectedValue as Guid?); } }