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


C# IO.BinaryReader类代码示例

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


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

示例1: 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

示例2: 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

示例3: From3DMAXStream

        public static FullAnimation From3DMAXStream(System.IO.Stream stream, SkeletonExtended skeleton, bool reverse)
        {
            Matrix[][] Frames;
            var clip = new FullAnimation();
            var reader = new System.IO.BinaryReader(stream);
            var start = reader.ReadInt32();
            var end = reader.ReadInt32();
            var length = end - start + 1;
            clip.BonesCount = reader.ReadInt32();
            var counter = reader.ReadInt32();
            Frames = new Matrix[length][];
            for (int i = 0; i < length; i++)
                Frames[i] = new Matrix[clip.BonesCount];
            for (int i = 0; i < clip.BonesCount; i++)
                for (int j = 0; j < length; j++)
                    Frames[j][i] = reader.ReadMatrix();
            //теперь надо вычислить дельты
            //(идёт загрузка экспортированного из макса)
            for (int i = 0; i < clip.BonesCount; i++)
                for (int @in = 0; @in < length; @in++)
                    Frames[@in][i] = skeleton.baseskelet.bones[i].BaseMatrix * Frames[@in][i];

            if (reverse)
            {
                //Matrix[][] FramesTmp = new Matrix[length][];
                Frames = Frames.Reverse().ToArray();
            }
            Matrix[][] relatedMatrices = Animation.GetRelatedMatrices(Frames, skeleton.baseskelet);
            DecomposedMatrix[][] decomposedMatrices = GetDecomposedMatrices(skeleton.baseskelet, relatedMatrices);

            clip.matrices = decomposedMatrices;
            return clip;
        }
开发者ID:KatekovAnton,项目名称:Game,代码行数:33,代码来源:AnimationFull.cs

示例4: Create

        public ActionResult Create([Bind(Include = "Id,IdUser,ProductName,Description,Status,RegisterDate")] Products products, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    var avatar = new File
                    {
                        FileName = System.IO.Path.GetFileName(upload.FileName),
                        FileType = FileType.Imagen,
                        ContentType = upload.ContentType
                    };
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        avatar.Content = reader.ReadBytes(upload.ContentLength);
                    }
                    products.Files = new List<File> { avatar };
                }
                products.IdUser = User.Identity.GetUserId();
                products.RegisterDate = @DateTime.Now;
                products.Status = "Activo";
                db.Products.Add(products);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(products);
        }
开发者ID:esmar,项目名称:appWeb,代码行数:28,代码来源:ProductsController.cs

示例5: 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

示例6: Load

        public static void Load()
        {
            IO.Log.Write("    Loading CampaingProgresss...");
            levelsCompleted.Clear();

            System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream("Saves/progress.lpg",
                System.IO.FileMode.Open));

            String s = "";
            int l = 0;
            while (br.PeekChar() > -1)
            {
                s = br.ReadString();
                l = br.ReadInt32();
                byte[] d = new byte[l];
                for (int j = 0; j < l; j++)
                {
                    d[j] = br.ReadByte();
                }
                levelsCompleted.Add(s, d);
            }

            br.Close();
            IO.Log.Write("    Loading complete");
        }
开发者ID:XZelnar,项目名称:MicroWorld,代码行数:25,代码来源:CampaingProgress.cs

示例7: DeserializeVoxelAreaData

		public static void DeserializeVoxelAreaData (byte[] bytes, VoxelArea target) {
			
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			stream.Write(bytes,0,bytes.Length);
			stream.Position = 0;
			zip = Ionic.Zip.ZipFile.Read(stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			
			zip["data"].Extract (stream2);
			stream2.Position = 0;
			System.IO.BinaryReader reader = new System.IO.BinaryReader(stream2);
			
			int width = reader.ReadInt32();
			int depth = reader.ReadInt32();
			if (target.width != width) throw new System.ArgumentException ("target VoxelArea has a different width than the data ("+target.width + " != " + width + ")");
			if (target.depth != depth) throw new System.ArgumentException ("target VoxelArea has a different depth than the data ("+target.depth + " != " + depth + ")");
			LinkedVoxelSpan[] spans = new LinkedVoxelSpan[reader.ReadInt32()];
			
			for (int i=0;i<spans.Length;i++) {
				spans[i].area = reader.ReadInt32();
				spans[i].bottom = reader.ReadUInt32();
				spans[i].next = reader.ReadInt32();
				spans[i].top = reader.ReadUInt32();
			}
			target.linkedSpans = spans;
		}
开发者ID:henryj41043,项目名称:TheUnseen,代码行数:27,代码来源:VoxelClasses.cs

示例8: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //if (this.Request.HttpMethod != "POST")
         //{
         //    this.Response.Write("Request method must be POST");
         //    return;
         //}
         // handle as image
         //string device = this.Request.Form["deviceid"].ToString();
         using (SmartCityEntities ctx = new SmartCityEntities())
         {
             SampledImage sImage = new SampledImage();
             sImage.device_id = Convert.ToInt32(this.Request.QueryString["device"]);
             sImage.image_timestamp = DateTime.Now;
             System.IO.BufferedStream bufRead = new System.IO.BufferedStream(this.Request.Files[0].InputStream);
             System.IO.BinaryReader binaryRead = new System.IO.BinaryReader(bufRead);
             sImage.imagesample = binaryRead.ReadBytes(this.Request.Files[0].ContentLength);
             ctx.SampledImage.Add(sImage);
             ctx.SaveChanges();
         }
         return;
     }
     catch (Exception ex)
     {
         this.Response.Write(ex.ToString());
         return;
     }
 }
