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


C# System.IO.BinaryReader.ReadBytes方法代码示例

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


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

示例1: Parse

        public void Parse(Header header, byte[] data)
        {
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data))
            {
                using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
                {
                    _authCode = br.ReadInt32();
                    _accountId = br.ReadUInt32();
                    _userLevel = br.ReadUInt32();
                    _lastLoginIP = br.ReadUInt32();
                    _lastLoginTime = br.ReadBytes(26);
                    _sex = br.ReadByte();

                    _serverList = new Dictionary<string, Server>();
                    for (int i = (int)ms.Position; i < header.Size; i += 32)
                    {
                        Server s = new Server();
                        s.IP = string.Format("{0}.{1}.{2}.{3}", br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte());
                        s.Port = br.ReadInt16();
                        s.Name = br.ReadBytes(22).NullByteTerminatedString();
                        s.Type = br.ReadInt16();
                        s.UserCount = br.ReadInt16();
                        _serverList.Add(s.Name, s);
                    }
                }
            }
        }
开发者ID:scriptord3,项目名称:Mjolnir,代码行数:27,代码来源:Accept_Login.cs

示例2: parse

        public static MidiData parse(FileStream input_file_stream)
        {
            var input_binary_reader = new BinaryReader(input_file_stream);

            HeaderChunk header_chunk;
            ushort number_of_tracks;
            {
                var header_chunk_ID = stringEncoder.GetString(input_binary_reader.ReadBytes(4));
                var header_chunk_size = BitConverter.ToInt32(input_binary_reader.ReadBytes(4).Reverse().ToArray<byte>(), 0);
                var header_chunk_data = input_binary_reader.ReadBytes(header_chunk_size);

                var format_type = BitConverter.ToUInt16(header_chunk_data.Take(2).Reverse().ToArray<byte>(), 0);
                number_of_tracks = BitConverter.ToUInt16(header_chunk_data.Skip(2).Take(2).Reverse().ToArray<byte>(), 0);
                var time_division = BitConverter.ToUInt16(header_chunk_data.Skip(4).Take(2).Reverse().ToArray<byte>(), 0);

                header_chunk = new HeaderChunk(format_type, time_division);
            }

            var tracks =
                Enumerable.Range(0, number_of_tracks)
                .Select(track_number =>
                {
                    var track_chunk_ID = stringEncoder.GetString(input_binary_reader.ReadBytes(4));
                    var track_chunk_size = BitConverter.ToInt32(input_binary_reader.ReadBytes(4).Reverse().ToArray<byte>(), 0);
                    var track_chunk_data = input_binary_reader.ReadBytes(track_chunk_size);

                    return Tuple.Create(track_chunk_size, track_chunk_data);
                }).ToList()
                .Select(raw_track => new TrackChunk(parse_events(raw_track.Item2, raw_track.Item1)));

            return new MidiData(header_chunk, tracks);
        }
开发者ID:OpaqueMegane,项目名称:Unity-Midi-Parser,代码行数:32,代码来源:FileParser.cs

示例3: Deserialize

 public static PushChunksRequestMessage Deserialize(byte[] bytes)
 {
     Guid requestID;
     Guid chunks;
     using (System.IO.MemoryStream MS = new System.IO.MemoryStream (bytes, false)) {
         using (System.IO.BinaryReader BR = new System.IO.BinaryReader (MS)) {
             requestID = new Guid (BR.ReadBytes (16));
             chunks = new Guid (BR.ReadBytes (16));
         }
     }
     return new PushChunksRequestMessage (requestID, chunks);
 }
开发者ID:vebin,项目名称:BD2,代码行数:12,代码来源:PollChunksResponseMessage.cs

示例4: Deserialize

 public static ChunkRangesRequest Deserialize(byte[] bytes)
 {
     Tuple<byte[],byte[]>[] ranges;
     using (System.IO.MemoryStream MS  = new System.IO.MemoryStream (bytes,false)) {
         using (System.IO.BinaryReader BR= new System.IO.BinaryReader(MS)) {
             ranges = new Tuple<byte[], byte[]>[BR.ReadInt32 ()];
             for (int n = 0; n != ranges.Length; n++) {
                 ranges [n] = new Tuple<byte[], byte[]> (BR.ReadBytes (BR.ReadInt32 ()), BR.ReadBytes (BR.ReadInt32 ()));
             }
         }
         return new ChunkRangesRequest (ranges);
     }
 }
开发者ID:vebin,项目名称:BD2,代码行数:13,代码来源:ChunkRangesRequest.cs

