private void Command_OnPrepare(Command c) { c.OnPrepare -= Command_OnPrepare; commandsPrepared++; if (commandsPrepared == commands.Count) { Debug.Log("Drone has prepared (" + commandsPrepared + ")"); OnPrepare?.Invoke(this); } }
public void Prepare(Drone d) { if (isInitialised) { return; } SetDrone(d); Initialise(); isInitialised = true; OnPrepare?.Invoke(this); }
public void Prepare() { _prepareTimer.Current = _prepareTime; _prepareTimer.IsStop = false; OnPrepare?.Invoke(); }
private void Read() { byte[] packetSize = new byte[4]; try { while (_stream.Read(packetSize, 0, 4) != 0) { #region Deserialize Message Size int messageSize = BitConverter.ToInt32(packetSize); byte[] messageData = new byte[messageSize]; #endregion #region Read Message int bytesRead = 0; do { bytesRead += _stream.Read(messageData, bytesRead, messageSize - bytesRead); } while (bytesRead < messageSize); #endregion #region Deserialize Message DataMessage message; using (MemoryStream memoryStream = new MemoryStream(messageData)) { if (memoryStream.CanRead) { message = (DataMessage) new BinaryFormatter().Deserialize(memoryStream); } else { return; } } #endregion #region Distribute Messages lock (_lock) { //Check reserved routes firsts switch (message.Route) { case "connect": //assign client id ClientId = message.ClientId; _allowEmit = true; OnConnect?.Invoke(message.ClientId); break; case "authentication": Emit("authentication", OnAuthentication?.Invoke(message)); break; case "prepare": OnPrepare?.Invoke(message); break; case "ready": _acceptData = true; OnReady?.Invoke(); break; case "disconnect": Disconnect("Server Requested Disconnect"); break; case "HeartBeat": _heartBeatLength = _timer.ElapsedMilliseconds - _previousHeartBeat; _previousHeartBeat = _timer.ElapsedMilliseconds; break; default: { #region Distribute Messages to Routes if (!_acceptData) { continue; } if (!_handlers.ContainsKey(message.Route)) { continue; } foreach (Action <DataMessage> handler in _handlers[message.Route]) { handler(message); } break; #endregion } } } #endregion } } catch (IOException) { Disconnect("Read Error"); } catch (ObjectDisposedException) { /*If this happens we do not care*/ } catch (Exception ex) { Console.WriteLine("Write Exception: {0}", ex); } }