Esempio n. 1
0
        private void update_user_for_contribution(TableTopDataClassesDataContext db, int contribution_id, int new_user_id, DateTime dt)
        {
            var mapping = from m in db.Collection_Contribution_Mappings
                          where m.contribution_id == contribution_id
                          select m;

            if (mapping.Count() == 0)
            {
                return;
            }
            Collection_Contribution_Mapping c1 = mapping.First <Collection_Contribution_Mapping>();

            if (mapping.Count() == 1)
            {
                var colls = from c in db.Collections
                            where c.id == c1.collection_id
                            select c;
                if (colls.Count() == 1)
                {
                    Collection c2 = colls.First <Collection>();
                    c2.user_id = new_user_id;
                    db.SubmitChanges();
                }
                //var mapping2 = from m in db.Collection_Contribution_Mappings
                //               where m.collection_id == c1.collection_id
                //               select m;
                //if (mapping2.Count() != 1)
                //    should_create_collection = true;
            }
        }
Esempio n. 2
0
        private void ProcessInsertDesignIdea(int id)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var designideas = from d in db.Contributions
                              where d.id == id
                              select d;

            if (designideas.Count() == 1)
            {
                Contribution di = designideas.Single <Contribution>();
                User         u  = find_user_of_contribution(di);
                Activity     a  = find_activity_of_contribution(di);
                if (u == null || a == null)
                {
                    return;
                }
                string   cid = a.technical_info.Split(new char[] { ';' })[0];
                SContext c   = server_api.GetContext(cid);
                if (c == null)
                {
                    return;
                }
                SNote note = server_api.CreateNote(u.name, "DesignIdea", di.note, c.name, di.status.ToString());
                if (note == null)
                {
                    return;
                }
                di.technical_info = note.id.ToString();
                db.SubmitChanges();
                if (RESTService.Last_Exception != null)
                {
                    this.errors.Add(RESTService.Last_Exception);
                }
            }
        }
Esempio n. 3
0
        private void button_remove_user_Click(object sender, EventArgs e)
        {
            if (cached_users.Count == 0)
            {
                MessageBox.Show("Please refresh the users list.");
                return;
            }
            if (comboBox_users.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a user.");
                return;
            }
            int id = cached_users[comboBox_users.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from u in db.Users
                        where u.id == id
                        select u;

            if (users.Count() != 1)
            {
                MessageBox.Show("Error. User not found.");
                return;
            }
            User the_user    = users.Single <User>();
            var  collections = from c in db.Collections
                               where c.user_id == the_user.id
                               select c;

            if (collections.Count() > 0)
            {
                MessageBox.Show("This user cannot be deleted, because of his/her collections.");
                return;
            }
            var feedbacks = from f in db.Feedbacks
                            where f.user_id == the_user.id
                            select f;

            if (feedbacks.Count() > 0)
            {
                MessageBox.Show("This user cannot be deleted, because of his/her feedbacks.");
                return;
            }
            db.Users.DeleteOnSubmit(the_user);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 3; action.user_id = 0; action.date = DateTime.UtcNow;
            action.object_type = "nature_net.User"; action.object_id = the_user.id;
            db.Actions.InsertOnSubmit(action); action.technical_info = the_user.name;
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
        }
Esempio n. 4
0
        private void comboBox_collections_addcontrib_SelectedIndexChanged(object sender, EventArgs e)
        {
            int cid = cached_user_collections[comboBox_collections_addcontrib.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            //
            Activity activity = (from c in db.Collections
                                 where c.id == cid
                                 select c).Single <Collection>().Activity;

            user_collection_activity            = activity;
            comboBox_activities_addcontrib.Text = activity.name;
        }
Esempio n. 5
0
        public void ProcessInsertInteractions_Forced()
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var interactions = from i in db.Interaction_Logs
                               where i.id > Configurations.last_interaction_id
                               select i;

            if (interactions.Count() == 0)
            {
                return;
            }
            CombineAndSendInteractions(interactions.ToList <Interaction_Log>(), db);
        }
Esempio n. 6
0
        private void button_refresh_activities_Click(object sender, EventArgs e)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from u in db.Activities
                             select u;

            cached_activities.Clear();
            cached_activities.AddRange(activities);
            comboBox_activities.Items.Clear();
            for (int counter = 1; counter < cached_activities.Count + 1; counter++)
            {
                comboBox_activities.Items.Add(counter.ToString() + " - " + cached_activities[counter - 1].name);
            }
        }
