Ejemplo n.º 1
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // create a new window instance based on the screen size
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            BL.Managers.UpdateManager.UpdateFinished += HandleFinishedUpdate;



//NOTE: this is a quick response to Apple's disapproval of the sqlite living in the /Documents/ folder
// in the previous versions of the app. A quick way to preserve the favorites when the sqlite is moved
// to /Library/
//HACK: not a good idea in the FinishedLaunching method, but it will do for now...
//HACK: we need to do this before triggering the static ctor on MwcDatabase!
            var    docsPath      = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string oldDBLocation = Path.Combine(docsPath, "MwcDB.db3"); // in Document
            string newDBLocation = oldDBLocation.Replace("Documents/MwcDB.db3", "Library/MwcDB.db3");

            try {
                ConsoleD.WriteLine("oldDbLocation=" + oldDBLocation);
                if (File.Exists(oldDBLocation)) // won't normally be there in new installs
                {
                    File.Delete(newDBLocation); // static ctor will have created it
                    File.Move(oldDBLocation, newDBLocation);
                    ConsoleD.WriteLine("Moved " + oldDBLocation + " to " + newDBLocation);
                }
                else
                {
                    ConsoleD.WriteLine("oldDBLocation didn't exist?");
                }
            } catch (Exception ex) {
                ConsoleD.WriteLine("Well, we tried! Couldn't save the old favorites..." + ex.Message);
                File.Delete(oldDBLocation);
            }



            // start updating all data in the background
            // by calling this asynchronously, we must check to see if it's finished
            // everytime we want to use/display data.
            new Thread(new ThreadStart(() => {
                var prefs = NSUserDefaults.StandardUserDefaults;

                bool hasSeedData = BL.Managers.UpdateManager.HasDataAlready;
                ConsoleD.WriteLine("hasSeedData=" + hasSeedData);
                if (!hasSeedData)
                {
                    // only happens when the database is empty (or wasn't there); use local file update
                    ConsoleD.WriteLine("Load seed data");
                    var appdir       = NSBundle.MainBundle.ResourcePath;
                    var seedDataFile = appdir + "/Images/SeedData.xml";
                    string xml       = System.IO.File.ReadAllText(seedDataFile);
                    BL.Managers.UpdateManager.UpdateFromFile(xml);

                    ConsoleD.WriteLine("Database lives at: " + MWC.DL.MwcDatabase.DatabaseFilePath);
                    // We SHOULDN'T skip backup because we are saving the Favorites in the same sqlite
                    // database as the sessions are stored. A more iCloud-friendly design would be
                    // to keep the user-data separate from the server-generated data...
                    NSFileManager.SetSkipBackupAttribute(MWC.DL.MwcDatabase.DatabaseFilePath, true);
                }
                else
                {
                    // if there's already data in the database, do/attempt server update
                    //ConsoleD.WriteLine("SkipBackup: "+NSFileManager.GetSkipBackupAttribute (MWC.DL.MwcDatabase.DatabaseFilePath));

                    var earliestUpdateString    = prefs.StringForKey(PrefsEarliestUpdate);
                    DateTime earliestUpdateTime = DateTime.MinValue;
                    if (!String.IsNullOrEmpty(earliestUpdateString))
                    {
                        CultureInfo provider = CultureInfo.InvariantCulture;

                        if (DateTime.TryParse(earliestUpdateString
                                              , provider
                                              , System.Globalization.DateTimeStyles.None
                                              , out earliestUpdateTime))
                        {
                            ConsoleD.WriteLine("Earliest update time: " + earliestUpdateTime);
                        }
                    }
                    if (earliestUpdateTime < DateTime.Now)
                    {
                        // we're past the earliest update time, so update!
                        if (Reachability.IsHostReachable(Constants.ConferenceDataBaseUrl))
                        {
                            ConsoleD.WriteLine("Reachability okay, update conference from server");
                            BL.Managers.UpdateManager.UpdateConference();
                        }
                        else
                        {
                            // no network
                            ConsoleD.WriteLine("No network, can't update data for now");
                        }
                    }
                    else
                    {
                        ConsoleD.WriteLine("Too soon to update " + DateTime.Now);
                    }
                }
            })).Start();

            tabBar = new Screens.Common.TabBarController();

            // couldn't do RespondsToSelector() on static 'Appearance' property)
            var majorVersionString = UIDevice.CurrentDevice.SystemVersion.Substring(0, 1);
            var majorVersion       = Convert.ToInt16(majorVersionString);

            if (majorVersion >= 5)               // gotta love Appearance in iOS5
            {
                UINavigationBar.Appearance.TintColor = ColorNavBarTint;
            }
            window.RootViewController = tabBar;
            window.MakeKeyAndVisible();

            return(true);
        }
