private void Application_Startup( object sender, StartupEventArgs e) { // Load the correspondence database. string databaseFileName = Directory.ApplicationData / "FacetedWorlds" / "Reversi" / "Correspondence.sdf"; _community = new Community(new SSCEStorageStrategy(databaseFileName)) .AddCommunicationStrategy(new WebServiceCommunicationStrategy()) .Register<CorrespondenceModule>() .Subscribe(() => _machineViewModel.User) .Subscribe(() => _machineViewModel.User == null ? Enumerable.Empty<Game>() : _machineViewModel.User.ActivePlayers.Select(player => player.Game)); // Recycle durations when the application is idle. DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.ApplicationIdle); timer.Interval = TimeSpan.FromSeconds(1.0); timer.Tick += Timer_Tick; timer.Start(); BeginDuration(); // Display the main window. MainWindow = new View.MainWindow(); MachineNavigationModel navigation = new MachineNavigationModel(); _machineViewModel = new MachineViewModel(_community, navigation); MainWindow.DataContext = ForView.Wrap(_machineViewModel); MainWindow.Show(); _synchronizationThread = new SynchronizationThread(_community); _community.FactAdded += () => _synchronizationThread.Wake(); _synchronizationThread.Start(); }
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)); }); }