Esempio n. 7
0
        private void button_refresh_ideas_Click(object sender, EventArgs e)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var ideas = from u in db.Design_Ideas
                        select u;

            cached_ideas.Clear();
            cached_ideas.AddRange(ideas);
            comboBox_ideas.Items.Clear();
            for (int counter = 1; counter < cached_ideas.Count + 1; counter++)
            {
                comboBox_ideas.Items.Add(counter.ToString() + " - " + cached_ideas[counter - 1].note);
            }
        }
Esempio n. 8
0
        private int get_or_create_collection(TableTopDataClassesDataContext db, string user_name, int activity_id, DateTime dt)
        {
            int user_id = 0;
            var ru      = from u in db.Users
                          where u.name == user_name
                          select u;

            if (ru.Count() == 0)
            {
                if (user_name.ToLower() != "default")
                {
                    return(0);
                }
            }
            else
            {
                user_id = ru.First <User>().id;
            }

            var r = from c in db.Collections
                    where ((c.user_id == user_id) && c.activity_id == activity_id)
                    orderby c.date descending
                    select c;

            if (r.Count() != 0)
            {
                foreach (Collection col in r)
                {
                    if (Configurations.GetDate_Formatted(col.date) == Configurations.GetDate_Formatted(dt))
                    {
                        return(col.id);
                    }
                }
            }

            // create new collection
            Collection cl = new Collection();

            cl.activity_id = activity_id;
            cl.date        = dt;
            cl.name        = Configurations.GetDate_Formatted(dt);
            cl.user_id     = user_id;
            db.Collections.InsertOnSubmit(cl);
            if (!SubmitChangesToLocalDB(db))
            {
                return(-1);
            }
            return(cl.id);
        }
Esempio n. 9
0
        public int ProcessInsertInteractions()
        {
            int result = 0;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var interactions = from i in db.Interaction_Logs
                               where i.id > Configurations.last_interaction_id
                               select i;

            if (interactions.Count() > Configurations.max_interaction_size)
            {
                int r = CombineAndSendInteractions(interactions.ToList <Interaction_Log>(), db);
                result = result + r;
            }
            return(result);
        }
Esempio n. 10
0
        public void GetChanges()
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var actions = from a in db.Actions
                          where a.id > Configurations.last_change_tabletop
                          select a;

            if (actions.Count() > 0)
            {
                this.changes = actions.ToList <sync.classes.Action>();
            }
            else
            {
                this.changes = new List <sync.classes.Action>();
            }
        }
