コード例 #1
0
 private async Task OpenAdvert(Project oppgave)
 {
     OppgaveList.SelectedItem = null;
     var url = oppgave.webpage;
     var type = "project";
     var WebPage = new WebPage(type, url);
     await Navigation.PushAsync(WebPage);  //opens new webpage in browser to given url
 }
コード例 #2
0
        /// <summary>
        /// Inserts the project and its respective children (only Company and CompanyProject) 
        /// into the database.
        /// </summary>
        /// <param name="project"></param>
        /// <returns>Returns true if the project was inserted, returns false if a project with the same 
        ///  uuid (primary key) already exists in the table.</returns>
        public bool InsertProject(Project project)
        {
            System.Diagnostics.Debug.WriteLine("DbProject InsertProject(Project project): initiated");
            if (CheckIfProjectExist(project.uuid))
            {
                return false;
            }

            //Project did not exist, safe to insert.
            DbCompany dbCompany = new DbCompany();

            foreach (Company c in project.companies)
            {
                dbCompany.InsertCompany(c);
            }

            lock (DbContext.locker)
            {
                Db.Insert(project);
                // Db.InsertOrReplaceWithChildren(project, recursive: true);
            }

            // This could perhaps be done in the above foreach loop, 
            // but because of lack of concurrency control in SQLite its done in its own loop.
            foreach (Company c in project.companies)
            {
                CompanyProject cp = new CompanyProject();
                cp.ProjectUuid = project.uuid;
                cp.CompanyId = c.id;
                lock (DbContext.locker)
                {
                    Db.Insert(cp);
                    // Db.InsertOrReplaceWithChildren(project, recursive: true);
                }
            }
            // Project was successfully inserted
            return true;
        }
