コード例 #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 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");
            }
        }
コード例 #3
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"));
        }
コード例 #4
0
            public ActivationService(MsmqActivation service, string protocol)
            {
                this.protocol = protocol;
                this.bindings = service.bindings;
                this.service  = service;
                this.paused   = false;

                this.groups = new Dictionary <int, QueueMonitorGroup>();
            }
コード例 #5
0
ファイル: BindingGeneric.cs プロジェクト: Theadd/SmartCore
 public void ChangeUpdatesPerSecond(UpdatesPerSecond newUpdatesPerSecond)
 {
     if (updatesPerSecond == newUpdatesPerSecond)
     {
         return;
     }
     BindingsManager.UnRegisterBinding(this, updatesPerSecond);
     updatesPerSecond = newUpdatesPerSecond;
     BindingsManager.RegisterBinding(this, updatesPerSecond);
 }
コード例 #6
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");
        }
コード例 #7
0
 public void Process(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
 {
     if (Type == PqlTokenType.WHILE || Type == PqlTokenType.IF)
     {
         ProcessContainerPattern(pkb, bindingsManager);
     }
     else
     {
         ProcessAssignPattern(pkb, bindingsManager);
     }
 }
コード例 #8
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);
        }
コード例 #9
0
        public void InitialiseBinding()
        {
            InitialiseArrow();

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


            ordersDatabase.Initialise();
        }
コード例 #10
0
        public MsmqActivation()
        {
            ServiceName         = ListenerConstants.MsmqActivationServiceName;
            CanHandlePowerEvent = false;
            AutoLog             = false;
            CanStop             = true;
            CanPauseAndContinue = true;
            CanShutdown         = true;

            this.bindings = new BindingsManager();

            this.integrationActivationService = new ActivationService(this, MsmqUri.FormatNameAddressTranslator.Scheme);
            this.transportActivationService   = new ActivationService(this, MsmqUri.NetMsmqAddressTranslator.Scheme);
        }
コード例 #11
0
ファイル: MsmqActivation.cs プロジェクト: JianwenSun/cc
        public MsmqActivation()
        {
            ServiceName = ListenerConstants.MsmqActivationServiceName;
            CanHandlePowerEvent = false;
            AutoLog = false;
            CanStop = true;
            CanPauseAndContinue = true;
            CanShutdown = true;

            this.bindings = new BindingsManager();

            this.integrationActivationService = new ActivationService(this, MsmqUri.FormatNameAddressTranslator.Scheme);
            this.transportActivationService = new ActivationService(this, MsmqUri.NetMsmqAddressTranslator.Scheme);
        }
コード例 #12
0
ファイル: EntityList.cs プロジェクト: adasinio97/Parserawka
        public IEntityList Intersection(IEntityList otherEntityList, BindingsManager bindingsManager)
        {
            EntityList entityList = otherEntityList as EntityList;

            for (int i = 0; i < list.Count; i++)
            {
                IEntity entity = GetEntityByIndex(i);
                if (!entityList.Contains(entity))
                {
                    bindingsManager.RemoveBoundEntity(entity, this);
                    i--;
                }
            }
            return(this);
        }
コード例 #13
0
        private void ProcessContainerPattern(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            PqlArgument leftRef = VarRef;

            if (leftRef is PqlString)
            {
                Variable variable = pkb.Variables.GetVariableByName((leftRef as PqlString).Value);
                for (int i = 0; i < Args.GetSize(); i++)
                {
                    Container container = Args.GetEntityByIndex(i) as Container;
                    if (!container.Condition.Name.Equals(variable.Name))
                    {
                        bindingsManager.RemoveBoundEntity(container, Args);
                        i--;
                    }
                }
            }
        }
コード例 #14
0
        public void Process(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            IEntityList leftBounds = ImplementationFactory.CreateEntityList();

            for (int i = 0; i < RightArgs.GetSize(); i++)
            {
                IEntity     arg    = RightArgs[i];
                IEntityList result = ImplementationFactory.CreateEntityList();
                string      attributeValue;
                if (RightType == PqlTokenType.CALL && (LeftType == PqlTokenType.PROCEDURE || LeftType == PqlTokenType.VARIABLE))
                {
                    attributeValue = arg.SecondaryAttribute.AttributeValue;
                }
                else
                {
                    attributeValue = arg.Attribute.AttributeValue;
                }

                if (LeftType == PqlTokenType.CALL && LeftRef.AttributeName.Equals("procName"))
                {
                    result.Sum(pkb.Statements.Copy().FilterBySecondaryAttribute(attributeValue));
                }
                else if (LeftType == PqlTokenType.PROCEDURE)
                {
                    result.AddEntity(pkb.Procedures.GetProcedureByName(attributeValue));
                }
                else if (LeftType == PqlTokenType.VARIABLE)
                {
                    result.AddEntity(pkb.Variables.GetVariableByName(attributeValue));
                }
                else
                {
                    result.AddEntity(pkb.Statements.GetEntityByAttribute(attributeValue));
                }

                if (RightRef is PqlSynonym)
                {
                    bindingsManager.CreateMultipleBindingsOneWay(arg, result, RightArgs, LeftArgs);
                }
                leftBounds.Sum(result);
            }
            LeftArgs.Intersection(leftBounds, bindingsManager);
        }
