public void Create6Issues(int numberOfIssues) { Issue issue = null; Issue priorIssue = null; using (SessionNoServer session = new SessionNoServer(systemDir)) { session.BeginUpdate(); for (int i = 0; i < numberOfIssues; i++) { IssueTracker issueTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false); User user = issueTracker.UserSet.Keys[rand.Next(issueTracker.UserSet.Count)]; User assignedTo = issueTracker.UserSet.Keys[rand.Next(issueTracker.UserSet.Count)]; Project project = issueTracker.ProjectSet.Keys[rand.Next(issueTracker.ProjectSet.Count)]; Component component = issueTracker.ComponentSet.Keys[rand.Next(issueTracker.ComponentSet.Count)]; ProductVersion version = issueTracker.VersionSet.Keys[rand.Next(issueTracker.VersionSet.Count)]; Issue.CategoryEnum category = (Issue.CategoryEnum)rand.Next(5); Issue.Resolution resolution = (Issue.Resolution)rand.Next(5); Issue.PriorityEnum priority = (Issue.PriorityEnum)rand.Next(5); Issue.StatusEnum status = (Issue.StatusEnum)rand.Next(5); if (status == Issue.StatusEnum.Open || status == Issue.StatusEnum.InProgress || status == Issue.StatusEnum.Reopened) resolution = Issue.Resolution.Incomplete; // the other states does not make sense DateTime dueDate = new DateTime(rand.Next()); string c = "project" + i.ToString(); string s = "summary" + i.ToString(); string e = "environment" + i.ToString(); string d = "idescription" + i.ToString(); issue = new Issue(user, priority, project, category, component, version, resolution, s, d, e, assignedTo, dueDate, null, status); issue.Persist(session, priorIssue == null ? issue : priorIssue); priorIssue = issue; issueTracker.Add(issue); } session.Commit(); } }
public void UpdateIssue(EditedIssue newValues) { try { object projectIndexObj = Session["ProjectSelected"]; int projectIndex = projectIndexObj == null ? 0 : (int)projectIndexObj; object componentIndexObj = Session["ComponentSelected"]; int componentIndex = componentIndexObj == null ? 0 : (int)componentIndexObj; object versionIndexObj = Session["VersionSelected"]; int versionIndex = versionIndexObj == null ? 0 : (int)versionIndexObj; object assignedToIndexObj = Session["AssignedToSelected"]; int assignedToIndex = assignedToIndexObj == null ? 0 : (int)assignedToIndexObj; object statusIndexObj = Session["StatusSelected"]; int statusIndex = statusIndexObj == null ? 0 : (int)statusIndexObj; object resolutionIndexObj = Session["ResolutionSelected"]; int resolutionIndex = resolutionIndexObj == null ? 0 : (int)resolutionIndexObj; object categoryIndexObj = Session["CategorySelected"]; int categoryIndex = categoryIndexObj == null ? 0 : (int)categoryIndexObj; object priorityIndexObj = Session["PrioritySelected"]; int priorityIndex = priorityIndexObj == null ? 0 : (int)priorityIndexObj; object updatedAttachementsObj = Session["UpdatedAttachments"]; SortedSetAny<Attachment> updatedAttachments = null; if (updatedAttachementsObj != null) updatedAttachments = (SortedSetAny<Attachment>)Session["UpdatedAttachments"]; Session["UpdatedAttachments"] = null; using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginUpdate(); IssueTracker issueTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false); Project project = issueTracker.ProjectSet.Keys[projectIndex]; Component component = issueTracker.ComponentSet.Keys[componentIndex]; ProductVersion version = issueTracker.VersionSet.Count > 0 ? issueTracker.VersionSet.Keys[versionIndex] : null; Issue.StatusEnum status = (Issue.StatusEnum)AllStatus().GetValue(statusIndex); Issue.CategoryEnum category = (Issue.CategoryEnum)AllCategory().GetValue(categoryIndex); Issue.PriorityEnum priority = (Issue.PriorityEnum)AllPriority().GetValue(priorityIndex); Issue.Resolution resolution = (Issue.Resolution)AllResolution().GetValue(resolutionIndex); User assignedTo = issueTracker.UserSet.Keys[assignedToIndex]; if (newValues.Id == 0) { if (newValues.Summary == null) Console.WriteLine("Issue null summary detected in Update method"); else { User user = lookupUser(issueTracker, session); Issue issue = new Issue(user, priority, project, category, component, version, resolution, newValues.Summary, newValues.Description, newValues.Environment, assignedTo, newValues.DueDate, updatedAttachments); if (updatedAttachments != null) foreach (Attachment attachment in updatedAttachments) attachment.IssueAttachedTo = new WeakIOptimizedPersistableReference<Issue>(issue); Placement placer = new Placement(issue.PlacementDatabaseNumber); issue.Persist(placer, session, true, true); issueTracker.Add(issue); } } else { Issue existingIssue = (Issue)session.Open(newValues.Id); if (existingIssue.Summary != newValues.Summary) { issueTracker.IssueSetBySummary.Remove(existingIssue); existingIssue.Summary = newValues.Summary; issueTracker.IssueSetBySummary.Add(existingIssue); } existingIssue.Description = newValues.Description; existingIssue.FixMessage = newValues.FixMessage; if (existingIssue.DueDate != newValues.DueDate) { issueTracker.IssueSetByDueDate.Remove(existingIssue); existingIssue.DueDate = newValues.DueDate; issueTracker.IssueSetByDueDate.Add(existingIssue); } issueTracker.IssueSetByDateTimeUpdated.Remove(existingIssue); existingIssue.DateTimeLastUpdated = DateTime.Now; issueTracker.IssueSetByDateTimeUpdated.Add(existingIssue); if (priorityIndexObj != null && existingIssue.Priority != priority) { issueTracker.IssueSetByPriority.Remove(existingIssue); existingIssue.Priority = priority; issueTracker.IssueSetByPriority.Add(existingIssue); } if (categoryIndexObj != null && existingIssue.Category != category) { issueTracker.IssueSetByCategory.Remove(existingIssue); existingIssue.Category = category; issueTracker.IssueSetByCategory.Add(existingIssue); } if (componentIndexObj != null && existingIssue.Component != component) { existingIssue.Component = component; project = component.Project; } if (versionIndexObj != null && existingIssue.Version != version) { issueTracker.IssueSetByVersion.Remove(existingIssue); existingIssue.Version = version; issueTracker.IssueSetByVersion.Add(existingIssue); } existingIssue.Environment = newValues.Environment; if (projectIndexObj != null && existingIssue.Project != project) { issueTracker.IssueSetByProject.Remove(existingIssue); existingIssue.Project = project; issueTracker.IssueSetByProject.Add(existingIssue); } if (assignedToIndexObj != null && existingIssue.AssignedTo != assignedTo) { issueTracker.IssueSetByAssignedTo.Remove(existingIssue); existingIssue.AssignedTo = assignedTo; issueTracker.IssueSetByAssignedTo.Add(existingIssue); } if (statusIndexObj != null && existingIssue.Status != status) { issueTracker.IssueSetByStatus.Remove(existingIssue); existingIssue.Status = status; issueTracker.IssueSetByStatus.Add(existingIssue); } if (resolutionIndexObj != null && existingIssue.FixResolution != resolution) { //issueTracker.IssueSetByStatus.Remove(existingIssue); existingIssue.FixResolution = resolution; //issueTracker.IssueSetByStatus.Add(existingIssue); } if (updatedAttachments != null) foreach (Attachment attachment in updatedAttachments) { attachment.IssueAttachedTo = new WeakIOptimizedPersistableReference<Issue>(existingIssue); existingIssue.Attachments.Add(attachment); } } session.Commit(); } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } }