Beispiel #1
0
        // -----------------------------------------------------------------------------------------
        // FUNCTIONS CALLED FROM CLIENT

        /// <summary>
        /// Add new element to canvas
        /// </summary>
        /// <param name="boardElement">element to add</param>
        public void doAdd(BoardElement boardElement) // add board element to ink canvas
        {
            if (selectedObject != boardElement.id)
            {
                if (allBoardElements.ContainsKey(boardElement.id) && selectedObject != boardElement.id)
                {
                    Dispatcher.Invoke(() =>
                    {
                        texting.Text = "ICI";
                        //texting.Text = Convert.ToString(boardElement.id);
                    }
                                      );
                    doDelete(boardElement.id);
                }
                Dispatcher.Invoke(
                    () =>
                {
                    boardElement.AddToCanvas(this, inkCanvas);
                    allBoardElements[boardElement.id] = boardElement;
                    bool firstTime = true;
                    long objectid  = objectIDGenerator.GetId(boardElement.getElement(), out firstTime);
                    objectIdToBoardId.Add(objectid, boardElement.id);
                });
            }
        }
Beispiel #2
0
 /// <summary>
 /// Delete element from canvas
 /// </summary>
 /// <param name="id">id of element to delete</param>
 public void doDelete(int id) // delete board element from ink canvas
 {
     if (allBoardElements.ContainsKey(id))
     {
         Dispatcher.Invoke(
             () =>
         {
             bool obol;
             BoardElement boardElement = allBoardElements[id];
             boardElement.DeleteFromCanvas(this, inkCanvas);
             objectIdToBoardId.Remove(objectIDGenerator.GetId(allBoardElements[id].getElement(), out obol));
             allBoardElements.Remove(id);
         });
     }
 }
Beispiel #3
0
        /*********************************************************************/
        /**Method the main window can invoke to issue request to the server***/
        /*********************************************************************/


        /// <summary>
        /// Method to invoke to ask the server to add an object
        /// </summary>
        /// <param name="b">Object to be added</param>
        public void ask_add(BoardElement b)
        {
            connexionServer.addInstruction("ADD" + b.GetString());
        }
Beispiel #4
0
 /// <summary>
 /// Method to invoke to ask the server to modify an object
 /// </summary>
 /// <param name="id"></param>
 /// <param name="b"></param>
 public void ask_modif(int id, BoardElement b)
 {
     connexionServer.addInstruction("MOD" + Convert.ToString(id) + " " + b.GetString());
 }
Beispiel #5
0
        /*******************************************************************/
        /**Method the server will invoke to send instruction to the client**/
        /*******************************************************************/

        /// <summary>
        /// Function that is to be called by the "connexionServer" object when it recieve a full instruction
        /// </summary>
        /// <param name="str">The instruction to treat</param>
        private void runInstruction(String str)
        {
            String instructionName = str.Substring(0, 3);

            if (instructionName.Equals("ADD")) //Adding request
            {
                int i = 3;
                while (i < str.Length && str[i] != m_limitor && str[i] != ' ')
                {
                    i++;
                }
                int          id = int.Parse(str.Substring(3, i - 3));
                BoardElement b  = ObjectConverter.ReconvertElement(str.Substring(i + 1));
                b.id = id;
                mainWindow.doAdd(b);
            }
            if (instructionName.Equals("SEL")) //Selecting request
            {
                int i = 3;
                while (i < str.Length && str[i] != m_limitor && str[i] != ' ')
                {
                    i++;
                }
                int id = int.Parse(str.Substring(3, i - 3));
                mainWindow.doSelect(id);
            }
            if (instructionName.Equals("DES")) //Deselecting request
            {
                mainWindow.doDeselect();
            }
            if (instructionName.Equals("DEL")) //Deletig request
            {
                int i = 3;
                while (i < str.Length && str[i] != m_limitor && str[i] != ' ')
                {
                    i++;
                }
                int id = int.Parse(str.Substring(3, i - 3));
                mainWindow.doDelete(id);
            }
            if (instructionName.Equals("CLR")) //Request to clear the board
            {
                mainWindow.doClearAll();
            }
            if (instructionName.Equals("INF")) //Give info to the clients
            {
                String[] infos = str.Substring(3).Split(' ');
                m_idCOnnexion = Convert.ToInt32(infos[0]);
                m_nameBoard   = infos[1];
            }
            if (instructionName.Equals("EXT")) //Tell the client to exit
            {
                mainWindow.doClearAll();
                connexionServer.stop();
            }
            if (instructionName.Equals("ERR")) //Indicate an error to the client
            {
                string text = str.Substring(3);
                mainWindow.doShowError(text);
            }
        }