Esempio n. 11
0
        //public bool ProcessInteractionLogChanges2()
        //{
        //    TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
        //    DirectoryInfo info = new DirectoryInfo(Configurations.GetAbsoluteInteractionLogFilePath());
        //    FileInfo[] files = info.GetFiles();
        //    long max_times = 0; current_interactions.Clear();
        //    for (int counter = 0; counter < files.Count(); counter++)
        //    {
        //        long time = 0;
        //        try { time = Convert.ToInt64(files[counter].Name.Substring(2)); }
        //        catch (Exception) { continue; }
        //        if (time > Configurations.last_change_interaction_files)
        //        {
        //            try
        //            {
        //                Stream writer = File.OpenWrite(files[counter].FullName);
        //                writer.Close(); // these two lines are to check if it is being used by another process or not
        //                StreamReader reader = new StreamReader(files[counter].FullName);
        //                string[] contents = reader.ReadToEnd().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
        //                reader.Close();
        //                int n = contents.Count();
        //                List<Interaction_Log> new_logs = new List<Interaction_Log>();
        //                for (int counter_c = 0; counter_c < n; counter_c++)
        //                {
        //                    string[] ilog = contents[counter_c].Split(new char[] { '\t' });
        //                    if (ilog.Count() < 6)
        //                    {
        //                        continue;
        //                    }
        //                    Interaction_Log log = new Interaction_Log();
        //                    log.date = Convert.ToDateTime(ilog[0]);
        //                    log.details = ilog[5];
        //                    log.touch_id = Convert.ToInt32(ilog[2]);
        //                    log.touch_x = Convert.ToDouble(ilog[3]);
        //                    log.touch_y = Convert.ToDouble(ilog[4]);
        //                    int log_type_id = (from t in db.Interaction_Types
        //                                       where t.type == ilog[1]
        //                                       select t.id).Single<int>();
        //                    log.type = log_type_id;
        //                    //new_logs.Add(log);
        //                    db.Interaction_Logs.InsertOnSubmit(log);
        //                    if (counter_c == Configurations.max_submit_changes)
        //                        db.SubmitChanges();
        //                }
        //                //db.Interaction_Logs.InsertAllOnSubmit(new_logs);
        //                db.SubmitChanges();
        //            }
        //            catch (Exception e) { Log.WriteErrorLog(e); continue; }
        //            if (max_times < time) max_times = time;
        //            current_interactions.Add(files[counter].Name);
        //        }
        //    }
        //    if (max_times != 0) Configurations.last_change_interaction_files = max_times;
        //    return true;
        //}

        public int ProcessInteractionLogChanges3()
        {
            int result = 0;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            DirectoryInfo info = new DirectoryInfo(Configurations.GetAbsoluteInteractionLogFilePath());

            FileInfo[] files     = info.GetFiles();
            DateTime   max_times = Configurations.last_change_interaction_files;

            for (int counter = 0; counter < files.Count(); counter++)
            {
                DateTime time;
                try { time = DateTime.ParseExact(files[counter].Name, "yyMMdd", System.Globalization.CultureInfo.InvariantCulture); }
                catch (Exception) { continue; }
                if (time >= Configurations.last_change_interaction_files)
                {
                    if (time > max_times)
                    {
                        max_times = time;
                    }
                    StreamReader reader = new StreamReader(files[counter].FullName);
                    while (!reader.EndOfStream)
                    {
                        string          ilog           = reader.ReadLine();
                        byte[]          mem_data       = Convert.FromBase64String(ilog);
                        MemoryStream    str_mem        = new MemoryStream(mem_data);
                        BinaryFormatter bformatter     = new BinaryFormatter();
                        Interaction_Log_Serializable i = (Interaction_Log_Serializable)bformatter.Deserialize(str_mem);
                        if (i.id > Configurations.last_change_interaction_files_id)
                        {
                            Interaction_Log i2 = new Interaction_Log();
                            i2.date     = i.date; i2.details = i.details; i2.technical_info = i.technical_info;
                            i2.touch_id = i.touch_id; i2.touch_x = i.touch_x; i2.touch_y = i.touch_y; i2.type = i.type;
                            db.Interaction_Logs.InsertOnSubmit(i2);
                            try { db.SubmitChanges(); }
                            catch (Exception ex) { Log.WriteErrorLog(ex); continue; }
                            Configurations.last_change_interaction_files_id = i.id;
                            result++;
                        }
                    }
                    reader.Close();
                }
            }
            Configurations.last_change_interaction_files = max_times;
            return(result);
        }
Esempio n. 12
0
        private void ProcessUpdateDesignIdea(int id)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var designideas = from d in db.Design_Ideas
                              where d.id == id
                              select d;

            if (designideas.Count() == 1)
            {
                Design_Idea di   = designideas.Single <Design_Idea>();
                SNote       note = server_api.UpdateNote(di.technical_info, di.status.ToString());
                if (RESTService.Last_Exception != null)
                {
                    this.errors.Add(RESTService.Last_Exception);
                }
            }
        }
Esempio n. 13
0
        private void button_remove_activity_Click(object sender, EventArgs e)
        {
            if (cached_activities.Count == 0)
            {
                MessageBox.Show("Please refresh the activities list.");
                return;
            }
            if (comboBox_activities.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an activity.");
                return;
            }
            int id = cached_activities[comboBox_activities.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from u in db.Activities
                             where u.id == id
                             select u;

            if (activities.Count() != 1)
            {
                MessageBox.Show("Error. Activity not found.");
                return;
            }
            Activity the_activity = activities.Single <Activity>();
            var      collections  = from c in db.Collections
                                    where c.activity_id == the_activity.id
                                    select c;

            if (collections.Count() > 0)
            {
                MessageBox.Show("This activity cannot be deleted, because of the contributions in the activity.");
                return;
            }
            db.Activities.DeleteOnSubmit(the_activity);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 3; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_activity.id;
            action.object_type = "nature_net.Activity"; action.technical_info = the_activity.technical_info;
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            MessageBox.Show("Removed from the local database. It will be synced once (Local -> Server) is enabled.");
        }
Esempio n. 14
0
        private void ProcessInsertUser(int user_id)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from u in db.Users
                        where u.id == user_id
                        select u;

            if (users.Count() == 1)
            {
                User us = users.Single <User>();
                server_api.CreateAccount(us.name, us.name, us.password, us.email, us.technical_info, us.affiliation.ToString(), us.avatar);
                if (RESTService.Last_Exception != null)
                {
                    this.errors.Add(RESTService.Last_Exception);
                }
            }
        }
