/// <summary> /// Loads the best sessions.json it can find - first look in SpecialFolder /// (if not there, load the one that was included in the app download) /// </summary> public override bool FinishedLaunching(UIApplication app, NSDictionary options) { documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder var builtInJsonPath = Path.Combine (System.Environment.CurrentDirectory, ConferenceManager.LocalJsonDataFilename); jsonPath = Path.Combine (libraryPath, ConferenceManager.LocalJsonDataFilename); // UserData = new UserDatabase(Path.Combine (libraryPath, SqliteDataFilename)); ParametersManager = new ConfererenceParametersManager(); var conferenceParameters = ParametersManager.Load(); Conference = new ConferenceManager(); Conference.OnDownloadSucceeded += (jsonString) => { // Save the payload to the local file system. File.WriteAllText (jsonPath, jsonString); NSUserDefaults.StandardUserDefaults.SetString(ConferenceManager.LastUpdatedDisplay, "LastUpdated"); Console.WriteLine("Local json file updated " + jsonPath); UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; }; Conference.OnDownloadFailed += (error) => { Console.WriteLine("OnDownloadFailed:" + error); UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; }; #region Get session data from json into memory... var json = ""; if (!File.Exists(jsonPath)) { //jsonPath = builtInJsonPath; // use the bundled file NSUserDefaults.StandardUserDefaults.SetString("2012-09-15 15:15:15", "LastUpdated"); try { File.Copy (builtInJsonPath, jsonPath); // so it is there for loading } catch(FileNotFoundException fileNotFound) { throw new ApplicationException( string.Format("Make sure there is a sessions file named {0} embedded in your app, and it is named correctly.", ConferenceManager.LocalJsonDataFilename) ,fileNotFound); } } json = File.ReadAllText(jsonPath); MonkeySpace.Core.ConferenceManager.LoadFromString (json); #endregion // Create the tab bar tabBarController = new TabBarController (); //#d4563e UINavigationBar.Appearance.TintColor = UIColor.Clear.FromHex(0x164684); // Create the main window and add the navigation controller as a subview window = new UIWindow (UIScreen.MainScreen.Bounds); window.RootViewController = tabBarController; window.MakeKeyAndVisible (); showSplashScreen(); return true; }
/// <summary> /// Loads the best conf.xml it can find - first look in SpecialFolder /// (if not there, load the one that was included in the app download) /// </summary> /// <remarks> /// I wonder if there could be a problem with newer app code trying to /// open an older Xml after an upgrade is installed? /// I guess newer apps that aren't backward compatible /// should use a different filename eg. conf2.xml... /// </remarks> public override bool FinishedLaunching(UIApplication app, NSDictionary options) { // setup SQLite for 'starred sessions' database var basedir = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); UserData = new UserDatabase(Path.Combine(basedir, SqliteDataFilename)); #region Get All Session data... string xmlPath = XmlDataFilename; // the 'built in' version // version 2 xmlPath = XmlDataFilename; // the 'built in' version if (File.Exists(Path.Combine(basedir, XmlDataFilename))) { // load a newer copy xmlPath = Path.Combine(basedir, XmlDataFilename); } long start = DateTime.Now.Ticks; using (TextReader reader = new StreamReader(xmlPath)) { XmlSerializer serializer = new XmlSerializer(typeof(Conference2)); ConferenceData2 = (Conference2)serializer.Deserialize(reader); // Version 2 'flat' data structure var sessDic2 = (from s2 in ConferenceData2.Sessions select s2).ToDictionary(item => item.Code); var speaDic2 = (from s3 in ConferenceData2.Speakers select s3).ToDictionary(item => item.Name); // var tagDic2 = (from s3 in ConferenceData2.Tags // select s3).ToDictionary(item => item.Value); // dictionaries to re-constitute version 1 data structure var speaDic1 = new Dictionary <string, MIX10Xml.Speaker>(); var sessDic1 = new Dictionary <string, MIX10Xml.Session>(); var tagDic1 = new Dictionary <string, MIX10Xml.Tag>(); // create version 1 speakers foreach (var sp2 in speaDic2) { MIX10Xml.Speaker sp1 = sp2.Value as MIX10Xml.Speaker; speaDic1.Add(sp1.Name, sp1); } // create version 1 sessions // add sessions to version 1 tags // add sessions to version 1 speakers foreach (var se2 in sessDic2.Values) { MIX10Xml.Session se1 = se2 as MIX10Xml.Session; sessDic1.Add(se1.Code, se1); foreach (var ta2 in se2.TagStrings) { if (!tagDic1.Keys.Contains(ta2)) { tagDic1.Add(ta2, new Tag { Value = ta2 }); } tagDic1[ta2].Sessions.Add(se1); se1.Tags.Add(tagDic1[ta2]); } // add speakers to version 1 sessions foreach (var spn in se2.SpeakerNames) { Console.WriteLine(spn); se1.Speakers.Add(speaDic1[spn]); speaDic1[spn].Sessions.Add(se1); } } // push into version 1 data structure, which rest of the app uses ConferenceData = new Conference(ConferenceData2); ConferenceData.Speakers = speaDic1.Values.ToList(); ConferenceData.Sessions = sessDic1.Values.ToList(); ConferenceData.Tags = tagDic1.Values.ToList(); } #endregion // Create the tab bar tabBarController = new Monospace11.TabBarController(); // Create the main window and add the navigation controller as a subview window = new UIWindow(UIScreen.MainScreen.Bounds); window.AddSubview(tabBarController.View); window.MakeKeyAndVisible(); showSplashScreen(); return(true); }
/// <summary> /// Loads the best conf.xml it can find - first look in SpecialFolder /// (if not there, load the one that was included in the app download) /// </summary> /// <remarks> /// I wonder if there could be a problem with newer app code trying to /// open an older Xml after an upgrade is installed? /// I guess newer apps that aren't backward compatible /// should use a different filename eg. conf2.xml... /// </remarks> public override bool FinishedLaunching(UIApplication app, NSDictionary options) { // setup SQLite for 'starred sessions' database var basedir = Environment.GetFolderPath (System.Environment.SpecialFolder.Personal); UserData = new UserDatabase(Path.Combine (basedir, SqliteDataFilename)); #region Get All Session data... string xmlPath = XmlDataFilename; // the 'built in' version // version 2 xmlPath = XmlDataFilename; // the 'built in' version if (File.Exists(Path.Combine(basedir, XmlDataFilename))) { // load a newer copy xmlPath = Path.Combine(basedir, XmlDataFilename); } //long start = DateTime.Now.Ticks; using (TextReader reader = new StreamReader(xmlPath)) { XmlSerializer serializer = new XmlSerializer(typeof(Conference2)); ConferenceData2 = (Conference2)serializer.Deserialize(reader); // Version 2 'flat' data structure var sessDic2 = (from s2 in ConferenceData2.Sessions select s2).ToDictionary(item => item.Code); var speaDic2 = (from s3 in ConferenceData2.Speakers select s3).ToDictionary(item => item.Name); // var tagDic2 = (from s3 in ConferenceData2.Tags // select s3).ToDictionary(item => item.Value); // dictionaries to re-constitute version 1 data structure var speaDic1 = new Dictionary<string, MIX10Xml.Speaker>(); var sessDic1 = new Dictionary<string, MIX10Xml.Session>(); var tagDic1 = new Dictionary<string, MIX10Xml.Tag>(); // create version 1 speakers foreach (var sp2 in speaDic2) { MIX10Xml.Speaker sp1 = sp2.Value as MIX10Xml.Speaker; speaDic1.Add(sp1.Name, sp1); } // create version 1 sessions // add sessions to version 1 tags // add sessions to version 1 speakers foreach (var se2 in sessDic2.Values) { MIX10Xml.Session se1 = se2 as MIX10Xml.Session; sessDic1.Add(se1.Code, se1); foreach (var ta2 in se2.TagStrings) { if (!tagDic1.Keys.Contains(ta2)) { tagDic1.Add(ta2,new Tag{Value=ta2}); } tagDic1[ta2].Sessions.Add(se1); se1.Tags.Add(tagDic1[ta2]); } // add speakers to version 1 sessions foreach (var spn in se2.SpeakerNames) { Console.WriteLine(spn); se1.Speakers.Add(speaDic1[spn]); speaDic1[spn].Sessions.Add(se1); } } // push into version 1 data structure, which rest of the app uses ConferenceData = new Conference(ConferenceData2); ConferenceData.Speakers = speaDic1.Values.ToList(); ConferenceData.Sessions = sessDic1.Values.ToList(); ConferenceData.Tags = tagDic1.Values.ToList(); } #endregion // Create the tab bar tabBarController = new Monospace11.TabBarController (); // Create the main window and add the navigation controller as a subview window = new UIWindow (UIScreen.MainScreen.Bounds); window.AddSubview(tabBarController.View); window.MakeKeyAndVisible (); showSplashScreen(); return true; }