示例#1
0
    void AddOrRemove(Parts destination, IParts source, int level)
    {
        var toBeAdded = source is Parts;

        Debug.Assert(
            source is Parts.NullParts || toBeAdded,
            $"Unsupported 'from' type ({source.GetType().FullName}).");

        var s = destination.SegmentPartsByNestingLevel(level);

        if (destination.NumberOfPathSegments == level + 1)
        {
            if (toBeAdded)
            {
                var leaf = new Tuple <Parts, Parts>(destination, source as Parts);
                LeavesToCreate.Add(s.Name, leaf);
            }
            else
            {
                LeavesToDrop.Add(s.Name, destination);
            }

            return;
        }

        if (!SubTreesToUpdate.TryGetValue(s.Name, out var targetTree))
        {
            targetTree = new TargetTree(s);
            SubTreesToUpdate.Add(s.Name, targetTree);
        }

        targetTree.AddOrRemove(destination, source, ++level);
    }
示例#2
0
        public static bool ZEqualsIPartsText(IParts ip1, IParts ip2)
        {
            int size = ip1.GetPartCount();

            object[] parts1 = ip1.GetParts();
            object[] parts2 = ip2.GetParts();
            for (int i = 0; i < size; i++)
            {
                var item1 = parts1[i];
                var item2 = parts2[i];
                if (item1 is string)
                {
                    if (!(item2 is string))
                    {
                        return(false);
                    }
                    var str1 = item2 as string;
                    var str2 = item1 as string;
                    if (str1 != str2)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#3
0
        static void NewMain(string[] args, ICalculator calculator, IParts parts, IService service, IDiscount discount)
        {
            var p = parts.GetParts(Decimal.Parse(args[0]));

            var s = service.GetService(Decimal.Parse(args[1]));

            var d = discount.GetDiscount(Decimal.Parse(args[2]));

            var total = calculator.GetTotal(p, s, d);

            Console.WriteLine("Total testy Price: $" + total);
        }
示例#4
0
    protected void AddOrRemove_Internal(IParts from, Parts to)
    {
        switch (from)
        {
        case Parts toAddOrUpdate:
            if (toAddOrUpdate.Type != to.Type)
            {
                throw new ArgumentException($"Cannot map [{toAddOrUpdate.Type}: {toAddOrUpdate.Url}] to [{to.Type}: {to.Url}]. ");
            }

            if (toBeRemovedEntries.Contains(to))
            {
                throw new InvalidOperationException($"Cannot add this as the target path '{to.Path}' in branch'{to.Branch}' of '{to.Owner}/{to.Repository}' as it's already scheduled for removal.");
            }

            if (!toBeAddedOrUpdatedEntries.TryGetValue(toAddOrUpdate, out var parts))
            {
                parts = new List <Parts>();
                toBeAddedOrUpdatedEntries.Add(toAddOrUpdate, parts);
            }

            parts.Add(to);

            break;

        case Parts.NullParts _:
            if (to.Type == TreeEntryTargetType.Tree)
            {
                throw new NotSupportedException($"Removing a '{nameof(TreeEntryTargetType.Tree)}' isn't supported.");
            }

            if (toBeAddedOrUpdatedEntries.Values.SelectMany(x => x).Contains(to))
            {
                throw new InvalidOperationException(
                          $"Cannot remove this as the target path '{to.Path}' in branch '{to.Branch}' of '{to.Owner}/{to.Repository}' as it's already scheduled for addition.");
            }

            if (toBeRemovedEntries.Contains(to))
            {
                return;
            }

            toBeRemovedEntries.Add(to);

            break;

        default:
            throw new InvalidOperationException($"Unsupported 'from' type ({from.GetType().FullName}).");
        }
    }
        public GraphicCard()
        {
            Console.WriteLine("GPU");
            IParts gpu = gCreator.FactoryMethod("GPU");

            this.list.Add(gpu);
            Console.WriteLine(gpu.getPrice());

            Console.WriteLine("Graphic Card Memory");
            IParts graphicCardMemory = gCreator.FactoryMethod("GraphicCardMemory");

            this.list.Add(graphicCardMemory);
            Console.WriteLine(graphicCardMemory.getPrice());
        }
        static void Main(string[] args)
        {
            Creator            c = new Creator();
            GraphicCardCreator graphicCardCreator = new GraphicCardCreator();
            Computer           computer           = new Computer();

            Console.WriteLine("Parts of Computer and their prices");

            Console.WriteLine("Monitor");
            IParts monitor = c.FactoryMethod("MONITOR");

            computer.add(monitor);
            Console.WriteLine(monitor.getPrice());

            Console.WriteLine("Keyboard");
            IParts keyboard = c.FactoryMethod("KEYBOARD");

            computer.add(keyboard);
            Console.WriteLine(keyboard.getPrice());

            Console.WriteLine("Memory");
            IParts memory = c.FactoryMethod("MEMORY");

            computer.add(memory);
            Console.WriteLine(memory.getPrice());

            Console.WriteLine("CPU");
            IParts cpu = c.FactoryMethod("CPU");

            computer.add(cpu);
            Console.WriteLine(cpu.getPrice());

            Console.WriteLine("Graphic card");
            IParts graphicCard = c.FactoryMethod("GRAPHIC");

            computer.add(graphicCard);
            Console.WriteLine("Total price of graphic card");
            Console.WriteLine(graphicCard.getPrice());

            Console.WriteLine("Total price of Computer");
            Console.WriteLine(computer.getPrice());

            Console.WriteLine("Press Any key to exit");
            Console.ReadLine();
        }
        private void Button_ConectorClicked(object sender, EventArgs e)
        {
            if (LineButton.IsChecked == false)
            {
                return;
            }


            if (output == null)
            {
                output = (IParts)sender;
            }
            tempLines  = new List <Line>();
            firstPoint = !firstPoint;

            lastPouint = Mouse.GetPosition(canvas);
            lastLine   = null;
            firstLine  = true;
        }
示例#8
0
        public static bool ZEqualsIPartsParameters(IParts ip1, IParts ip2)
        {
            int size = ip1.GetPartCount();

            object[] parts1 = ip1.GetParts();
            object[] parts2 = ip2.GetParts();
            for (int i = 0; i < size; i++)
            {
                var item1 = parts1[i];
                var item2 = parts2[i];
                if (item1 is IBracket)
                {
                    if (!(item2 is IBracket))
                    {
                        return(false);
                    }
                    var b1 = item1 as IBracket;
                    var b2 = item2 as IBracket;
                    return(ZEqualsIBracket(b1, b2));
                }
            }
            return(true);
        }
示例#9
0
 public static bool ZEqualsIPartsCount(IParts ip1, IParts ip2)
 {
     return(ip1.GetPartCount() == ip2.GetPartCount());
 }
示例#10
0
 public void ReplacePart(IParts part)
 {
     parts.RemoveAll(item => item.Type() == part.Type());
     parts.Add(part);
 }
示例#11
0
 public CartController(IParts repo, Cart cart)
 {
     repository = repo;
     this.cart  = cart;
 }
示例#12
0
 public HomeController(IParts iparts)
 {
     _parts = iparts;
 }
示例#13
0
 public void AddParts(IParts _parts)
 {
     parts.Add(_parts);
 }
示例#14
0
        private void input_ConectorClicked(object sender, EventArgs e)
        {
            if (LineButton.IsChecked == false)
            {
                return;
            }
            if (output != null)
            {
                output.parts.Add((IParts)sender);
                ((IParts)sender).input = output;

                if (!firstPoint)
                {
                    //Line redLine = new Line();
                    //redLine.X1 = Mouse.GetPosition(canvas).X;
                    //redLine.Y1 = Mouse.GetPosition(canvas).Y;
                    //redLine.X2 = lastPouint.X;
                    //redLine.Y2 = lastPouint.Y;
                    //lastPouint = Mouse.GetPosition(canvas);
                    //// Create a red Brush
                    //SolidColorBrush redBrush = new SolidColorBrush();
                    //redBrush.Color = Colors.Red;

                    //// Set Line's width and color
                    //redLine.StrokeThickness = 4;
                    //redLine.Stroke = redBrush;

                    //// Add line to the Grid.
                    //canvas.Children.Add(redLine);
                    //lastLine = redLine;
                    //Lines.Add(redLine);
                    //  ((IHolder)sender).lines.Add(redLine);
                    ((Part)sender).parrent.lines.AddRange(tempLines);
                    ((Part)output).parrent.lines.AddRange(tempLines);
                    ((Part)sender).parrent.connectors.AddRange(tempConnectors);
                    ((Part)output).parrent.connectors.AddRange(tempConnectors);
                    ((IParts)sender).lines.Add(lastLine);

                    firstPoint = !firstPoint;
                }

                output = null;
            }
            else if (((IParts)sender).input != null)
            {
                output = ((IParts)sender).input;

                if (!firstPoint)
                {
                    //Line redLine = new Line();
                    //redLine.X1 = Mouse.GetPosition(canvas).X;
                    //redLine.Y1 = Mouse.GetPosition(canvas).Y;
                    //redLine.X2 = lastPouint.X;
                    //redLine.Y2 = lastPouint.Y;
                    //lastPouint = Mouse.GetPosition(canvas);
                    //// Create a red Brush
                    //SolidColorBrush redBrush = new SolidColorBrush();
                    //redBrush.Color = Colors.Red;

                    //// Set Line's width and color
                    //redLine.StrokeThickness = 4;
                    //redLine.Stroke = redBrush;

                    //// Add line to the Grid.
                    //canvas.Children.Add(redLine);

                    //lastLine = redLine;
                    ((Part)sender).InputParts.Add(output);
                    ((Part)sender).parrent.lines.AddRange(tempLines);
                    ((Part)output).parrent.lines.AddRange(tempLines);
                    ((Part)sender).parrent.connectors.AddRange(tempConnectors);
                    ((Part)output).parrent.connectors.AddRange(tempConnectors);
                    ((IHolder)sender).lines.Add(lastLine);

                    Lines.Add(lastLine);
                }
                firstPoint = !firstPoint;
            }
        }
示例#15
0
 public FactoryFirst(IParts parts)
 {
     _parts = parts;
 }
示例#16
0
 public void ReplacePart(IParts part)
 {
     vehicle.RemoveAll(item => item.GetPartType() == part.GetPartType());
     vehicle.Add(part);
 }
 public void add(IParts parts)
 {
     this.list.Add(parts);
 }
        //ShopUserPartModel supm = new ShopUserPartModel();



        public AdminPanelController(IAdminOrder io, IParts ip)
        {
            adorders = io;
            _parts   = ip;
        }
 public void remove(IParts parts)
 {
     list.Remove(parts);
 }
示例#20
0
 public void AddPart(IParts part)
 {
     vehicle.Add(part);
 }