当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.MemoryStream.GetBuffer方法代码示例

本文整理汇总了C#中System.IO.MemoryStream.GetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.GetBuffer方法的具体用法?C# System.IO.MemoryStream.GetBuffer怎么用?C# System.IO.MemoryStream.GetBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.MemoryStream的用法示例。


在下文中一共展示了System.IO.MemoryStream.GetBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMessageData

        public override IData GetMessageData(IList<Message> messages)
        {
            Beetle.Express.IData data = null;
            byte[] buffer;
            long index = 0;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                foreach (Message message in messages)
                {

                    stream.Write(new byte[4], 0, 4);
                    byte[] typedata = MessageCenter.GetMessageTypeData(message.Type);
                    stream.Write(typedata, 0, typedata.Length);
                    if (message.Value != null)
                    {
                        var serializer = SerializationContext.Default.GetSerializer(message.Type);
                        serializer.Pack(stream, message.Value);
                    }
                    buffer = stream.GetBuffer();
                    BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
                    index = stream.Position;
                }

                data = new Data(stream.GetBuffer(), (int)stream.Length);
                data.Tag = messages;

            }
            return data;
        }
开发者ID:qcjxberin,项目名称:ec,代码行数:29,代码来源:MsgPackPacket.cs

示例2: BarcodeForm

        public BarcodeForm()
        {
            InitializeComponent();
            try
            {
                string sPath="";
                if (isIntermec)
                    sPath = "MEFdemo1.HAL.Intermec.*Control*.dll";
                else
                    sPath = "MEFdemo1.HAL.ACME.*Control*.dll";

                //I was unable to use the different catalog and let it look in a subfolder
                //so the plugin names are used as a filter
                catalog2 = new DirectoryCatalog(".", sPath);

                foreach (string s in catalog2.LoadedFiles)
                    System.Diagnostics.Debug.WriteLine(s);

                container2 = new CompositionContainer(catalog2);

            #if DEBUG
                //some diagnostics...
                //see http://mef.codeplex.com/wikipage?title=Debugging%20and%20Diagnostics&referringTitle=Guide
                // using Samples\.... as in MEF preview 7 and 8
                CompositionInfo ci = new CompositionInfo(catalog2, container2);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                System.IO.TextWriter tw = new System.IO.StreamWriter(ms);
                CompositionInfoTextFormatter.Write(ci, tw);
                System.Diagnostics.Debug.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer(), 0, ms.GetBuffer().Length));
                foreach (PartDefinitionInfo pi in ci.PartDefinitions)
                {
                    System.Diagnostics.Debug.WriteLine("isRejected: " + pi.IsRejected.ToString());
                    System.Diagnostics.Debug.WriteLine("partInfo: " + pi.PartDefinition.ToString());
                }
                tw.Close();
            #endif
                container2.ComposeParts(this);
                initBarcode();
            }
            catch (Exception ex)
            {
                if (ex is ChangeRejectedException)
                    MessageBox.Show("HW-Components not found!");
                else
                    MessageBox.Show("Exception in ComposeParts: " + ex.Message + "\n" + ex.StackTrace);
                this.Close();
            }
        }
开发者ID:grothag,项目名称:pocketmef,代码行数:48,代码来源:BarcodeForm.cs

示例3: TestStreams

                public void TestStreams()
                {
                    Variant dict = new Variant(Variant.EnumType.Dictionary);
                    dict.Add("key1", new Variant("value1"));
                    dict.Add("key2", new Variant("value2"));

                    Variant input = new Variant(Variant.EnumType.List);
                    for (int i = 0; i < 10000; ++i)
                    {
                        input.Add(dict);
                    }

                    System.IO.MemoryStream istream = new System.IO.MemoryStream();
                    using(BinaryWriter writer = new BinaryWriter(istream))
                    {
                        writer.Write(input);
                    }

                    Variant output;
                    System.IO.MemoryStream ostream = new System.IO.MemoryStream(istream.GetBuffer());
                    using (BinaryReader reader = new BinaryReader(ostream))
                    {
                        output = reader.Read();
                    }

                    Assert.True(input.Equals(output));
                }
