public void SyncRockData( SeriesDownloaded seriesCallback, HttpRequest.RequestResult resultCallback ) { ResultCallback = resultCallback; // have the launch data request the series before it does anything else. RockLaunchData.Instance.GetNoteDB( delegate { seriesCallback( ); // if we're logged in, sync any changes we've made with the server. if( RockMobileUser.Instance.LoggedIn == true ) { Rock.Mobile.Util.Debug.WriteLine( "Logged in. Syncing out-of-sync data." ); //( this includes notes, profile changes, etc.) RockMobileUser.Instance.TrySyncDirtyObjects( delegate(System.Net.HttpStatusCode statusCode, string statusDescription) { // IF THERE WAS A PROBLEM SYNCING, DO NOT PULL DOWN THE LATEST PROFILE. // That would cause pending changes to be lost. if( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true ) { Rock.Mobile.Util.Debug.WriteLine( "Syncing with server worked. Pulling down latest data." ); // now get their profile. Assuming there weren't any profile changes, this will download // their latest profile. That way if someone made a change directly in Rock, it'll be reflected here. RockMobileUser.Instance.GetProfileAndCellPhone( delegate { // get the address, which is certainly part RockMobileUser.Instance.GetFamilyAndAddress( delegate { // and hey, why not their profile picture too // if they have a profile picture, grab it. RockMobileUser.Instance.TryDownloadProfilePicture( PrivateGeneralConfig.ProfileImageSize, delegate { // failure or not, server syncing is finished, so let's go ahead and // get launch data. RockLaunchData.Instance.GetLaunchData( LaunchDataReceived ); }); }); }); } else { Rock.Mobile.Util.Debug.WriteLine( "Syncing with server FAILED. Skipping profile download to protect dirty data." ); // failure or not, server syncing is finished, so let's go ahead and // get launch data. RockLaunchData.Instance.GetLaunchData( LaunchDataReceived ); } }); } else { Rock.Mobile.Util.Debug.WriteLine( "Not Logged In. Skipping sync." ); RockLaunchData.Instance.GetLaunchData( LaunchDataReceived ); } } ); }
public void SyncRockData(SeriesDownloaded seriesCallback, HttpRequest.RequestResult resultCallback) { // if a request is already being made, don't handle a second one. if (Requesting == false) { Requesting = true; ResultCallback = resultCallback; // have the launch data request the series before it does anything else. RockLaunchData.Instance.GetNoteDB( delegate(System.Net.HttpStatusCode statusCode, string statusDescription) { if (seriesCallback != null) { seriesCallback( ); } // if it worked, keep going. if not, don't worry about getting anything more. if (Rock.Mobile.Network.Util.StatusInSuccessRange(statusCode) == true) { // if we're logged in, sync any changes we've made with the server. if (RockMobileUser.Instance.LoggedIn == true) { Rock.Mobile.Util.Debug.WriteLine("Logged in. Syncing out-of-sync data."); // now get their profile. This will download // their latest profile. That way if someone made a change directly in Rock, it'll be reflected here. RockMobileUser.Instance.GetPersonData(delegate { // if they have a profile picture, grab it. RockMobileUser.Instance.TryDownloadProfilePicture(PrivateGeneralConfig.ProfileImageSize, delegate { // failure or not, server syncing is finished, so let's go ahead and // get launch data. RockLaunchData.Instance.GetLaunchData(RockMobileUser.Instance.Person.Id, LaunchDataReceived); }); }); } else { Rock.Mobile.Util.Debug.WriteLine("Not Logged In. Skipping sync."); RockLaunchData.Instance.GetLaunchData(null, LaunchDataReceived); } } else { LaunchDataReceived(statusCode, statusDescription); } }); } }