开发者ID:ReNASAsense,项目名称:SmartCity,代码行数:30,代码来源:PutImage.aspx.cs

示例9: Populate

        public void Populate(int iOffset, bool useMemoryStream)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(map.SelectedMeta.MS);
            //set offsets
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap = iOffset + this.chunkOffset;
            // If we need to read / save tag info directly to file...
            if (!useMemoryStream)
            {
                map.OpenMap(MapTypes.Internal);
                BR = map.BR;
                BR.BaseStream.Position = this.offsetInMap;
            }
            else
                this.offsetInMap += map.SelectedMeta.offset;

            if (this.entUnicode)
            {
                this.value = Encoding.Unicode.GetString(BR.ReadBytes(this.length));
            }
            else
            {
                this.value = new String(BR.ReadChars(this.length));
            }
            this.value = this.value.TrimEnd('\0');
            //this.RemoveNullCharFromValue();
            this.textBox1.Text = this.value;
            this.textBox1.Size = this.textBox1.PreferredSize;
            this.textBox1.Width += 5;

            // ...and then close the file once we are done!
            if (!useMemoryStream)
                map.CloseMap();
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:35,代码来源:EntStrings.cs

示例10: 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

示例11: Create

        public ActionResult Create([Bind(Include = "SlideId,SlideLink,SlideDescription")] Slide slide, HttpPostedFileBase upload)
        {
            try {
                if (ModelState.IsValid)
                {
                    if (upload != null && upload.ContentLength > 0)
                    {
                        var img = new SlideImg
                        {
                            SlideImgName = System.IO.Path.GetFileName(upload.FileName),
                            FileType = FileType.Image,
                            SlideImgContentType = upload.ContentType
                        };
                        using (var reader = new System.IO.BinaryReader(upload.InputStream))
                        {
                            img.SlideImgContent = reader.ReadBytes(upload.ContentLength);
                        }
                        slide.SlideImg = new List<SlideImg> { img };
                    }
                    db.Slides.Add(slide);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

                return View(slide);
            }
            catch (RetryLimitExceededException)
            {
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
                }
                return View(slide);
            }
        }
开发者ID:nhan-nguyen,项目名称:AcmeMenwear,代码行数:34,代码来源:SlidesController.cs

示例12: 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

示例13: 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

示例14: Section

 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 21JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * constructor.
  */
 protected Section(BinaryReader reader,
         long offset, long size)
 {
     this._offset = offset;
     this._reader = reader;
     this._size = size;
 }
开发者ID:237rxd,项目名称:maptiledownloader,代码行数:16,代码来源:Section.cs

示例15: Create

        public ActionResult Create(StudentAward studentAward)
        {
            try
            {
                if (Request.Files.Count == 1)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {

                        using (var reader = new System.IO.BinaryReader(file.InputStream))
                        {
                            studentAward.Photo = reader.ReadBytes(file.ContentLength);
                        }
                    }
                }
                _ctx.StudentAwards.Add(studentAward);
                _ctx.SaveChanges();
                return RedirectToAction("List", new RouteValueDictionary(
               new { controller = "StudentAward", action = "List", StudentId = studentAward.Student_ID }));
            }
            catch
            {
                return View();
            }
        }
开发者ID:ltuser1,项目名称:ASP,代码行数:27,代码来源:StudentAwardController.cs


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