상속: OptimizedPersistable
예제 #1
0
 public void Create1Root()
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     IssueTracker issueTracker = new IssueTracker(10, session);
     User user = new User(null, "*****@*****.**", "Mats", "Persson", "matspca");
     session.Persist(user);
     PermissionScheme permissions = new PermissionScheme(user);
     issueTracker.Permissions = permissions;
     session.Persist(issueTracker);
     session.Commit();
   }
 }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Page.Header.Title = "VelocityWeb - Issue Tracking";
        HtmlGenericControl menu = (HtmlGenericControl)Master.FindControl("liIssues");
        menu.Attributes.Add("class", "active");
        IssueTracker bugTracker = null;
        User user = null;
        int sessionId = -1;
        SessionBase session = null;
        try
        {
          session = s_sessionPool.GetSession(out sessionId);
          using (var transaction = session.BeginUpdate())
          {
            bugTracker = session.AllObjects<IssueTracker>(false).FirstOrDefault();
            if (bugTracker == null)
            {
              bugTracker = new IssueTracker(10, session);
              session.Persist(bugTracker);
              user = lookupUser(bugTracker, session);
              PermissionScheme permissions = new PermissionScheme(user);
              bugTracker.Permissions = permissions;
              createInitialObjects(bugTracker, user, session);
            }
            else
              user = lookupUser(bugTracker, session);

            transaction.Commit();
            s_sharedReadOnlySession.ForceDatabaseCacheValidation();
          }
        }
        catch (Exception ex)
        {
          Console.Out.WriteLine(ex.StackTrace);
        }
        finally
        {
          s_sessionPool.FreeSession(sessionId, session);
        }
        if (Session["filterById"] == null)
        {
          Session["filterById"] = false;
          Session["priorityFilter"] = new List<int>();
          Session["statusFilter"] = new List<int>();
          Session["categoryFilter"] = new List<int>();
        }
        viewString = Request.QueryString["view"];
        int view = 1;
        if (viewString != null)
          view = int.Parse(viewString);
        switch (view)
        {
          case 0:
            Session["UpdatedAttachments"] = null;
            IssueDetailsView.ChangeMode(DetailsViewMode.Insert);
            IssuesGridView.SelectedIndex = -1;
            IssueDetailsView.InsertItem(false);
            IssueDetailsView.Visible = true;
            IssueDetailsView.DataBind();
            MultiView1.SetActiveView(IssueEdit);
            break;
          case 1:
            Session["filterOn"] = false;
            MultiView1.SetActiveView(IssuesView);
            break;
          case 2:
            bindFilterRanges(bugTracker);
            object sessionState = Session["filterById"];
            bool filterById = (bool)sessionState;
            TreeNode root = IssueFilterTree.Nodes[0];
            TreeNode id = root.ChildNodes[0];
            id.Checked = filterById;
            MultiView1.SetActiveView(IssuesFilter);
            break;
          case 3:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
              MultiView1.SetActiveView(IssuesView);
            else
              MultiView1.SetActiveView(ProjectsView);
            break;
          case 4:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete components";
              MultiView1.SetActiveView(IssuesView);
            }
            else
              MultiView1.SetActiveView(ComponentsView);
            break;
          case 5:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete users";
              MultiView1.SetActiveView(IssuesView);
            }
            else
              MultiView1.SetActiveView(UsersView);
            break;
          case 6:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete versions";
              MultiView1.SetActiveView(IssuesView);
            }
            else
              MultiView1.SetActiveView(VersionsView);
            break;
          case 7:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete permissions";
              MultiView1.SetActiveView(IssuesView);
            }
            else
            {
              AdminUsers.DataSource = bugTracker.Permissions.AdminSet.Keys;
              DeveloperUsers.DataSource = bugTracker.Permissions.DeveloperSet.Keys;
              RegularUsers.DataSource = bugTracker.UserSet.Keys;
              AdminUsers.DataBind();
              DeveloperUsers.DataBind();
              RegularUsers.DataBind();
              MultiView1.SetActiveView(PermissionsView);
            }
            break;
        }
      }
    }
