コード例 #1
0
        public static void RunSimpleInvertibleDemo()
        {
            Source      source             = new Source();
            Destination dest               = new Destination();
            InvertibleArrow <int, int> arr = Op.Arr((int x) => x + 1, (int x) => x - 1);

            BindingsManager.CreateBinding(source.GetBindPoint("source"), arr, dest.GetBindPoint("result"));

            bool   passed = true;
            Random rand   = new Random();

            for (int i = 0; i < 100; i++)
            {
                int next = rand.Next();
                source.source = next;
                if (dest.result != next + 1)
                {
                    passed = false;
                }
                dest.result -= 1;
                if (source.source != next - 1)
                {
                    passed = false;
                }
            }

            if (passed)
            {
                Console.WriteLine("Invertible works too!");
            }
            else
            {
                Console.WriteLine("Invertible doesn't work tho D:");
            }
        }
コード例 #2
0
        public static void RunSimpleDemo()
        {
            Source           source = new Source();
            Destination      dest   = new Destination();
            Arrow <int, int> arr    = new IDArrow <int>();

            BindingsManager.CreateBinding(source.GetBindPoint("source"), arr, dest.GetBindPoint("result"));

            bool   passed = true;
            Random rand   = new Random();

            for (int i = 0; i < 100; i++)
            {
                int next = rand.Next();
                source.source = next;
                if (dest.result != source.source)
                {
                    passed = false;
                }
            }

            if (passed)
            {
                Console.WriteLine("Works!");
            }
            else
            {
                Console.WriteLine("Doesn't work D:");
            }

            //BindingsManager.CreateBinding(source.GetBindPoint("source"), Op.Arr((int x) => x - 1), dest.GetBindPoint("result"));
        }
コード例 #3
0
        public static void RunSimpleMultiDemo()
        {
            Source      source = new Source();
            Destination dest   = new Destination();

            Arrow <Tuple <int, int>, int> multiplier = Op.Arr((Tuple <int, int> x) => x.Item1 * x.Item2);

            Arrow <int, int>     square = Op.Arr((int x) => x * x);
            Func <int, int, int> add    = (int x, int y) => x + y;

            Arrow <Tuple <int, int>, int> pythagoras = Op.And(square, square)
                                                       .Unsplit(add)
                                                       .Combine(Op.Arr((int x) => (int)Math.Sqrt(x)));

            BindingsManager.CreateBinding(BindingsManager.BindPoints(new BindPoint(source, "source"), new BindPoint(source, "multiplies")),
                                          pythagoras,
                                          BindingsManager.BindPoints(new BindPoint(dest, "result")));
            source.multiplies = 2;
            source.source     = 3;

            if (dest.result == pythagoras.Invoke(Tuple.Create(source.source, source.multiplies)))
            {
                Console.WriteLine("Multibindings in one direction work :)");
            }
            else
            {
                Console.WriteLine("Ohnoes multibindings in one direction don't work");
            }
        }
コード例 #4
0
        public void InitialiseBindings()
        {
            BindingsManager.CreateBinding(
                BindingsManager.Sources(name.GetBindPoint("Name")),
                nameArrow,
                BindingsManager.Destinations(splitName.GetBindPoint("Forename"), splitName.GetBindPoint("Surname")));

            InitialiseNameBinding(ForenameBox, "Forename");
            InitialiseNameBinding(SurnameBox, "Surname");
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Database data = new Database();

            ordersFromMicrosoft     = new ListOutput();
            ordersToCambridge       = new ListOutput();
            bulkOrders              = new ListOutput();
            averageOrdersToScotland = new IntOutput();

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Supplier.Name == "Microsoft")
                .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                ordersFromMicrosoft.GetBindPoint("Orders"));

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Customer.Location == "Cambridge")
                .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                ordersToCambridge.GetBindPoint("Orders"));

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Volume > 30)
                .OrderBy((Order x, Order y) => x.Customer.Name.CompareTo(y.Customer.Name)),
                bulkOrders.GetBindPoint("Orders"));

            var averagingArrow = Op.Split <IEnumerable <int> >()
                                 .Combine(Op.And(
                                              ListArrow.Foldl((int x, int y) => x + y, 0),
                                              ListArrow.Foldl((int x, int y) => x + 1, 0)))
                                 .Unsplit((int total, int count) => total / count);

            BindingsManager.CreateBinding(
                data.GetBindPoint("orders"),
                ListArrow.Filter((Order x) => x.Customer.Location == "Glasgow" || x.Customer.Location == "Aberdeen")
                .Map((Order x) => x.Volume)
                .Combine(averagingArrow),
                averageOrdersToScotland.GetBindPoint("Result"));

            data.Initialise();

            PrintOutput("Orders from Microsoft", ordersFromMicrosoft);
            PrintOutput("Orders to Cambridge", ordersToCambridge);
            PrintOutput("Bulk orders", bulkOrders);
            Console.WriteLine("Average orders to Scotland: {0}", averageOrdersToScotland.Result);
            Console.WriteLine();

            IncreaseMoragsOrder(data);
            MoveBrendaToCambridge(data);
            MicrosoftTakeover(data);
        }
コード例 #6
0
        public void InitialiseBinding()
        {
            InitialiseArrow();

            BindingsManager.CreateBinding(
                ordersDatabase.GetBindPoint("Orders"),
                arrow,
                arrowResult.GetBindPoint("Result"));
            InitialiseWPFBinding();


            ordersDatabase.Initialise();
        }
コード例 #7
0
        public void Run()
        {
            Arrow <int, int> id = new IDArrow <int>();
            A a = new A();
            B b = new B();
            C c = new C();

            BindingHandle aToB = BindingsManager.CreateBinding(
                a.GetBindPoint("Value"),
                id,
                b.GetBindPoint("Value"));

            BindingHandle bToA = BindingsManager.CreateBinding(
                b.GetBindPoint("Value"),
                id,
                a.GetBindPoint("Value"));

            BindingHandle bToC = BindingsManager.CreateBinding(
                b.GetBindPoint("Value"),
                id,
                c.GetBindPoint("Value")
                );

            BindingHandle cToB = BindingsManager.CreateBinding(
                c.GetBindPoint("Value"),
                id,
                b.GetBindPoint("Value")
                );

            try
            {
                BindingHandle cToA = BindingsManager.CreateBinding(
                    c.GetBindPoint("Value"),
                    id,
                    a.GetBindPoint("Value")
                    );
            }
            catch (BindingConflictException)
            {
                Console.WriteLine("Cycle exception was thrown successfully!");
            }
        }
コード例 #8
0
        public static void RunInvertibleMultiDemo()
        {
            Source           source = new Source();
            MultiDestination dest   = new MultiDestination();

            var swapper = new SwapArrow <int, int>();

            BindingsManager.CreateBinding(BindingsManager.Sources(source.GetBindPoint("source"), source.GetBindPoint("multiplies")),
                                          swapper,
                                          BindingsManager.Destinations(dest.GetBindPoint("leftResult"), dest.GetBindPoint("rightResult")));

            source.source     = 3;
            source.multiplies = 4;

            if (dest.leftResult == source.multiplies && dest.rightResult == source.source)
            {
                Console.WriteLine("Invertible multibindings work!");
            }
            else
            {
                Console.WriteLine("Invertible multibindings do not work D:");
            }
        }