开发者ID:rokstrnisa,项目名称:protean,代码行数:27,代码来源:TestBinaryStreams.cs

示例4: GetMessagesData

        public override IData GetMessagesData(IList<Message> messages)
        {
            IData data = null;
            byte[] buffer;
            long index = 0;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                foreach (Message message in messages)
                {
                    stream.Write(new byte[4], 0, 4);
                    short typevalue = TypeMapper.GetValue(message.Type);
                    if (typevalue == 0)
						throw new Exception (string.Format ("{0} type value not registed", message.Type));
                      
                    byte[] typedata = BitConverter.GetBytes(typevalue);
                    stream.Write(typedata, 0, typedata.Length);
                    if (message.Value != null)
                        ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message.Value);
                    buffer = stream.GetBuffer();
                    BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
                    index = stream.Position;
                }
                byte[] array = stream.ToArray();
                data = new Data(array,0, array.Length);
             

            }
            return data;
        }
开发者ID:kueiwa,项目名称:EC.Clients,代码行数:29,代码来源:ProtobufPacket.cs

示例5: DecodeResponse

		private async Task<string> DecodeResponse(HttpWebResponse response)
		{
			foreach (System.Net.Cookie cookie in response.Cookies)
			{
				_cookies.Add(new Uri(response.ResponseUri.GetLeftPart(UriPartial.Authority)), cookie);
			}

			if (response.StatusCode == HttpStatusCode.Redirect)
			{
				var location = response.Headers[HttpResponseHeader.Location];
				if (!string.IsNullOrEmpty(location))
					return await Get(new Uri(location));
			}	
			
			var stream = response.GetResponseStream();
			var buffer = new System.IO.MemoryStream();
			var block = new byte[65536];
			var blockLength = 0;
			do{
				blockLength = stream.Read(block, 0, block.Length);
				buffer.Write(block, 0, blockLength);
			}
			while(blockLength == block.Length);

			return Encoding.UTF8.GetString(buffer.GetBuffer());
		}
开发者ID:malteclasen,项目名称:DracWake,代码行数:26,代码来源:WebClient.cs

