public InertialProperty(Func<float> getTargetValue, Func<bool> getHasInertia)
 {
     _getTargetValue = getTargetValue;
     _getHasInertia = getHasInertia;
     _depTargetValue = new Computed(UpdateTargetValue);
     _depParameters = new Computed(UpdateParameters);
     _depValue = new Computed(UpdateValue);
 }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     ForView.Unwrap<OnboardingViewModel>(DataContext, vm =>
     {
         _lastException = new Computed<string>(() => vm.LastException);
         _subscription = _lastException.Subscribe(v => { if (v != null) { ShowError.Begin(); } });
     });
 }
示例#3
0
 public InertialProperty(Func <float> getTargetValue, Func <bool> getHasInertia)
 {
     _getTargetValue = getTargetValue;
     _getHasInertia  = getHasInertia;
     _depTargetValue = new Computed(UpdateTargetValue);
     _depParameters  = new Computed(UpdateParameters);
     _depValue       = new Computed(UpdateValue);
 }
示例#4
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync();
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            _pageStack = new Computed<ImmutableList<Type>>(() =>
                ComputePageStack().ToImmutableList());
        }
            public Command(Func<bool> canExecute, Action execute)
            {
                _canExecuteFunction = canExecute;
                _execute = execute;

                // Create a computed sentry to control the "can execute" flag.
                _depCanExecute = new Computed(UpdateCanExecute);
                _depCanExecute.Invalidated += new Action(Invalidated);

                // It begins its life out-of-date, so prepare to update it.
                Invalidated();
            }
示例#6
0
            public Command(Func <bool> canExecute, Action execute)
            {
                _canExecuteFunction = canExecute;
                _execute            = execute;

                // Create a computed sentry to control the "can execute" flag.
                _depCanExecute              = new Computed(UpdateCanExecute);
                _depCanExecute.Invalidated += new Action(Invalidated);

                // It begins its life out-of-date, so prepare to update it.
                Invalidated();
            }
示例#7
0
        /// <summary>
        /// Call this function just before setting the field that this
        /// sentry controls.
        /// </summary>
        /// <remarks>
        /// Any computed fields that depend upon this field will become
        /// out-of-date.
        /// </remarks>
        public void OnSet()
        {
            // Verify that computeds are not changing observables, as that
            // could be a logical circular dependency.
            if (Computed.GetCurrentUpdate() != null)
            {
                Debug.Assert(false, "An observable was changed while updating a computed.");
            }

            // When an observable field changes,
            // its computeds become out-of-date.
            MakeDependentsOutOfDate();
        }
 private void Page_Unloaded(object sender, RoutedEventArgs e)
 {
     if (_subscription != null)
     {
         _subscription.Unsubscribe();
         _subscription = null;
     }
     if (_lastException != null)
     {
         _lastException.Dispose();
         _lastException = null;
     }
 }
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     ForView.Unwrap<SubscriptionViewModel>(DataContext, vm =>
     {
         _state = new Computed<string>(() => vm.HasSelectedSubscription
             ? "ShowDetail"
             : "ShowMaster");
         _stateSubscription = _state.Subscribe(s =>
         {
             VisualStateManager.GoToState(this, s, _isInitialized);
             _isInitialized = true;
         });
     });
 }
示例#10
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ForView.Unwrap<SearchViewModel>(DataContext, vm =>
            {
                _state = new Computed<string>(() => vm.HasSelectedSearchResult
                    ? "ShowDetail"
                    : "ShowMaster");
                _stateSubscription = _state.Subscribe(s =>
                {
                    VisualStateManager.GoToState(this, s, _isInitialized);
                    _isInitialized = true;
                });

                _lastException = new Computed<string>(() => vm.LastException);
                _subscription = _lastException.Subscribe(v => { if (v != null) { ShowError.Begin(); } });
            });
        }
示例#11
0
 private bool Contains(Computed update)
 {
     lock (this)
     {
         if (_computedArray != null)
         {
             return(WeakArray.Contains(ref _computedArray, update));
         }
         else if (_computedHash != null)
         {
             return(_computedHash.Contains(update));
         }
         else
         {
             return(false);
         }
     }
 }
示例#12
0
        /// <summary>
        /// Establishes a relationship between this precedent and the currently
        /// updating dependent.
        /// </summary>
        internal void RecordDependent()
        {
            // Get the current dependent.
            Computed update = Computed.GetCurrentUpdate();

            if (update != null && !Contains(update) && update.AddPrecedent(this))
            {
                if (Insert(update))
                {
                    GainDependent();
                }
            }
            else if (!Any())
            {
                // Though there is no lasting dependency, someone
                // has shown interest.
                GainDependent();
                LoseDependent();
            }
        }
 public ObjectPropertyAtom(IObjectInstance objectInstance, ClassProperty classProperty)
     : base(objectInstance, classProperty)
 {
     if (ClassProperty.CanRead)
     {
         // When the property is out of date, update it from the wrapped object.
         _depProperty = new Computed(delegate
         {
             object value = ClassProperty.GetObjectValue(ObjectInstance.WrappedObject);
             value = TranslateOutgoingValue(value);
             if (!Object.Equals(_value, value))
                 _value = value;
             if (_firePropertyChanged)
                 ObjectInstance.FirePropertyChanged(ClassProperty.Name);
             _firePropertyChanged = true;
         });
         // When the property becomes out of date, trigger an update.
         _depProperty.Invalidated += () => UpdateScheduler.ScheduleUpdate(UpdateNow);
     }
 }