示例5: Create

        public ActionResult Create([Bind(Include = "IDPublicacion,IDMarca,IDModelo,Precio,IDColor,IDTipoCombustible,IDTipoVehiculo,IDCondicion,IDUser,WDate,Status")] Publicacion publicacion, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var avatar = new File
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        FileType = FileType.Avatar,
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        avatar.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    publicacion.Files = new List<File> { avatar };
                }
                db.Publicaciones.Add(publicacion);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.IDColor = new SelectList(db.Colores, "IDColor", "colorDesc", publicacion.IDColor);
            ViewBag.IDCondicion = new SelectList(db.Condiciones, "IDCondicion", "condicionDesc", publicacion.IDCondicion);
            ViewBag.IDMarca = new SelectList(db.Marcas, "IDMarca", "marcaDesc", publicacion.IDMarca);
            ViewBag.IDModelo = new SelectList(db.Modelos, "IDModelo", "modeloDesc", publicacion.IDModelo);
            ViewBag.IDTipoCombustible = new SelectList(db.TipoCombustibles, "IDTipoCombustible", "tipoCombustibledesc", publicacion.IDTipoCombustible);
            ViewBag.IDTipoVehiculo = new SelectList(db.TiposVehiculos, "IDTipoVehiculo", "tipoVehiculodesc", publicacion.IDTipoVehiculo);
            return View(publicacion);
        }
开发者ID:jr2n,项目名称:bleh,代码行数:31,代码来源:PublicacionesController.cs

示例6: CreateNote

        public ViewResult CreateNote(Note note, Location location, HttpPostedFileBase upload)
        {
            if (upload != null)
            {
                var file = new File
                {
                    FileName = upload.FileName,
                    ContentType = upload.ContentType
                };

                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    file.Content = reader.ReadBytes(upload.ContentLength);
                }

                note.File = file;
            }

            note.UserId = this.User.Identity.GetUserId();
            note.CreationDate = DateTime.Now;
            note.CreationLocation = LocationUtil.ParseLocation(location);

            this.noteService.CreateNote(note);

            return this.View("FinishNoteCreation", note);
        }
开发者ID:thiagosenador,项目名称:PollInTheAir,代码行数:26,代码来源:NoteController.cs

示例7: Create

 public ActionResult Create([Bind(Include = "ProductId,ProductTitle,ProductDescription,ProductPrice,CategoryId")] Product product, HttpPostedFileBase upload)
 {
     try {
         if (ModelState.IsValid)
         {
             if (upload != null && upload.ContentLength > 0)
             {
                 var image = new File
                 {
                     FileName = System.IO.Path.GetFileName(upload.FileName),
                     FileType = FileType.Image,
                     ContentType = upload.ContentType
                 };
                 using (var reader = new System.IO.BinaryReader(upload.InputStream))
                 {
                     image.Content = reader.ReadBytes(upload.ContentLength);
                 }
                 product.Files = new List<File> { image };
             }
             db.Products.Add(product);
             db.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch (RetryLimitExceededException)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", product.CategoryId);
     return View(product);
 }
开发者ID:nhan-nguyen,项目名称:AcmeMenwear,代码行数:31,代码来源:ProductsController.cs

示例8: Create

        public ActionResult Create([Bind(Include = "ID,Title,Genre,ReleaseDate,Length,Directors,Actor,Intro,TrailerURL")] Movie movie, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                // Upload Picture
                if (upload != null && upload.ContentLength > 0)
                {
                    var picture = new File
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        picture.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    movie.Files = new List<File> { picture };
                }
                else
                {
                    // Mặc định up hình ở đây.
                }
                db.Movies.Add(movie);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(movie);
        }
开发者ID:phuonguit2015,项目名称:QuanLyDatVeXemPhimASP,代码行数:29,代码来源:MoviesController.cs

示例9: Create

        public ActionResult Create([Bind(Include = "ID,Title,Body,Date,Type,ContentType")] Tutorial tutorial, HttpPostedFileBase upload)
        {
            string userid = User.Identity.GetUserId();
            var currentuser = db.Users.SingleOrDefault(u => u.Id == userid);

            if (ModelState.IsValid)
            {

                if (upload != null && upload.ContentLength > 0)
                {
                    var pic = new FileMain
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        FileType = FileType.Pic,
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        pic.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    tutorial.FileMains = new List<FileMain> { pic };
                }

                tutorial.User = currentuser;
                tutorial.Date = DateTime.Now;

                db.Tutorials.Add(tutorial);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(tutorial);
        }
开发者ID:Wikirials,项目名称:wikirials,代码行数:33,代码来源:TutorialController.cs

示例10: Create

        public ActionResult Create([Bind(Include = "CarTypeId,CarCode,DailyPrice,DailyLatePrice")] CarType carType, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var carImage = new File
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        FileType = FileType.CarImage,
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        carImage.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    carType.Files = new List<File> { carImage };
                }
                db.CarTypes.Add(carType);
                db.SaveChanges();
                TempData["Added"] = carType.CarCode + " Added";
                return RedirectToAction("Index");
            }

            return View(carType);
        }
开发者ID:rnmisrahi,项目名称:JB,代码行数:26,代码来源:CarTypesController.cs

示例11: Create

        public ActionResult Create([Bind(Include = "Id,Description,Codigo,IdCategory,IdMarca,IdMoneda")] product product, List<HttpPostedFileBase> fileUpload)
        {
            if (ModelState.IsValid)
            {
                db.products.Add(product);
                db.SaveChanges();
                int id = product.Id;

                for (int i = 0; i < fileUpload.Count; i++)
                {
                    ImgProduct image = new ImgProduct
                    {
                        Name = System.IO.Path.GetFileName(fileUpload[i].FileName),
                        Id = id
                    };
                    using (var reader = new System.IO.BinaryReader(fileUpload[i].InputStream))
                    {
                        image.Image = reader.ReadBytes(fileUpload[i].ContentLength);
                        image.IdProduct = product.Id;
                        db.ImgProducts.Add(image);
                        db.SaveChanges();
                    }
                }

                ViewBag.IdCategory = new SelectList(db.Categories, "Id", "Description");
                ViewBag.IdMarca = new SelectList(db.Marcas, "Id", "Description", product.IdMarca);
                ViewBag.IdMoneda = new SelectList(db.Monedas, "Id", "Description", product.IdMoneda);
                return RedirectToAction("Index");
            }

            return View(product);
        }
开发者ID:ProjectsPy,项目名称:cms_prov,代码行数:32,代码来源:productsController.cs

示例12: ProfilePage

        public ActionResult ProfilePage(HttpPostedFileBase upload)
        {
            ViewBag.Message = "Your contact page.";
            string userid = User.Identity.GetUserId();
            var currentuser = db.Users.SingleOrDefault(u => u.Id == userid);

            if (upload != null && upload.ContentLength > 0)
            {
                if (currentuser.Files.Any(f => f.FileType == FileType.Avatar))
                {
                    db.Files.Remove(currentuser.Files.First(f => f.FileType == FileType.Avatar));
                }
                var avatar = new File
                {
                    FileName = System.IO.Path.GetFileName(upload.FileName),
                    FileType = FileType.Avatar,
                    ContentType = upload.ContentType
                };
                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    avatar.Content = reader.ReadBytes(upload.ContentLength);
                }
                currentuser.Files = new List<File> { avatar };
            }

            db.Entry(currentuser).State = EntityState.Modified;
            db.SaveChanges();

            return View(currentuser);
        }
