Example #1
0
        private List <object> DictToFormsList(JArray content)
        {
            List <object> forms = new List <object>();

            foreach (JObject coloredForm in content)
            {
                Dictionary <string, object> pdict       = JsonConvert.DeserializeObject <Dictionary <string, object> >(coloredForm.ToString());
                Dictionary <string, string> formElement = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                switch (pdict["type"])
                {
                case "LINE":
                    ColoredLine line = DictToLine(formElement);
                    forms.Add(line);
                    break;

                case "CIRCLE":
                    ColoredCircle circle = DictToCircle(formElement);
                    forms.Add(circle);
                    break;

                case "PATH":
                    ColoredPath path = DictToPath(formElement);
                    forms.Add(path);
                    break;

                case "RECTANGLE":
                    ColoredRectangle rectangle = DictToRectangle(formElement);
                    forms.Add(rectangle);
                    break;
                }
            }
            return(forms);
        }
Example #2
0
        private JObject Jsonify(ColoredPath path)
        {
            string  colourHash  = path.Color.ToString();
            string  SVGPath     = path.Path.ToSvgPathData();
            float   strokeWidth = path.StrokeWidth;
            JObject json        = new JObject(new JProperty("type", "PATH"),
                                              new JProperty("content", new JObject(
                                                                new JProperty("svgpath", SVGPath),
                                                                new JProperty("colorHash", colourHash),
                                                                new JProperty("strokeWidth", strokeWidth))));

            return(json);
        }
        //Evenement déclenché quand une nouvelle forme ou instruction est reçue par le client
        private void UpdateUi(Object o, UpdateUIEventArgs eventArgs)
        {
            lock (forms)
            {
                switch (eventArgs.Type)
                {
                case "PATH":
                    ColoredPath coloredPath = eventArgs.Path;
                    forms.Add(coloredPath);
                    break;

                case "CIRCLE":
                    ColoredCircle coloredCircle = eventArgs.Circle;
                    forms.Add(coloredCircle);
                    break;

                case "LINE":
                    ColoredLine coloredLine = eventArgs.Line;
                    forms.Add(coloredLine);
                    break;

                case "RECTANGLE":
                    ColoredRectangle coloredRectangle = eventArgs.Rectangle;
                    forms.Add(coloredRectangle);
                    break;

                case "CLEAR":
                    forms.Clear();
                    break;

                case "SIZE":
                    width  = eventArgs.Width;
                    height = eventArgs.Height;
                    break;

                case "REQUEST_STATUS":
                    asyncClient.RestoreWhiteboard(this.forms, eventArgs.client_id);
                    break;

                case "RESTORE":
                    forms = eventArgs.Forms;
                    break;
                }
                View.InvalidateSurface();
            }
        }
Example #4
0
        private void ReceivePackage(Object o, PacketReceivedEventArgs eventArgs)
        {
            Dictionary <string, object> pdict = JsonConvert.DeserializeObject <Dictionary <string, object> >(eventArgs.data);
            Dictionary <string, string> content;;


            UpdateUIEventArgs UiEventArgs;

            switch (pdict["type"])
            {
            case "PATH":
                content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                ColoredPath path = DictToPath(content);
                UiEventArgs = new UpdateUIEventArgs {
                    Type = "PATH", Path = path
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "CIRCLE":
                content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                ColoredCircle circle = DictToCircle(content);
                UiEventArgs = new UpdateUIEventArgs {
                    Type = "CIRCLE", Circle = circle
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "LINE":
                content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                ColoredLine line = DictToLine(content);
                UiEventArgs = new UpdateUIEventArgs {
                    Type = "LINE", Line = line
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "REQUEST_STATUS":
                //Called for the host, when a new client is requesting the whiteboard's current state
                content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                int id = int.Parse(content["id"]);
                //the id corresponds to the client's id from the server's perspective
                UiEventArgs = new UpdateUIEventArgs {
                    Type = "REQUEST_STATUS", client_id = id
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "RECTANGLE":
                content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                ColoredRectangle rectangle = DictToRectangle(content);
                UiEventArgs = new UpdateUIEventArgs {
                    Rectangle = rectangle, Type = "RECTANGLE"
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "SIZE":
                content = JsonConvert.DeserializeObject <Dictionary <string, string> >(pdict["content"].ToString());
                float w = float.Parse(content["width"]);
                float h = float.Parse(content["height"]);
                UiEventArgs = new UpdateUIEventArgs {
                    Width = w, Height = h, Type = "SIZE"
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "CLEAR":
                UiEventArgs = new UpdateUIEventArgs {
                    Type = "CLEAR"
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            case "RESTORE":
                JArray        jArray = JArray.Parse(pdict["content"].ToString());
                List <object> forms  = DictToFormsList(jArray);
                UiEventArgs = new UpdateUIEventArgs {
                    Type = "RESTORE", Forms = forms
                };
                UpdateUIEventHandler.OnUpdateUI(this, UiEventArgs);
                break;

            default:
                Console.WriteLine("error parsing received data: {0}", eventArgs.data);
                throw new ArgumentException(eventArgs.data);
            }
        }
Example #5
0
        public void Send(ColoredPath path)
        {
            JObject json = Jsonify(path);

            SendData(json);
        }