/// <summary> /// Update the role of a user in the specified course /// </summary> public bool UpdateRole(string username, int courseID, string role, IProviderTransaction tran) { //Check permission Authorize(courseID, Permission.COURSE, "updateuserrole", courseID, tran); return(m_dp.UpdateCourseRole(username, courseID, role, tran)); }
private void CheckThrowTransactionActive(IProviderTransaction providerTransaction) { if (providerTransaction.IsTransactional && providerTransaction.WasCommitted) { throw new TransactionCompletedException("Transaction cannot be completed as it is not active. Transaction type: " + providerTransaction.GetType().FullName); } }
/// <summary> /// Create a new user /// </summary> public bool Create(string username, string password, string first, string last, string email, IProviderTransaction tran) { if (GetInfo(username, null) != null) { throw new DataAccessException("User already exists"); } if (password.Length < Globals.MinPasswordLength) { throw new DataAccessException("Password must be at least " + Globals.MinPasswordLength + " characters long!"); } User user = new User(); user.UserName = username; user.FirstName = first; user.LastName = last; user.Email = email; user.VerifyKey = Globals.GeneratePassword(8); bool result = m_dp.CreateUser(user, password, tran); if (result) { SendVerifyEmail(user); } return(result); }
private void ConditionalRollback(IProviderTransaction providerTransaction) { if (providerTransaction.IsTransactional && providerTransaction.IsActive) { providerTransaction.Rollback(this); } }
protected AbstractEntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext) : base(providerMetadata, frameworkContext) { Transaction = providerTransaction; Revisions = new NullProviderRevisionRepository <TypedEntity>(providerMetadata, frameworkContext); Schemas = new NullProviderSchemaRepository(providerMetadata, frameworkContext); }
protected AbstractSchemaRepository(ProviderMetadata providerMetadata, AbstractRevisionRepository <EntitySchema> revisions, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext) : base(providerMetadata, revisions, frameworkContext) { CanWrite = true; Transaction = providerTransaction; Revisions = revisions; Revisions.RelatedEntitiesLoader = x => ProviderRepositoryHelper.CreateRelationLazyLoadDelegate(this, x).Invoke(x); }
private void ConditionalCommit(IProviderTransaction providerTransaction) { if (providerTransaction.IsTransactional && providerTransaction.IsActive) { providerTransaction.Commit(this); _committedTransactions.Add(providerTransaction); } }
public SchemaRepository(ProviderMetadata providerMetadata, AbstractRevisionRepository <EntitySchema> revisions, IProviderTransaction providerTransaction, ISession nhSession, IFrameworkContext frameworkContext, bool isReadOnly) : base(providerMetadata, revisions, providerTransaction, frameworkContext) { IsReadonly = isReadOnly; Transaction = providerTransaction; Helper = new NhSessionHelper(nhSession, frameworkContext); }
/// <summary> /// Verify the user running the component has permissions /// Direct Provider layer call /// </summary> protected void Authorize(int courseID, string etype, string perm, int entityID, IProviderTransaction tran) { if (!m_dp.CheckPermission(m_ident.Name, courseID, perm, entityID, etype, tran)) { throw new DataAccessException("Permission denied for action: " + perm); } }
protected AbstractRevisionRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext) : base(providerMetadata, frameworkContext) { CanWrite = true; Transaction = providerTransaction; RevisionDataAddedOrUpdated = new HashSet <RevisionData>(); EntityDataAddedOrUpdated = new HashSet <T>(); }
public RevisionRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, ISession nhSession, IFrameworkContext frameworkContext, bool isReadOnly) : base(providerMetadata, providerTransaction, frameworkContext) { IsReadonly = isReadOnly; Transaction = providerTransaction; Helper = new NhSessionHelper(nhSession, frameworkContext); }
public RevisionRepository( ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext, ExamineHelper helper) : base(providerMetadata, providerTransaction, frameworkContext) { Helper = helper; ExamineTransaction = providerTransaction as ExamineTransaction; }
/// <summary> /// Returns extended user information /// If the user is unknown, error handling takes place /// </summary> public User GetInfo(string username, IProviderTransaction tran) { User user = new User(); if (!m_dp.GetUserInfo(username, user, tran)) { //TODO: Do error handling stuff return(null); } return(user); }
public EntityRepository( ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext, AbstractRevisionRepository <TypedEntity> revisionRepository, AbstractSchemaRepository schemaSession, ExamineHelper helper) : base(providerMetadata, providerTransaction, revisionRepository, schemaSession, frameworkContext) { Helper = helper; ExamineTransaction = providerTransaction as ExamineTransaction; Mandate.That(ExamineTransaction != null, x => new InvalidCastException("The IProviderTransaction for the Examine EntityRepository must be of Type ExamineTransaction")); }
/// <summary> /// Get staff roles from a course /// </summary> public CourseRole.CourseRoleList GetTypedRoles(int courseID, bool staff, IProviderTransaction tran) { CourseRole.CourseRoleList roles = GetRoles(courseID, tran); CourseRole.CourseRoleList sroles = new CourseRole.CourseRoleList(); foreach (CourseRole role in roles) { if ((staff && role.Staff) || (!staff && !role.Staff)) { sroles.Add(role); } } return(sroles); }
/// <summary> /// Add users to the course from an XML stream /// </summary> public void BatchAddUsers(Stream xmlStream, int courseID, bool sync) { //TODO: Error checking User mem = new User(); Users usersDB = new Users(m_ident); DataSet xmldata = new DataSet(); xmldata.ReadXml(xmlStream); DataRowCollection users = xmldata.Tables["User"].Rows; IProviderTransaction tran = m_dp.BeginTransaction(); foreach (DataRow row in users) { mem.UserName = (string)row["UserName"]; string role = (string)row["Role"]; //Make sure the user is in the system if (null == usersDB.GetInfo(mem.UserName, tran)) { m_dp.RollbackTransaction(tran); throw new DataAccessException("User: "******" is not in the FrontDesk database"); } User.UserList cmems = GetMembers(courseID, tran); //The user already exists in the course if (cmems.Contains(mem)) { if (sync) { UpdateRole(mem.UserName, courseID, role, tran); } else { m_dp.RollbackTransaction(tran); throw new DataAccessException("User: "******" already exists in the course. " + "Do a merge if you want to change the roles"); } } else { m_dp.CreateCourseMember(mem.UserName, courseID, role, tran); } } m_dp.CommitTransaction(tran); }
private void ConditionalCommit(IProviderTransaction providerTransaction) { if (providerTransaction.IsTransactional && providerTransaction.IsActive) { providerTransaction.Commit(this); _committedTransactions.Add(providerTransaction); } else if (!providerTransaction.IsTransactional && providerTransaction.HasCommitalActionsToPerform()) { // The "transaction" is just a placeholder and doesn't commit, but still has actions that need performing // e.g. cache clearing. For example the IO provider uses a NullProviderTransaction as of May 2012 // but still needs to clear relation caches when adding or updating files providerTransaction.PerformPreCommitalActions(); } }
protected AbstractEntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, AbstractRevisionRepository <TypedEntity> revisions, AbstractSchemaRepository schemas, IFrameworkContext frameworkContext) : base(providerMetadata, revisions, schemas, frameworkContext) { Transaction = providerTransaction; Revisions = revisions; Schemas = schemas; Revisions.RelatedEntitiesLoader = x => ProviderRepositoryHelper.CreateRelationLazyLoadDelegate(this, x).Invoke(x); Revisions.RegisterRelatedEntities = relation => { if (this.CanWriteRelations) { this.AddRelation(relation); } }; }
/// <summary> /// Add a user into a course /// </summary> public bool AddUser(string username, string role, int courseID, IProviderTransaction tran) { //Check permission if (m_ident.Name != username) Authorize(courseID, Permission.COURSE, "adduser", courseID, tran); User.UserList cmems = GetMembers(courseID, null); //Check an make sure the user isn't already in the course foreach (User user in cmems) if (user.UserName == username) throw new DataAccessException("User already enrolled in course"); return m_dp.CreateCourseMember(username, courseID, role, tran); }
/// <summary> /// Get all staff from a course /// </summary> public User.UserList GetStaff(int courseID, IProviderTransaction tran) { User.UserList staff = new User.UserList(); User.UserList all = GetMembers(courseID, tran); //Filter out students foreach (User cm in all) { if (GetRole(cm.UserName, courseID, tran).Staff) { staff.Add(cm); } } return(staff); }
/// <summary> /// Create a set of users specified by XML data /// </summary> public void BatchCreate(Stream xmlStream, bool sync) { User user = new User(); Users userDB = new Users(Globals.CurrentIdentity); DataSet xmldata = new DataSet(); xmldata.ReadXml(xmlStream); DataRowCollection users = xmldata.Tables["User"].Rows; IProviderTransaction tran = m_dp.BeginTransaction(); foreach (DataRow row in users) { user.UserName = (string)row["UserName"]; user.FirstName = (string)row["FirstName"]; user.LastName = (string)row["LastName"]; user.Email = (string)row["Email"]; //If the user is already in the system if (null != userDB.GetInfo(user.UserName, tran)) { if (sync) { m_dp.UpdateUser(user, tran); } else { m_dp.RollbackTransaction(tran); throw new DataAccessException("User: "******" is already in the FrontDesk database. Use a merge to add additional users."); } } else { string passwd = Globals.GeneratePassword(Globals.MinPasswordLength); m_dp.CreateUser(user, passwd, tran); new EmailWizard(m_ident).SendByUsername(user.UserName, "FrontDesk: User Account Created", String.Format(Globals.GetMessage("CreateUser"), user.UserName, passwd, user.Email)); } } m_dp.CommitTransaction(tran); }
/// <summary> /// Add a user into a course /// </summary> public bool AddUser(string username, string role, int courseID, IProviderTransaction tran) { //Check permission if (m_ident.Name != username) { Authorize(courseID, Permission.COURSE, "adduser", courseID, tran); } User.UserList cmems = GetMembers(courseID, null); //Check an make sure the user isn't already in the course foreach (User user in cmems) { if (user.UserName == username) { throw new DataAccessException("User already enrolled in course"); } } return(m_dp.CreateCourseMember(username, courseID, role, tran)); }
public EntityRepository(ProviderMetadata providerMetadata, AbstractSchemaRepository schemas, AbstractRevisionRepository <TypedEntity> revisions, IProviderTransaction providerTransaction, ISession nhSession, IFrameworkContext frameworkContext, bool isReadOnly) : base(providerMetadata, providerTransaction, revisions, schemas, frameworkContext) { Helper = new NhSessionHelper(nhSession, frameworkContext); IsReadonly = isReadOnly; #if DEBUG if (schemas is SchemaRepository) { var sesh = schemas as SchemaRepository; if (sesh.Helper.NhSession != Helper.NhSession) { throw new InvalidOperationException("NHibernate provider can only be used in conjunction with an NHibernate schema provider when they share the same NHibernate session"); } } #endif }
/// <summary> /// Clear job from queue and actives /// Direct Provider layer call /// </summary> public bool Finish(int jobID, IProviderTransaction tran) { return(m_dp.DeleteAutoJob(jobID, tran)); }
/// <summary> /// Get all the role in a course /// Direct Provider layer call /// </summary> public CourseRole.CourseRoleList GetRoles(int courseID, IProviderTransaction tran) { return m_dp.GetCourseRoles(courseID, tran); }
/// <summary> /// Get a user's role /// </summary> public CourseRole GetRole(string username, int courseID, IProviderTransaction tran) { return m_dp.GetUserCourseRole(username, courseID, tran); }
/// <summary> /// Create a new user /// </summary> public bool Create(string username, string password, string first, string last, string email, IProviderTransaction tran) { if (GetInfo(username, null) != null) throw new DataAccessException("User already exists"); if (password.Length < Globals.MinPasswordLength) throw new DataAccessException("Password must be at least " + Globals.MinPasswordLength + " characters long!"); User user = new User(); user.UserName = username; user.FirstName = first; user.LastName = last; user.Email = email; user.VerifyKey = Globals.GeneratePassword(8); bool result = m_dp.CreateUser(user, password, tran); if (result) SendVerifyEmail(user); return result; }
public ISession GetSessionFromTransaction(IProviderTransaction transaction, bool isReadonly) { var nhTransaction = transaction as NhProviderTransaction; return nhTransaction != null ? nhTransaction.NhSession : GetNHibernateSession(isReadonly); }
/// <summary> /// Update the role of a user in the specified course /// </summary> public bool UpdateRole(string username, int courseID, string role, IProviderTransaction tran) { //Check permission Authorize(courseID, Permission.COURSE, "updateuserrole", courseID, tran); return m_dp.UpdateCourseRole(username, courseID, role, tran); }
/// <summary> /// Update user information /// </summary> public bool Update(User user, IProviderTransaction tran) { return m_dp.UpdateUser(user, tran); }
private void CheckThrowTransactionActive(IProviderTransaction providerTransaction) { if (providerTransaction.IsTransactional && providerTransaction.WasCommitted) throw new TransactionCompletedException("Transaction cannot be completed as it is not active. Transaction type: " + providerTransaction.GetType().FullName); }
/// <summary> /// Get auto jobs for this asst /// Direct Provider layer call /// </summary> public AutoJob.AutoJobList GetAutoJobs(int asstID, IProviderTransaction tran) { return m_dp.GetAllAsstJobs(asstID, tran); }
protected void Authorize(int courseID, string perm, int entityID, IProviderTransaction tran) { Authorize(courseID, Permission.ASSIGNMENT, perm, entityID, tran); }
/// <summary> /// Get all staff from a course /// </summary> public User.UserList GetStaff(int courseID, IProviderTransaction tran) { User.UserList staff = new User.UserList(); User.UserList all = GetMembers(courseID, tran); //Filter out students foreach (User cm in all) if (GetRole(cm.UserName, courseID, tran).Staff) staff.Add(cm); return staff; }
/// <summary> /// Get staff roles from a course /// </summary> public CourseRole.CourseRoleList GetTypedRoles(int courseID, bool staff, IProviderTransaction tran) { CourseRole.CourseRoleList roles = GetRoles(courseID, tran); CourseRole.CourseRoleList sroles = new CourseRole.CourseRoleList(); foreach (CourseRole role in roles) if ((staff && role.Staff) || (!staff && !role.Staff)) sroles.Add(role); return sroles; }
private void ConditionalRollback(IProviderTransaction providerTransaction) { if (providerTransaction.IsTransactional && providerTransaction.IsActive) providerTransaction.Rollback(this); }
public EntityRepository(ProviderMetadata providerMetadata, AbstractSchemaRepository schemas, AbstractRevisionRepository <TypedEntity> revisions, IProviderTransaction providerTransaction, Settings settings, IFrameworkContext frameworkContext) : base(providerMetadata, providerTransaction, revisions, schemas, frameworkContext) { Settings = settings; EnsureRootPath(); }
/// <summary> /// Verify the user running the component has permissions /// Direct Provider layer call /// </summary> protected void Authorize(int courseID, string etype, string perm, int entityID, IProviderTransaction tran) { if (!m_dp.CheckPermission(m_ident.Name, courseID, perm, entityID, etype, tran)) throw new DataAccessException("Permission denied for action: " + perm); }
public ISession GetSessionFromTransaction(IProviderTransaction transaction, bool isReadonly) { var nhTransaction = transaction as NhProviderTransaction; return(nhTransaction != null ? nhTransaction.NhSession : GetNHibernateSession(isReadonly)); }
/// <summary> /// Get all members of a course /// Direct Provider layer call /// </summary> public User.UserList GetMembers(int courseID, IProviderTransaction tran) { return m_dp.GetCourseMembers(courseID, tran); }
/// <summary> /// Returns extended user information /// If the user is unknown, error handling takes place /// </summary> public User GetInfo(string username, IProviderTransaction tran) { User user = new User(); if (!m_dp.GetUserInfo(username, user, tran)) { //TODO: Do error handling stuff return null; } return user; }
public SchemaRepository(ProviderMetadata providerMetadata, AbstractRevisionRepository <EntitySchema> revisions, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext, DependencyHelper helper) : base(providerMetadata, revisions, providerTransaction, frameworkContext) { _helper = helper; }
public EntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext, DependencyHelper helper) : base(providerMetadata, providerTransaction, frameworkContext) { _helper = helper; }
public EntityRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, AbstractRevisionRepository <TypedEntity> revisions, AbstractSchemaRepository schemas, IFrameworkContext frameworkContext, DependencyHelper helper) : base(providerMetadata, providerTransaction, revisions, schemas, frameworkContext) { _helper = helper; }
/// <summary> /// Clear job from queue and actives /// Direct Provider layer call /// </summary> public bool Finish(int jobID, IProviderTransaction tran) { return m_dp.DeleteAutoJob(jobID, tran); }
protected AbstractSchemaRepository(ProviderMetadata providerMetadata, IProviderTransaction providerTransaction, IFrameworkContext frameworkContext) : this(providerMetadata, new NullProviderRevisionRepository <EntitySchema>(providerMetadata, frameworkContext), providerTransaction, frameworkContext) { Transaction = providerTransaction; }