Ejemplo n.º 1
0
        PostItCommand decodeAddCommand(byte[] data)
        {
            string commndStr = Encoding.UTF8.GetString(data);

            if (!commndStr.Contains(Encoding.UTF8.GetString(PostItCommand.ADD_PREFIX)) ||
                !commndStr.Contains(Encoding.UTF8.GetString(PostItCommand.ADD_POSTFIX)))
            {
                return(null);
            }
            if (!commndStr.StartsWith(Encoding.UTF8.GetString(PostItCommand.ADD_PREFIX)))
            {
                return(null);
            }
            //start to extract part of the message;
            //structure of an Add command
            //<ADD> ID X Y Orientation Size DataType Data </ADD>
            PostItCommand command = new PostItCommand();

            command.CommandType = PostItCommandType.Add;
            int        index = PostItCommand.ADD_PREFIX.Length;
            PostItNote note  = new PostItNote();

            //ID
            byte[] buffer = new byte[4];
            Array.Copy(data, index, buffer, 0, 4);
            note.Id = Utilities.UtilitiesLib.Bytes2Int(buffer);
            index  += 4;
            //X
            Array.Copy(data, index, buffer, 0, 4);
            note.CenterX = Utilities.UtilitiesLib.Bytes2Float(buffer);
            index       += 4;
            //Y
            Array.Copy(data, index, buffer, 0, 4);
            note.CenterY = Utilities.UtilitiesLib.Bytes2Float(buffer);
            index       += 4;
            //skip 4 bytes of orientation, can be used in the future
            index += 4;
            //get size of the content
            Array.Copy(data, index, buffer, 0, 4);
            int contentSize = Utilities.UtilitiesLib.Bytes2Int(buffer);

            index += 4;
            //get content data type
            Array.Copy(data, index, buffer, 0, 4);
            note.DataType = PostItCommand.GetPostItContentType(buffer);
            index        += 4;
            //start getting content
            buffer = new byte[contentSize];
            Array.Copy(data, index, buffer, 0, buffer.Length);
            note.ParseContentFromBytes(note.DataType, buffer);
            command.CommandData = note;
            return(command);
        }
Ejemplo n.º 2
0
 public void handleDownloadedStreamsFromCloud(Dictionary <int, Stream> noteStreams)
 {
     foreach (int noteID in noteStreams.Keys)
     {
         Stream stream = noteStreams[noteID];
         if (stream is MemoryStream)
         {
             PostItNote note = new PostItNote();
             note.Id       = noteID;
             note.CenterX  = 0;
             note.CenterY  = 0;
             note.DataType = PostItContentDataType.WritingImage;
             note.ParseContentFromBytes(note.DataType, (stream as MemoryStream).ToArray());
             if (newNoteExtractedEventHandler != null)
             {
                 newNoteExtractedEventHandler(note);
             }
         }
     }
 }