Exemple #1
0
        public void AlternativeComposite()
        {
            var composite = new CompositeComponent();

            composite.AddComponent(new Leaf());
            composite.AddComponent(new SecondTypeOfLeaf());
            composite.AddComponent(new AThirdLeafType());

            component = composite;
            composite.Something();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var composite = new CompositeComponent();

            composite.AddComponent(new Leaf());
            composite.AddComponent(new Leaf());
            composite.AddComponent(new Leaf());

            component = composite;
            composite.Something();
        }
        public CancelDocumentRequest(IComponentSerializer serializaer) : base(serializaer)
        {
            _cancelNode   = new CompositeComponent("CANCELA");
            _registryNode = new CompositeComponent("REGISTRO");

            _cancelNode.AddComponent(_registryNode);
        }
Exemple #4
0
        public DocumentTrackingRequest(IComponentSerializer serializaer) : base(serializaer)
        {
            _document = new CompositeComponent("DOCUMENTO");
            _registry = new CompositeComponent("REGISTRO");

            _document.AddComponent(_registry);
        }
Exemple #5
0
        public static ISerializableComponent ToSerializableComponent(this IZelerisModel obj, string rootName)
        {
            var type       = obj.GetType();
            var properties = type.GetProperties();

            ISerializableComponent _root = new CompositeComponent(rootName);

            foreach (var prop in properties)
            {
                var value = prop.GetValue(obj);
                if (value == null)
                {
                    continue;
                }

                var jsonProperty = prop.GetCustomAttributes(true).Where(c => c.GetType() == typeof(JsonPropertyAttribute)).FirstOrDefault() as JsonPropertyAttribute;
                if (jsonProperty == null)
                {
                    continue;
                }

                var name = jsonProperty.PropertyName;
                ISerializableComponent node = new NodeComponent(name, value.ToString());
                _root.AddComponent(node);
            }

            return(_root);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            component = new DecoratorComponent(new ConcreteComponent());
            component.Something();


            var composite = new CompositeComponent();

            composite.AddComponent(new Leaf());
            composite.AddComponent(new SecondTypeOfLeaf());
            composite.AddComponent(new AThirdLeafType());
            composite.AddComponent(new Leaf());

            component = composite;
            component.Something();

            var calculator = new LoggingCalculator(new ConcreteCalculator());

            calculator.Add(129, 234);

            //var profilingComponent = new ProfilingComponent(new SlowComponent(), new LoggingStopwatch(new StopwatchAdapter()));
            //profilingComponent.Something();

            var asyncComponent = new AsyncComponent(new ProfilingComponent(new SlowComponent(), new LoggingStopwatch(new StopwatchAdapter())));

            asyncComponent.Something();

            Console.ReadLine();
            Console.WriteLine("five");

            Console.ReadLine();
            Console.WriteLine("four");

            Console.ReadLine();
            Console.WriteLine("three");

            Console.ReadLine();
            Console.WriteLine("two");

            Console.ReadLine();
            Console.WriteLine("one");

            Console.ReadLine();
            Console.WriteLine("zero -- program exited.");
        }
        public DocumentInformationRequest(IComponentSerializer serializaer) : base(serializaer)
        {
            _document = new CompositeComponent("DOCUMENTO");
            _registry = new CompositeComponent("REGISTRO");
            _header   = new CompositeComponent("CABECERA");

            _registry.AddComponent(_header);
            _document.AddComponent(_registry);
        }
Exemple #8
0
        static void Main(string[] args)
        {
            var composite = new CompositeComponent("First Composite Component");

            composite.AddComponent(new Leaf());
            composite.AddComponent(new Leaf());
            composite.AddComponent(new Leaf());

            // Fluent version since AddComponent return "this"
            composite = new CompositeComponent("Second Composite Component")
                        .AddComponent(new Leaf())
                        .AddComponent(new SecondTypeOfLeaf())
                        .AddComponent(new AThirdTypeOfLeaf())
                        .AddComponent(composite); // First will now become child of Second

            IComponent component = composite;

            component.Something(); // Will call Something() for all objects in the tree
        }
        public void AccountInfo_Composite_Serialization()
        {
            ISerializableComponent accountInfo = new CompositeComponent("INFOCUENTA");
            IComponentSerializer   serializer  = new XmlComponentSerializer();

            accountInfo
            .AddComponent(new NodeComponent("USUARIO", "user"))
            .AddComponent(new NodeComponent("CLAVE", "123"))
            .AddComponent(new NodeComponent("FECHA", "yyyyMMddHHmmss"));

            var result = accountInfo.Serialize(serializer).Build();

            string expectedResult = "<INFOCUENTA><USUARIO>user</USUARIO><CLAVE>123</CLAVE><FECHA>yyyyMMddHHmmss</FECHA></INFOCUENTA>";

            Assert.AreEqual(result, expectedResult);
        }
Exemple #10
0
        public override void DoAdd(Component c, int objectId, Component modifier)
        {
            CompositeComponent compositeModifier = (CompositeComponent)DoFindRoot(modifier);

            if (compositeModifier.IsObjectIdEquals(objectId))
            {
                compositeModifier.AddComponent(c);
                c.SetAncestor(modifier);
            }
            else
            {
                foreach (var item in compositeModifier.GetComponents())
                {
                    item.Add(c, objectId);
                }
            }
        }
 public CancelDocumentRequest AddClientId(string clientId)
 {
     _registryNode.AddComponent(new NodeComponent("ID_CLIENTE", clientId));
     return(this);
 }
 public ModifyDocumentRequest AddLineItem(LineItem item)
 {
     _registry.AddComponent(item.ToSerializableComponent("LINEA"));
     return(this);
 }