Exemple #1
0
        private void Draw(Canvas target, CustomBrush brush, double x1, double y1, double x2, double y2)
        {
            DrawEllipse(target, brush, x1, y1);
            DrawLine(target, brush, x1, y1, x2, y2);

            /*
             * UseDispatcher(TBl_Debug, DispatcherPriority.Loaded, delegate
             * {
             *  drawCount += 2;
             *  TBl_Debug.Text = drawCount.ToString();
             * });
             */
        }
Exemple #2
0
 private void DrawLine(Canvas target, CustomBrush brush, double x1, double y1, double x2, double y2)
 {
     target.Children.Add(new Line()
     {
         Stroke          = brush.ColorBrush,
         StrokeThickness = brush.Thickness,
         X1 = x1,
         Y1 = y1,
         X2 = x2,
         Y2 = y2
     });
     //Console.WriteLine(string.Format("{0}:{1} -> {2}:{3}", x1, y1, x2, y2));
 }
Exemple #3
0
        private void DrawEllipse(Canvas target, CustomBrush brush, double x1, double y1)
        {
            mouseLastEllipsePosition.X = x1;
            mouseLastEllipsePosition.Y = y1;
            Ellipse ell = new Ellipse()
            {
                Stroke          = brush.ColorBrush,
                StrokeThickness = brush.Thickness,
                Width           = brush.Thickness,
                Height          = brush.Thickness
            };

            ell.SetValue(Canvas.LeftProperty, x1 - brush.Thickness / 2);
            ell.SetValue(Canvas.TopProperty, y1 - brush.Thickness / 2);
            Canvas_Drawing.Children.Add(ell);
        }
Exemple #4
0
        public void Receive()
        {
            try
            {
                while (true)
                {
                    Transfer <MessageContainer> transfer = new Transfer <MessageContainer>(Listener.AcceptTcpClient());
                    mw.WriteDebug("Client connected", LogLevels.Info);
                    int transferCount;
                    lock (__lockTransfers)
                        Transfers.Add(transfer);
                    transferCount = Transfers.Count + 1;

                    mw.UseDispatcher(mw.Canvas_Drawing, delegate
                    {
                        var msgList = new List <Message>();

                        if (mw.Canvas_Drawing.Children.Count < 1000) // Init with normal DrawData
                        {
                            //Send Drawing Data

                            foreach (var el in mw.Canvas_Drawing.Children)
                            {
                                if (el as Line != null)
                                {
                                    Line l = (Line)el;
                                    msgList.Add(new DrawData(l.X1, l.Y1, l.X2, l.Y2, (double)l.GetValue(Shape.StrokeThicknessProperty), l.GetValue(Shape.StrokeProperty).ToString()));
                                }
                            }

                            if (mw.DrawingLocked)
                            {
                                msgList.Add(new DrawLock());
                            }
                            else
                            {
                                msgList.Add(new DrawUnlock());
                            }

                            Send(transfer, new MessageContainer(msgList));

                            //Update other users
                            SendAll(new UserCount(transferCount));
                        }
                        else // Init with async DrawDataBlock
                        {
                            var msgListDrawData = new List <Message>();
                            msgList.Add(new DrawDataBlockFlag());

                            if (mw.DrawingLocked)
                            {
                                msgList.Add(new DrawLock());
                            }
                            //send no DrawUnlock to ensure the board is locked until DrawDataBlock

                            Send(transfer, new MessageContainer(msgList));

                            //Update other users
                            SendAll(new UserCount(transferCount));

                            //Send DrawDataBlock
                            CustomBrush lastBrush = null;
                            var lastLines         = new List <NetCommunication.MessageTypes.SupportClasses.Line>();
                            foreach (var el in mw.Canvas_Drawing.Children)
                            {
                                if (el as Line != null)
                                {
                                    Line l = (Line)el;
                                    if (lastBrush == null)
                                    {
                                        lastBrush = new CustomBrush((SolidColorBrush)l.Stroke, l.StrokeThickness);
                                    }
                                    if (l.StrokeThickness != lastBrush.Thickness || l.Stroke != lastBrush.ColorBrush)
                                    {
                                        msgListDrawData.Add(new DrawDataBlock(lastBrush.ColorBrush.ToString(), lastBrush.Thickness, new List <NetCommunication.MessageTypes.SupportClasses.Line>(lastLines)));
                                        lastLines.Clear();
                                        lastBrush = new CustomBrush((SolidColorBrush)l.Stroke, l.StrokeThickness);
                                    }
                                    lastLines.Add(new NetCommunication.MessageTypes.SupportClasses.Line(l.X1, l.Y1, l.X2, l.Y2));
                                }
                            }
                            msgListDrawData.Add(new DrawDataBlock(lastBrush.ColorBrush.ToString(), lastBrush.Thickness, new List <NetCommunication.MessageTypes.SupportClasses.Line>(lastLines)));

                            Send(transfer, new MessageContainer(msgListDrawData));
                        }
                    });

                    //Start Receiver-Thread
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        try
                        {
                            while (true)
                            {
                                MessageReceived?.Invoke(transfer, new MessageReceivedEventArgs(transfer.Receive()));
                            }
                        }
                        catch (IOException)
                        {
                            OnClientDisconnect(transfer);
                            mw.WriteDebug("IOException in Server.Receive in transfer.Receive", LogLevels.Debug);
                        }
                    });
                    mw.UseDispatcher(mw.TBl_UserCount, delegate { mw.TBl_UserCount.Text = (transferCount).ToString(); });
                }
            }
            catch (SocketException ex)
            {
                if (ex.ErrorCode != 10004) //WSACancelBlockingCall
                {
                    mw.WriteDebug("WSACancelBlockingCall in Server.Recieve", LogLevels.Debug);
                    throw ex;
                }
            }
        }