void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (local_to_server != null && (Configurations.sync_interactions_to_server || Configurations.sync_interactions_to_dropbox)) { local_to_server.ProcessInsertInteractions_Forced(); } Configurations.SaveSettings(); }
public void ProcessChanges() { for (int counter = 0; counter < changes.Count; counter++) { if (changes[counter].type_id == 1 && changes[counter].object_type == "nature_net.User") { this.ProcessInsertUser(changes[counter].object_id); } if (changes[counter].type_id == 2 && changes[counter].object_type == "nature_net.User") { this.ProcessUpdateUser(changes[counter].object_id); } if (changes[counter].type_id == 3 && changes[counter].object_type == "nature_net.User") { this.ProcessDeleteUser(changes[counter].technical_info); } if (changes[counter].type_id == 1 && changes[counter].object_type == "nature_net.Contribution" && changes[counter].technical_info == "Design Idea") { this.ProcessInsertDesignIdea(changes[counter].object_id); } if (changes[counter].type_id == 2 && changes[counter].object_type == "nature_net.Contribution") { this.ProcessUpdateDesignIdea(changes[counter].object_id); } if (changes[counter].type_id == 3 && changes[counter].object_type == "nature_net.Contribution") { this.ProcessDeleteDesignIdea(changes[counter].technical_info); } if (changes[counter].type_id == 1 && changes[counter].object_type == "nature_net.Feedback") { this.ProcessInsertFeedback(changes[counter].object_id); } if (changes[counter].type_id == 1 && changes[counter].object_type == "nature_net.Activity") { this.ProcessInsertActivity(changes[counter].object_id); } if (changes[counter].type_id == 2 && changes[counter].object_type == "nature_net.Activity") { this.ProcessUpdateActivity(changes[counter].object_id); } if (changes[counter].type_id == 3 && changes[counter].object_type == "nature_net.Activity") { this.ProcessDeleteActivity(changes[counter].technical_info); } Configurations.last_change_tabletop = changes[counter].id; Configurations.SaveSettings(); } //if (Configurations.sync_interactions_to_dropbox) //ProcessInsertInteractions(); }
public bool ProcessWebUserChanges() { DateTime save_time = DateTime.UtcNow; List <SWebAccount> accounts = null; accounts = server_api.GetWebAccountsCreatedSince(Configurations.last_change_server_webusers.Year.ToString(), Configurations.last_change_server_webusers.Month.ToString(), Configurations.last_change_server_webusers.Day.ToString(), Configurations.last_change_server_webusers.Hour.ToString(), Configurations.last_change_server_webusers.Minute.ToString()); if (accounts == null) { return(false); } else { this.current_webaccounts = accounts; } TableTopDataClassesDataContext db = Configurations.GetTableTopDB(); for (int counter = 0; counter < accounts.Count; counter++) { if (accounts[counter].username == "default") { continue; } var ru = from u in db.WebUsers where u.username == accounts[counter].username select u; if (ru.Count() == 0) { WebUser u_new = new WebUser(); u_new.username = accounts[counter].username; u_new.password = accounts[counter].password; u_new.email = accounts[counter].email; u_new.fullname = accounts[counter].name; u_new.technical_info = accounts[counter].consent; u_new.affiliation = accounts[counter].affiliation; if (accounts[counter].icon_url.StartsWith("nn_")) { u_new.avatar = accounts[counter].icon_url; } else { u_new.avatar = Configurations.GetRandomAvatar(); } try { SAccount related_account = server_api.GetAccount(accounts[counter].account_id); string uname = "default"; if (related_account != null) { uname = related_account.username; } if (uname == "default") { u_new.user_id = 0; } else { var u = from u0 in db.Users where u0.name == uname select u0; User related_user = u.Single <User>(); u_new.user_id = related_user.id; } } catch (Exception ex) { Log.WriteErrorLog(ex); } db.WebUsers.InsertOnSubmit(u_new); } else { if (ru.Count() == 1) { WebUser u = ru.Single <WebUser>(); u.password = accounts[counter].password; u.affiliation = accounts[counter].affiliation; if (accounts[counter].icon_url.StartsWith("nn_")) { u.avatar = accounts[counter].icon_url; } u.email = accounts[counter].email; u.technical_info = accounts[counter].consent; try { SAccount related_account = server_api.GetAccount(accounts[counter].account_id); string uname = related_account.username; if (uname == "default") { u.user_id = 0; } else { var u1 = from u0 in db.Users where u0.name == uname select u0; User related_user = u1.Single <User>(); u.user_id = related_user.id; } } catch (Exception ex) { Log.WriteErrorLog(ex); } db.SubmitChanges(); } } } if (accounts.Count == 0) { return(true); } if (SubmitChangesToLocalDB(db)) { Configurations.last_change_server_webusers = save_time; Configurations.SaveSettings(); return(true); } return(false); }
public bool ProcessFeedbackChanges() { DateTime save_time = DateTime.UtcNow; List <SFeedback> feedbacks = server_api.GetFeedbacksCreatedSince(Configurations.last_change_server_feedbacks.Year.ToString(), Configurations.last_change_server_feedbacks.Month.ToString(), Configurations.last_change_server_feedbacks.Day.ToString(), Configurations.last_change_server_feedbacks.Hour.ToString(), Configurations.last_change_server_feedbacks.Minute.ToString(), true); if (feedbacks == null) { return(false); } else { current_feedbacks = feedbacks; } TableTopDataClassesDataContext db = Configurations.GetTableTopDB(); bool all_fine = true; for (int counter = 0; counter < feedbacks.Count; counter++) { if (feedbacks[counter].kind == "Landmark") { continue; } var fdbacks = from f in db.Feedbacks where f.technical_info == feedbacks[counter].id.ToString() select f; if (fdbacks.Count() > 1) { continue; } if (fdbacks.Count() == 1) { // update feedback Feedback f = fdbacks.Single <Feedback>(); f.note = feedbacks[counter].content; f.web_username = feedbacks[counter].webusername; //f.date = (Configurations.unix_epoch.AddMilliseconds(feedbacks[counter].modified_at)).ToLocalTime(); var usrs = from u in db.Users where u.name == feedbacks[counter].account.username select u; if (usrs.Count() > 0) { f.user_id = usrs.First <User>().id; } else { f.user_id = 0; } db.SubmitChanges(); continue; } Feedback fb = new Feedback(); fb.date = (Configurations.unix_epoch.AddMilliseconds(feedbacks[counter].created_at)).ToLocalTime(); fb.web_username = feedbacks[counter].webusername; if (feedbacks[counter].kind.ToLower() == "comment") { fb.type_id = 1; // comment } if (feedbacks[counter].kind.ToLower() == "like") { fb.type_id = 2; // like } if (feedbacks[counter].kind.ToLower() == "rating") { fb.type_id = 3; // rating } if (feedbacks[counter].kind.ToLower() == "like") { fb.note = "true"; } else { fb.note = feedbacks[counter].content; } // find local user id var users = from u in db.Users where u.name == feedbacks[counter].account.username select u; if (users.Count() > 0) { fb.user_id = users.First <User>().id; } else { fb.user_id = 0; } fb.parent_id = 0; if (feedbacks[counter].parent_id != 0) { // find local parent id var parents = from p in db.Feedbacks where p.technical_info == feedbacks[counter].parent_id.ToString() select p; if (parents.Count() == 1) { fb.parent_id = parents.Single <Feedback>().id; } } if (feedbacks[counter].target.model.ToLower() == "note") { // search for the object_id in local database var cntribs = from c in db.Contributions where c.technical_info == feedbacks[counter].target.id.ToString() select c; if (cntribs.Count() > 0) { fb.object_id = cntribs.First <Contribution>().id; fb.object_type = "nature_net.Contribution"; } } if (feedbacks[counter].target.model.ToLower() == "account") { string username = find_account(feedbacks[counter].target.id); // search for the object_id in local database var cntribs = from c in db.Users where c.name == username select c; if (cntribs.Count() > 0) { fb.object_id = cntribs.First <User>().id; fb.object_type = "nature_net.User"; } } if (feedbacks[counter].target.model.ToLower() == "context") { string context_name = find_context(feedbacks[counter].target.id); // search for the object_id in local database if (context_name.StartsWith(Configurations.GetSiteNameForServer() + "_landmark")) { //search for locations var cntribs = from c in db.Locations where c.id == Convert.ToInt32(context_name.Substring(Configurations.GetSiteNameForServer().Length + "_landmark".Length)) select c; if (cntribs.Count() > 0) { fb.object_id = cntribs.First <Location>().id; fb.object_type = "nature_net.Location"; } } else { //search for activities var cntribs = from c in db.Activities where c.name == context_name select c; if (cntribs.Count() > 0) { fb.object_id = cntribs.First <Activity>().id; fb.object_type = "nature_net.Activity"; } } } fb.technical_info = feedbacks[counter].id.ToString(); //fb.technical_info = ""; db.Feedbacks.InsertOnSubmit(fb); if (!SubmitChangesToLocalDB(db)) { all_fine = false; return(false); } } if (feedbacks.Count == 0) { return(true); } if (all_fine) { Configurations.last_change_server_feedbacks = save_time; Configurations.SaveSettings(); return(true); } return(false); }
public bool ProcessUserChanges() { DateTime save_time = DateTime.UtcNow; List <SAccount> accounts = null; accounts = server_api.GetAccountsCreatedSince(Configurations.last_change_server_users.Year.ToString(), Configurations.last_change_server_users.Month.ToString(), Configurations.last_change_server_users.Day.ToString(), Configurations.last_change_server_users.Hour.ToString(), Configurations.last_change_server_users.Minute.ToString(), true); if (accounts == null) { return(false); } else { this.current_accounts = accounts; } TableTopDataClassesDataContext db = Configurations.GetTableTopDB(); for (int counter = 0; counter < accounts.Count; counter++) { if (accounts[counter].username == "default") { continue; } var ru = from u in db.Users where u.name == accounts[counter].username select u; if (ru.Count() == 0) { User u_new = new User(); u_new.name = accounts[counter].username; u_new.password = accounts[counter].password; u_new.email = accounts[counter].email; u_new.technical_info = accounts[counter].consent; u_new.affiliation = accounts[counter].affiliation; if (accounts[counter].icon_url.StartsWith("nn_")) { u_new.avatar = accounts[counter].icon_url; } else { u_new.avatar = Configurations.GetRandomAvatar(); } db.Users.InsertOnSubmit(u_new); } else { if (ru.Count() == 1) { User u = ru.Single <User>(); u.password = accounts[counter].password; u.affiliation = accounts[counter].affiliation; if (accounts[counter].icon_url.StartsWith("nn_")) { u.avatar = accounts[counter].icon_url; } u.email = accounts[counter].email; u.technical_info = accounts[counter].consent; db.SubmitChanges(); } } } if (accounts.Count == 0) { return(true); } if (SubmitChangesToLocalDB(db)) { Configurations.last_change_server_users = save_time; Configurations.SaveSettings(); return(true); } return(false); }
public bool ProcessContributionChanges() { DateTime save_time = DateTime.UtcNow; List <SNote> notes; notes = server_api.GetNotesCreatedSince(Configurations.last_change_server_contributions.Year.ToString(), Configurations.last_change_server_contributions.Month.ToString(), Configurations.last_change_server_contributions.Day.ToString(), Configurations.last_change_server_contributions.Hour.ToString(), Configurations.last_change_server_contributions.Minute.ToString(), true); if (notes == null) { return(false); } else { this.current_notes = notes; } bool submit_changes = true; TableTopDataClassesDataContext db = Configurations.GetTableTopDB(); for (int counter = 0; counter < notes.Count; counter++) { var cntribs = from c in db.Contributions where c.technical_info == notes[counter].id.ToString() select c; if (cntribs.Count() > 0) { // existing contribution -- update it Contribution c1 = cntribs.First <Contribution>(); c1.modified_date = (Configurations.unix_epoch.AddMilliseconds(notes[counter].modified_at)).ToLocalTime(); c1.location_id = find_location_id(notes[counter]); c1.note = notes[counter].content; c1.status = notes[counter].status; c1.web_username = notes[counter].webusername; if (notes[counter].kind == "DesignIdea") { c1.tags = "Design Idea"; } else { if (notes[counter].medias != null && notes[counter].medias.Count > 0) { c1.tags = notes[counter].medias[0].kind; c1.media_url = notes[counter].medias[0].link; } } int a_id = 0; // free observation if (notes[counter].context.name.Substring(Configurations.GetSiteNameForServer().Count() + 1) == "design_idea") { a_id = 1; // design idea } var activities0 = from a in db.Activities where a.name == notes[counter].context.title select a; if (activities0.Count() > 0) { a_id = activities0.First <Activity>().id; } c1.technical_info = notes[counter].id.ToString(); db.SubmitChanges(); //if (a_id != 1) update_or_create_collection(db, c1.id, a_id, c1.date); // updating the user string new_username = notes[counter].account.username; int new_user_id = 0; var usrs = from u in db.Users where u.name == new_username select u; if (usrs.Count() == 1) { new_user_id = usrs.Single <User>().id; } this.update_user_for_contribution(db, c1.id, new_user_id, c1.date); continue; } string username = notes[counter].account.username; DateTime note_date = (Configurations.unix_epoch.AddMilliseconds(notes[counter].created_at)).ToLocalTime(); DateTime note_modified_date = note_date; if (notes[counter].modified_at != null && notes[counter].modified_at > 0) { note_modified_date = (Configurations.unix_epoch.AddMilliseconds(notes[counter].modified_at)).ToLocalTime(); } //DateTime note_date= DateTime.FromOADate(notes[counter].created_at //int activity_id = notes[counter].context.?? int activity_id = 0; // free observation //int activity_id = 1; // design idea //int activity_id = other; // other activities if (notes[counter].context.name.Substring(Configurations.GetSiteNameForServer().Count() + 1) == "design_idea") { activity_id = 1; } var activities = from a in db.Activities where a.name == notes[counter].context.title select a; if (activities.Count() > 0) { activity_id = activities.First <Activity>().id; } int col_id = this.get_or_create_collection(db, username, activity_id, note_date); if (col_id == -1) { continue; } foreach (SMedia media in notes[counter].medias) { bool could_create = create_contribution(notes[counter], media, note_date, note_modified_date, notes[counter].content, notes[counter].id.ToString(), (notes[counter].kind == "DesignIdea"), col_id, notes[counter].status, db); if (!could_create) { submit_changes = false; } } if (notes[counter].medias == null) { notes[counter].medias = new List <SMedia>(); } if (notes[counter].medias.Count == 0) { bool could_create = create_contribution(notes[counter], null, note_date, note_modified_date, notes[counter].content, notes[counter].id.ToString(), (notes[counter].kind == "DesignIdea"), col_id, notes[counter].status, db); if (!could_create) { submit_changes = false; } } } if (notes.Count == 0) { return(true); } if (submit_changes) { Configurations.last_change_server_contributions = save_time; Configurations.SaveSettings(); return(true); } return(false); }