예제 #3
0
    void bindFilterRanges(IssueTracker bugTracker)
    {
      var issueQuery = from issue in bugTracker.IssueSetById.Keys orderby issue.Id select issue;
      int ct = issueQuery.Count();
      IdFromDropDownList.DataSource = issueQuery;
      IdToDropDownList.DataSource = issueQuery;
      IdToDropDownList.SelectedIndex = ct - 1;
      IdFromDropDownList.DataBind();
      IdToDropDownList.DataBind();
      Session["idFrom"] = IdFromDropDownList.SelectedValue;
      Session["idTo"] = IdToDropDownList.SelectedValue;

      var issueQuery2 = from issue in bugTracker.IssueSetById.Keys orderby issue.DateTimeCreated select issue.DateTimeCreated;
      int numberOfDateTimeCreatedInUse = issueQuery2.Count(p => p != null);
      issueQuery2 = issueQuery2.Distinct();
      DateTimeCreatedFromDropDownList.DataSource = issueQuery2;
      DateTimeCreatedToDropDownList.DataSource = issueQuery2;
      DateTimeCreatedToDropDownList.SelectedIndex = numberOfDateTimeCreatedInUse - 1;
      DateTimeCreatedFromDropDownList.DataBind();
      DateTimeCreatedToDropDownList.DataBind();

      var issueQuery3 = from issue in bugTracker.IssueSetById.Keys orderby issue.ReportedBy select issue.ReportedBy;
      issueQuery3 = issueQuery3.Distinct();
      int numberOfReportedByInUse = issueQuery3.Count(p => p != null);
      ReportedByFromDropDownList.DataSource = issueQuery3;
      ReportedByToDropDownList.DataSource = issueQuery3;
      ReportedByToDropDownList.SelectedIndex = numberOfReportedByInUse - 1;
      ReportedByFromDropDownList.DataBind();
      ReportedByToDropDownList.DataBind();

      var issueQuery4 = from issue in bugTracker.IssueSetById.Keys orderby issue.DateTimeLastUpdated select issue.DateTimeLastUpdated;
      issueQuery4 = issueQuery4.Distinct();
      int numberOfDateTimeLastUpdatedInUse = issueQuery4.Count(p => p != null);
      DateTimeLastUpdatedFromDropDownList.DataSource = issueQuery4;
      DateTimeLastUpdatedToDropDownList.DataSource = issueQuery4;
      DateTimeLastUpdatedToDropDownList.SelectedIndex = numberOfDateTimeLastUpdatedInUse - 1;
      DateTimeLastUpdatedFromDropDownList.DataBind();
      DateTimeLastUpdatedToDropDownList.DataBind();

      var issueQuery5 = from issue in bugTracker.IssueSetById.Keys orderby issue.LastUpdatedBy select issue.LastUpdatedBy;
      issueQuery5 = issueQuery5.Distinct();
      int numberOfLastUpdatedByInUse = issueQuery5.Count(p => p != null);
      LastUpdatedByFromDropDownList.DataSource = bugTracker.UserSet.Keys;
      LastUpdatedByToDropDownList.DataSource = issueQuery5;
      LastUpdatedByToDropDownList.SelectedIndex = numberOfLastUpdatedByInUse - 1;
      LastUpdatedByFromDropDownList.DataBind();
      LastUpdatedByToDropDownList.DataBind();

      var issueQuery6 = (from issue in bugTracker.IssueSetById.Keys orderby issue.AssignedTo select issue).ToList();
      CompareAssignedTo compareAssignedTo = new CompareAssignedTo();
      issueQuery6 = issueQuery6.Distinct(compareAssignedTo).ToList();
      int numberOfAssignedToInUse = issueQuery6.Count(p => p != null);
      AssignedToFromDropDownList.DataSource = issueQuery6;
      AssignedToToDropDownList.DataSource = issueQuery6;
      AssignedToToDropDownList.SelectedIndex = numberOfAssignedToInUse - 1;
      AssignedToToDropDownList.DataBind();
      AssignedToFromDropDownList.DataBind();

      var issueQuery7 = from issue in bugTracker.IssueSetById.Keys orderby issue.Project select issue.Project;
      issueQuery7 = issueQuery7.Distinct();
      int numberOfProjectsInUse = issueQuery7.Count(p => p != null);
      ProjectFromDropDownList.DataSource = issueQuery7;
      ProjectToDropDownList.DataSource = issueQuery7;
      ProjectToDropDownList.SelectedIndex = numberOfProjectsInUse - 1;
      ProjectFromDropDownList.DataBind();
      ProjectToDropDownList.DataBind();

      var issueQuery8 = from issue in bugTracker.IssueSetById.Keys orderby issue.Project, issue.Component select issue.Component;
      issueQuery8 = issueQuery8.Distinct();
      int numberOfComponentsInUse = issueQuery8.Count(p => p != null);
      ComponentFromDropDownList.DataSource = issueQuery8;
      ComponentToDropDownList.DataSource = issueQuery8;
      ComponentToDropDownList.SelectedIndex = numberOfComponentsInUse - 1;
      ComponentFromDropDownList.DataBind();
      ComponentToDropDownList.DataBind();

      var issueQuery9 = from issue in bugTracker.IssueSetById.Keys where issue.Version != null orderby issue.Version select issue.Version;
      issueQuery9 = issueQuery9.Distinct();
      int numberOfVersionsInUse = issueQuery9.Count(p => p != null);
      VersionFromDropDownList.DataSource = issueQuery9;
      VersionToDropDownList.DataSource = issueQuery9;
      VersionToDropDownList.SelectedIndex = numberOfVersionsInUse - 1;
      VersionFromDropDownList.DataBind();
      VersionToDropDownList.DataBind();
    }
