public void SetLength_NoModify() { BlockStream s; BlockArray ba; byte[] buf; int cb; ba = new BlockArray(new Block(new byte[] { 0, 1, 2, 3, 4 }), new Block(new byte[] { 5, 6, 7, 8, 9 })); s = new BlockStream(ba); Assert.Equal(10, s.Length); s.Position = 10; s.SetLength(5, false); Assert.Equal(5, s.Length); Assert.Equal(5, s.Position); Assert.Equal(2, ba.Count); s.Position = 0; buf = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; cb = s.Read(buf, 0, 10); Assert.Equal(5, cb); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 0, 0, 0, 0, 0 }, buf); s.Position = 0; s.SetLength(10, false); buf = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; cb = s.Read(buf, 0, 10); Assert.Equal(10, cb); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, buf); }
/// <summary> /// Initiates content parsing. /// </summary> /// <param name="received">The request/response data received so far.</param> /// <param name="dataPos">Position of the first byte of content data after the headers.</param> /// <returns><c>true</c> if the data has been completely parsed.</returns> /// <remarks> /// <para> /// This method will return true indicating that all of the content has been parsed /// if the content was included in the blocks received while parsing the headers. /// </para> /// <note> /// The block array passed should not be used again /// after making this call. Ownership should be considered to /// have been passed to this instance. /// </note> /// </remarks> /// <exception cref="HttpBadProtocolException">Badly formatted HTTP message.</exception> /// <exception cref="HttpContentSizeException">The content size exceeds the maximum allowed.</exception> public bool BeginParse(BlockArray received, int dataPos) { isChunked = String.Compare(headers.Get("Transfer-Encoding", "identity"), "chunked", true) == 0; if (isChunked) { cbContent = 0; chunkState = ChunkState.Start; return(ChunkParser(received, dataPos)); } content = received.Extract(dataPos); isRequest = headers.IsRequest; // Get the content length. If this is not present and this is an // HTTP request then assume that there is no content. For responses, // we're going to assume that the server will close its side of // the socket to signal the end of the content. cbContent = headers.Get("Content-Length", -1); if (cbContent < 0) { if (isRequest) { cbContent = 0; return(true); } cbContent = -1; } // Return true if we already have all of the content. return(cbContent != -1 && content.Size >= cbContent); }
public override void AutonomousInit() { SmartDashboard.PutBoolean("Pixy Status", Pixy.IsConnected); BlockArray blocks = new BlockArray(2); SmartDashboard.PutNumber("Pixy Count", Pixy.GetBlocks(2, blocks)); }
/// <summary> /// Completes the parsing of the request. /// </summary> public void EndParse() { string host; int pos; if (parseState != ParseState.GotAll) { throw new InvalidOperationException(BadParseMsg); } content = contentParser.EndParse(); contentParser = null; parseState = ParseState.Done; // Build up the request URI. host = base["Host"]; if (host == null) { host = "localhost"; } pos = host.IndexOf(':'); // Strip off the port if present if (pos != -1) { host = host.Substring(0, pos); } uri = new Uri(new Uri(string.Format("http://{0}:{1}", host, parsePort)), base.RawUri); }
public static BlockArray frompointer(Block t) { global::System.IntPtr cPtr = pixyPINVOKE.BlockArray_frompointer(Block.getCPtr(t)); BlockArray ret = (cPtr == global::System.IntPtr.Zero) ? null : new BlockArray(cPtr, false); return(ret); }
public override void AutonomousPeriodic() { BlockArray blocks = new BlockArray(2); SmartDashboard.PutNumber("Pixy Count", Pixy.GetBlocks(2, blocks)); SmartDashboard.PutNumber("Pixy Area", blocks.getitem(0).height *blocks.getitem(0).width); }
public void Reload() { BlockArray ba; Block b; byte v; ba = new BlockArray(0, 10, 5); ba.ExtendTo(10); Assert.Equal(10, ba.Size); v = ba[5]; b = ba.GetBlock(0); b.Offset = 0; b.Length = b.Buffer.Length; for (int i = 0; i < b.Length; i++) { b.Buffer[i] = (byte)i; } b = ba.GetBlock(1); b.Offset = 0; b.Length = b.Buffer.Length; for (int i = 0; i < b.Length; i++) { b.Buffer[i] = (byte)(i + 100); } ba.Reload(); Assert.Equal(20, ba.Size); Assert.Equal(5, ba[5]); }
/// <summary> /// Constructs a response to be parsed from a network stream. /// </summary> /// <param name="cbContentMax">Maximum allowed content size or <b>-1</b> to disable checking.</param> public HttpResponse(int cbContentMax) : base(false) { this.parseState = ParseState.None; this.contentParser = null; this.content = null; this.cbContentMax = cbContentMax; }
/// <summary> /// Constructs a request to be parsed from a network stream. /// </summary> /// <param name="cbContentMax">Maximum allowed content size or <b>-1</b> to disable checking.</param> public HttpRequest(int cbContentMax) : base(true) { this.parseState = ParseState.None; this.contentParser = null; this.content = null; this.cbContentMax = cbContentMax; }
private void Zero(BlockArray blocks) { for (int i = 0; i < blocks.Size; i++) { blocks[i] = 0; } blocks.Reset(); }
public void showReservationDates() { //***Add control array, ShiftDates, to show the dates of the shifts – instantiate with parameters roomDates = new BlockArray(this, 30, 100, 50, 7); //these blocks will appear in a column int intcnt = 0; // show all 31 days in the month for (intcnt = 0; intcnt <= 30; intcnt++) { roomDates.AddNewBlock(); roomDates.Item(intcnt).Text = Convert.ToString(intcnt + 1); // determine colour using the reservations collection in reservationController roomDates.Item(intcnt).FlatStyle = FlatStyle.Flat; roomDates.Item(intcnt).Click += SlotSelected; // add action event listener to each button int count = 0; // determine number of reservations on each day for (int i = 0; i < reservationController.AllReservations.Count; i++) { // get single reservation Reservation reserved = reservationController.AllReservations[i]; // check the start and end date string start = reserved.StartDate; string end = reserved.EndDate; DateTime startDT = Convert.ToDateTime(start); DateTime endDT = Convert.ToDateTime(end); int startDay = Convert.ToInt32(startDT.Day); int endDay = Convert.ToInt32(endDT.Day); if (intcnt + 1 >= startDay && intcnt + 1 <= endDay) { count++; } } // colour dates depending on availability if (count == 0) { roomDates.Item(intcnt).BackColor = Color.White; } if (count > 0 && count < 5) { roomDates.Item(intcnt).BackColor = Color.Yellow; } if (count == 5) { roomDates.Item(intcnt).BackColor = Color.Red; roomDates.Item(intcnt).Enabled = false; } } }
/// <summary> /// Constructs a HTTP 1.1 response. /// </summary> /// <param name="status">HTTP response status code.</param> /// <param name="reason">Response reason phrase.</param> public HttpResponse(HttpStatus status, string reason) : base(status, reason) { this.parseState = ParseState.Disabled; if (content == null) { content = new BlockArray(); } }
/// <summary> /// Constructs a HTTP 1.1 response. /// </summary> /// <param name="status">HTTP response status code.</param> /// <remarks> /// The reason phrase will be initialized to the standard phrase /// from HttpStack.GetReasonPhrase(). /// </remarks> public HttpResponse(HttpStatus status) : base(status, HttpStack.GetReasonPhrase(status)) { this.parseState = ParseState.Disabled; if (content == null) { content = new BlockArray(); } }
/// <summary> /// Constructs a HTTP response. /// </summary> /// <param name="version">HTTP protocol version.</param> /// <param name="status">HTTP response status code.</param> /// <param name="reason">Response reason phrase.</param> public HttpResponse(Version version, HttpStatus status, string reason) : base(version, status, reason) { this.parseState = ParseState.Disabled; this.cbContentMax = -1; if (content == null) { content = new BlockArray(); } }
/// <summary> /// Completes the parsing of the response. /// </summary> public void EndParse() { if (parseState != ParseState.GotAll) { throw new InvalidOperationException(BadParseMsg); } content = contentParser.EndParse(); contentParser = null; parseState = ParseState.Done; }
/// <summary> /// Completes the parsing of the content by returning the parsed /// content as a BlockArray. /// </summary> /// <returns>The content data.</returns> public BlockArray EndParse() { try { return(content); } finally { content = null; // Release this reference to help to GC. } }
/// <summary> /// Constructs a HTTP 1.1 request. /// </summary> /// <param name="method">HTTP method (GET, POST, PUT,...)</param> /// <param name="rawUri">The raw (escaped) request URI.</param> /// <param name="content">The request content (or <c>null</c>).</param> public HttpRequest(string method, string rawUri, BlockArray content) : base(method, rawUri) { this.parseState = ParseState.Disabled; if (content == null) { content = new BlockArray(); } this.content = content; }
private void ShiftsMonthCalendar_DateSelected(object sender, DateRangeEventArgs e) { System.DateTime aDate = default(System.DateTime); //Calendar control functions to set the Start and End date startDate = shiftsMonthCalendar.SelectionRange.Start; endDate = shiftsMonthCalendar.SelectionRange.End; //***Add control array, ShiftDates, to show the dates of the shifts shiftDates = new BlockArray(this, 50, 100, 200, 1); aDate = startDate; int intcnt = 0; for (intcnt = 0; intcnt <= 6; intcnt++) { shiftDates.AddNewBlock(); shiftDates.Item(intcnt).BackColor = Color.White; shiftDates.Item(intcnt).Text = aDate.ToShortDateString(); //Show date on Button aDate = aDate.AddDays(1); //**This function allows you to go to the NEXT day } //***Add a block for each slot on all the shifts – ShiftBookings control array shiftBookings = new BlockArray(this, 50, 100, 300, 6); for (intcnt = 0; intcnt <= 41; intcnt++) { shiftBookings.AddNewBlock(); if (intcnt % 6 > 2) { shiftBookings.Item(intcnt).BackColor = Color.Turquoise; } //*** ONLY 4 slots on a SUNDAY (2 slots per shift) if (intcnt == 2 || intcnt == 5) { shiftBookings.Item(intcnt).BackColor = Color.DarkSlateGray; // shiftBookings.Item(intcnt).Enabled = false; } else { //***NB NB Add a click event dynamically to make button respond on the click of the user NB NB shiftBookings.Item(intcnt).Click += SlotSelected; } } shiftsMonthCalendar.Visible = false; calendarMessageLabel.Visible = false; FillCombo(); //workshop 7 SHIFT CONTROLLER METHOD WILL BE CALLED HERE TO SAVE NEW SHIFT TO MEMORY AND shiftController.NewShedule(startDate, endDate); //THEN WRITE TO DATABASE--LATER ShowControls(true); }
private void ShiftsMonthCalendar_DateSelected(object sender, DateRangeEventArgs e) { System.DateTime aDate = default(System.DateTime); // Find the systems date //Calendar control functions to set the Start and End date startDate = shiftsMonthCalendar.SelectionRange.Start; endDate = shiftsMonthCalendar.SelectionRange.Start; //***Add control array, ShiftDates, to show the dates of the shifts – instantiate with parameters shiftDates = new BlockArray(this, 50, 100, 400, 1); //these blocks will appear in a column aDate = startDate; int intcnt = 0; for (intcnt = 0; intcnt <= 6; intcnt++) { shiftDates.AddNewBlock(); shiftDates.Item(intcnt).BackColor = Color.White; shiftDates.Item(intcnt).Text = aDate.ToShortDateString(); //Display the date on the Button aDate = aDate.AddDays(1); //**This function allows you to go to the NEXT day } //***Add a block for each slot on all the shifts (6 slots) – ShiftBookings control array shiftBookings = new BlockArray(this, 50, 100, 500, 6); for (intcnt = 0; intcnt <= 41; intcnt++) // Why 41 blocks? W7-Q1 { // Add a new block for the shiftBooking shiftBookings.AddNewBlock(); // Afternoon slots should be turquoise (HINT: 6 blocks, use the remainder operator) if (intcnt % 6 > 2) { shiftBookings.Item(intcnt).BackColor = Color.Turquoise; } //*** ONLY 4 slots on a SUNDAY (indices 2 or 5)– ie 2 slots per shift, 2 INACTIVE Slots // ***the colours of these blocks (identify the indices) will change to Color.DarkSlateGray if (intcnt == 2 || intcnt == 5) { shiftBookings.Item(intcnt).BackColor = Color.DarkSlateGray; } else { //A click event to be added dynamically to make button respond on user click // subscribe to the eventhandler event for ALL slots except INACTIVE ones shiftBookings.Item(intcnt).Click += SlotSelected; } } // Hide the calendar & the message below the calendar shiftsMonthCalendar.Visible = false; calendarMessageLabel.Visible = false; // ***Call the method to fill the Combo box – the list of waiters becomes the datasource FillCombo(); //Call NewSchedule ShiftController method to create a ShiftBookings array in memory shiftController.NewShedule(startDate, endDate); //Show controls for ComboBox and labels ShowControls(true); }
/// <summary> /// Appends a block array to the end of the underlying BlockArray. /// </summary> /// <param name="blocks">The array to append.</param> /// <remarks> /// The underyling block array's SetExactSize() method will be /// called before appending the block. The stream position will /// be set to the end of the stream before the method returns. /// /// This method is a performance improvement over writing the /// a buffer to the stream via one of the write methods. /// </remarks> public void Append(BlockArray blocks) { this.blocks.SetExactSize(length); for (int i = 0; i < blocks.Count; i++) { this.blocks.Append(blocks.GetBlock(i)); } length += blocks.Size; pos = length; }
public void Extract() { BlockArray ba; BlockArray ex; //------------------------- ba = new BlockArray(); ex = ba.Extract(0, 0); Assert.Equal(0, ex.Size); Assert.Equal(0, ex.Count); //------------------------- ba = new BlockArray(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); ex = ba.Extract(0, 10); Assert.Equal(10, ex.Size); Assert.Equal(1, ex.Count); Assert.Equal(0, ex.GetBlock(0).Offset); Assert.Equal(10, ex.GetBlock(0).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.GetBlock(0).Buffer); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); ba.GetBlock(0).Offset = 5; ba.GetBlock(0).Length = 5; ba.Reload(); Assert.Equal(new byte[] { 5, 6, 7, 8, 9 }, ba.ToByteArray()); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); //------------------------- ba = new BlockArray(new Block(new byte[] { 0, 0, 0, 0, 0, 0, 1, 2, 3, 4 }, 5, 5), new Block(new byte[] { 0, 0, 0, 0, 0, 5, 6, 7, 8, 9 }, 5, 5)); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ba.ToByteArray()); ex = ba.Extract(0, 10); Assert.Equal(2, ex.Count); Assert.Equal(5, ex.GetBlock(0).Offset); Assert.Equal(5, ex.GetBlock(0).Length); Assert.Equal(5, ex.GetBlock(1).Offset); Assert.Equal(5, ex.GetBlock(1).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); ex = ba.Extract(2, 5); Assert.Equal(2, ex.Count); Assert.Equal(7, ex.GetBlock(0).Offset); Assert.Equal(3, ex.GetBlock(0).Length); Assert.Equal(5, ex.GetBlock(1).Offset); Assert.Equal(2, ex.GetBlock(1).Length); Assert.Equal(new byte[] { 2, 3, 4, 5, 6 }, ex.ToByteArray()); ex = ba.Extract(5); Assert.Equal(new byte[] { 5, 6, 7, 8, 9 }, ex.ToByteArray()); }
/// <summary> /// Constructs a HTTP 1.1 request. /// </summary> /// <param name="method">HTTP method (GET, POST, PUT,...)</param> /// <param name="uri">The request URI.</param> /// <param name="content">The request content (or <c>null</c>).</param> public HttpRequest(string method, Uri uri, BlockArray content) : base(method, Helper.EscapeUri(uri.PathAndQuery)) { this.parseState = ParseState.Disabled; if (content == null) { content = new BlockArray(); } this.content = content; base["Host"] = uri.Host; }
public void Clone() { BlockArray ba; BlockArray ex; ba = new BlockArray(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); ex = ba.Clone(); Assert.Equal(10, ex.Size); Assert.Equal(1, ex.Count); Assert.Equal(0, ex.GetBlock(0).Offset); Assert.Equal(10, ex.GetBlock(0).Length); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.GetBlock(0).Buffer); Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, ex.ToByteArray()); }
public void BlockOffset() { BlockArray ba; ba = new BlockArray(0, 10, 5); ba.ExtendTo(10); Assert.Equal(10, ba.Size); Assert.Equal(10, ba.GetBlock(0).Buffer.Length); Assert.Equal(5, ba.GetBlock(0).Length); Assert.Equal(5, ba.GetBlock(0).Offset); Assert.Equal(10, ba.GetBlock(1).Buffer.Length); Assert.Equal(5, ba.GetBlock(1).Length); Assert.Equal(5, ba.GetBlock(1).Offset); }
/// <summary> /// Performs the necessary initialization before /// data recieved on the network can be parsed. /// </summary> public void BeginParse() { if (headers != null) { throw new InvalidOperationException("Headers already initialized."); } if (blocks != null) { throw new InvalidOperationException("Parsing already begun."); } blocks = new BlockArray(); dataPos = -1; }
public void HttpRequest_Serialize() { HttpRequest r; byte[] buf; BlockArray blocks; //------------------------- r = new HttpRequest("get", "/foo.htm", null); CollectionAssert.AreEqual(Encoding.ASCII.GetBytes("GET /foo.htm HTTP/1.1\r\nContent-Length: 0\r\n\r\n"), r.Serialize(15).ToByteArray()); //------------------------- r.Content = new BlockArray(Encoding.ASCII.GetBytes("abcdefg")); CollectionAssert.AreEqual(Encoding.ASCII.GetBytes("GET /foo.htm HTTP/1.1\r\nContent-Length: 7\r\n\r\nabcdefg"), r.Serialize(15).ToByteArray()); //------------------------- r = new HttpRequest(); buf = Encoding.ASCII.GetBytes("GET /foo.htm HTTP/1.1\r\nHeader1: Test1\r\nHeader2: Test2\r\nContent-Length: 4\r\n\r\nabcd"); r.BeginParse(80); Assert.IsTrue(r.Parse(buf, buf.Length)); r.EndParse(); buf = r.Serialize(3).ToByteArray(); blocks = new BlockArray(Encoding.ASCII.GetBytes("GET /foo.htm HTTP/1.1\r\nHeader1: Test1\r\nHeader2: Test2\r\nContent-Length: 4\r\n\r\nabcd")); r = new HttpRequest(); r.BeginParse(80); for (int i = 0; i < blocks.Count; i++) { Block block = blocks.GetBlock(i); Assert.AreEqual(0, block.Offset); r.Parse(block.Buffer, block.Length); } r.EndParse(); Assert.AreEqual("GET", r.Method); Assert.AreEqual("/foo.htm", r.RawUri); Assert.AreEqual("4", r["Content-Length"]); Assert.AreEqual("Test1", r["Header1"]); Assert.AreEqual("Test2", r["Header2"]); CollectionAssert.AreEqual(Encoding.ASCII.GetBytes("abcd"), r.Content.ToByteArray()); }
public void TruncateTo() { BlockArray blocks; blocks = new BlockArray(); blocks.TruncateTo(0); Assert.Equal(0, blocks.Size); Assert.Empty(blocks.GetBlocks()); blocks.ExtendTo(1); blocks.TruncateTo(1); Assert.Equal(blocks.BlockSize, blocks.Size); Assert.Single(blocks.GetBlocks()); blocks.TruncateTo(1000000); blocks.TruncateTo(1); Assert.Equal(blocks.BlockSize, blocks.Size); Assert.Single(blocks.GetBlocks()); blocks.TruncateTo(0); Assert.Equal(0, blocks.Size); Assert.Empty(blocks.GetBlocks()); blocks.ExtendTo(blocks.BlockSize * 4); blocks.GetBlocks()[0].Buffer[0] = 0; blocks.GetBlocks()[1].Buffer[0] = 1; blocks.GetBlocks()[2].Buffer[0] = 2; blocks.GetBlocks()[3].Buffer[0] = 3; blocks.TruncateTo(blocks.BlockSize * 3); Assert.Equal(blocks.BlockSize * 3, blocks.Size); Assert.Equal(3, blocks.GetBlocks().Length); Assert.Equal(0, blocks.GetBlocks()[0].Buffer[0]); Assert.Equal(1, blocks.GetBlocks()[1].Buffer[0]); Assert.Equal(2, blocks.GetBlocks()[2].Buffer[0]); blocks.TruncateTo(blocks.BlockSize * 2 + 1); Assert.Equal(blocks.BlockSize * 3, blocks.Size); Assert.Equal(3, blocks.GetBlocks().Length); Assert.Equal(0, blocks.GetBlocks()[0].Buffer[0]); Assert.Equal(1, blocks.GetBlocks()[1].Buffer[0]); Assert.Equal(2, blocks.GetBlocks()[2].Buffer[0]); blocks.TruncateTo(blocks.BlockSize); Assert.Equal(blocks.BlockSize, blocks.Size); Assert.Single(blocks.GetBlocks()); Assert.Equal(0, blocks.GetBlocks()[0].Buffer[0]); }
public void HttpResponse_Serialize() { HttpResponse r; byte[] buf; BlockArray blocks; //------------------------- r = new HttpResponse(HttpStatus.OK, "OK"); CollectionAssert.AreEqual(Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"), r.Serialize(15).ToByteArray()); //------------------------- r.Content = new BlockArray(Encoding.ASCII.GetBytes("abcdefg")); CollectionAssert.AreEqual(Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\nabcdefg"), r.Serialize(15).ToByteArray()); //------------------------- r = new HttpResponse(); buf = Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\r\nHeader1: Test1\r\nHeader2: Test2\r\nContent-Length: 4\r\n\r\nabcd"); r.BeginParse(); Assert.IsTrue(r.Parse(buf, buf.Length)); r.EndParse(); buf = r.Serialize(3).ToByteArray(); blocks = new BlockArray(Encoding.ASCII.GetBytes("HTTP/1.1 200 OK\r\nHeader1: Test1\r\nHeader2: Test2\r\nContent-Length: 4\r\n\r\nabcd")); r = new HttpResponse(); r.BeginParse(); for (int i = 0; i < blocks.Count; i++) { Block block = blocks.GetBlock(i); Assert.AreEqual(0, block.Offset); r.Parse(block.Buffer, block.Length); } r.EndParse(); Assert.AreEqual(HttpStatus.OK, r.Status); Assert.AreEqual("OK", r.Reason); Assert.AreEqual("4", r["Content-Length"]); Assert.AreEqual("Test1", r["Header1"]); Assert.AreEqual("Test2", r["Header2"]); CollectionAssert.AreEqual(Encoding.ASCII.GetBytes("abcd"), r.Content.ToByteArray()); }
void DoLoading(object obj) { Wavefile wave = m_Wavefile; Mp3Stream stream = (Mp3Stream)obj; BlockArray <Sample> array = wave.m_Samples; //SafeStream safeStream = new SafeStream(stream); Sample[] sample = new Sample[10000]; byte[] buffer = new byte[sample.Length * 4]; Thread.Sleep(1000); while (true) //safeStream.Position < safeStream.Length) { //int count; //int countMax = (int)Math.Min(1024, (safeStream.Length - safeStream.Position)/4); //for (count=0; count <countMax; count ++) //{ // //sample[count] = new Sample(ReadI2(safeStream), ReadI2(safeStream)); // sample[count] = ReadSI2(safeStream); //} int byteCount = stream.Read(buffer, 0, buffer.Length); if (byteCount == 0) { break; } int sampleCount = byteCount / 4; for (int i = 0, j = 0; i < sampleCount; i++, j += 4) { sample[i] = new Sample((short)(buffer[j] | buffer[j + 1] << 8), (short)(buffer[j + 2] | buffer[j + 3] << 8)); } array.Write(sample, 0, sampleCount); Thread.Sleep(0); } stream.Dispose(); wave.FinishedLoading = true; }
public void SetExactSize() { BlockArray blocks; blocks = new BlockArray(); blocks.SetExactSize(0); Assert.Equal(0, blocks.Size); Assert.Equal(0, blocks.Count); blocks.SetExactSize(1); Assert.Equal(1, blocks.Size); Assert.Equal(1, blocks.Count); Assert.Equal(1, blocks.GetBlock(0).Length); blocks.SetExactSize(blocks.BlockSize); Assert.Equal(blocks.BlockSize, blocks.Size); Assert.Equal(2, blocks.Count); Assert.Equal(1, blocks.GetBlock(0).Length); Assert.Equal(blocks.BlockSize - 1, blocks.GetBlock(1).Length); blocks.SetExactSize(blocks.BlockSize + 1); Assert.Equal(blocks.BlockSize + 1, blocks.Size); Assert.Equal(3, blocks.Count); Assert.Equal(1, blocks.GetBlock(0).Length); Assert.Equal(blocks.BlockSize - 1, blocks.GetBlock(1).Length); Assert.Equal(1, blocks.GetBlock(2).Length); blocks = new BlockArray(); blocks.ExtendTo(blocks.BlockSize * 3); blocks.SetExactSize(blocks.Size - blocks.BlockSize / 2); Assert.Equal(3, blocks.Count); Assert.Equal(blocks.BlockSize, blocks.GetBlock(0).Length); Assert.Equal(blocks.BlockSize, blocks.GetBlock(1).Length); Assert.Equal(blocks.BlockSize - blocks.BlockSize / 2, blocks.GetBlock(2).Length); blocks.SetExactSize(blocks.BlockSize * 2); Assert.Equal(2, blocks.Count); Assert.Equal(blocks.BlockSize, blocks.GetBlock(0).Length); Assert.Equal(blocks.BlockSize, blocks.GetBlock(1).Length); blocks.SetExactSize(blocks.BlockSize + 1); Assert.Equal(2, blocks.Count); Assert.Equal(blocks.BlockSize, blocks.GetBlock(0).Length); Assert.Equal(1, blocks.GetBlock(1).Length); }