Exemplo n.º 1
0
        public TwoWayBinding(BindPoint source, InvertibleArrow <T1, T2> arrow, BindPoint destination)
            : base(source, arrow, destination)
        {
            this.reverseArrow = arrow.Invert();

            SubscribeToBindable(destination.Object);
        }
Exemplo n.º 2
0
        public static BindingHandle CreateBinding <A, B>(BindPoint source, Arrow <A, B> arrow, BindPoint destination)
        {
            /*
             * Creates a one-to-one binding from a source, an arrow and a destination. Infers
             * whether it should be bidirectional from the type of the supplied arrow.
             */

            if (LinkWouldCauseConflict(source, destination))
            {
                throw new BindingConflictException();
            }

            Binding <A, B> result;

            if (arrow is InvertibleArrow <A, B> )
            {
                result = new TwoWayBinding <A, B>(source, (InvertibleArrow <A, B>)arrow, destination);
                UpdateBindingGraphBothWays(source, destination);
            }
            else
            {
                result = new Binding <A, B>(source, arrow, destination);
                UpdateBindingGraph(source, destination);
            }

            BindingHandle handle = new BindingHandle(result);

            bindings.Add(handle, result);

            return(handle);
        }
Exemplo n.º 3
0
        public static BindingHandle CreateBinding <A, B>(Bindable source, string sourceProperty, Arrow <A, B> arrow, Bindable destination, string destinationProperty)
        {
            BindPoint sourcePoint      = new BindPoint(source, sourceProperty);
            BindPoint destinationPoint = new BindPoint(destination, destinationProperty);

            return(CreateBinding(sourcePoint, arrow, destinationPoint));
        }
Exemplo n.º 4
0
        //public Binding(Bindable source, string sourceVar, Bindable dest, string destVar)
        public Binding(BindPoint source, Arrow <T1, T2> arrow, BindPoint dest)
        {
            this.source      = source;
            this.destination = dest;
            this.arrow       = arrow;

            SubscribeToBindable(source.Object);
        }
Exemplo n.º 5
0
        public static bool LinkWouldCauseConflict(BindPoint a, BindPoint b)
        {
            BindingGraph tempGraph = bindGraph.Copy();

            tempGraph.Add(a);
            tempGraph.Add(b);
            tempGraph.Bind(a, b);
            return(tempGraph.HasConflict());
        }
        private static dynamic GetValue(BindPoint point)
        {
            /*
             * Gets the value associated with a BindPoint
             * (This greatly simplifies the mess of calling Object.GetVariable<dynamic> everywhere)
             */

            return(point.Object.GetVariable <dynamic>(point.Var));
        }
Exemplo n.º 7
0
 public void TrySetVariable <T>(BindPoint bindPoint, T newValue)
 {
     try
     {
         bindPoint.Object.LockAndSetVariable(bindPoint.Var, newValue);
     }
     catch (VariableLockedException)
     {
         // Nothing to do here
     }
 }
Exemplo n.º 8
0
        private bool BindPointInList(BindPoint bindPoint, List <BindPoint> list)
        {
            bool isInList = false;

            foreach (BindPoint point in list)
            {
                isInList = isInList || (bindPoint.Object.Equals(point.Object) && bindPoint.Var == point.Var);
            }

            return(isInList);
        }
Exemplo n.º 9
0
 public override bool Equals(object obj)
 {
     if (obj is BindPoint)
     {
         BindPoint otherBindPoint = (BindPoint)obj;
         return(ReferenceEquals(this.Object, otherBindPoint.Object) &&
                this.Var == otherBindPoint.Var);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 10
0
        public static BindingHandle CreateBinding <A, B>(BindPoint source, Arrow <A, B> arrow, BindPoint destination)
        {
            // TODO: Check for cycles here

            Binding <A, B> result;

            if (arrow is InvertibleArrow <A, B> )
            {
                result = new TwoWayBinding <A, B>(source, (InvertibleArrow <A, B>)arrow, destination);
            }
            else
            {
                result = new Binding <A, B>(source, arrow, destination);
            }

            return(new BindingHandle(result));
        }
Exemplo n.º 11
0
 public static void UpdateBindingGraphBothWays(BindPoint a, BindPoint b)
 {
     UpdateBindingGraph(a, b);
     UpdateBindingGraph(b, a);
 }
Exemplo n.º 12
0
 public static void UpdateBindingGraph(BindPoint source, BindPoint destination)
 {
     bindGraph.AddMany(source, destination);
     bindGraph.Bind(source, destination);
 }