예제 #4
0
    void createInitialObjects(IssueTracker issueTracker, User user, SessionBase session)
    {
      Project project = new Project(user, "VelocityDB", "Object Database Management System");
      session.Persist(project);
      issueTracker.ProjectSet.Add(project);

      Component webSite = new Component(user, "Web Site", "VelocityDB.com", project);
      session.Persist(webSite);
      issueTracker.ComponentSet.Add(webSite);

      Component samples = new Component(user, "Samples", "Samples applications provided", project);
      session.Persist(samples);
      issueTracker.ComponentSet.Add(samples);

      Component collections = new Component(user, "Collections", "Any of the collection classes", project);
      session.Persist(collections);
      issueTracker.ComponentSet.Add(collections);

      Component performance = new Component(user, "Performance", "Any performance issue", project);
      session.Persist(performance);
      issueTracker.ComponentSet.Add(performance);

      ProductVersion version = new ProductVersion(user, "5.0.16", "First initial version", new DateTime(2015, 11, 29));
      session.Persist(version);
      issueTracker.VersionSet.Add(version);
      version = new ProductVersion(user, "4.7", "June 13 version", new DateTime(2015, 06, 13));
      session.Persist(version);
      issueTracker.VersionSet.Add(version);
    }
예제 #5
0
 User lookupUser(IssueTracker issueTracker, SessionBase session)
 {
   string userEmail = this.User.Identity.Name;
   User user = new User(userEmail);
   string dataPath = HttpContext.Current.Server.MapPath("~/Database");
   if (!issueTracker.UserSet.TryGetValue(user, ref user))
   {
     CustomerContact existingCustomer = null;
     string firstName = null;
     string lastName = null;
     string userName = null;
     try
     {
       using (SessionNoServer session2 = new SessionNoServer(dataPath, 2000, true, true))
       {
         session2.BeginRead();
         Root velocityDbroot = session2.AllObjects<Root>(false).FirstOrDefault();
         CustomerContact lookup = new CustomerContact(userEmail, null);
         velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer);
         session2.Commit();
         firstName = existingCustomer.FirstName;
         lastName = existingCustomer.LastName;
         userName = existingCustomer.UserName;
       }
     }
     catch (System.Exception ex)
     {
       this.errorLabel.Text = ex.ToString();
     }
     user = new User(null, userEmail, firstName, lastName, userName);
     session.Persist(user);
     issueTracker.UserSet.Add(user);
   }
   return user;
 }
