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;
            });
        }
Example #2
0
        public MainPage()
        {
            this.InitializeComponent();

            _depAllSessionsView = Update.WhenNecessary(UpdateAllSessionsView);
            _depMyScheduleView = Update.WhenNecessary(UpdateMyScheduleView);
        }
 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;
     }
 }
 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;
 }
Example #5
0
		public ProjectModel(TaskRunner runner, OptionsModel options) 
		{ 
			_runner = runner; 
			_options = options;
			_runner.TaskComplete += new Action<ITask, Exception>(OnTaskComplete);
			_depFileSystemWatchers = new Dependent(UpdateFileSystemWatchers);
			_updater = new GuiUpdateHelper(_depFileSystemWatchers);
		}
Example #6
0
 public InertialProperty(Func<float> getTargetValue, Func<bool> getHasInertia)
 {
     _getTargetValue = getTargetValue;
     _getHasInertia = getHasInertia;
     _depTargetValue = new Dependent(UpdateTargetValue);
     _depParameters = new Dependent(UpdateParameters);
     _depValue = new Dependent(UpdateValue);
 }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string sessionId = NavigationContext.QueryString["SessionId"];
            ViewModelLocator locator = Application.Current.Resources["Locator"] as ViewModelLocator;
            if (locator != null)
                DataContext = locator.GetSessionEvaluationViewModel(sessionId);

            _depSubmitEnabled = this.UpdateWhenNecessary(() => this.Button(0).IsEnabled = CanSubmit);
        }
Example #8
0
        public LocalGameState(LocalGame game, MainNavigationModel mainNavigation)
        {
            _game = game;
            _mainNavigation = mainNavigation;

            _depGameBoardRaw = new Dependent(UpdateGameBoardRaw);
            _depGameBoard = new Dependent(UpdateGameBoard);
            _depPreviewBoard = new Dependent(UpdatePreviewBoard);
        }
        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();
        }
Example #10
0
        public GameState(Player player)
        {
            _player = player;
            if (_player != null)
            {
                _myColor = _player.Index == 0 ? PieceColor.Black : PieceColor.White;
            }

            _depGameBoard = new Dependent(UpdateGameBoard);
        }
Example #11
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;
 }
        protected PlayerGameViewModel(MainNavigationModel mainNavigation)
        {
            _mainNavigation = mainNavigation;

            _depGameState = new Dependent(() =>
            {
                _gameState = Player == null
                    ? null
                    : new RemoteGameState(Player, _mainNavigation);
            });
        }
        public ObjectPropertyCollection(IObjectInstance objectInstance, ClassProperty classProperty)
            : base(objectInstance, classProperty)
        {
            if (ClassProperty.CanRead)
            {
                // When the collection is out of date, update it from the wrapped object.
                _depCollection = new Dependent(OnUpdateCollection);

                // When the property becomes out of date, trigger an update.
                _depCollection.Invalidated += TriggerUpdate;
            }
        }
Example #14
0
        /// <summary>
        /// Call this function just before setting the field that this
        /// sentry controls.
        /// </summary>
        /// <remarks>
        /// Any dependent fields that depend upon this field will become
        /// out-of-date.
        /// </remarks>
        public void OnSet()
        {
            // Verify that dependents are not changing independents, as that
            // could be a logical circular dependency.
            if (Dependent.GetCurrentUpdate() != null)
            {
                Debug.Assert(false, "An independent was changed while updating a dependent.");
            }

            // When an independent field changes,
            // its dependents become out-of-date.
            MakeDependentsOutOfDate();
        }
Example #15
0
        public RemoteGameState(Player player, MainNavigationModel mainNavigation)
        {
            _player = player;
            _mainNavigation = mainNavigation;
            if (_player != null)
            {
                _myColor = _player.Index == 0 ? PieceColor.Black : PieceColor.White;
            }

            _depGameBoardRaw = new Dependent(UpdateGameBoardRaw);
            _depGameBoard = new Dependent(UpdateGameBoard);
            _depPreviewBoard = new Dependent(UpdatePreviewBoard);
        }
