private void BeginRecording() { frame = 0; state = RecorderState.Recording; MemoryStream baseStream = new MemoryStream(); stream = new RecordingStream(1, write: true, baseStream); }
private void BeginPlayback() { frame = 0; Human.instance.enabled = false; state = RecorderState.Playing; byte[] buffer = File.ReadAllBytes("Recording.bytes"); MemoryStream baseStream = new MemoryStream(buffer); stream = new RecordingStream(0, write: false, baseStream); StripBehaviors(); }
public void ExceedingCapacityThrows() { var bytes = new byte[] { 74, 117, 97, 110, 32, 67, 97, 114, 108, 111, 115, 32, 59, 41 }; var inner = new MemoryStream(); inner.Write(bytes, 0, bytes.Length); inner.Position = 0; var wrapper = RecordingStream.ReadRecordingStream(inner, bytes.Length - 1); var buffer = new byte[bytes.Length]; Assert.Throws <InvalidOperationException>(() => wrapper.Read(buffer, 0, bytes.Length)); }
public void TestCanReadOrCanWrite() { var inner = new MemoryStream(); var readWrapper = RecordingStream.ReadRecordingStream(inner, size: null); Assert.True(readWrapper.CanRead); Assert.False(readWrapper.CanWrite); var writeWrapper = RecordingStream.WriteRecordingStream(inner); Assert.False(writeWrapper.CanRead); Assert.True(writeWrapper.CanWrite); }
public void BeginPlayback(byte[] data, float startingTime) { time = startingTime; Human.instance.enabled = false; state = RecorderState.Playing; MemoryStream baseStream = new MemoryStream(data); stream = new RecordingStream(0, write: false, baseStream); StripBehaviors(); int num = Mathf.RoundToInt(startingTime * 60f); stream.stream.Position = 4 + 28 * num * transforms.Count; }
public void BytesAreWrittenAndRecorded() { var bytes = new byte[] { 74, 117, 97, 110, 32, 67, 97, 114, 108, 111, 115, 32, 59, 41 }; var inner = new MemoryStream(); var wrapper = RecordingStream.WriteRecordingStream(inner); wrapper.Write(bytes, 0, bytes.Length); var recorded = wrapper.RecordedBytes; Assert.Equal(bytes.Length, recorded.Length); Assert.Equal(bytes, recorded); }
private void Serialize(RecordingStream rs) { foreach (Transform transform in transforms) { Vector3 data = transform.localPosition; Quaternion data2 = transform.localRotation; rs.Serialize(ref data); rs.Serialize(ref data2); if (rs.isReading) { transform.localPosition = data; transform.localRotation = data2; } } }
public void BytesAreReadAndRecorded() { var bytes = new byte[] { 74, 117, 97, 110, 32, 67, 97, 114, 108, 111, 115, 32, 59, 41 }; var inner = new MemoryStream(); inner.Write(bytes, 0, bytes.Length); inner.Position = 0; var wrapper = RecordingStream.ReadRecordingStream(inner, bytes.Length); var buffer = new byte[bytes.Length]; var bytesRead = wrapper.Read(buffer, 0, bytes.Length); Assert.Equal(bytes.Length, bytesRead); Assert.Equal(bytes, buffer); Assert.Equal(bytes, wrapper.RecordedBytes); }
public RecordingClient_WindowsCoreApi(Factory_WindowsCoreApi.IAudioClient Client, int NumChannel, int FrameSize, uint SamplesRate, Type DataFormat) { object opaqueService; _IAudioClient = Client; _IAudioClient.GetService(ref IID_IAudioCaptureClient, out opaqueService); _IAudioCaptureClient = (IAudioCaptureClient)opaqueService; _IAudioClient.GetBufferSize(out _BufferFrameCount); _SampleRate = SamplesRate; _Format = DataFormat; _ChannelCount = NumChannel; _IAudioClient = Client; _Stream = new RecordingStream(this); _Thread = new System.Threading.Thread(Loop); _FrameSize = FrameSize; }
/// <summary> /// Occurs when new data should be read from the underlying device. /// </summary> protected override void OnReadPacket() { // Read a sentence from the underlying stream NmeaSentence sentence = _stream.ReadTypedSentence(); // If we have a sentence, the device is NMEA! Flag it if needed. if (Device != null && !Device.IsGpsDevice) { Device.SetIsGpsDevice(true); } /* The NmeaInterpreter in GPS.NET 3.0 uses a slimmed-down architecture to reduce * the memory and CPU footprint of processing NMEA data. */ // All data updates in a single shot to prevent race conditions lock (DataChangeSyncRoot) { // Parse the sentence Parse(sentence); } // If we're recording, output the sentence lock (RecordingSyncRoot) { if (RecordingStream != null) { byte[] buffer = Encoding.ASCII.GetBytes(sentence.Sentence + "\r\n"); RecordingStream.Write(buffer, 0, buffer.Length); OnSentenceRecorded(sentence); } } #if DEBUG // Notify of the sentence OnSentenceReceived(sentence); #endif }
#pragma warning disable CS1998 // No async operations in mock /// <summary> /// Implements the same method as the real service interface allowing the mock to be plugged in /// </summary> /// <typeparam name="Response"></typeparam> /// <typeparam name="Request"></typeparam> /// <param name="resource"></param> /// <param name="verb"></param> /// <param name="request"></param> /// <param name="deleteBody"></param> /// <param name="session"></param> /// <returns></returns> public async Task <ShippingApiResponse <Response> > HttpRequest <Response, Request>(string resource, HttpVerb verb, Request request, bool deleteBody, ISession session = null) where Request : IShippingApiRequest { string fullPath = request.RecordingFullPath(resource, session); if (File.Exists(fullPath)) { var apiResponse = new ShippingApiResponse <Response> { HttpStatus = HttpStatusCode.OK, Success = true }; long jsonPosition = 0; using (var fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read)) using (var mimeStream = new MimeStream(fileStream)) { mimeStream.SeekNextPart(); //request mimeStream.SeekNextPart(); //response mimeStream.ClearHeaders(); mimeStream.ReadHeaders(); // reads http headers as well if (!mimeStream.FirstLine.StartsWith("HTTP", StringComparison.InvariantCulture)) { apiResponse = new ShippingApiResponse <Response> { HttpStatus = HttpStatusCode.InternalServerError, Success = false }; session.LogDebug(string.Format("Mock request failed {0}", fullPath)); apiResponse.Errors.Add(new ErrorDetail() { ErrorCode = "Mock 500", Message = "Bad format " + fullPath }); return(apiResponse); } var hrc = mimeStream.FirstLine.Split(' '); apiResponse.HttpStatus = (HttpStatusCode)int.Parse(hrc[1]); apiResponse.Success = apiResponse.HttpStatus == HttpStatusCode.OK; foreach (var h in mimeStream.Headers) { apiResponse.ProcessResponseAttribute(h.Key, h.Value); } using (var recordingStream = new RecordingStream(mimeStream, request.RecordingFullPath(resource, session), FileMode.Create, RecordingStream.RecordType.PlainText)) { try { //dont open the record file recordingStream.IsRecording = false; ShippingApiResponse <Response> .Deserialize(session, recordingStream, apiResponse, jsonPosition); } catch (Exception ex) { session.LogError(string.Format("Mock request {0} got deserialization exception {1}", fullPath, ex.Message)); throw ex; } } } return(apiResponse); } else { var apiResponse = new ShippingApiResponse <Response> { HttpStatus = HttpStatusCode.NotFound, Success = false }; session.LogDebug(string.Format("Mock request failed {0}", fullPath)); apiResponse.Errors.Add(new ErrorDetail() { ErrorCode = "Mock 401", Message = "Could not find response file" + fullPath }); return(apiResponse); } }
private void EndRecording() { File.WriteAllBytes("Recording.bytes", stream.stream.ToArray()); state = RecorderState.Idle; stream = null; }
private void EndPlayback() { Human.instance.enabled = true; state = RecorderState.Idle; stream = null; }