예제 #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        Page.Header.Title = "VelocityWeb - Issue Tracking";
        HtmlGenericControl menu = (HtmlGenericControl)Master.FindControl("liIssues");
        menu.Attributes.Add("class", "active");
        IssueTracker bugTracker = null;
        User user;
        using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, false))
        {
          session.BeginUpdate();
          bugTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false);
          if (bugTracker == null)
          {
            Placement placementRoot = new Placement(IssueTracker.PlaceInDatabase, 1, 1, 1000, 1000);
            bugTracker = new IssueTracker(10, session);
            bugTracker.Persist(placementRoot, session, true, true);
            user = lookupUser(bugTracker, session);
            PermissionScheme permissions = new PermissionScheme(user);
            bugTracker.Permissions = permissions;
            createInitialObjects(bugTracker, user, session);
          }
          else
            user = lookupUser(bugTracker, session);

          session.Commit();
        }
        if (Session["filterById"] == null)
        {
          Session["filterById"] = false;
          Session["priorityFilter"] = new List<int>();
          Session["statusFilter"] = new List<int>();
          Session["categoryFilter"] = new List<int>();
        }
        viewString = Request.QueryString["view"];
        int view = 1;
        if (viewString != null)
          view = int.Parse(viewString);
        switch (view)
        {
          case 0:
            Session["UpdatedAttachments"] = null;
            IssueDetailsView.ChangeMode(DetailsViewMode.Insert);
            IssuesGridView.SelectedIndex = -1;
            IssueDetailsView.InsertItem(false);
            IssueDetailsView.Visible = true;
            IssueDetailsView.DataBind();
            MultiView1.SetActiveView(IssueEdit);
            break;
          case 1:
            Session["filterOn"] = false;
            MultiView1.SetActiveView(IssuesView);
            break;
          case 2:
            bindFilterRanges(bugTracker);
            object sessionState = Session["filterById"];
            bool filterById = (bool)sessionState;
            TreeNode root = IssueFilterTree.Nodes[0];
            TreeNode id = root.ChildNodes[0];
            id.Checked = filterById;
            MultiView1.SetActiveView(IssuesFilter);
            break;
          case 3:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
              MultiView1.SetActiveView(IssuesView);
            else
              MultiView1.SetActiveView(ProjectsView);
            break;
          case 4:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete components";
              MultiView1.SetActiveView(IssuesView);
            }
            else
              MultiView1.SetActiveView(ComponentsView);
            break;
          case 5:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete users";
              MultiView1.SetActiveView(IssuesView);
            }
            else
              MultiView1.SetActiveView(UsersView);
            break;
          case 6:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete versions";
              MultiView1.SetActiveView(IssuesView);
            }
            else
              MultiView1.SetActiveView(VersionsView);
            break;
          case 7:
            if (bugTracker.Permissions.AdminSet.Contains(user) == false)
            {
              errorLabel.Text = "Sorry, you don't have permission to create/edit/delete permissions";
              MultiView1.SetActiveView(IssuesView);
            }
            else
            {
              AdminUsers.DataSource = bugTracker.Permissions.AdminSet.Keys;
              DeveloperUsers.DataSource = bugTracker.Permissions.DeveloperSet.Keys;
              RegularUsers.DataSource = bugTracker.UserSet.Keys;
              AdminUsers.DataBind();
              DeveloperUsers.DataBind();
              RegularUsers.DataBind();
              MultiView1.SetActiveView(PermissionsView);
            }
            break;
        }
      }
    }
예제 #7
0
 User lookupUser(IssueTracker issueTracker, SessionBase session)
 {
   string userEmail = this.User.Identity.Name;
   User user = new User(userEmail);
   if (!issueTracker.UserSet.TryGetValue(user, ref user))
   {
     CustomerContact existingCustomer = null;
     string firstName = null;
     string lastName = null;
     string userName = null;
     try
     {
       using (SessionNoServer session2 = new SessionNoServer(dataPath, 2000, true, true))
       {
         session2.BeginRead();
         Root velocityDbroot = (Root)session2.Open(Root.PlaceInDatabase, 1, 1, false);
         CustomerContact lookup = new CustomerContact(userEmail, null);
         velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer);
         session2.Commit();
         firstName = existingCustomer.FirstName;
         lastName = existingCustomer.LastName;
         userName = existingCustomer.UserName;
       }
     }
     catch (System.Exception ex)
     {
       this.errorLabel.Text = ex.ToString();
     }
     user = new User(null, userEmail, firstName, lastName, userName);
     Placement placer = new Placement(user.PlacementDatabaseNumber);
     user.Persist(placer, session, true, true);
     issueTracker.UserSet.Add(user);
   }
   return user;
 }