Example #16
0
        public MachineViewModel(
            Community community,
            MachineNavigationModel navigation)
        {
            _community = community;
            _navigation = navigation;

            _depUser = new Dependent(delegate
            {
                _user = String.IsNullOrEmpty(_navigation.UserName)
                    ? null
                    : _community.AddFact(new User(_navigation.UserName));
            });
        }
Example #17
0
 private bool Contains(Dependent update)
 {
     lock (this)
     {
         for (DependentNode current = _firstDependent; current != null; current = current.Next)
         {
             if (current.Dependent.Target == update)
             {
                 return(true);
             }
         }
         return(false);
     }
 }
 public ObjectPropertyAtom(IObjectInstance objectInstance, ClassMember classProperty)
     : base(objectInstance, classProperty)
 {
     if (ClassProperty.CanRead)
     {
         // When the property is out of date, update it from the wrapped object.
         _depProperty = new Dependent(() => BindingInterceptor.Current.UpdateValue(this));
         // When the property becomes out of date, trigger an update.
         // The update should have lower priority than user input & drawing,
         // to ensure that the app doesn't lock up in case a large model is
         // being updated outside the UI (e.g. via timers or the network).
         _depProperty.Invalidated += () => UpdateScheduler.ScheduleUpdate(this);
     }
 }
        public CloudViewModel(Cloud cloud, CloudNavigationModel navigation)
        {
            _cloud = cloud;
            _navigation = navigation;

            _depCenterByThought = new Dependent(() =>
            {
                _centerByThought = CalculateCenterByThought();
                UpdateInertialCoordinates();
            });

            DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(0.05);
            timer.Tick += new EventHandler(AnimateThoughts);
            timer.Start();
        }
Example #20
0
        public GameControl()
        {
            _depNewPieceState = new Dependent(UpdateNewPieceState);
            _depNewPieceState.Invalidated += TriggerUpdateNewPieceState;
            TriggerUpdateNewPieceState();

            // Required to initialize variables
            InitializeComponent();

            _timer.Tick += delegate(object s2, EventArgs e2)
            {
                if (ViewModel != null)
                    ViewModel.CommitMove();
                _timer.Stop();
            };
        }
Example #21
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());
            };
        }
Example #22
0
 private Dependent First()
 {
     lock (this)
     {
         while (_firstDependent != null)
         {
             Dependent dependent = (Dependent)_firstDependent.Dependent.Target;
             if (dependent != null)
             {
                 return(dependent);
             }
             else
             {
                 _firstDependent = _firstDependent.Next;
             }
         }
         return(null);
     }
 }
Example #23
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 dependent
 /// is currently updating, that dependent depends upon this one; when this
 /// dependent 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.
         Dependent currentUpdate = _currentUpdate.Get();
         if (currentUpdate != null)
         {
             currentUpdate.MakeOutOfDate();
         }
     }
 }
Example #24
0
        /// <summary>
        /// Establishes a relationship between this precedent and the currently
        /// updating dependent.
        /// </summary>
        internal void RecordDependent()
        {
            // Get the current dependent.
            Dependent update = Dependent.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 Dependent(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(this);
     }
 }
Example #26
0
 private bool Delete(Dependent dependent)
 {
     lock (this)
     {
         int           count = 0;
         DependentNode prior = null;
         for (DependentNode current = _firstDependent; current != null; current = current.Next)
         {
             object target = current.Dependent.Target;
             if (target == null || target == dependent)
             {
                 if (target == null)
                 {
                     System.Diagnostics.Debug.WriteLine(String.Format("Dead reference {0}", _referenceCount++));
                 }
                 if (target == dependent)
                 {
                     ++count;
                 }
                 if (prior == null)
                 {
                     _firstDependent = current.Next;
                 }
                 else
                 {
                     prior.Next = current.Next;
                 }
             }
             else
             {
                 prior = current;
             }
         }
         if (count != 1)
         {
             Debug.Assert(false, String.Format("Expected 1 dependent, found {0}.", count));
         }
         return(_firstDependent == null);
     }
 }