コード例 #15
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!");
            }
        }
コード例 #16
0
        private void ProcessAssignPattern(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            PqlArgument leftRef  = VarRef;
            PqlExpr     rightRef = Expr;

            if (leftRef is PqlString)
            {
                Variable variable = pkb.Variables.GetVariableByName((leftRef as PqlString).Value);
                for (int i = 0; i < Args.GetSize(); i++)
                {
                    Assign assignment = Args.GetEntityByIndex(i) as Assign;
                    if (assignment == null || !assignment.Left.Name.Equals(variable.Name))
                    {
                        bindingsManager.RemoveBoundEntity(assignment, Args);
                        i--;
                    }
                }
            }

            if (rightRef != null)
            {
                for (int i = 0; i < Args.GetSize(); i++)
                {
                    Assign assignment = Args.GetEntityByIndex(i) as Assign;
                    if (assignment == null)
                    {
                        Args.RemoveEntity(assignment);
                        i--;
                    }
                    else
                    {
                        bool match = Expr.IsExact ? CompareTrees(assignment.Right, Expr.ExprTree, true) : FindTree(assignment.Right, Expr.ExprTree);
                        if (!match)
                        {
                            bindingsManager.RemoveBoundEntity(assignment, Args);
                            i--;
                        }
                    }
                }
            }
        }
コード例 #17
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:");
            }
        }
コード例 #18
0
ファイル: MsmqActivation.cs プロジェクト: JianwenSun/cc
            public ActivationService(MsmqActivation service, string protocol)
            {
                this.protocol = protocol;
                this.bindings = service.bindings;
                this.service = service;
                this.paused = false;

                this.groups = new Dictionary<int, QueueMonitorGroup>();
            }
コード例 #19
0
        public void Process(IProgramKnowledgeBase pkb, BindingsManager bindingsManager)
        {
            if (LeftArgs.GetSize() < RightArgs.GetSize())
            {
                IEntityList rightBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < LeftArgs.GetSize(); i++)
                {
                    IEntity     arg    = LeftArgs[i];
                    IEntityList result = ProcessLeftSide(pkb, arg);
                    if (LeftRef is PqlSynonym && RightRef is PqlSynonym)
                    {
                        bindingsManager.CreateMultipleBindings(arg, result, LeftArgs, RightArgs);
                    }
                    rightBounds.Sum(result);
                }
                RightArgs.Intersection(rightBounds, bindingsManager);

                IEntityList leftBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < RightArgs.GetSize(); i++)
                {
                    IEntity     arg    = RightArgs[i];
                    IEntityList result = ProcessRightSide(pkb, arg);
                    leftBounds.Sum(result);
                }
                LeftArgs.Intersection(leftBounds, bindingsManager);
            }
            else
            {
                IEntityList leftBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < RightArgs.GetSize(); i++)
                {
                    IEntity     arg    = RightArgs[i];
                    IEntityList result = ProcessRightSide(pkb, arg);
                    leftBounds.Sum(result);
                }
                LeftArgs.Intersection(leftBounds, bindingsManager);

                IEntityList rightBounds = ImplementationFactory.CreateEntityList();
                for (int i = 0; i < LeftArgs.GetSize(); i++)
                {
                    IEntity     arg    = LeftArgs[i];
                    IEntityList result = ProcessLeftSide(pkb, arg);
                    if (LeftRef is PqlSynonym && RightRef is PqlSynonym)
                    {
                        bindingsManager.CreateMultipleBindings(arg, result, LeftArgs, RightArgs);
                    }
                    rightBounds.Sum(result);
                }
                RightArgs.Intersection(rightBounds, bindingsManager);
            }

            if (LeftArgs == RightArgs)
            {
                List <IEntity> toRemove = new List <IEntity>();
                for (int i = 0; i < LeftArgs.GetSize(); i++)
                {
                    if (!CheckFull(pkb, LeftArgs[i], LeftArgs[i]))
                    {
                        toRemove.Add(LeftArgs[i]);
                    }
                }
                foreach (IEntity arg in toRemove)
                {
                    bindingsManager.RemoveBoundEntity(arg, LeftArgs);
                }
            }
        }
コード例 #20
0
ファイル: BindingGeneric.cs プロジェクト: Theadd/SmartCore
 void Awake()
 {
     BindingsManager.RegisterBinding(this, updatesPerSecond);
 }
コード例 #21
0
ファイル: BindingGeneric.cs プロジェクト: Theadd/SmartCore
 void OnDestroy()
 {
     BindingsManager.UnRegisterBinding(this, updatesPerSecond);
 }