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:"); } }
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"); } }
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")); }
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>(); }
public void ChangeUpdatesPerSecond(UpdatesPerSecond newUpdatesPerSecond) { if (updatesPerSecond == newUpdatesPerSecond) { return; } BindingsManager.UnRegisterBinding(this, updatesPerSecond); updatesPerSecond = newUpdatesPerSecond; BindingsManager.RegisterBinding(this, updatesPerSecond); }
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"); }
public void Process(IProgramKnowledgeBase pkb, BindingsManager bindingsManager) { if (Type == PqlTokenType.WHILE || Type == PqlTokenType.IF) { ProcessContainerPattern(pkb, bindingsManager); } else { ProcessAssignPattern(pkb, bindingsManager); } }
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); }
public void InitialiseBinding() { InitialiseArrow(); BindingsManager.CreateBinding( ordersDatabase.GetBindPoint("Orders"), arrow, arrowResult.GetBindPoint("Result")); InitialiseWPFBinding(); ordersDatabase.Initialise(); }
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); }
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); }
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--; } } } }
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); }
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!"); } }
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--; } } } } }
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:"); } }
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>(); }
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); } } }
void Awake() { BindingsManager.RegisterBinding(this, updatesPerSecond); }
void OnDestroy() { BindingsManager.UnRegisterBinding(this, updatesPerSecond); }