Esempio n. 15
0
        private User find_user_of_contribution(Contribution c)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from mappings in db.Collection_Contribution_Mappings
                        where mappings.contribution_id == c.id
                        select mappings.Collection.User;

            if (users == null)
            {
                return(null);
            }
            if (users.Count() == 0)
            {
                return(null);
            }
            return(users.First <User>());
        }
Esempio n. 16
0
        private Activity find_activity_of_contribution(Contribution c)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from mappings in db.Collection_Contribution_Mappings
                             where mappings.contribution_id == c.id
                             select mappings.Collection.Activity;

            if (activities == null)
            {
                return(null);
            }
            if (activities.Count() == 0)
            {
                return(null);
            }
            return(activities.First <Activity>());
        }
Esempio n. 17
0
        private void button_add_contrib_Click(object sender, EventArgs e)
        {
            try
            {
                int uid = cached_users[comboBox_users_addcontrib.SelectedIndex].id;
                int cid = cached_user_collections[comboBox_collections_addcontrib.SelectedIndex].id;
                int lid = cached_locations[comboBox_locations_addcontrib.SelectedIndex].id;

                TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
                Contribution c = new Contribution();
                c.date          = DateTime.Now;
                c.modified_date = DateTime.Now;
                c.location_id   = lid;
                c.media_url     = textBox_mediaurl_addcontrib.Text;
                c.note          = textBox_desc_addcontrib.Text;
                c.tags          = textBox_tags_addcontrib.Text;
                c.status        = "";
                db.Contributions.InsertOnSubmit(c);
                db.SubmitChanges();

                if (checkBox_new_collection.Checked)
                {
                    Collection c2 = new Collection();
                    c2.activity_id = cached_activities_addcontrib[comboBox_activities_addcontrib.SelectedIndex].id;
                    c2.date        = DateTime.Now;
                    c2.user_id     = uid;
                    c2.name        = Configurations.GetDate_Formatted(c2.date);
                    db.Collections.InsertOnSubmit(c2);
                    db.SubmitChanges();
                    cid = c2.id;
                }

                Collection_Contribution_Mapping ccm = new Collection_Contribution_Mapping();
                ccm.collection_id   = cid;
                ccm.contribution_id = c.id;
                ccm.date            = DateTime.Now;
                db.Collection_Contribution_Mappings.InsertOnSubmit(ccm);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n--\r\n" + ex.StackTrace);
            }
            MessageBox.Show("Contribution was added successfully.");
        }
Esempio n. 18
0
        private void button_update_activity_Click(object sender, EventArgs e)
        {
            if (cached_activities.Count == 0)
            {
                MessageBox.Show("Please refresh the activities list.");
                return;
            }
            if (comboBox_activities.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an activity.");
                return;
            }
            if (textBox_activity_name.Text == "" || textBox_activity_description.Text == "")
            {
                MessageBox.Show("Please fill the name and description textboxes.");
                return;
            }
            int id = cached_activities[comboBox_activities.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from u in db.Activities
                             where u.id == id
                             select u;

            if (activities.Count() != 1)
            {
                MessageBox.Show("Error. Activity not found.");
                return;
            }
            Activity the_activity = activities.Single <Activity>();

            the_activity.name        = textBox_activity_name.Text;
            the_activity.description = textBox_activity_description.Text;
            the_activity.avatar      = textBox_activity_icon_url.Text;
            sync.classes.Action action = new classes.Action();
            action.type_id     = 2; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_activity.id;
            action.object_type = "nature_net.Activity"; action.technical_info = "Updating name/desc.";
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            MessageBox.Show("Updated in the local database. It will be synced once (Local -> Server) is enabled.");
        }
Esempio n. 19
0
        private void ProcessUpdateActivity(int id)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from d in db.Activities
                             where d.id == id
                             select d;

            if (activities.Count() == 1)
            {
                Activity di         = activities.Single <Activity>();
                string   context_id = di.technical_info.Split(new char[] { ';' })[0];
                SContext context    = server_api.UpdateContext(context_id, di.name, di.description, di.avatar);
                if (RESTService.Last_Exception != null)
                {
                    this.errors.Add(RESTService.Last_Exception);
                }
            }
        }
