public static Dependent UpdateWhenNecessary(this DependencyObject dependencyObject, Action update)
 {
     Dependent dependent = new Dependent(update);
     dependent.Invalidated += () => dependencyObject.Dispatcher.BeginInvoke(() => dependent.OnGet());
     dependent.OnGet();
     return dependent;
 }
Esempio n. 2
0
        public NewGameViewModel(Identity identity, MainNavigationModel mainNavigation, NameNavigationModel nameNavigation)
        {
            _identity = identity;
            _mainNavigation = mainNavigation;
            _nameNavigation = nameNavigation;

            _depState = new Dependent(delegate
            {
                _state =
                    _identity.User != null ? StateId.Challenge :
                    _identity.Claims.Any(claim => !claim.Responses.Any()) ? StateId.PendingUserName :
                    StateId.YourName;
            });
            _depChallenge = new Dependent(delegate
            {
                _depState.OnGet();
                _challenge = _state == StateId.Challenge
                    ? new ChallengeViewModel(_identity.User, _mainNavigation)
                    : null;
            });
            _depYourName = new Dependent(delegate
            {
                _depState.OnGet();
                _yourName = _state == StateId.YourName
                    ? new YourNameViewModel(_identity, _nameNavigation)
                    : null;
            });
            _depPendingUserName = new Dependent(delegate
            {
                _depState.OnGet();
                _pendingUserName = _state == StateId.PendingUserName
                    ? new PendingUserNameViewModel(_identity.Claims.FirstOrDefault(claim => !claim.Responses.Any()))
                    : null;
            });
        }
Esempio n. 3
0
 void IUpdatable.UpdateNow()
 {
     if (_running)
     {
         _dependent.OnGet();
     }
 }
Esempio n. 4
0
        private void UpdateParameters()
        {
            // If we're currently at rest, start the timer.
            if (_atRest)
            {
                _ticks = Environment.TickCount;
            }

            _depTargetValue.OnGet();
            if (!_initialized)
            {
                // Start at the target value.
                _targetTicks = _ticks;
                _a           = 1.0F;
                _c           = _targetValue;
                _initialized = true;
            }
            else if (!_hasInertia)
            {
                // Fix at the target value.
                _targetTicks = _ticks;
                _a           = 1.0F;
                _c           = _targetValue;
            }
            else if (_c != _targetValue)
            {
                // Get the starting state using the previous parameters.
                float y0;
                float yp0;
                long  relativeToEnd = unchecked (_ticks - _targetTicks);
                if (relativeToEnd < 0)
                {
                    float x = relativeToEnd * SPEED;
                    y0  = _a * (2.0F * x + 3.0F) * x * x + _c;
                    yp0 = _a * (6.0F * x + 6.0F) * x;
                }
                else
                {
                    y0  = _c;
                    yp0 = 0.0F;
                }

                // Calculate the parameters of the curve based on the target value.
                float x0 = -1.0F;
                if (Math.Abs(yp0) > EPSILON)
                {
                    float t = 6.0F * (y0 - _targetValue) / yp0;         // Temporary
                    float d = (float)Math.Sqrt((t + 2.0F) * t + 9.0F);  // Square root of discriminant
                    float c = (t - 3.0F + d) / 4.0F;                    // Larger candidate root.

                    // x0 must be negative. If larger candidate is negative, use it. Otherwise, use smaller one.
                    x0 = (c < 0.0F) ? c : ((t - 3.0F - d) / 4.0F);
                }
                _a           = (y0 - _targetValue) / ((2.0F * x0 + 3.0F) * x0 * x0);
                _c           = _targetValue;
                _targetTicks = unchecked (_ticks - (long)(x0 / SPEED));
            }

            _atRest = false;
        }
 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 Dependent(delegate
         {
             object value = ClassProperty.GetObjectValue(ObjectInstance.Model, ObjectInstance.ViewModel);
             object translatedValue = TranslateOutgoingValue(value);
             bool changed = !Object.Equals(_value, translatedValue);
             _value = translatedValue;
             if (changed && _firePropertyChanged)
                 ObjectInstance.FirePropertyChanged(ClassProperty.Name);
             _firePropertyChanged = true;
         });
         // When the property becomes out of date, trigger an update.
         Action triggerUpdate = new Action(delegate
         {
             ObjectInstance.Dispatcher.BeginInvoke(new Action(delegate
             {
                 using (NotificationGate.BeginOutbound())
                 {
                     _depProperty.OnGet();
                 }
             }));
         });
         _depProperty.Invalidated += triggerUpdate;
     }
 }
Esempio n. 6
0
        public ChatPage()
        {
            InitializeComponent();

            ApplicationBar = new ApplicationBar();
            _sendButton = AddButton("/Images/appbar.send.rest.png", "send",
                (sender, args) => ViewModel.Send.Execute(null));
            _depSendEnabled = new Dependent(delegate
            {
                _sendButton.IsEnabled = ViewModel.Send.CanExecute(null);
            });
            _depSendEnabled.OnGet();
            _depSendEnabled.Invalidated += delegate
            {
                Dispatcher.BeginInvoke(() => _depSendEnabled.OnGet());
            };
        }
        public CloudTabItem(CloudTabViewModel viewModel)
        {
            _viewModel = viewModel;

            Content = new CloudView { DataContext = ForView.Wrap(_viewModel.Content) };

            _depHeader = new Dependent(() => Header = _viewModel.Header);
            _depHeader.Invalidated += () => Deployment.Current.Dispatcher.BeginInvoke(() => _depHeader.OnGet());
            _depHeader.Touch();
        }
Esempio n. 8
0
 public static Dependent WhenNecessary(Action updateMethod)
 {
     var dependent = new Dependent(updateMethod);
     Update update = new Update(dependent);
     dependent.Invalidated += delegate
     {
         UpdateScheduler.ScheduleUpdate(update);
     };
     dependent.OnGet();
     return dependent;
 }
Esempio n. 9
0
 private void UpdateValue()
 {
     _depParameters.OnGet();
     if (!_atRest)
     {
         // Calculate the current value based on the current time and the parameters of the curve.
         _dynTicks.OnGet();
         long relativeToEnd = unchecked (_ticks - _targetTicks);
         if (relativeToEnd >= 0)
         {
             // We've reached the target. Stop moving.
             _atRest = true;
             _value  = _c;
         }
         else
         {
             // Determine the current position based on how much time is left.
             float x = relativeToEnd * SPEED;
             _value = _a * (2.0F * x + 3.0F) * x * x + _c;
         }
     }
 }