コード例 #3
0
        /// <summary>
        /// Deserializes a singular Project with children objects. 
        /// </summary>
        /// <param name="jsonString">Serialized data contain information about project and its children</param>
        /// <returns>A deserialized Project object</returns>
        private Project Deserialize(string jsonString)
        {
            DbProject db = new DbProject();
            Dictionary<string, object> dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
            System.Diagnostics.Debug.WriteLine("DeserializeApiData. Printing Key Value:");
            string[] keys = dict.Keys.ToArray();
            Project p = new Project();
            p.companies = new List<Company>();
            p.courses = new List<Course>();
            p.studyGroups = new List<StudyGroup>();
            p.jobTypes = new List<JobType>();

            foreach (var key in keys)
            {
                System.Diagnostics.Debug.WriteLine("key: " + key);
                System.Diagnostics.Debug.WriteLine("value: " + dict[key].ToString());
                /*
                if (!key.Equals("companies") || !key.Equals("courses") || !key.Equals("degrees")
                    || !key.Equals("jobTypes") || !key.Equals("studyGroup")) {} */
                if (key.Equals("uuid"))
                {
                    p.uuid = dict[key].ToString();
                }
                if (key.Equals("title"))
                {
                    p.title = dict[key].ToString();
                }

                /*
                if (key.Equals("description"))
                {
                    p.description = dict[key].ToString();
                }
                */

                if (key.Equals("webpage"))
                {
                    p.webpage = dict[key].ToString();
                }
                if (key.Equals("published"))
                {
                    DateTime dateTime = (DateTime)dict[key];
                    p.published = long.Parse(dateTime.ToString("yyyyMMddHHmmss"));
                }

                if (key.Equals("modified"))
                {
                    DateTime dateTime = (DateTime)dict[key];
                    p.modified = long.Parse(dateTime.ToString("yyyyMMddHHmmss"));
                }

                if (key.Equals("companies"))
                {
                    // if not true then company already exist and needs to be updated.
                    CompaniesController cc = new CompaniesController();
                    DbCompany dbCompany = new DbCompany();
                    IEnumerable companies = (IEnumerable)dict[key];
                    //`Newtonsoft.Json.Linq.JArray'
                    System.Diagnostics.Debug.WriteLine("companies created");
                    foreach (var comp in companies)
                    {
                        System.Diagnostics.Debug.WriteLine("foreach initiated");
                        Dictionary<string, object> companyDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(comp.ToString());
                        Company company = cc.DeserializeCompany(companyDict);
                        System.Diagnostics.Debug.WriteLine("Deserialize: company.id: " + company.id);
                        p.companies.Add(company);
                        dbCompany.UpdateCompany(company);
                        System.Diagnostics.Debug.WriteLine("Deserialize: After j.companies.Add(company)");
                        string projectUuid = dict["uuid"].ToString();
                        dbCompany.InsertCompanyProject(company.id, projectUuid);

                    }
                }
     
                if (key.Equals("courses"))
                {
                    DbCourse dbCourse = new DbCourse();
                    IEnumerable courses = (IEnumerable)dict[key];
                    //Newtonsoft.Json.Linq.JArray'
                    System.Diagnostics.Debug.WriteLine("location created");
                    foreach (var course in courses)
                    {
                        System.Diagnostics.Debug.WriteLine("foreach initiated");
                        Dictionary<string, object> courseDict =
                            JsonConvert.DeserializeObject<Dictionary<string, object>>(course.ToString());

                        Course co = new Course();
                        if (courseDict.ContainsKey("id"))
                        {

                            co.id = courseDict["id"].ToString();
                            System.Diagnostics.Debug.WriteLine("Course id: " + co.id);
                        }

                        if (courseDict.ContainsKey("name"))
                        {
                            co.name = courseDict["name"].ToString();
                        }

                        dbCourse.InsertCourse(co);
                        p.courses.Add(co);
                        string projectUuid = dict["uuid"].ToString();
                        dbCourse.InsertCourseProject(co.id, projectUuid);
                    }
                }
                
               if (key.Equals("studyGroups"))
                {
                    DbStudyGroup dbStudyGroup = new DbStudyGroup();
                    IEnumerable studyGroups = (IEnumerable)dict[key];
                    //Newtonsoft.Json.Linq.JArray'
                    System.Diagnostics.Debug.WriteLine("studyGroups created");
                    foreach (var studyGroup in studyGroups)
                    {
                        System.Diagnostics.Debug.WriteLine("foreach initiated");
                        Dictionary<string, object> studyGroupDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(studyGroup.ToString());

                        
                        StudyGroup sg = new StudyGroup();
                        if (studyGroupDict.ContainsKey("id"))
                        {
                            sg.id = studyGroupDict["id"].ToString();
                        }

                        if (studyGroupDict.ContainsKey("name"))
                        {
                            sg.name = studyGroupDict["name"].ToString();
                        }

                        p.studyGroups.Add(sg);

                        string projectUuid = dict["uuid"].ToString();
                        dbStudyGroup.InsertStudyGroupProject(sg.id, projectUuid);

                    }
                }
                /*
                if (key.Equals("approvedCourses"))
                {
                    
                    Same as companies implementation
                    
                }

                if (key.Equals("degrees"))
                {
                    
                    Same as companies implementation
                    
                }
                */
                if (key.Equals("jobTypes"))
                {
                    DbJobType dbJobType = new DbJobType();
                    IEnumerable jobTypes = (IEnumerable)dict[key];
                    //Newtonsoft.Json.Linq.JArray'
                    System.Diagnostics.Debug.WriteLine("jobTypes created");
                    foreach (var jobType in jobTypes)
                    {
                        System.Diagnostics.Debug.WriteLine("foreach initiated");
                        Dictionary<string, object> jtDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(jobType.ToString());

                        JobType jt = new JobType();
                        if (jtDict.ContainsKey("id"))
                        {
                            jt.id = jtDict["id"].ToString();
                        }

                        if (jtDict.ContainsKey("name"))
                        {
                            jt.name = jtDict["name"].ToString();
                        }

                        dbJobType.InsertJobType(jt);
                        System.Diagnostics.Debug.WriteLine("before p.jobTypes.Add(jt);");
                        p.jobTypes.Add(jt);

                        string projectUuid = dict["uuid"].ToString();
                        dbJobType.InsertJobTypeProject(jt.id, projectUuid);
                    }
                }
            }
            db.UpdateProject(p);
            return p;
        }
