private void CreateIndividual(HTTPConfigurationProvider http) { Community.Perform(async delegate { Individual individual = await _community.LoadFactAsync <Individual>(ThisIndividual); if (individual == null) { string randomId = Punctuation.Replace(Guid.NewGuid().ToString(), String.Empty).ToLower(); individual = await _community.AddFactAsync(new Individual(randomId)); await _community.SetFactAsync(ThisIndividual, individual); } Individual = individual; http.Individual = individual; }); }
public void Initialize() { var storage = new FileStreamStorageStrategy(); var http = new HTTPConfigurationProvider(); var communication = new BinaryHTTPAsynchronousCommunicationStrategy(http); _community = new Community(storage); _community.AddAsynchronousCommunicationStrategy(communication); _community.Register <CorrespondenceModel>(); _community.Subscribe(() => Individual); _community.Subscribe(() => Individual.MessageBoards); // Synchronize periodically. DispatcherTimer timer = new DispatcherTimer(); int timeoutSeconds = Math.Min(http.Configuration.TimeoutSeconds, 30); timer.Interval = TimeSpan.FromSeconds(5 * timeoutSeconds); timer.Tick += delegate(object sender, object e) { Synchronize(); }; timer.Start(); CreateIndividual(http); // Synchronize whenever the user has something to send. _community.FactAdded += delegate { Synchronize(); }; // Synchronize when the network becomes available. System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += (sender, e) => { if (NetworkInterface.GetIsNetworkAvailable()) { Synchronize(); } }; // And synchronize on startup or resume. Synchronize(); }
public void Initialize() { var storage = new FileStreamStorageStrategy(); var http = new HTTPConfigurationProvider(); var communication = new BinaryHTTPAsynchronousCommunicationStrategy(http); _community = new Community(storage); _community.AddAsynchronousCommunicationStrategy(communication); _community.Register<CorrespondenceModel>(); _community.Subscribe(() => Individual); _community.Subscribe(() => Individual.MessageBoards); // Synchronize periodically. DispatcherTimer timer = new DispatcherTimer(); int timeoutSeconds = Math.Min(http.Configuration.TimeoutSeconds, 30); timer.Interval = TimeSpan.FromSeconds(5 * timeoutSeconds); timer.Tick += delegate(object sender, object e) { Synchronize(); }; timer.Start(); CreateIndividual(http); // Synchronize whenever the user has something to send. _community.FactAdded += delegate { Synchronize(); }; // Synchronize when the network becomes available. System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged += (sender, e) => { if (NetworkInterface.GetIsNetworkAvailable()) Synchronize(); }; // And synchronize on startup or resume. Synchronize(); }
private void CreateIndividual(HTTPConfigurationProvider http) { Community.Perform(async delegate { Individual individual = await _community.LoadFactAsync<Individual>(ThisIndividual); if (individual == null) { string randomId = Punctuation.Replace(Guid.NewGuid().ToString(), String.Empty).ToLower(); individual = await _community.AddFactAsync(new Individual(randomId)); await _community.SetFactAsync(ThisIndividual, individual); } Individual = individual; http.Individual = individual; }); }