Ejemplo n.º 2
0
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			// create a new window instance based on the screen size
			window = new UIWindow (UIScreen.MainScreen.Bounds);
		
			BL.Managers.UpdateManager.UpdateFinished += HandleFinishedUpdate;
			


//NOTE: this is a quick response to Apple's disapproval of the sqlite living in the /Documents/ folder
// in the previous versions of the app. A quick way to preserve the favorites when the sqlite is moved
// to /Library/
//HACK: not a good idea in the FinishedLaunching method, but it will do for now...
//HACK: we need to do this before triggering the static ctor on MwcDatabase!
var docsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
string oldDBLocation = Path.Combine(docsPath, "MwcDB.db3");	 // in Document					
string newDBLocation = oldDBLocation.Replace("Documents/MwcDB.db3", "Library/MwcDB.db3");
try {	
	ConsoleD.WriteLine ("oldDbLocation="+oldDBLocation);
	if (File.Exists(oldDBLocation)) { // won't normally be there in new installs
		File.Delete(newDBLocation);  // static ctor will have created it
		File.Move(oldDBLocation, newDBLocation);
		ConsoleD.WriteLine ("Moved " + oldDBLocation + " to " + newDBLocation);
	} else ConsoleD.WriteLine ("oldDBLocation didn't exist?");
} catch (Exception ex) {
	ConsoleD.WriteLine ("Well, we tried! Couldn't save the old favorites..." + ex.Message);
	File.Delete(oldDBLocation);
}




			// start updating all data in the background
			// by calling this asynchronously, we must check to see if it's finished
			// everytime we want to use/display data.
			new Thread(new ThreadStart(() => {
				var prefs = NSUserDefaults.StandardUserDefaults;

				bool hasSeedData = BL.Managers.UpdateManager.HasDataAlready;
				ConsoleD.WriteLine ("hasSeedData="+hasSeedData);
				if (!hasSeedData) {
					// only happens when the database is empty (or wasn't there); use local file update
					ConsoleD.WriteLine ("Load seed data");
					var appdir = NSBundle.MainBundle.ResourcePath;
					var seedDataFile = appdir + "/Images/SeedData.xml";
					string xml = System.IO.File.ReadAllText (seedDataFile);
					BL.Managers.UpdateManager.UpdateFromFile(xml);

					ConsoleD.WriteLine("Database lives at: "+MWC.DL.MwcDatabase.DatabaseFilePath);
					// We SHOULDN'T skip backup because we are saving the Favorites in the same sqlite
					// database as the sessions are stored. A more iCloud-friendly design would be 
					// to keep the user-data separate from the server-generated data...
					NSFileManager.SetSkipBackupAttribute (MWC.DL.MwcDatabase.DatabaseFilePath, true);
				} else {
					// if there's already data in the database, do/attempt server update
					//ConsoleD.WriteLine("SkipBackup: "+NSFileManager.GetSkipBackupAttribute (MWC.DL.MwcDatabase.DatabaseFilePath));

					var earliestUpdateString = prefs.StringForKey(PrefsEarliestUpdate);
					DateTime earliestUpdateTime = DateTime.MinValue;
					if (!String.IsNullOrEmpty(earliestUpdateString)) {
						CultureInfo provider = CultureInfo.InvariantCulture;

						if (DateTime.TryParse (earliestUpdateString
								, provider
								, System.Globalization.DateTimeStyles.None
								, out earliestUpdateTime)) {
							ConsoleD.WriteLine ("Earliest update time: " + earliestUpdateTime);
						}
					}
					if (earliestUpdateTime < DateTime.Now) {
						// we're past the earliest update time, so update!
						if (Reachability.IsHostReachable (Constants.ConferenceDataBaseUrl)) {
							ConsoleD.WriteLine ("Reachability okay, update conference from server"); 
							BL.Managers.UpdateManager.UpdateConference ();
						} else {
							// no network
							ConsoleD.WriteLine ("No network, can't update data for now");
						}
					} else ConsoleD.WriteLine ("Too soon to update " + DateTime.Now);
				}
			})).Start();

			tabBar = new Screens.Common.TabBarController ();
			
			// couldn't do RespondsToSelector() on static 'Appearance' property)
			var majorVersionString = UIDevice.CurrentDevice.SystemVersion.Substring (0,1);
			var majorVersion = Convert.ToInt16(majorVersionString);
			if (majorVersion >= 5) { // gotta love Appearance in iOS5
				UINavigationBar.Appearance.TintColor = ColorNavBarTint;			
			}
			window.RootViewController = tabBar;
			window.MakeKeyAndVisible ();

			return true;
		}