// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { Debug.WriteLine("LAUNCHING"); using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists(SerialStore)) { myIsolatedStorage.DeleteFile(SerialStore); } } //this has asynchroneous components that will run while the UI loads and whatnot NetworkInterface.GetIsNetworkAvailable() if (DeviceNetworkInformation.IsNetworkAvailable && !rootHasBeenSavedInISO) { getAreas(); //in the future //JSONInterface2.populateCollectionView(fillCollection); } else { // clear loading screen PhoneApplicationService.Current.State[App.InitializeWithLoadingScreen] = false; } // Create the database if it does not exist. //the using statement guarntees that setup and teardown will always happen, and properly using (iFixitDataContext tDB = new iFixitDataContext(DBConnectionString)) { // Create the local database. if (!tDB.DatabaseExists()) { tDB.CreateDatabase(); // Save categories to the database. tDB.SubmitChanges(); } } }
public bool insertGuideIntoDB(GuideHolder guide) { //convert the GuideHolder we got into a DB object Debug.WriteLine("inserting guide " + guide.guide.title + " into db from net"); using (iFixitDataContext db = new iFixitDataContext(App.DBConnectionString)) { //SourceGuide = db.GuidesTable.SingleOrDefault(g => g.GuideID == this.guideID); SourceGuide = DBHelpers.GetCompleteGuide(this.guideID, db); if (SourceGuide == null) { Debug.WriteLine("\tdid not find old"); SourceGuide = new Guide(guide); db.GuidesTable.InsertOnSubmit(SourceGuide); } else { Debug.WriteLine("\tfound old"); SourceGuide.FillFields(guide); } InsertStepsAndLines(SourceGuide, guide.guide.steps, db); //insert it into the DB SourceGuide.Populated = true; db.SubmitChanges(); } //force view model to update vm.UpdateContentFromGuide(SourceGuide); this.gTitle.Text = vm.GuideTitle; this.gTopic.Text = vm.GuideTopic; //PivotItem infoPivot = buildInfoPivotItem(); //GuidePivot.Items.Add(infoPivot); this.DataContext = vm; //GuidePivot.ItemsSource = temp; //hide the loading bar LoadingBarInfo.Visibility = System.Windows.Visibility.Collapsed; return true; }
private void DeleteCached_Tap(object sender, EventArgs e) { //go through all guides/steps/lines and topics and dump them using (iFixitDataContext db = new iFixitDataContext(App.DBConnectionString)) { var cachedGuides = from g in db.GuidesTable where g.Populated == true select g; foreach (Guide g in cachedGuides) { var cachedSteps = from s in db.StepsTable where s.parentName == g.GuideID select s; foreach (Step s in cachedSteps) { var cachedLines = from l in db.LinesTable where l.parentName == g.GuideID select l; //Debug.WriteLine("got " + cachedLines.Count() + " lines"); db.LinesTable.DeleteAllOnSubmit(cachedLines); } //Debug.WriteLine("got " + cachedSteps.Count() + " steps"); db.StepsTable.DeleteAllOnSubmit(cachedSteps); } //Debug.WriteLine("got " + cachedGuides.Count() + " guides"); db.GuidesTable.DeleteAllOnSubmit(cachedGuides); var cachedTopics = from top in db.TopicsTable where top.Populated == true select top; db.TopicsTable.DeleteAllOnSubmit(cachedTopics); db.SubmitChanges(); } //nuke all cached images using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { //iterate through all files if (isoStore.DirectoryExists(ImgCache.BASE_PATH)) { foreach (string file in isoStore.GetFileNames(ImgCache.BASE_PATH + "\\*")) { //Debug.WriteLine(file); isoStore.DeleteFile(file); } } } UpdateBinding(); }
/* * Insert the data from the JSON parser into the database */ private bool insertDevInfoIntoDB(DeviceInfoHolder devInfo) { //something is wrong and the device was not found. Bail if (devInfo == null) { Debug.WriteLine("something went terribly wrong with a DeviceInfo. Bailing"); NavigationService.GoBack(); return false; } Topic top = null; Debug.WriteLine("putting device info into DB..."); //try to get a topic of this name from the DB //if it fails, make a new one. if it works, update the old using (iFixitDataContext db = new iFixitDataContext(App.DBConnectionString)) { bool gotTopicFromDB = true; top = DBHelpers.GetCompleteTopic(devInfo.topic_info.name, db); if (top == null) { top = new Topic(); gotTopicFromDB = false; } //translate devInfo in a Topic() //name is already the same top.Name = devInfo.topic_info.name; top.parentName = devInfo.title; top.Contents = devInfo.description; top.ImageURL = devInfo.image.text + ".medium"; top.Populated = true; //TODO inject metatdata here like # answers top.Description = ""; top.Description += prepHTML(devInfo.contents, devInfo); //now do the same for all attached guides foreach (DIGuides g in devInfo.guides) { Debug.WriteLine("\tguide " + g.title); //search if the guide already exists, and get or update it Guide gOld = new Guide(); gOld.FillFieldsFromDeviceInfo(navTopicName, g); gOld = db.GuidesTable.FirstOrDefault(other => other.GuideID == gOld.GuideID); if (gOld == null) { gOld = new Guide(); db.GuidesTable.InsertOnSubmit(gOld); } gOld.FillFieldsFromDeviceInfo(navTopicName, g); // hang it below the topic, it its collection of guides top.AddGuide(gOld); //FIXME do we need to specifically add this to the guide table? is that magic? db.SubmitChanges(); } if (!gotTopicFromDB) { db.TopicsTable.InsertOnSubmit(top); } //update the Topic() into the database db.SubmitChanges(); //force the view model to update infoVM.UpdateData(); updateInfoBrowser(); //force the views to update this.InfoStack.DataContext = infoVM; this.GuidesStack.DataContext = infoVM; //disable the loading bars this.LoadingBarInfo.Visibility = System.Windows.Visibility.Collapsed; this.LoadingBarGuides.Visibility = System.Windows.Visibility.Collapsed; } return true; }