コード例 #4
0
        private async void TestInsertProject(object sender, EventArgs e)
        {
            DbContext DbContext = DbContext.GetDbContext;
            SQLiteConnection Db = DbContext.Db;

            System.Diagnostics.Debug.WriteLine("Before insert Project.Count: " +
                                               Db.Query<Project>("Select * from Project").Count());

            ProjectsController jc = new ProjectsController();


            string testUuid = "colemak";
            Project project = new Project()
            {
                uuid = testUuid,
            };

            string companyId = "Ikea";
            Company comp = new Company()
            {
                id = companyId
            };

            string courseId = "sverige";
            Course course = new Course()
            {
                id = courseId
            };

            string sgId = "dykking";
            StudyGroup sg = new StudyGroup()
            {
                id = sgId
            };

            StudyGroupProject sgj = new StudyGroupProject()
            {
                StudyGroupId = sgId,
                ProjectUuid = testUuid
            };

            CourseProject lj = new CourseProject()
            {
                CourseId = courseId,
                ProjectUuid = testUuid
            };

            CompanyProject cp = new CompanyProject()
            {
                CompanyId = companyId,
                ProjectUuid = testUuid
            };

            string jtId = "10aarErfaringEcma6";
            JobType jt = new JobType()
            {
                id = jtId
            };

            JobTypeProject jtp = new JobTypeProject()
            {
                ProjectUuid = testUuid,
                JobTypeId = jtId
            };

            // try catch on tables that will not be affected by a job delete
            try
            {
                Db.Insert(comp);
            }
            catch
            {
            }
            Db.Insert(project);
            try
            {
                Db.Insert(course);
            }
            catch
            {
            }
            try
            {
                Db.Insert(sg);
            }
            catch
            {
            }
            Db.Insert(sgj);
            Db.Insert(lj);
            Db.Insert(cp);
            try
            {
                Db.Insert(jt);
            }
            catch
            {
            }
            Db.Insert(jtp);

            System.Diagnostics.Debug.WriteLine("After insert: Project.Count: " +
                                               Db.Query<Project>("Select * from Project").Count());
        }
コード例 #5
0
        /// <summary>
        /// Inserts a new Project with the param as primary key 
        /// </summary>
        /// <param name="uuid">The new Projects primary key</param>
        /// <returns>Returns true if the project was inserted, returns false if a project with the same 
        ///  uuid (primary key) already exists in the table.</returns>
        public bool InsertProject(string uuid)
        {
            System.Diagnostics.Debug.WriteLine("DbProject InsertProject(string uuid): initiated");
            if (CheckIfProjectExist(uuid))
            {
                System.Diagnostics.Debug.WriteLine("DbProject InsertProject(string uuid): Project already exists");
                return false;
            }

            //Project did not exist so it will be inserted
            Project p = new Project();
            p.uuid = uuid;
            lock (DbContext.locker)
            {
                Db.Insert(p);
                //Db.InsertOrReplaceWithChildren(p, recursive: true);
                System.Diagnostics.Debug.WriteLine("DbProject - InsertProject(string uuid): Project Inserted");
                return true;
            }
        }
コード例 #6
0
 /// <summary>
 /// Gets a list of all companies that are related to the spesific Project
 /// </summary>
 /// <param name="project"></param>
 /// <returns></returns>
 public List<Company> GetAllCompaniesRelatedToProject(Project project)
 {
     lock (DbContext.locker)
     {
         return Db.Query<Company>("Select * from Company"
                                   + " inner join CompanyProject on Company.id = CompanyProject.CompanyId"
                                   + " inner join Project on CompanyProject.ProjectUuid = Project.uuid"
                                   + " where Project.uuid = ?", project.uuid);
     }
 }
コード例 #7
0
        /// <summary>
        /// Updates an entry in the Project table. 
        /// If it doesnt already exist InsertProject will be called.
        /// </summary>
        /// <param name="project"></param>
        public void UpdateProject(Project project)
        {
            if (!CheckIfProjectExist(project.uuid))
            {
                System.Diagnostics.Debug.WriteLine(
                    "DbProject - UpdateProject: There was no stored record of Project.");
                InsertProject(project);
            }

            else
            {
                try
                {
                    lock (DbContext.locker)
                    {
                        System.Diagnostics.Debug.WriteLine("DbProject - UpdateProject: Before Updating project.");
                        Db.Update(project);
                        System.Diagnostics.Debug.WriteLine("DbProject - UpdateProject: After Updating project.");
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("DbProject - UpdateProject: project update failed");
                    System.Diagnostics.Debug.WriteLine("DbProject - UpdateProject: Exception msg: " + e.Message);
                    System.Diagnostics.Debug.WriteLine("DbProject - UpdateProject: Stack Trace: \n" + e.StackTrace);
                    System.Diagnostics.Debug.WriteLine("DbProject - UpdateProject: End Of Stack Trace");
                }
            }
        }