Пример #1
0
    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;
        int sessionId = -1;
        SessionBase session = null;
        try
        {
          session = s_sessionPool.GetSession(out sessionId);
          session.BeginUpdate();
          IssueTracker issueTracker = session.AllObjects<IssueTracker>(false).FirstOrDefault();
          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);
              session.Persist(issue);
              issueTracker.Add(issue);
            }
          }
          else
          {
            Issue existingIssue = (Issue)session.Open(newValues.Id);
            User user = lookupUser(issueTracker, session);
            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);
            }
            if (existingIssue.LastUpdatedBy != user)
            {
              issueTracker.IssueSetByLastUpdatedBy.Remove(existingIssue);
              existingIssue.LastUpdatedBy = user;
              issueTracker.IssueSetByLastUpdatedBy.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();
          s_sharedReadOnlySession.ForceDatabaseCacheValidation();
        }
        catch (Exception ex)
        {
          session?.Abort();
          Console.Out.WriteLine(ex.StackTrace);
        }
        finally
        {
          s_sessionPool.FreeSession(sessionId, session);
        }
      }
      catch (System.Exception ex)
      {
        Console.WriteLine(ex.ToString());
        this.errorLabel.Text = ex.ToString();
      }
    }
Пример #2
0
 public void InsertIssue(EditedIssue newValues)
 {
   newValues.Id = 0;
   newValues.Oid = "";
   newValues.Summary = "";
   newValues.Description = "";
   newValues.DueDate = DateTime.MaxValue;
 }
Пример #3
0
    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());
      }
    }