本文整理汇总了C#中System.IO.MemoryStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.Seek方法的具体用法?C# System.IO.MemoryStream.Seek怎么用?C# System.IO.MemoryStream.Seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了System.IO.MemoryStream.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSaleRankChart
public FileResult GetSaleRankChart()
{
var gQuery = (from m in orderDetailRepo.GetWithFilterAndOrder()
group m by m.Meal.MealName into g
orderby g.Sum(item => item.Quantity * 1) descending
select new Group<string, int> { Key = g.Key, Value = g.Sum(item=> item.Quantity * 1) })
.Take(5);
var chart = new Chart();
chart.ChartAreas.Add(new ChartArea("Default"));
chart.Width = 500;
chart.Height = 400;
chart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
chart.ChartAreas["Default"].Area3DStyle.Inclination = 15;
chart.ChartAreas["Default"].Area3DStyle.Rotation = 15;
chart.Series.Add(new Series("Data"));
foreach (var item in gQuery)
{
chart.Series["Data"].Points.AddXY(item.Key, item.Value);
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
chart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, System.IO.SeekOrigin.Begin);
return File(ms, "image/png");
}
示例2: GetBytesFromBmp
private byte[] GetBytesFromBmp(System.Drawing.Image img, int visibleWidth, int visibleHeight)
{
byte[] imgBytes = new byte[visibleWidth * 3 * visibleHeight];
//since bmp format requests certain image width (of multiples of 4) we have to take padding into account
var padding = (img.Width % 4);
padding = padding == 0 ? 0 : 4 - padding;
var bitmapHeaderOffset = 54;
using (var ms = new System.IO.MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
ms.Seek(bitmapHeaderOffset, System.IO.SeekOrigin.Begin);
if (img.Height - visibleHeight > 0)
{
//3 for rgb image (1 byte for each color channel)
ms.Seek((3 * img.Width + padding) * (img.Height - visibleHeight), System.IO.SeekOrigin.Current);
}
for (int i = 0; i < visibleHeight; i++)
{
ms.Read(imgBytes, i * visibleWidth * 3, visibleWidth * 3);
ms.Seek(padding, System.IO.SeekOrigin.Current);
ms.Seek((img.Width - visibleWidth) * 3, System.IO.SeekOrigin.Current);
}
}
return imgBytes.Where((x, i) => (i + 1) % 4 != 255).ToArray();
}
示例3: TestBooleanQuerySerialization
public void TestBooleanQuerySerialization()
{
Lucene.Net.Search.BooleanQuery lucQuery = new Lucene.Net.Search.BooleanQuery();
lucQuery.Add(new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("field", "x")), Occur.MUST);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bf.Serialize(ms, lucQuery);
ms.Seek(0, System.IO.SeekOrigin.Begin);
Lucene.Net.Search.BooleanQuery lucQuery2 = (Lucene.Net.Search.BooleanQuery)bf.Deserialize(ms);
ms.Close();
Assert.AreEqual(lucQuery, lucQuery2, "Error in serialization");
Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir, true);
int hitCount = searcher.Search(lucQuery, 20).TotalHits;
searcher.Close();
searcher = new Lucene.Net.Search.IndexSearcher(dir, true);
int hitCount2 = searcher.Search(lucQuery2, 20).TotalHits;
Assert.AreEqual(hitCount, hitCount2, "Error in serialization - different hit counts");
}
示例4: BackupCompradoresLinkButton_Click
protected void BackupCompradoresLinkButton_Click(object sender, EventArgs e)
{
if (CedWebRN.Fun.NoEstaLogueadoUnUsuarioPremium((CedWebEntidades.Sesion)Session["Sesion"]))
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Esta funcionalidad es exclusiva del SERVICIO PREMIUM. Contáctese con Cedeira Software Factory para acceder al servicio.');</script>");
}
else
{
List<CedWebEntidades.Comprador> compradores = CedWebRN.Comprador.Lista(((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta, (CedEntidades.Sesion)Session["Sesion"], false);
if (compradores.Count == 0)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('No hay datos de Compradores para descargar.');</script>");
}
else
{
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(compradores.GetType());
System.IO.MemoryStream m = new System.IO.MemoryStream();
System.Xml.XmlWriter writerdememoria = new System.Xml.XmlTextWriter(m, System.Text.Encoding.GetEncoding("ISO-8859-1"));
x.Serialize(writerdememoria, compradores);
m.Seek(0, System.IO.SeekOrigin.Begin);
string nombreArchivo = "eFact-Compradores-" + ((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta.Id.Replace(".", String.Empty).ToUpper() + ".xml";
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(@"~/Temp/" + nombreArchivo), System.IO.FileMode.Create);
m.WriteTo(fs);
fs.Close();
Server.Transfer("~/DescargaTemporarios.aspx?archivo=" + nombreArchivo, false);
}
}
}
示例5: BinWriteDataSetToStream
private static void BinWriteDataSetToStream(System.IO.Stream stream, System.Data.DataSet ds)
{
//Version
IO.StreamPersistence.Write(stream, c_BinaryVersion);
//Schema byte[]
byte[] bytesSchema;
using (System.IO.MemoryStream schemaStream = new System.IO.MemoryStream())
{
ds.WriteXmlSchema(schemaStream);
schemaStream.Flush();
schemaStream.Seek(0, System.IO.SeekOrigin.Begin);
bytesSchema = schemaStream.ToArray();
}
IO.StreamPersistence.Write(stream, bytesSchema);
//Tables
for (int iTable = 0; iTable < ds.Tables.Count; iTable++)
{
System.Data.DataTable table = ds.Tables[iTable];
//Only the current Rows
System.Data.DataRow[] rows = table.Select(null, null, System.Data.DataViewRowState.CurrentRows);
IO.StreamPersistence.Write(stream, rows.Length);
//Rows
for (int r = 0; r < rows.Length; r++)
{
//Columns
for (int c = 0; c < table.Columns.Count; c++)
BinWriteFieldToStream(stream, rows[r][c], table.Columns[c].DataType);
}
}
}
示例6: BackupVendedorLinkButton_Click
protected void BackupVendedorLinkButton_Click(object sender, EventArgs e)
{
try
{
if (CedWebRN.Fun.NoEstaLogueadoUnUsuarioPremium((CedWebEntidades.Sesion)Session["Sesion"]))
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Esta funcionalidad es exclusiva del SERVICIO PREMIUM. Contáctese con Cedeira Software Factory para acceder al servicio.');</script>");
}
else
{
CedWebEntidades.Vendedor vendedor = new CedWebEntidades.Vendedor();
vendedor.IdCuenta = ((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta.Id;
CedWebRN.Vendedor.Leer(vendedor, (CedEntidades.Sesion)Session["Sesion"]);
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(vendedor.GetType());
System.IO.MemoryStream m = new System.IO.MemoryStream();
System.Xml.XmlWriter writerdememoria = new System.Xml.XmlTextWriter(m, System.Text.Encoding.GetEncoding("ISO-8859-1"));
x.Serialize(writerdememoria, vendedor);
m.Seek(0, System.IO.SeekOrigin.Begin);
string nombreArchivo = "eFact-Vendedor-" + ((CedWebEntidades.Sesion)Session["Sesion"]).Cuenta.Id.Replace(".", String.Empty).ToUpper() + ".xml";
System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(@"~/Temp/" + nombreArchivo), System.IO.FileMode.Create);
m.WriteTo(fs);
fs.Close();
Server.Transfer("~/DescargaTemporarios.aspx?archivo=" + nombreArchivo, false);
}
}
catch (Microsoft.ApplicationBlocks.ExceptionManagement.Validaciones.ElementoInexistente)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('No hay datos del Vendedor para descargar.');</script>");
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('" + ex.Message.ToString() + "');</script>");
}
}
示例7: ToStream
/// <summary>
/// 将 byte[] 转成 Stream
/// </summary>
/// <param name="bytes"></param>
/// <returns></returns>
private static System.IO.Stream ToStream(byte[] bytes)
{
var stream = new System.IO.MemoryStream(bytes);
// 设置当前流的位置为流的开始
stream.Seek(0, System.IO.SeekOrigin.Begin);
return stream;
}
示例8: ToStream
/// <summary>
/// string 转换为 Stream
/// </summary>
/// <returns></returns>
public static System.IO.Stream ToStream(string str)
{
System.IO.Stream stream = new System.IO.MemoryStream(ToBytes(str));
// 设置当前流的位置为流的开始
stream.Seek(0, System.IO.SeekOrigin.Begin);
return stream;
}
示例9: Deserialize
public static object Deserialize(byte[] data)
{
var tempStream = new System.IO.MemoryStream();
tempStream.Write(data, 0, data.Length);
tempStream.Seek(0, System.IO.SeekOrigin.Begin);
return formatter.Deserialize(tempStream);
}
示例10: TestSerializeSchemaPropertyValueCollection
public void TestSerializeSchemaPropertyValueCollection()
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
SchemaPropertyValueCollection obj1 = new SchemaPropertyValueCollection();
SCGroup group = SCObjectGenerator.PrepareGroupObject();
foreach (string key in group.Properties.GetAllKeys())
{
obj1.Add(group.Properties[key]);
}
bf.Serialize(ms, obj1);
ms.Seek(0, System.IO.SeekOrigin.Begin);
var obj2 = (SchemaPropertyValueCollection)bf.Deserialize(ms);
Assert.AreEqual(obj1.Count, obj2.Count);
var keys1 = obj1.GetAllKeys();
foreach (var key in keys1)
{
Assert.IsTrue(obj2.ContainsKey(key));
Assert.AreEqual(obj1[key].StringValue, obj2[key].StringValue);
}
}
示例11: save
public void save(DevExpress.XtraGrid.Views.Grid.GridView view)
{
System.IO.Stream str = new System.IO.MemoryStream();
view.SaveLayoutToStream(str);
str.Seek(0, System.IO.SeekOrigin.Begin);
System.IO.StreamReader reader = new System.IO.StreamReader(str);
layout = reader.ReadToEnd();
}
示例12: Header2
/// <summary>
/// <para>Represents the Header2 section of the EWF file.</para>
/// <para>Holds various meta-data about the acquisition.</para>
/// </summary>
/// <param name="bytes">The bytes that make up the Header2 section.</param>
public Header2(byte[] bytes)
{
string header = null; // Will eventually hold the decompressed Header2 info
#region Decompress zlib'd data
{
byte[] buff = new byte[1024];
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes))
{
using (Compression.ZlibStream zs = new Compression.ZlibStream(ms, System.IO.Compression.CompressionMode.Decompress, false))
{
using (System.IO.MemoryStream decomp = new System.IO.MemoryStream())
{
int n;
while ((n = zs.Read(buff, 0, buff.Length)) != 0)
{
decomp.Write(buff, 0, n);
}
decomp.Seek(0, System.IO.SeekOrigin.Begin);
System.IO.StreamReader sr = new System.IO.StreamReader(decomp, System.Text.Encoding.UTF8);
header = sr.ReadToEnd();
}
}
}
}
#endregion
string[] parts = header.Split(new char[] { (char)0x0A });
int catsCount = int.Parse(parts[0]);
Categories = new List<Header2Category>(catsCount);
if (catsCount == 1) // EnCase 4
{
for (int i = 0; i < parts.Length; i++) // Header seems to have 0x0A on the end
parts[i] = parts[i].TrimEnd('\r');
if (parts[1] != "main")
throw new ArgumentException(string.Format("unexpected category: {0}", parts[1]));
Categories.Add(new Header2Category("main", parts[2], parts[3]));
}
else if (catsCount == 3) // EnCase 5-7
{
if (parts[1] != "main")
throw new ArgumentException(string.Format("unexpected category: {0}", parts[1]));
Categories.Add(new Header2Category("main", parts[2], parts[3]));
if (parts[5] != "srce")
throw new ArgumentException(string.Format("unexpected category: {0}", parts[5]));
Categories.Add(new Header2Category("srce", parts[7], parts[9]));
if (parts[11] != "sub")
throw new ArgumentException(string.Format("unexpected category: {0}", parts[13]));
Categories.Add(new Header2Category("sub", parts[13], parts[15]));
}
else
{
throw new ArgumentException(string.Format("unknown category layout ({0} categories)", catsCount));
}
}
示例13: Main
public static void Main()
{
Framework.Program.Initial();
//學校組態基本上就是儲存在 App.Configuration 之中。
Class.Instance.SyncAllBackground();
Class.Instance.WaitLoadingComplete();
Student.Instance.SyncAllBackground();
Student.Instance.WaitLoadingComplete();
Teacher.Instance.SyncAllBackground();
Teacher.Instance.WaitLoadingComplete();
Course.Instance.SyncAllBackground();
Course.Instance.WaitLoadingComplete();
Student.Instance.SetupPresentation();
Class.Instance.SetupPresentation();
Teacher.Instance.SetupPresentation();
Course.Instance.SetupPresentation();
//設定 ASPOSE 元件的 License。
System.IO.Stream stream = new System.IO.MemoryStream(Properties.Resources.Aspose_Total);
stream.Seek(0, System.IO.SeekOrigin.Begin);
new Aspose.Cells.License().SetLicense(stream);
FISCA.LogAgent.ApplicationLog.Log("[特殊歷程]", "登入", string.Format("使用者{0}已登入系統", FISCA.Authentication.DSAServices.UserAccount));
// 變更使用者密碼
FISCA.Presentation.MotherForm.StartMenu["安全性"].BeginGroup = true;
FISCA.Presentation.MotherForm.StartMenu["安全性"].Image = Properties.Resources.foreign_key_lock_64;
FISCA.Presentation.MotherForm.StartMenu["安全性"]["變更密碼"].Enable = User.Acl["StartButton0004"].Executable;
FISCA.Presentation.MotherForm.StartMenu["安全性"]["變更密碼"].Click += delegate
{
UserInfoManager uim = new UserInfoManager();
uim.ShowDialog();
};
// 管理學校基本資料
FISCA.Presentation.MotherForm.StartMenu["管理學校基本資料"].Image = Properties.Resources.school_fav_64;
FISCA.Presentation.MotherForm.StartMenu["管理學校基本資料"].Enable = User.Acl["StartButton0003"].Executable;
FISCA.Presentation.MotherForm.StartMenu["管理學校基本資料"].Click += delegate
{
SchoolInfoMangement sim = new SchoolInfoMangement();
sim.ShowDialog();
};
Framework.Security.RoleAclSource.Instance["系統"].Add(new Framework.Security.RibbonFeature("StartButton0003", "管理學校基本資料"));
Framework.Security.RoleAclSource.Instance["系統"].Add(new Framework.Security.RibbonFeature("StartButton0004", "變更密碼"));
FISCA.Presentation.MotherForm.StartMenu["重新登入"].Image = Properties.Resources.world_upload_64;
FISCA.Presentation.MotherForm.StartMenu["重新登入"].BeginGroup = true;
FISCA.Presentation.MotherForm.StartMenu["重新登入"].Click += new EventHandler(Restart_Click);
//設定畫面選取Count
SelectedListChanged();
}
示例14: Bitmap2Texture
/// <summary>
/// Build's a <see cref="Texture2D"/> from an <see cref="Bitmap"/>
/// </summary>
/// <param name="Bitmap"></param>
/// <returns></returns>
public static Texture2D Bitmap2Texture(System.Drawing.Bitmap Bitmap, GraphicsDevice gd) {
Texture2D texture = null;
using (System.IO.MemoryStream s = new System.IO.MemoryStream()) {
Bitmap.Save(s, System.Drawing.Imaging.ImageFormat.Png);
s.Seek(0, System.IO.SeekOrigin.Begin);
texture = Texture2D.FromStream(gd, s);
}
return texture;
}
示例15: ToXml
public System.IO.MemoryStream ToXml(object o)
{
var result = new System.IO.MemoryStream();
if (o == null)
{
return result;
}
using (var writer = XmlDictionaryWriter.CreateTextWriter(result, Encoding.UTF8, false))
{
var serializer = serializers[o.GetType()];
serializer.WriteObject(writer, o);
}
result.Seek(0, System.IO.SeekOrigin.Begin);
if (WorkContext.IsMono)
{
var xml = new XmlDocument();
xml.PreserveWhitespace = true;
xml.Load(result);
result.Close();
//remove incorrect ns
foreach (XmlNode entry in xml.SelectNodes("//entry"))
{
var nsattr = entry.Attributes.Cast<XmlAttribute>().FirstOrDefault(a => a.Value == typeof(FileEntry).Name);
if (nsattr != null)
{
foreach (XmlAttribute a in entry.Attributes)
{
if (a.Value.StartsWith(nsattr.LocalName + ":"))
{
a.Value = a.Value.Substring(nsattr.LocalName.Length + 1);
}
}
entry.Attributes.Remove(nsattr);
}
}
//http://stackoverflow.com/questions/13483138/mono-does-not-honor-system-runtime-serialization-datamemberattribute-emitdefault
var nsmanager = new XmlNamespaceManager(xml.NameTable);
nsmanager.AddNamespace("i", "http://www.w3.org/2001/XMLSchema-instance");
foreach (XmlNode nil in xml.SelectNodes("//*[@i:nil='true']", nsmanager))
{
nil.ParentNode.RemoveChild(nil);
}
result = new System.IO.MemoryStream();
xml.Save(result);
result.Seek(0, System.IO.SeekOrigin.Begin);
}
return result;
}