/// <summary> /// When a connection to the server is established and we can start reading the data, this will be called. /// </summary> /// <param Name="asyncInfo">Info about the connection.</param> /// <param Name="status">Status of the connection</param> private async void RcvNetworkConnectedHandler(IAsyncAction asyncInfo, AsyncStatus status) { // Status completed is successful. if (status == AsyncStatus.Completed) { DataReader networkDataReader; // Since we are connected, we can read the data being sent to us. using (networkDataReader = new DataReader(networkConnection.InputStream)) { // read four bytes to get the size. DataReaderLoadOperation drlo = networkDataReader.LoadAsync(4); while (drlo.Status == AsyncStatus.Started) { // just waiting. } int dataSize = networkDataReader.ReadInt32(); if (dataSize < 0) { Debug.Log("Super bad super big data size"); } // Need to allocate a new buffer with the dataSize. mostRecentDataBuffer = new byte[dataSize]; // Read the data. await networkDataReader.LoadAsync((uint)dataSize); networkDataReader.ReadBytes(mostRecentDataBuffer); // And fire our data ready event. DataReadyEvent?.Invoke(mostRecentDataBuffer); } } else { Debug.Log("Failed to establish connection for rcv. Error Code: " + asyncInfo.ErrorCode); // In the failure case we'll requeue the data and wait before trying again. // And set the defer time so the update loop can do the 'Unity things' // on the main Unity thread. DeferredActionQueue.Enqueue(() => { Invoke("RequestDataRetry", timeToDeferFailedConnections); }); } networkConnection.Dispose(); waitingForConnection = false; }
public void SetViewModel(object context) { if (context is TViewModel viewModel) { DataContext = viewModel; } else { Her.Warn($"{context} is not matching {typeof(TViewModel)}"); } DataReadyEvent?.Invoke(); }
/// <summary> /// When a connection to the server is established and we can start reading the data, this will be called. /// </summary> /// <param name="asyncInfo">Info about the connection.</param> /// <param name="status">Status of the connection</param> private async void RcvNetworkConnectedHandler(IAsyncAction asyncInfo, AsyncStatus status) { // Status completed is successful. if (status == AsyncStatus.Completed) { DataReader networkDataReader; // Since we are connected, we can read the data being sent to us. using (networkDataReader = new DataReader(networkConnection.InputStream)) { // read four bytes to get the size. DataReaderLoadOperation drlo = networkDataReader.LoadAsync(4); while (drlo.Status == AsyncStatus.Started) { // just waiting. } int dataSize = networkDataReader.ReadInt32(); if (dataSize < 0) { Debug.Log("Super bad super big datasize"); } // Need to allocate a new buffer with the dataSize. mostRecentDataBuffer = new byte[dataSize]; // Read the data. await networkDataReader.LoadAsync((uint)dataSize); networkDataReader.ReadBytes(mostRecentDataBuffer); // And fire our data ready event. DataReadyEvent?.Invoke(mostRecentDataBuffer); } } else { Debug.Log("Failed to establish connection for rcv. Error Code: " + asyncInfo.ErrorCode); } networkConnection.Dispose(); waitingForConnection = false; }
private void HandleTransponderDataReady(object sender, RawTransponderDataEventArgs e) { Tracks = new Track[e.TransponderData.Count]; char[] separator = { ';' }; int trackIndex = 0; foreach (var data in e.TransponderData) { string[] tokens = data.Split(separator); Tracks[trackIndex] = new Track() { Tag = tokens[0], X = int.Parse(tokens[1]), Y = int.Parse(tokens[2]), Z = int.Parse(tokens[3]), Timestamp = DateTime.ParseExact(tokens[4], "yyyyMMddHHmmssfff", null) }; trackIndex++; } DataReadyEvent?.Invoke(null, new DataReceivedEventArgs(Tracks.ToList())); }
public void SetViewModel(TViewModel dataContext) { DataContext = dataContext; DataReadyEvent?.Invoke(); }
private void OnCommunicatorData(string ip, int port, long time, byte[] bytes, int offset, int length, string ID, ushort[] ipChunks) { // Not used normally DataReadyEvent?.Invoke(ip, port, time, bytes, offset, length, ID, ipChunks); }
public virtual void FireDataEvent(string ip, int port, long time, byte[] bytes, int offset, int length, string ID, ushort[] ipChunks = null) { DataReadyEvent?.Invoke(ip, port, time, bytes, offset, length, ID, ipChunks); }