public static void AddTag(Tag pTag) { PrivateData.Tags.Add(pTag); }
public static void Initialise() { if (!Data.Users.Any(user => user.Id.ToString() == _ActiveUser.Id.ToString())) { AddUser(_ActiveUser); } using (SqlConnection conn = new SqlConnection(Data.OnlineConnStr)) { conn.Open(); DateTime GetUserOrgsStart = DateTime.Now; GetUserOrgs(); DateTime GetUserOrgsEnd = DateTime.Now; double GetUserOrgsTimeTaken = (GetUserOrgsEnd - GetUserOrgsStart).TotalSeconds; DateTime GetOrgMembersStart = DateTime.Now; GetOrgMembers(); DateTime GetOrgMembersEnd = DateTime.Now; double GetOrgMembersTimeTaken = (GetOrgMembersEnd - GetOrgMembersStart).TotalSeconds; DateTime GetOrgMemberUsersStart = DateTime.Now; GetOrgMemberUsers(); DateTime GetOrgMemberUsersEnd = DateTime.Now; double GetOrgMemberUsersTimeTaken = (GetOrgMemberUsersEnd - GetOrgMemberUsersStart).TotalSeconds; DateTime GetOrgTagTypesStart = DateTime.Now; GetOrgTagTypes(); DateTime GetOrgTagTypesEnd = DateTime.Now; double GetOrgTagTypesTimeTaken = (GetOrgTagTypesEnd - GetOrgTagTypesStart).TotalSeconds; DateTime GetOrgProductsStart = DateTime.Now; GetOrgProducts(); DateTime GetOrgProductsEnd = DateTime.Now; double GetOrgProductsTimeTaken = (GetOrgProductsEnd - GetOrgProductsStart).TotalSeconds; DateTime GetProductBugsStart = DateTime.Now; GetProductBugs(); DateTime GetProductBugsEnd = DateTime.Now; double GetProductBugsTimeTaken = (GetProductBugsEnd - GetProductBugsStart).TotalSeconds; DateTime GetBugAssigneesStart = DateTime.Now; GetBugAssignees(); DateTime GetBugAssigneesEnd = DateTime.Now; double GetBugAssigneesTimeTaken = (GetBugAssigneesEnd - GetBugAssigneesStart).TotalSeconds; DateTime GetBugTagsStart = DateTime.Now; GetBugTags(); DateTime GetBugTagsEnd = DateTime.Now; double GetBugTagsTimeTaken = (GetBugTagsEnd - GetBugTagsStart).TotalSeconds; DateTime GetBugNotesStart = DateTime.Now; GetBugNotes(); DateTime GetBugNotesEnd = DateTime.Now; double GetBugNotesTimeTaken = (GetBugNotesEnd - GetBugNotesStart).TotalSeconds; AppLog.Debug(String.Format("({0}) Active user's organisations were loaded from the database in {0} seconds", GetUserOrgsTimeTaken)); AppLog.Debug(String.Format("({0}) Organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetOrgMembersTimeTaken)); AppLog.Debug(String.Format("({0}) Members of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetOrgMemberUsersTimeTaken)); AppLog.Debug(String.Format("({0}) Tag types of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetOrgTagTypesTimeTaken)); AppLog.Debug(String.Format("({0}) Products of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetOrgProductsTimeTaken)); AppLog.Debug(String.Format("({0}) Bugs of the products of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetProductBugsTimeTaken)); AppLog.Debug(String.Format("({0}) Assignees of the bugs of the products of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetBugAssigneesTimeTaken)); AppLog.Debug(String.Format("({0}) Tags of the bugs of the products of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetBugTagsTimeTaken)); AppLog.Debug(String.Format("({0}) Notes of the bugs of the products of the organisations which 'active user' is a member of were loaded from the database in {0} seconds", GetBugNotesTimeTaken)); AppLog.Debug(String.Format("({0}) Success! All items from the database were loaded successfully! Total load time = ", (GetUserOrgsTimeTaken + GetOrgMembersTimeTaken + GetOrgMemberUsersTimeTaken + GetOrgTagTypesTimeTaken + GetOrgProductsTimeTaken + GetProductBugsTimeTaken + GetBugAssigneesTimeTaken + GetBugTagsTimeTaken + GetBugNotesTimeTaken ))); bool GetUserOrgs() { SqlCommand SelectUsersOrgMembersips = new SqlCommand("SELECT OrgId FROM t_OrgMembers WHERE " + "UserId = @UserId", conn); SelectUsersOrgMembersips.Parameters.Add(new SqlParameter("UserId", ActiveUser.Id)); int NoOfOrgMemberships = 0; List <Guid> UsersOrgIds = new List <Guid>(); using (SqlDataReader UsersOrgMembershipsReader = SelectUsersOrgMembersips.ExecuteReader()) { while (UsersOrgMembershipsReader.Read()) { NoOfOrgMemberships++; UsersOrgIds.Add(Guid.Parse(UsersOrgMembershipsReader[0].ToString())); } } AppLog.Debug(String.Format("{0} is a member of {1} organisation(s). Attempting to download these organisations...", ActiveUser.FullName, NoOfOrgMemberships)); int NoOfOrgsDownloaded = 0; foreach (Guid UserOrgId in UsersOrgIds) { SqlCommand SelectOrganisations = new SqlCommand("SELECT * FROM t_Organisations WHERE Id = @Id;", conn); SelectOrganisations.Parameters.Add(new SqlParameter("Id", UserOrgId.ToString())); Organisation TempOrg; using (SqlDataReader OrgReader = SelectOrganisations.ExecuteReader()) { if (OrgReader.Read()) { AddOrganisation(new Organisation(new Guid(UserOrgId.ToString()), OrgReader[1].ToString().Trim(), Convert.ToDateTime(OrgReader[2]))); NoOfOrgsDownloaded++; } else { return(false); } } } AppLog.Debug(String.Format("Success! The {0}/{1} of the organisations which {2} is a member of were downloaded.", NoOfOrgsDownloaded, NoOfOrgMemberships, ActiveUser.FullName)); return(true); } bool GetOrgMembers() { foreach (Organisation org in Organisations) { SqlCommand GetOrganisationMembers = new SqlCommand("SELECT * FROM t_OrgMembers WHERE OrgId = @OrgId", conn); GetOrganisationMembers.Parameters.Add(new SqlParameter("OrgId", org.Id)); int NoOfOrgMembersDownloaded = 0; using (SqlDataReader ReadOrgansiationMembers = GetOrganisationMembers.ExecuteReader()) { while (ReadOrgansiationMembers.Read()) { AddOrgMember(new OrgMember(Guid.Parse(ReadOrgansiationMembers[1].ToString()), org.Id, Convert.ToDateTime(ReadOrgansiationMembers[2]))); } } NoOfOrgMembersDownloaded++; AppLog.Debug(String.Format("Found {0} member(s) of {1}", NoOfOrgMembersDownloaded, org.Name)); } return(true); } bool GetOrgMemberUsers() { foreach (OrgMember orgmemb in OrgMembers) { SqlCommand GetUsers = new SqlCommand("SELECT * FROM t_Users WHERE Id = @UserId", conn); GetUsers.Parameters.Add(new SqlParameter("UserId", orgmemb.UserId)); int NoOfOrgMemberUsersDownloaded = 0; using (SqlDataReader ReadOrgansiationMemberUsers = GetUsers.ExecuteReader()) { while (ReadOrgansiationMemberUsers.Read()) { User TempUser = new User(new Guid(ReadOrgansiationMemberUsers[0].ToString()), ReadOrgansiationMemberUsers[1].ToString().Trim(), ReadOrgansiationMemberUsers[2].ToString().Trim(), ReadOrgansiationMemberUsers[5].ToString().Trim(), ReadOrgansiationMemberUsers[6].ToString().Trim(), ReadOrgansiationMemberUsers[7].ToString().Trim(), ReadOrgansiationMemberUsers[8].ToString().Trim(), Convert.ToDateTime(ReadOrgansiationMemberUsers[12])); if (ReadOrgansiationMemberUsers[3] != DBNull.Value) { TempUser.DOB = Convert.ToDateTime(ReadOrgansiationMemberUsers[3]); } if (ReadOrgansiationMemberUsers[4] != DBNull.Value) { TempUser.Gender = ReadOrgansiationMemberUsers[4].ToString().ToCharArray()[0]; } if (ReadOrgansiationMemberUsers[9] != DBNull.Value) { TempUser.Phone = ReadOrgansiationMemberUsers[9].ToString().Trim(); } if (ReadOrgansiationMemberUsers[10] != DBNull.Value) { TempUser.Phone = ReadOrgansiationMemberUsers[10].ToString().Trim(); } if (ReadOrgansiationMemberUsers[11] != DBNull.Value) { TempUser.Phone = ReadOrgansiationMemberUsers[11].ToString().Trim(); } if (!Data.Users.Any(user => user.Id.ToString() == TempUser.Id.ToString())) { AddUser(TempUser); } } } NoOfOrgMemberUsersDownloaded++; AppLog.Debug(String.Format("Found {0} users(s)", NoOfOrgMemberUsersDownloaded)); } AppLog.Debug("There are " + Data.Users.Count() + "users!"); return(true); } bool GetOrgTagTypes() { foreach (Organisation org in Organisations) { SqlCommand GetTagTypes = new SqlCommand("SELECT * FROM t_TagTypes WHERE OrgId = @OrgId", conn); GetTagTypes.Parameters.Add(new SqlParameter("OrgId", org.Id)); int NoOfDownloadedTagTypes = 0; using (SqlDataReader ReadTagTypes = GetTagTypes.ExecuteReader()) { while (ReadTagTypes.Read()) { AddTagType(new TagType(new Guid(ReadTagTypes[0].ToString()), org.Id, ReadTagTypes[2].ToString().Trim())); NoOfDownloadedTagTypes++; } } AppLog.Debug(String.Format("Found {0} tagtypes(s) for {1}", NoOfDownloadedTagTypes, org.Name)); } return(true); } bool GetOrgProducts() { foreach (Organisation org in Organisations) { int NoOfDownloadedProducts = 0; SqlCommand GetProducts = new SqlCommand("SELECT * FROM t_Products WHERE OrgId = @OrgId", conn); GetProducts.Parameters.Add(new SqlParameter("OrgId", org.Id)); using (SqlDataReader ProductReader = GetProducts.ExecuteReader()) { while (ProductReader.Read()) { AddProduct(new Product(new Guid(ProductReader[0].ToString()), org.Id, ProductReader[2].ToString())); NoOfDownloadedProducts++; } } AppLog.Debug(String.Format("Found {0} products(s) for {1}", NoOfDownloadedProducts, org.Name)); } return(true); } bool GetProductBugs() { AppLog.Debug("BEN !!! Getting organisation's bugs"); foreach (Product prod in Products) { SqlCommand GetBugs = new SqlCommand("SELECT * FROM t_Bugs WHERE ProductId = @ProductId", conn); GetBugs.Parameters.Add(new SqlParameter("ProductId", prod.Id)); AppLog.Debug(String.Format("Searching for bugs for Product ({0} {1})", prod.Name.Trim(), prod.Id)); using (SqlDataReader reader = GetBugs.ExecuteReader()) { int NoOfDownloadedBugs = 0; while (reader.Read()) { Bug TempBug = new Bug(new Guid(reader[0].ToString()), new Guid(reader[1].ToString()), new Guid(reader[2].ToString()), reader[3].ToString(), "", Convert.ToInt32(reader[5]), Convert.ToDateTime(reader[6]), DateTime.MinValue, Convert.ToDateTime(reader[8]), new Guid(reader[9].ToString())); if (reader[4] != DBNull.Value) { TempBug.Description = reader[4].ToString(); } /*if (reader[7] != DBNull.Value) * { * TempBug.ResolvedDateTime = reader[7].ToString(); * }*/ AddBug(TempBug); NoOfDownloadedBugs++; } AppLog.Debug(String.Format("Found {0} bug(s) for {1}", NoOfDownloadedBugs, prod.Name)); } } return(true); } bool GetBugAssignees() { foreach (Bug mybug in Bugs) { SqlCommand DownloadBug_Assignees = new SqlCommand("SELECT * FROM t_Assignees WHERE " + "BugId = @BugId", conn); DownloadBug_Assignees.Parameters.Add(new SqlParameter("BugId", mybug.Id)); using (SqlDataReader reader = DownloadBug_Assignees.ExecuteReader()) { int NoOfDownloadedAssignees = 0; while (reader.Read()) { Assignee TempAssignee = new Assignee(new Guid(reader[0].ToString()), new Guid(reader[1].ToString()), Convert.ToInt16(reader[2]), Convert.ToInt16(reader[3]), Convert.ToDateTime(reader[4])); AddAssignee(TempAssignee); NoOfDownloadedAssignees++; } //AppLog.Debug(String.Format("Found {0} assignees(s) for {1}", NoOfDownloadedAssignees, mybug.Title)); } } return(true); } bool GetBugTags() { foreach (Bug mybug in Bugs) { SqlCommand DownloadBug_Tags = new SqlCommand("SELECT * FROM t_Tags WHERE BugId = @BugId", conn); int NoOfDownloadedTags = 0; DownloadBug_Tags.Parameters.Add(new SqlParameter("BugId", mybug.Id)); using (SqlDataReader reader = DownloadBug_Tags.ExecuteReader()) { while (reader.Read()) { Tag TempTag = new Tag(new Guid(reader[0].ToString()), mybug.Id, Convert.ToDateTime(reader[2]), new Guid(reader[3].ToString())); AddTag(TempTag); NoOfDownloadedTags++; } } //AppLog.Debug(String.Format("Found {0} tag(s) for {1}", NoOfDownloadedTags, mybug.Title)); } return(true); } bool GetBugNotes() { foreach (Bug mybug in Bugs) { SqlCommand DownloadBug_Notes = new SqlCommand("SELECT * FROM t_Notes WHERE BugId = @BugId", conn); DownloadBug_Notes.Parameters.Add(new SqlParameter("BugId", mybug.Id)); int NoOfDownloadedNotes = 0; using (SqlDataReader reader = DownloadBug_Notes.ExecuteReader()) { while (reader.Read()) { AddNote(new Note(new Guid(reader[0].ToString()), new Guid(reader[1].ToString()), new Guid(reader[2].ToString()), Convert.ToDateTime(reader[3]), new Guid(reader[4].ToString()), Convert.ToDateTime(reader[5].ToString()), reader[6].ToString(), reader[7].ToString())); NoOfDownloadedNotes++; } } //AppLog.Debug(String.Format("Found {0} notes(s) for {1}", NoOfDownloadedNotes, mybug.Title)); } return(true); } } }