示例#14
0
 /// <summary>
 /// Call this method before reading the value of a controlled field.
 /// </summary>
 /// <remarks>
 /// If the controlled field is out-of-date, this function calls the
 /// update procedure to bring it back up-to-date. If another computed
 /// is currently updating, that computed depends upon this one; when this
 /// computed goes out-of-date again, that one does as well.
 /// </remarks>
 public void OnGet()
 {
     // Ensure that the attribute is up-to-date.
     if (MakeUpToDate())
     {
         // Establish dependency between the current update
         // and this attribute.
         RecordDependent();
     }
     else
     {
         // We're still not up-to-date (because of a concurrent change).
         // The current update should similarly not be up-to-date.
         Computed currentUpdate = _currentUpdate.Value;
         if (currentUpdate != null)
         {
             currentUpdate.MakeOutOfDate();
         }
     }
 }
示例#15
0
        internal bool MakeUpToDate()
        {
            StatusType formerStatus;
            bool       isUpToDate = true;

            lock (this)
            {
                // Get the former status.
                formerStatus = _status;

                // Reserve the right to update.
                if (_status == StatusType.OUT_OF_DATE)
                {
                    _status = StatusType.UPDATING;
                }
            }

            if (formerStatus == StatusType.UPDATING ||
                formerStatus == StatusType.UPDATING_AND_OUT_OF_DATE)
            {
                // Report cycles.
                ReportCycles();
                //MLP: Don't throw, because this will mask any exception in an update which caused reentrance.
                //throw new InvalidOperationException( "Cycle discovered during update." );
            }
            else if (formerStatus == StatusType.OUT_OF_DATE)
            {
                // Push myself to the update stack.
                Computed stack = _currentUpdate.Value;
                _currentUpdate.Value = this;

                // Update the attribute.
                try
                {
                    _update();
                }
                finally
                {
                    // Pop myself off the update stack.
                    Computed that = _currentUpdate.Value;
                    Debug.Assert(that == this);
                    _currentUpdate.Value = stack;

                    lock (this)
                    {
                        // Look for changes since the update began.
                        if (_status == StatusType.UPDATING)
                        {
                            _status = StatusType.UP_TO_DATE;
                        }
                        else if (_status == StatusType.UPDATING_AND_OUT_OF_DATE)
                        {
                            _status    = StatusType.OUT_OF_DATE;
                            isUpToDate = false;
                        }
                        else
                        {
                            Debug.Assert(false, "Unexpected state in MakeUpToDate");
                        }
                    }
                }
            }

            return(isUpToDate);
        }
示例#16
0
 public ViewModelContainer(Action firePropertyChanged, Func <object> constructor)
 {
     _computed              = new Computed(() => _viewModel = ForView.Wrap(constructor()));
     _computed.Invalidated += () => UpdateScheduler.ScheduleUpdate(firePropertyChanged);
 }
示例#17
0
 public ComputedAtom(Action firePropertyChanged, Func <T> getMethod)
 {
     _firePropertyChanged   = firePropertyChanged;
     _depValue              = new Computed(() => _value = getMethod());
     _depValue.Invalidated += () => UpdateScheduler.ScheduleUpdate(UpdateNow);
 }
示例#18
0
 private bool Delete(Computed dependent)
 {
     lock (this)
     {
         if (_computedArray != null)
         {
             WeakArray.Remove(ref _computedArray, dependent);
             return _computedArray == null;
         }
         else if (_computedHash != null)
         {
             _computedHash.Remove(dependent);
             if (_computedHash.Count == 0)
             {
                 _computedHash = null;
                 return true;
             }
             return false;
         }
         else
             return false;
     }
 }
示例#19
0
 private bool Insert(Computed update)
 {
     lock (this)
     {
         if (_computedHash != null)
         {
             _computedHash.Add(update);
             return false;
         }
         if (WeakArray.Contains(ref _computedArray, update))
             return false;
         bool first = _computedArray == null;
         if (WeakArray.GetCount(ref _computedArray) >= _maxArraySize)
         {
             _computedHash = new WeakHashSet<Computed>();
             foreach (var item in WeakArray.Enumerate<Computed>(_computedArray))
                 _computedHash.Add(item);
             _computedArray = null;
             _computedHash.Add(update);
             return false;
         }
         WeakArray.Add(ref _computedArray, update);
         return first;
     }
 }
 public ViewModelContainer(Action firePropertyChanged, Func<object> constructor)
 {
     _computed = new Computed(() => _viewModel = ForView.Wrap(constructor()));
     _computed.Invalidated += () => UpdateScheduler.ScheduleUpdate(firePropertyChanged);
 }
示例#21
0
 private bool Contains(Computed update)
 {
     lock (this)
     {
         if (_computedArray != null)
             return WeakArray.Contains(ref _computedArray, update);
         else if (_computedHash != null)
             return _computedHash.Contains(update);
         else
             return false;
     }
 }
示例#22
0
 internal void RemoveDependent(Computed dependent)
 {
     if (Delete(dependent))
         LoseDependent();
 }
示例#23
0
 public ComputedJob(Action action)
 {
     _computed = new Computed(action);
     _computed.Invalidated += () => UpdateScheduler.ScheduleUpdate(UpdateNow);
 }
 public void Stop()
 {
     _running = false;
     _computed.Dispose();
     _computed = null;
 }
示例#25
0
 public PrecedentVisualizer(Computed self)
 {
     _self = self;
 }
示例#26
0
 public void Stop()
 {
     _running = false;
     _computed.Dispose();
     _computed = null;
 }
示例#27
0
			public PrecedentVisualizer(Computed self) { _self = self; }
 public ComputedJob(Action action)
 {
     _computed              = new Computed(action);
     _computed.Invalidated += () => UpdateScheduler.ScheduleUpdate(UpdateNow);
 }