Esempio n. 20
0
        public void ProcessInsertActivity(int id)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var activities = from d in db.Activities
                             where d.id == id
                             select d;

            if (activities.Count() == 1)
            {
                Activity di      = activities.Single <Activity>();
                SContext context = server_api.AddContext(di.name, di.description, di.avatar);
                di.technical_info = context.id.ToString() + ";" + context.extras;
                if (RESTService.Last_Exception != null)
                {
                    this.errors.Add(RESTService.Last_Exception);
                }
            }
        }
Esempio n. 21
0
        private void comboBox_users_addcontrib_SelectedIndexChanged(object sender, EventArgs e)
        {
            int uid = cached_users[comboBox_users_addcontrib.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            //
            var collections = from c in db.Collections
                              where c.user_id == uid
                              select c;

            cached_user_collections.Clear();
            cached_user_collections.AddRange(collections);
            comboBox_collections_addcontrib.Items.Clear();
            for (int counter = 0; counter < cached_user_collections.Count; counter++)
            {
                comboBox_collections_addcontrib.Items.Add(cached_user_collections[counter].name);
            }
            comboBox_collections_addcontrib.SelectedIndex = 0;
            //
        }
Esempio n. 22
0
        private void button_remove_idea_Click(object sender, EventArgs e)
        {
            if (cached_ideas.Count == 0)
            {
                MessageBox.Show("Please refresh the ideas list.");
                return;
            }
            if (comboBox_ideas.SelectedIndex < 0)
            {
                MessageBox.Show("Please select an idea.");
                return;
            }
            int id = cached_ideas[comboBox_ideas.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var ideas = from u in db.Contributions
                        where u.id == id
                        select u;

            if (ideas.Count() != 1)
            {
                MessageBox.Show("Error. Design idea not found.");
                return;
            }
            Contribution the_idea = ideas.Single <Contribution>();
            var          mappings = from m in db.Collection_Contribution_Mappings
                                    where m.contribution_id == the_idea.id
                                    select m;

            db.Collection_Contribution_Mappings.DeleteAllOnSubmit(mappings);
            db.Contributions.DeleteOnSubmit(the_idea);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 3; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_idea.id;
            action.object_type = "nature_net.Contribution"; action.technical_info = the_idea.technical_info;
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
        }
Esempio n. 23
0
        private void button_refresh_users_addcontrib_Click(object sender, EventArgs e)
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from u in db.Users
                        where u.id > 0
                        select u;

            cached_users.Clear();
            cached_users.AddRange(users);
            comboBox_users_addcontrib.Items.Clear();
            for (int counter = 1; counter < cached_users.Count + 1; counter++)
            {
                comboBox_users_addcontrib.Items.Add(counter.ToString() + " - " + cached_users[counter - 1].name);
            }
            //
            var locations = from l in db.Locations
                            select l;

            cached_locations.Clear();
            cached_locations.AddRange(locations);
            comboBox_locations_addcontrib.Items.Clear();
            for (int counter = 0; counter < cached_locations.Count; counter++)
            {
                comboBox_locations_addcontrib.Items.Add(cached_locations[counter].name);
            }
            comboBox_locations_addcontrib.SelectedIndex = 0;
            //
            var activities = from a in db.Activities
                             select a;

            cached_activities_addcontrib.Clear();
            cached_activities_addcontrib.AddRange(activities);
            comboBox_activities_addcontrib.Items.Clear();
            for (int counter = 0; counter < cached_activities_addcontrib.Count; counter++)
            {
                comboBox_activities_addcontrib.Items.Add(cached_activities_addcontrib[counter].name);
            }
        }
Esempio n. 24
0
        private void button_update_affiliation_Click(object sender, EventArgs e)
        {
            if (cached_users.Count == 0)
            {
                MessageBox.Show("Please refresh the users list.");
                return;
            }
            if (comboBox_users.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a user.");
                return;
            }
            int id = cached_users[comboBox_users.SelectedIndex].id;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            var users = from u in db.Users
                        where u.id == id
                        select u;

            if (users.Count() != 1)
            {
                MessageBox.Show("Error. User not found.");
                return;
            }
            User the_user = users.Single <User>();

            the_user.affiliation = textBox_affiliation.Text;
            sync.classes.Action action = new classes.Action();
            action.type_id     = 2; action.user_id = 0; action.date = DateTime.UtcNow; action.object_id = the_user.id;
            action.object_type = "nature_net.User"; action.technical_info = "Updating affiliation.";
            db.Actions.InsertOnSubmit(action);
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
        }
Esempio n. 25
0
        private void button_add_activity_Click(object sender, EventArgs e)
        {
            if (textBox_activity_name.Text == "" || textBox_activity_description.Text == "")
            {
                MessageBox.Show("Please fill the name and description textboxes.");
                return;
            }
            Activity a = new Activity();

            a.name        = textBox_activity_name.Text;
            a.description = textBox_activity_description.Text;
            a.avatar      = textBox_activity_icon_url.Text;
            a.avatar      = ""; a.creation_date = DateTime.UtcNow; a.location_id = 0;
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();

            db.Activities.InsertOnSubmit(a);
            sync.classes.Action action = new classes.Action();
            action.type_id     = 1; action.user_id = 0; action.date = DateTime.UtcNow;
            action.object_type = "nature_net.Activity"; action.technical_info = "Adding an activity.";
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            action.object_id = a.id;
            db.Actions.InsertOnSubmit(action);
            db.SubmitChanges();
            try { db.SubmitChanges(); }
            catch (Exception ex)
            {
                MessageBox.Show("Error (" + ex.Message + "):\r\n" + ex.StackTrace);
                return;
            }
            MessageBox.Show("Added to the local database. It will be synced once (Local -> Server) is enabled.");
        }
Esempio n. 26
0
        public bool ProcessInteractionLogChanges()
        {
            TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
            List <SInteractionLog>         logs;

            logs = server_api.GetInteractionLogs(Configurations.last_change_server_interactions.Year.ToString(),
                                                 Configurations.last_change_server_interactions.Month.ToString(), Configurations.last_change_server_interactions.Day.ToString(),
                                                 Configurations.last_change_server_interactions.Hour.ToString(), Configurations.last_change_server_interactions.Minute.ToString());

            if (logs == null)
            {
                return(false);
            }
            if (logs.Count == 0)
            {
                return(false);
            }
            for (int counter = 0; counter < logs.Count; counter++)
            {
                var existings = from i in db.Interaction_Logs
                                where i.technical_info == logs[counter].id.ToString()
                                select i;
                if (existings.Count() > 0)
                {
                    continue;
                }
                Interaction_Log log = new Interaction_Log();
                log.date     = Convert.ToDateTime(logs[counter].date); log.details = logs[counter].details;
                log.touch_id = logs[counter].touch_id; log.touch_x = logs[counter].touch_x; log.touch_y = logs[counter].touch_y;
                log.type     = logs[counter].type; log.technical_info = logs[counter].id.ToString();
                db.Interaction_Logs.InsertOnSubmit(log);
                db.SubmitChanges();
            }
            Configurations.last_change_server_interactions = DateTime.UtcNow;
            return(true);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        private void update_or_create_collection(TableTopDataClassesDataContext db, int contribution_id, int new_activity_id, DateTime dt)
        {
            bool should_create_collection = false;

            var mapping = from m in db.Collection_Contribution_Mappings
                          where m.contribution_id == contribution_id
                          select m;

            if (mapping.Count() == 0)
            {
                return;
            }
            Collection_Contribution_Mapping c1 = mapping.First <Collection_Contribution_Mapping>();

            if (mapping.Count() != 1)
            {
                should_create_collection = true;
            }
            else
            {
                var colls = from c in db.Collections
                            where c.id == c1.collection_id
                            select c;
                if (colls.Count() == 1)
                {
                    Collection c2 = colls.First <Collection>();
                    c2.activity_id = new_activity_id;
                    db.SubmitChanges();
                }
                //var mapping2 = from m in db.Collection_Contribution_Mappings
                //               where m.collection_id == c1.collection_id
                //               select m;
                //if (mapping2.Count() != 1)
                //    should_create_collection = true;
            }
            //int user_id = c1.Collection.user_id;
            //if (should_create_collection)
            //{
            //    // create new collection
            //    Collection c2 = new Collection();
            //    c2.activity_id = new_activity_id;
            //    c2.date = dt;
            //    c2.name = Configurations.GetDate_Formatted(dt);
            //    c2.user_id = user_id;
            //    db.Collections.InsertOnSubmit(c2);
            //    db.SubmitChanges();
            //    var mapping_old = from m in db.Collection_Contribution_Mappings
            //                      where m.contribution_id == contribution_id
            //                      select m;
            //    db.Collection_Contribution_Mappings.DeleteAllOnSubmit(mapping_old);
            //    db.SubmitChanges();
            //    Collection_Contribution_Mapping mapping_new = new Collection_Contribution_Mapping();
            //    mapping_new.collection_id = c2.id;
            //    mapping_new.contribution_id = contribution_id;
            //    mapping_new.date = dt;
            //    db.SubmitChanges();
            //}
            //else
            //{
            //    c1.Collection.activity_id = new_activity_id;
            //    db.SubmitChanges();
            //}
        }
Esempio n. 29
0
        private bool create_contribution(SNote note, SMedia media, DateTime note_date, DateTime note_mod_date, string content, string note_id, bool is_design_idea, int collection_id, string status, TableTopDataClassesDataContext db)
        {
            Contribution c = new Contribution();

            c.date          = note_date;
            c.modified_date = note_mod_date;
            c.location_id   = find_location_id(note);
            string note_content = content;

            if (media != null)
            {
                c.media_url = media.link;
            }
            else
            {
                c.media_url = "";
            }

            c.note   = note_content;
            c.status = status;
            if (is_design_idea)
            {
                c.tags = "Design Idea";
            }
            else
            {
                if (media != null)
                {
                    c.tags = media.kind;
                }
                else
                {
                    c.tags = note.kind;
                }
            }
            c.technical_info = note_id;
            c.web_username   = note.webusername;
            db.Contributions.InsertOnSubmit(c);
            if (!SubmitChangesToLocalDB(db))
            {
                return(false);
            }
            //
            Collection_Contribution_Mapping map = new Collection_Contribution_Mapping();

            map.collection_id   = collection_id;
            map.contribution_id = c.id;
            map.date            = note_date;
            db.Collection_Contribution_Mappings.InsertOnSubmit(map);
            if (!SubmitChangesToLocalDB(db))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 30
0
        public bool UpdateLocalActivitites()
        {
            try
            {
                List <SContext> contexts          = server_api.GetContextsForSite(Configurations.GetSiteNameForServer());
                TableTopDataClassesDataContext db = Configurations.GetTableTopDB();
                if (contexts != null)
                {
                    if (contexts.Count > 0)
                    {
                        var activities = from ac in db.Activities
                                         select ac;
                        for (int counter = 0; counter < contexts.Count; counter++)
                        {
                            if (contexts[counter].kind != "Landmark" && contexts[counter].title != "Pilot")
                            {
                                Activity a = null;
                                foreach (Activity activity in activities)
                                {
                                    if (activity.technical_info.Split(new char[] { ';' })[0] == contexts[counter].id.ToString())
                                    {
                                        a = activity;
                                        break;
                                    }
                                }

                                if (a == null)
                                {
                                    //create the activity
                                    a             = new Activity(); a.name = contexts[counter].title; a.location_id = 0;
                                    a.description = contexts[counter].description; a.creation_date = DateTime.UtcNow;
                                    Extras ex = JsonConvert.DeserializeObject <Extras>(contexts[counter].extras);
                                    a.technical_info = contexts[counter].id.ToString() + ";" + contexts[counter].kind + ";" + contexts[counter].extras;
                                    if (ex != null)
                                    {
                                        a.avatar = ex.icon;
                                        if (!ex.active)
                                        {
                                            a.expire_date = DateTime.Now;
                                        }
                                    }
                                    db.Activities.InsertOnSubmit(a);
                                }
                                else
                                {
                                    //modify it
                                    a.name        = contexts[counter].title;
                                    a.description = contexts[counter].description;
                                    Extras ex = JsonConvert.DeserializeObject <Extras>(contexts[counter].extras);
                                    a.technical_info = contexts[counter].id.ToString() + ";" + contexts[counter].kind + ";" + contexts[counter].extras;
                                    a.avatar         = ex.icon;
                                    if (!ex.active)
                                    {
                                        a.expire_date = DateTime.Now;
                                    }
                                    else
                                    {
                                        a.expire_date = null;
                                    }
                                }
                                if (!SubmitChangesToLocalDB(db))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }
            return(true);
        }