示例#1
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Citation                     = new Citation(ActionFactory.Build(ActionFactory.ActionType.Music));
     Container                    = ShapeFactory.Build(ShapeFactory.ShapeType.Rectangle, ActionFactory.Build(ActionFactory.ActionType.Music), Citation);
     Container.SystemShape        = CreateRectangle(Colors.White, canvas.ActualHeight, canvas.ActualWidth);
     Container.SystemShape.Width  = 3000;
     Container.SystemShape.Height = 2000;
     canvas.Children.Add(Container.SystemShape);
     dict.Add(Container.SystemShape, new Tuple <DesignPatternCL.Models.Shapes.Shape, DesignPatternCL.Models.Shapes.Shape>(null, Container));
     SelectedShape            = Container.SystemShape;
     SelectedShapeSize.Height = SelectedShape.Height;
     SelectedShapeSize.Width  = SelectedShape.Width;
 }
示例#2
0
        private void AddShapeBtn_Click(object sender, RoutedEventArgs e)
        {
            DesignPatternCL.Models.Shapes.Shape shape = null;
            switch (Shapes[ShapesCombobox.SelectedIndex])
            {
            case ShapeFactory.ShapeType.Rectangle:
                shape             = ShapeFactory.Build(ShapeFactory.ShapeType.Rectangle, Container.Action, Citation);
                shape.SystemShape = CreateRectangle(Color.FromRgb(Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255))));
                break;

            case ShapeFactory.ShapeType.Circle:
                shape             = ShapeFactory.Build(ShapeFactory.ShapeType.Circle, Container.Action, Citation);
                shape.SystemShape = CreateEllipse(Color.FromRgb(Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255))));
                break;

            case ShapeFactory.ShapeType.Square:
                shape             = ShapeFactory.Build(ShapeFactory.ShapeType.Square, Container.Action, Citation);
                shape.SystemShape = CreateSquare(Color.FromRgb(Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255))));
                break;

            default:
                shape             = ShapeFactory.Build(ShapeFactory.ShapeType.Square, Container.Action, Citation);
                shape.SystemShape = CreateSquare(Color.FromRgb(Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255)), Convert.ToByte(rand.Next(255))));
                break;
            }
            var s = dict[SelectedShape];

            if (s != null && s.Item2.GetType() == ShapeFactory.ShapeType.Rectangle)
            {
                ((DesignPatternCL.Models.Shapes.Rectangle)s.Item2).Shapes.Add(shape);
                canvas.Children.Add(shape.SystemShape);
                Details.Text = Container.Details();
                dict.Add(shape.SystemShape, new Tuple <DesignPatternCL.Models.Shapes.Shape, DesignPatternCL.Models.Shapes.Shape>(s.Item2, shape));
            }
            else
            {
                MessageBox.Show($"We can't add shape to {s?.GetType().ToString()}");
            }
        }
        static void Main(string[] args)
        {
            // TP1 ===> Singleton
            //LogRepository logRepository = new LogRepository();

            //for (int i = 0; i < 100; i++)
            //{
            //  logRepository.Insert(new Log()
            //  {
            //    Session = $"User {i}",
            //    Object = $"Object {i}",
            //    Action = $"Action {i}"
            //  });

            //  Console.WriteLine($" Object inserted with Connection Id  =>  { DbConnection.ConnectionId}");
            //}

            //var l = logRepository.Get();

            //Console.ReadKey();
            //**************************************************************************

            //TP2 ====> Faactory & Strategy


            //IAction Music = ActionFactory.Build(ActionFactory.ActionType.Music);
            //IAction Noise = ActionFactory.Build(ActionFactory.ActionType.Noise);
            //IAction Message = ActionFactory.Build(ActionFactory.ActionType.Message);

            //List<Shape> shapes = new List<Shape>();
            //Citation c = new Citation();
            //shapes.Add(ShapeFactory.Build(ShapeFactory.ShapeType.Rectangle, Music,c));
            //shapes.Add(ShapeFactory.Build(ShapeFactory.ShapeType.Circle, Noise,c));
            //shapes.Add(ShapeFactory.Build(ShapeFactory.ShapeType.Square, Message,c));

            //foreach (var shape in shapes)
            //{
            //  Console.WriteLine();
            //  Console.WriteLine($"  * form : {shape.GetShape()} ===>  {shape.Action.GetAction()}");
            //}
            //******************************************************************
            // TP4 ====> Observateur


            //Citation citation = new Citation(ActionFactory.Build(ActionFactory.ActionType.Music));

            //Shape rectangle = ShapeFactory.Build(ShapeFactory.ShapeType.Rectangle, ActionFactory.Build(ActionFactory.ActionType.Noise), citation);
            //Shape ellipse = ShapeFactory.Build(ShapeFactory.ShapeType.Circle, ActionFactory.Build(ActionFactory.ActionType.Noise), citation);
            //Shape square = ShapeFactory.Build(ShapeFactory.ShapeType.Square, ActionFactory.Build(ActionFactory.ActionType.Music), citation);

            //Console.WriteLine($" {rectangle.GetShape()} - {rectangle.Action.GetAction()}");
            //Console.WriteLine($" {ellipse.GetShape()} - {ellipse.Action.GetAction()}");
            //Console.WriteLine($" {square.GetShape()} - {square.Action.GetAction()}");

            //Console.WriteLine();
            //Console.WriteLine("========= Subscribe rectangle && square && ellipse");
            //Console.WriteLine();

            //citation.Subscribe(rectangle);
            //citation.Subscribe(ellipse);
            //citation.Subscribe(square);
            //citation.Notify();
            //Console.WriteLine($" {rectangle.GetShape()} - {rectangle.Action.GetAction()}");
            //Console.WriteLine($" {ellipse.GetShape()} - {ellipse.Action.GetAction()}");
            //Console.WriteLine($" {square.GetShape()} - {square.Action.GetAction()}");

            //Console.WriteLine();
            //Console.WriteLine("========= Unsubscribe rectangle && square");
            //Console.WriteLine();

            //citation.Unsubscribe(rectangle);
            //citation.Unsubscribe(square);
            //citation.Action = ActionFactory.Build(ActionFactory.ActionType.Noise);
            //citation.Notify();
            //Console.WriteLine($" {rectangle.GetShape()} - {rectangle.Action.GetAction()}");
            //Console.WriteLine($" {ellipse.GetShape()} - {ellipse.Action.GetAction()}");
            //Console.WriteLine($" {square.GetShape()} - {square.Action.GetAction()}");


            //**************************************

            Shape rectangle = ShapeFactory.Build(ShapeFactory.ShapeType.Rectangle, ActionFactory.Build(ActionFactory.ActionType.Music), new Citation());

            Shape c  = new BackgroundColor(rectangle);
            Shape r1 = new BackgroundColor(c);

            r1 = ShapeFactory.Build(ShapeFactory.ShapeType.Circle, ActionFactory.Build(ActionFactory.ActionType.Noise), new Citation());
            Shape r2 = new BackgroundColor(r1);

            r1 = new BackgroundColor(r1);
            r1 = new BorderColor(r1);
            Console.WriteLine($"{rectangle.GetShape()} - {rectangle.GetPoid()}");
            Console.WriteLine($"{c.GetShape()} - {c.GetPoid()}");

            c = new BorderColor(c);

            Console.WriteLine($"{r1.GetShape()} - {r1.GetPoid()}");
            Console.WriteLine($"{c.GetShape()} - {c.GetPoid()}");


            Console.ReadKey();
        }