Example #27
0
        public ViewModelLocator(Identity identity, IPresentationServices presentationServices, MainNavigationModel mainNavigationModel, NameNavigationModel nameNavigationModel)
        {
            _identity = identity;
            _presentationServices = presentationServices;
            _mainNavigationModel = mainNavigationModel;
            _nameNavigationModel = nameNavigationModel;

            _main = new MainViewModel(_presentationServices, _identity, _mainNavigationModel);
            _newGame = new NewGameViewModel(_identity, _mainNavigationModel, _nameNavigationModel);
            _depGame = new Dependent(delegate
            {
                if (_mainNavigationModel.SelectedPlayer != null)
                {
                    _game = new RemoteGameViewModel(_mainNavigationModel.SelectedPlayer, _mainNavigationModel);
                }
                else if (_mainNavigationModel.SelectedGameRequest != null)
                {
                    _game = new GameRequestViewModel(_mainNavigationModel.SelectedGameRequest, _mainNavigationModel);
                }
                else
                {
                    LocalGame localGame = _identity.ActiveLocalGames.FirstOrDefault();
                    if (localGame != null)
                        _game = new LocalGameViewModel(localGame, _mainNavigationModel);
                    else
                        _game = null;
                }
            });
            _depChat = new Dependent(delegate
            {
                _chat = _mainNavigationModel.SelectedPlayer == null
                    ? null
                    : new ChatViewModel(_mainNavigationModel.SelectedPlayer, _mainNavigationModel);
            });
            _settings = new SettingsViewModel(_identity);
        }
Example #28
0
 private Update(Dependent dependent)
 {
     _dependent = dependent;
 }
Example #29
0
 public void Stop()
 {
     _running = false;
     _dependent.Dispose();
     _dependent = null;
 }
Example #30
0
 public PrecedentVisualizer(Dependent self)
 {
     _self = self;
 }
Example #31
0
 public DependentJob(Action action)
 {
     _dependent              = new Dependent(action);
     _dependent.Invalidated += () => UpdateScheduler.ScheduleUpdate(this);
 }
Example #32
0
 private bool Contains(Dependent update)
 {
     lock (this)
     {
         for (DependentNode current = _firstDependent; current != null; current = current.Next)
             if (current.Dependent.Target == update)
                 return true;
         return false;
     }
 }
Example #33
0
 internal void RemoveDependent(Dependent dependent)
 {
     if (Delete(dependent))
         LoseDependent();
 }
Example #34
0
 private bool Delete(Dependent dependent)
 {
     lock (this)
     {
         int count = 0;
         DependentNode prior = null;
         for (DependentNode current = _firstDependent; current != null; current = current.Next)
         {
             object target = current.Dependent.Target;
             if (target == null || target == dependent)
             {
                 if (target == null)
                     System.Diagnostics.Debug.WriteLine(String.Format("Dead reference {0}", _referenceCount++));
                 if (target == dependent)
                     ++count;
                 if (prior == null)
                     _firstDependent = current.Next;
                 else
                     prior.Next = current.Next;
             }
             else
                 prior = current;
         }
         if (count != 1) Debug.Assert(false, String.Format("Expected 1 dependent, found {0}.", count));
         return _firstDependent == null;
     }
 }
 void ScheduleTimeControl_Loaded(object sender, RoutedEventArgs e)
 {
     _visualState = Update.WhenNecessary(UpdateVisualState);
 }
Example #36
0
 private bool Insert(Dependent update)
 {
     lock (this)
     {
         bool first = _firstDependent == null;
         _firstDependent = new DependentNode { Dependent = new WeakReference(update), Next = _firstDependent };
         return first;
     }
 }
 public DependentUpdatable(Dependent dependent)
 {
     _dependent = dependent;
 }
Example #38
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.
                Dependent stack = _currentUpdate.Get();
                _currentUpdate.Set(this);

                // Update the attribute.
                try
                {
                    _update();
                }
                finally
                {
                    // Pop myself off the update stack.
                    Dependent that = _currentUpdate.Get();
                    Debug.Assert(that == this);
                    _currentUpdate.Set(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);
        }
Example #39
0
 public void Stop()
 {
     _running = false;
     _dependent.Dispose();
     _dependent = null;
 }
Example #40
0
 public Model()
 {
     _depAccountBalance = new Dependent(UpdateAccountBalance);
 }