public void recieveLine(string obj)
        {
            try
            {
                while (true)
                {
                    int    index   = obj.IndexOf('}');
                    string objtemp = obj.Substring(0, index + 1);

                    MyLine myLine = JsonConvert.DeserializeObject <MyLine>(objtemp);
                    Line   line   = MyLine.newLine(myLine.X1, myLine.Y1, myLine.X2, myLine.Y2, myLine.thickness, myLine.rgb);
                    canvas.Children.Add(line);

                    if (objtemp.Length == obj.Length)
                    {
                        break;
                    }
                    obj = obj.Substring(index + 1, obj.Length - index - 1);
                }
            }
            catch
            {
            }
        }
Beispiel #2
0
        public void recieve(string obj)
        {
            try
            {
                while (true)
                {
                    int      index   = obj.IndexOf("}}") + 1;
                    string   objtemp = obj.Substring(0, index + 1);
                    Envelope unknown = JsonConvert.DeserializeObject <Envelope>(objtemp);


                    if (unknown.type == "MyLine")
                    {
                        MyLine myLine = JsonConvert.DeserializeObject <MyLine>(unknown.obj.ToString());
                        Line   line   = MyLine.newLine(myLine.X1, myLine.Y1, myLine.X2, myLine.Y2, myLine.thickness, myLine.rgb);
                        canvas.Children.Add(line);
                    }
                    else if (unknown.type == "Message")
                    {
                        Message m = JsonConvert.DeserializeObject <Message>(unknown.obj.ToString());
                        string  s = m.user + ": " + m.text + "\n";
                        chatWindow.Text += s;
                    }
                    else
                    {
                        break;
                    }

                    /*
                     * MyLine l = null;
                     * l = (unknown as MyLine);
                     * if (l==null)
                     * {
                     *  MessageBox.Show("This doesn't show");
                     * }
                     * if (l is MyLine)
                     * {
                     *  MessageBox.Show("This doesn't show either???");
                     * }
                     */
                    /*
                     * try
                     * {
                     *  unknown = unknown as MyLine;
                     * }catch
                     * {
                     *  unknown = unknown as Message;
                     * }
                     * if (unknown is MyLine)
                     * {
                     *  MessageBox.Show("It's a line");
                     * }
                     * else if (unknown is Message)
                     * {
                     *  MessageBox.Show("It's a message");
                     * }
                     */



                    if (objtemp.Length == obj.Length)
                    {
                        break;
                    }
                    obj = obj.Substring(index + 1, obj.Length - index - 1);
                }
            }
            catch
            {
            }
        }