开发者ID:Wikirials,项目名称:wikirials,代码行数:30,代码来源:ProfileController.cs

示例13: btnfileupload_Click

        protected void btnfileupload_Click(object sender, EventArgs e)
        {
            if (fileImage.HasFile)
            {
                System.IO.Stream fs = fileImage.PostedFile.InputStream;
                System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
                Byte[] bytesPhoto = br.ReadBytes((Int32)fs.Length);
                string base64String = Convert.ToBase64String(bytesPhoto, 0, bytesPhoto.Length);
                imgPhoto.ImageUrl = "data:image/png;base64," + base64String;
                imgPhoto.Visible = true;
                string fileName = fileImage.PostedFile.FileName;
                fileImage.SaveAs(Server.MapPath("~/Images/" + fileName));
                using (var db = new BadCostumesEntities ())
                {
                    var newCostume = new Costume();
                    newCostume.Participant = Request.QueryString["Participant"]; //this has to be the id
                    newCostume.ParticipantId = Convert.ToInt32( Request.QueryString["Participant"]); //this has to be the id
                    newCostume.Image = fileName;
                    newCostume.Votes = "1";
                    db.Costumes.Add(newCostume);
                    db.SaveChanges();
                }
                string gotourl = string.Format("~/SiteParticipant.aspx?Participant={0}", Request.QueryString["Participant"]);
                Response.Redirect(gotourl);

            }
        }
开发者ID:jzfields80,项目名称:BadCostumesForCharity,代码行数:27,代码来源:SuggestACostume.aspx.cs

示例14: Create

        public ActionResult Create([Bind(Include = "GameID,GameName,Official,Website,CoverArt,Genre,Description,Approved")] Game game, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var art = new CoverArt
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        art.Image = reader.ReadBytes(upload.ContentLength);
                    }
                    game.CoverArt = art;
                }

                db.Games.Add(game);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(game);
        }
开发者ID:Kethsar,项目名称:CS296N,代码行数:25,代码来源:GamesController.cs

示例15: Create

 public ActionResult Create([Bind(Include = "LastName,FirstMidName,EnrollmentDate")] Student student, HttpPostedFileBase upload)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (upload != null && upload.ContentLength > 0)
             {
                 var avatar = new File
                 {
                     FileName = System.IO.Path.GetFileName(upload.FileName),
                     FileType = FileType.Avatar,
                     ContentType = upload.ContentType
                 };
                 using (var reader = new System.IO.BinaryReader(upload.InputStream))
                 {
                     avatar.Content = reader.ReadBytes(upload.ContentLength);
                 }
                 student.Files = new List<File> { avatar };
             }
             db.Students.Add(student);
             db.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     catch (DataException /* dex */)
     {
         //Log the error (uncomment dex variable name and add a line here to write a log.
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return View(student);
 }
开发者ID:devi99,项目名称:University,代码行数:32,代码来源:StudentController.cs


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