示例6: ActualizarUsuario

        public void ActualizarUsuario(String user, String Pwd, String PwdRecover, String PwdAnswer, PictureBox pb)
        {
            try
            {
                sql = new SqlConnection(CadCon.Servidor());
                sql.Open();
                string query = "ActualizarUsuario";
                cmd = new SqlCommand(query, sql);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.Add("@usuario", SqlDbType.NVarChar);
                cmd.Parameters.Add("@pass", SqlDbType.NVarChar);
                cmd.Parameters.Add("@PwdRecover", SqlDbType.NVarChar);
                cmd.Parameters.Add("@PwdAnswer", SqlDbType.NVarChar);
                cmd.Parameters.Add("@Foto", SqlDbType.Image);

                cmd.Parameters["@usuario"].Value = user;
                cmd.Parameters["@pass"].Value = Pwd;
                cmd.Parameters["@PwdRecover"].Value = PwdRecover;
                cmd.Parameters["@PwdAnswer"].Value = PwdAnswer;

                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                pb.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                cmd.Parameters["@Foto"].Value = ms.GetBuffer();
                int f = cmd.ExecuteNonQuery();
                if (f != 0)
                {
                    MessageBox.Show("Actualizado exitosamente", "Usuario Almacenado",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmd.Dispose();
                    sql.Close();
                }
            }
            catch (SqlException ex) { MessageBox.Show(ex.Message); }
        }
开发者ID:unscharf,项目名称:Gestion-de-casting,代码行数:35,代码来源:Usuarios.cs

示例7: GetMessageData

        public override IData GetMessageData(IList<Message> messages)
        {
            Beetle.Express.IData data = null;
            byte[] buffer;
            long index = 0;
            using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
            {
                foreach (Message message in messages)
                {
                    stream.Write(new byte[4], 0, 4);
                    short typevalue = TypeMapper.GetValue(message.Type);
                    if (typevalue == 0)
                        "{0} type value not registed".ThrowError<Exception>(message.Type);
                    byte[] typedata = BitConverter.GetBytes(typevalue);
                    stream.Write(typedata, 0, typedata.Length);
                    if (message.Value != null)
                    {
                        var serializer = SerializationContext.Default.GetSerializer(message.Type);
                        serializer.Pack(stream, message.Value);
                    }
                    buffer = stream.GetBuffer();
                    BitConverter.GetBytes((int)stream.Length - 4 - (int)index).CopyTo(buffer, index);
                    index = stream.Position;
                }
                byte[] array = stream.ToArray();
                data = new Data(array, array.Length);
                data.Tag = messages;

            }
            return data;
        }
开发者ID:qcjxberin,项目名称:ec,代码行数:31,代码来源:MsgPackPacket.cs

示例8: CreateImageCode

 public FileContentResult CreateImageCode()
 {
     string code = CreateVerifyCode(4);
     Session["PictureCode"] = code.ToUpper();
     int fSize = FontSize;
     int fWidth = fSize + Padding;
     int imageWidth = (int)(code.Length * fWidth) + 4 + Padding * 2;
     int imageHeight = fSize * 2 + Padding;
     System.Drawing.Bitmap image = new System.Drawing.Bitmap(imageWidth, imageHeight);
     Graphics g = Graphics.FromImage(image);
     g.Clear(BackgroundColor);
     Random rand = new Random();
     //给背景添加随机生成的燥点
     if (this.Chaos)
     {
         Pen pen = new Pen(ChaosColor, 0);
         int c = Length * 10;
         for (int i = 0; i < c; i++)
         {
             int x = rand.Next(image.Width);
             int y = rand.Next(image.Height);
             g.DrawRectangle(pen, x, y, 1, 1);
         }
     }
     int left = 0, top = 0, top1 = 1, top2 = 1;
     int n1 = (imageHeight - FontSize - Padding * 2);
     int n2 = n1 / 4;
     top1 = n2;
     top2 = n2 * 2;
     Font f;
     Brush b;
     int cindex, findex;
     //随机字体和颜色的验证码字符
     for (int i = 0; i < code.Length; i++)
     {
         cindex = rand.Next(Colors.Length - 1);
         findex = rand.Next(Fonts.Length - 1);
         f = new System.Drawing.Font(Fonts[findex], fSize, System.Drawing.FontStyle.Bold);
         b = new System.Drawing.SolidBrush(Colors[cindex]);
         if (i % 2 == 1)
         {
             top = top2;
         }
         else
         {
             top = top1;
         }
         left = i * fWidth;
         g.DrawString(code.Substring(i, 1), f, b, left, top);
     }
     //画一个边框 边框颜色为Color.Gainsboro
     g.DrawRectangle(new Pen(Color.Gainsboro, 0), 0, 0, image.Width - 1, image.Height - 1);
     g.Dispose();
     //产生波形
     image = TwistImage(image, true, 0, 4);
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     //将图像保存到指定的流
     image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
     return File(ms.GetBuffer(), "image/JPEG");
 }
开发者ID:Aaronguo,项目名称:Fx.InformationPlatform.,代码行数:60,代码来源:CaptchaController.cs

示例9: SendMessage

        private static void SendMessage(object radarData)
        {
            try
            {
                if (server == null || server.continueUpdate)
                {
                    server = new Server(Common.ServerPort);
                    server.Start();
                }
                var data = (radarData as RadarData);

                if (data == null) return;

                if (Common.IgnoreWoWWindowActive)
                {
                    data.IsWowWindowActive = true;
                }

                byte[] buffer = null;
                using (var ms = new System.IO.MemoryStream())
                {
                    BlackRain.Serialization.BinarySerializer.SerializeObject<RadarData>(ms, data);
                    buffer = ms.GetBuffer();
                    ms.Close();
                }
                server.SendMessage(buffer);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
开发者ID:RaptorFactor,项目名称:devmaximus,代码行数:32,代码来源:Program.cs

示例10: WritePacket

 public byte[] WritePacket(SLPacket packet)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(packet.GetType());
     serializer.Serialize(ms, packet);
     return ms.GetBuffer();
 }
开发者ID:by-Kirya,项目名称:SLan,代码行数:7,代码来源:SLPacketCreator.cs

示例11: recive

        public string recive()
        {
            System.Text.Encoding enc = System.Text.Encoding.UTF8;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            byte[] resBytes = new byte[256];
            int resSize = 0;

            if (ns.DataAvailable)
            {

                do
                {
                    //データの一部を受信する
                    resSize = ns.Read(resBytes, 0, resBytes.Length);

                    //受信したデータを蓄積する
                    ms.Write(resBytes, 0, resSize);

                    // 受信を続ける
                } while (ns.DataAvailable || resBytes[resSize - 1] != '\n');

                //受信したデータを文字列に変換
                string resMsg = enc.GetString(ms.GetBuffer(), 0, (int)ms.Length);
                ms.Close();
                //末尾の\nを削除
                resMsg = resMsg.TrimEnd('\n');

                return resMsg;
            }
            else
            {
                return "0";
            }
        }
开发者ID:kousokujin,项目名称:RemoteTaskManagerServer,代码行数:34,代码来源:tcp_connection.cs

示例12: BinaryStreamFromObject

 /// <summary>
 /// Uses the System formatters to save the MapXtreme objects in the session state as a binary blob.
 /// </summary>
 /// <param name="ser">A serializable object.</param>
 /// <remarks>If you simply send it to the Session state it will automatically extract itself the next time the user accesses the site. This allows you to deserialize certain objects when you want them. This method takes an object and saves it's binary stream.</remarks>
 /// <returns>A byte array to hold binary format version of object you passed in.</returns>
 public static byte[] BinaryStreamFromObject(object ser)
 {
     System.IO.MemoryStream memStr = new System.IO.MemoryStream();
     System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     formatter.Serialize(memStr, ser);
     return memStr.GetBuffer();
 }
开发者ID:rupeshkumar399,项目名称:seemapcell,代码行数:13,代码来源:ManualSerializer.cs

示例13: btnAdd_Click

        private void btnAdd_Click(object sender, EventArgs e)
        {
            newPicture = new Images();
            newPicture.TIPO = eTipoImages.ARTICULO;
            newPicture.CODIGO = COD_ARTICULO;
            // Se crea el OpenFileDialog
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.Filter = "Bitmap files (*.bmp)|*.bmp|Gif files (*.gif)|*.gif|JGP files (*.jpg)|*.jpg|All (*.*)|*.* |PNG (*.*)|*.png ";
            // Se muestra al usuario esperando una acción
            DialogResult result = dialog.ShowDialog();
            // Si seleccionó un archivo (asumiendo que es una imagen lo que seleccionó)
            // la mostramos en el PictureBox de la inferfaz
            if (result == DialogResult.OK)
            {
                IMAGEN.BackgroundImage = Image.FromFile(dialog.FileName);
                // Stream usado como buffer
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                // Se guarda la imagen en el buffer
                IMAGEN.BackgroundImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                // Se extraen los bytes del buffer para asignarlos como valor para el
                // parámetro.
                newPicture.IMAGEN = ms.GetBuffer();
                DialogResult guardar = MessageBox.Show("¿Guardar Imagen ?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (guardar == DialogResult.Yes)
                {
                    if (dbImages.guardarImagen(newPicture,HOME.Instance().USUARIO.COD_EMPLEADO))
                    {
                        cargarImagenes();
                    }
                }

            }
        }
开发者ID:Alex-Palacios,项目名称:Prendasal,代码行数:34,代码来源:FotoArticuloForm.cs

示例14: Serialize

 public byte[] Serialize(BuildInTypesDto dto)
 {
     using (var stream = new System.IO.MemoryStream())
     {
         JsonSerializer.SerializeToStream<BuildInTypesDto>(dto, stream);
         return stream.GetBuffer();
     }
 }
开发者ID:DeVZ93,项目名称:RAN_serialization,代码行数:8,代码来源:JSONStreamSerializer.cs

示例15: Serialize

 public byte[] Serialize(IDictionary<string, object> map)
 {
   using (var stream = new System.IO.MemoryStream())
   {
     serial.Serialize(stream, map);
     return stream.GetBuffer();
   }
 }
开发者ID:MarcoDorantes,项目名称:spike,代码行数:8,代码来源:Program.cs


注:本文中的System.IO.MemoryStream.GetBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。