public void decodeCommandInByteArray(byte[] data)
        {
            byte[]            allData     = concatWithRemainingBuffer(data);
            PostItCommandType commandType = classifyCommand(allData);
            PostItCommand     command     = null;

            switch (commandType)
            {
            case PostItCommandType.Add:
                command = decodeAddCommand(allData);
                break;

            case PostItCommandType.Update:
                command = decodeUpdateCommand(allData);
                break;

            case PostItCommandType.Delete:
                command = decodeDeleteCommand(allData);
                break;
            }
            if (command != null)
            {
                if (commandDecodedEventHandler != null)
                {
                    commandDecodedEventHandler(command.CommandType, command.CommandData);
                }
                buffer = null;
            }
            else
            {
                buffer = allData;
            }
        }
示例#2
0
        public void ProcessPostItNoteCommand(PostItCommandType commandType, object commandArg)
        {
            switch (commandType)
            {
            case PostItCommandType.Add:
                PostItNote addedNote = (PostItNote)commandArg;
                if (getNoteWithID(addedNote.Id) == null)
                {
                    postItNotes.Add(addedNote);
                }
                if (noteAddedEventHandler != null)
                {
                    noteAddedEventHandler(addedNote);
                }
                break;

            case PostItCommandType.Update:
                PostItNote updatedNote  = (PostItNote)commandArg;
                PostItNote matchingNote = getNoteWithID(updatedNote.Id);
                if (!(matchingNote == null))
                {
                    matchingNote.CenterX = updatedNote.CenterX;
                    matchingNote.CenterX = updatedNote.CenterY;
                    if (updatedNote.Content != null)
                    {
                        matchingNote.Content = updatedNote.Content;
                    }
                    if (noteUpdatedEventHandler != null)
                    {
                        noteUpdatedEventHandler(matchingNote);
                    }
                }
                break;

            case PostItCommandType.Delete:
                int        noteID      = (int)commandArg;
                PostItNote tobeRemoved = getNoteWithID(noteID);
                if (tobeRemoved != null)
                {
                    postItNotes.Remove(tobeRemoved);
                    if (noteRemovedEventHandler != null)
                    {
                        noteRemovedEventHandler(tobeRemoved);
                    }
                }
                break;
            }
        }