public static void DoAction(MessagesMeaning msgMeaning, int cnt, byte[] receivedBytes) { switch (msgMeaning) { case MessagesMeaning.ClientReady: ApplicationUseManager.Instance.TriggerApplicationReady(); break; case MessagesMeaning.ClassificationAsLetters: int lengthOfString = (int)receivedBytes[1]; byte[] lastAdjustmentIdBytes = new byte[4]; lastAdjustmentIdBytes[0] = receivedBytes[2]; lastAdjustmentIdBytes[1] = receivedBytes[3]; lastAdjustmentIdBytes[2] = receivedBytes[4]; lastAdjustmentIdBytes[3] = receivedBytes[5]; int lastAdjustmentId = CommonUtils.Transform4BytesToInt(lastAdjustmentIdBytes); String responseMultipleCharactersAsString = ""; for (int i = 6, counter = 1; counter <= lengthOfString; counter++, i++) { byte currentByte = receivedBytes[i]; responseMultipleCharactersAsString += Convert.ToChar(currentByte); } // use writing observer and connectedComponentsTool to update the word //UIUpdater.UpdatePredictedWord(responseMultipleCharactersAsString); Tuple <List <ConnectedComponent>, ConnectedComponent> latestAdjustment = connectedComponentsTool.GetAdjustmentById(lastAdjustmentId); List <String> possibleChars = new List <String>(); possibleChars.Add(responseMultipleCharactersAsString); writingObserver.AdjustExistingWords(latestAdjustment.Item1, latestAdjustment.Item2, possibleChars); break; case MessagesMeaning.Unknown: Console.WriteLine("received unkown message from client: "); Console.WriteLine(receivedBytes); break; } }
public static void interpretMessageAndDoAction(int cnt, byte[] receivedBytes) { MessagesMeaning msgMeaning = interpretMessage(cnt, receivedBytes); DoAction(msgMeaning, cnt, receivedBytes); }