Пример #1
0
        /// <summary>
        /// Unlock a user.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <returns>T/F if unlocked.</returns>
        public override bool UnlockUser(string username)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();

            objScope.Transaction.Begin();
            Employee e = ResolveEmployeeByName(objScope, username);

            e.IsLockedOut       = false;
            e.LastLockedOutDate = DateTime.Now;
            objScope.Transaction.Commit();
            return(true);
        }
Пример #2
0
        private MembershipUser GetMembershipUser(IObjectScope objScope, bool userIsOnline, Employee e)
        {
            MembershipUser membershipUser = GetUserFromEmployee(e);

            if (userIsOnline)
            {
                objScope.Transaction.Begin();
                e.LastActivityDate = DateTime.Now;
                objScope.Transaction.Commit();
            }
            return(membershipUser);
        }
Пример #3
0
        public static string AddGroup(string gname, string currentuseruid)
        {
            string Output = string.Empty;

            try
            {
                // open access dynamic databse configuration
                string SiteUrl = HttpContext.Current.Request.UrlReferrer.Scheme + "://" +
                                 HttpContext.Current.Request.UrlReferrer.Host + ":" +
                                 HttpContext.Current.Request.UrlReferrer.Port + "/" +
                                 HttpContext.Current.Request.UrlReferrer.Segments[1];
                if (MyUtilities.DevelopMode)
                {
                    SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);
                }

                MyUtilities.ModifyConnectionString(SiteUrl);

                using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                {
                    List <Groups> groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                            from d in c.groups
                                            where c.ResourceUID.Equals(currentuseruid) && d.name.Equals(gname)
                                            select d).ToList();
                    if (groups.Count == 0)
                    {
                        List <Users> userses = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                                where c.ResourceUID.Equals(currentuseruid)
                                                select c).ToList();
                        if (userses.Count > 0)
                        {
                            scope.Transaction.Begin();
                            var new_group = new Groups();
                            new_group.name = gname;
                            new_group.UID  = Guid.NewGuid().ToString();
                            userses[0].groups.Add(new_group);
                            scope.Add(userses[0]);
                            scope.Transaction.Commit();
                            Output = new_group.UID;
                        }
                    }
                    else
                    {
                        Output = groups[0].UID;
                    }
                }
            }
            catch (Exception)
            {
                // Error log here
            }
            return(Output);
        }
Пример #4
0
        public override string[] GetAllRoles()
        {
            IObjectScope objScope      = ORM.GetNewObjectScope();
            const string queryAllRoles = @"SELECT o.Name FROM RoleExtent AS o";

            using (IQueryResult result = objScope.GetOqlQuery(queryAllRoles).Execute())
            {
                string[] roles = new string[result.Count];
                result.CopyTo(roles, 0);
                return(roles);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets a list of the roles that a specified user is in for the
        /// configured <see cref="ApplicationName"/>.
        /// </summary>
        /// <remarks>
        /// This method is called by the ASP.NET runtime when using
        /// UrlAuthorizationModule (the <c>authorization</c> element of web.config)
        /// to secure your website, or when calling IsInRole() on the current
        /// IPrincipal (ex: Page.User.IsInRole("Admin"))
        /// </remarks>
        /// <param name="username">The user to return a list of roles for.</param>
        /// <returns>A string array containing the names of all the roles that the
        /// specified user is in for the configured <see cref="ApplicationName"/>
        /// </returns>
        public override string[] GetRolesForUser(string username)
        {
            IObjectScope objScope          = ORM.GetNewObjectScope();
            const string queryRolesForUser =
                @"SELECT o.Name FROM RoleExtent AS o, o.Employees AS e WHERE e.Name = $1";

            using (IQueryResult result = objScope.GetOqlQuery(queryRolesForUser).Execute(username))
            {
                string[] roles = new string[result.Count];
                result.CopyTo(roles, 0);
                return(roles);
            }
        }
Пример #6
0
        /// <summary>
        /// Set/store the property values for the user profile.
        /// </summary>
        /// <param name="context">Application context.</param>
        /// <param name="settingsPropertyValues">Profile property value settings.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection settingsPropertyValues)
        {
            if (true == (bool)context["IsAuthenticated"])
            {
                IObjectScope objScope = ORM.GetNewObjectScope();
                string       userName = GetUserName((string)context["UserName"]);
                objScope.Transaction.Begin();
                EmployeeProfile ep = ResolveEmployeeProfileByName(objScope, userName);
                if (null == ep)
                {
                    ep          = new EmployeeProfile();
                    ep.Employee = ResolveEmployeeByName(objScope, userName);
                    objScope.Add(ep);
                }
                foreach (SettingsPropertyValue settingsPropertyValue in settingsPropertyValues)
                {
                    switch (settingsPropertyValue.Property.Name)
                    {
                    case "Language":
                        ep.Language        = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "StyleTheme":
                        ep.StyleTheme      = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "Factory_Name":
                        ep.Factory_Name    = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "Operation_Name":
                        ep.Operation_Name  = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "WorkCenter_Name":
                        ep.WorkCenter_Name = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    default:
                        throw new ProviderException("Unsupported property.");
                    }
                }
                objScope.Transaction.Commit();
            }
        }
Пример #7
0
        /// <summary>
        /// Gets the number of users currently on-line.
        /// </summary>
        /// <returns>  /// # of users on-line.</returns>
        public override int GetNumberOfUsersOnline()
        {
            const string queryOnlineNum = @"ELEMENT (SELECT COUNT(*) FROM EmployeeExtent AS o WHERE o.LastActivityDate > $1)";
            TimeSpan     onlineSpan     = new TimeSpan(0, System.Web.Security.Membership.UserIsOnlineTimeWindow, 0);
            DateTime     compareTime    = DateTime.Now.Subtract(onlineSpan);

            IObjectScope objScope = ORM.GetNewObjectScope();
            IQuery       oqlQuery = objScope.GetOqlQuery(queryOnlineNum);

            using (IQueryResult result = oqlQuery.Execute(compareTime))
            {
                return((int)result[0]);
            }
        }
Пример #8
0
        private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
        {
            Employee     e = null;
            const string queryEmployeeByName = "ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1)";
            IQuery       oqlQuery            = objScope.GetOqlQuery(queryEmployeeByName);

            using (IQueryResult result = oqlQuery.Execute(name))
            {
                if (result.Count > 0)
                {
                    e = result[0] as Employee;
                }
            }
            return(e);
        }
Пример #9
0
        public override bool IsUserInRole(string username, string roleName)
        {
            IObjectScope objScope             = ORM.GetNewObjectScope();
            const string queryUserInRoleExist =
                @"SELECT o.Name FROM RoleExtent AS o WHERE EXISTS e IN o.Employees : (e.Name = $1) AND o.Name = $2";

            using (IQueryResult result = objScope.GetOqlQuery(queryUserInRoleExist).Execute(username, roleName))
            {
                if (result.Count > 0)
                {
                    return(true);
                }
                return(false);
            }
        }
Пример #10
0
        /// <summary>
        /// Delete a user.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="deleteAllRelatedData">Whether to delete all related data.</param>
        /// <returns>T/F if the user was deleted.</returns>
        public override bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();

            objScope.Transaction.Begin();
            Employee e = ResolveEmployeeByName(objScope, username);

            if (deleteAllRelatedData)
            {
                //Process commands to delete all data for the user in the database.
            }
            objScope.Remove(e);
            objScope.Transaction.Commit();
            return(true);
        }
Пример #11
0
        private bool Checkauthorization(IObjectScope scope, string username)
        {
            List <User> users = (from c in scope.GetOqlQuery <User>().ExecuteEnumerable()
                                 where c.Username.ToLower().Equals(username.ToLower())
                                 select c).ToList();

            if (users.Count > 0 && users[0].IsheAdmin)
            {
                ViewData["IsheAdmin"]            = users[0].IsheAdmin;
                ViewData["IsheDonationReceiver"] = users[0].IsheDonationReceiver;
                return(true);
            }
            ViewData["IsheAdmin"]            = false;
            ViewData["IsheDonationReceiver"] = false;
            return(false);
        }
Пример #12
0
        /// <summary>
        /// Change the question and answer for a password validation.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="password">Password.</param>
        /// <param name="newPwdQuestion">New question text.</param>
        /// <param name="newPwdAnswer">New answer text.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPwdQuestion, string newPwdAnswer)
        {
            if (!ValidateUser(username, password))
            {
                return(false);
            }

            IObjectScope objScope = ORM.GetNewObjectScope();

            objScope.Transaction.Begin();
            Employee e = ResolveEmployeeByName(objScope, username);

            e.PasswordQuestion = newPwdQuestion;
            e.PasswordAnswer   = EncodePassword(newPwdAnswer);
            objScope.Transaction.Commit();
            return(true);
        }
Пример #13
0
        /// <summary>
        /// Create a new user.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="password">Password.</param>
        /// <param name="email">Email address.</param>
        /// <param name="passwordQuestion">Security quesiton for password.</param>
        /// <param name="passwordAnswer">Security quesiton answer for password.</param>
        /// <param name="isApproved"></param>
        /// <param name="userID">User ID</param>
        /// <param name="status"></param>
        /// <returns>MembershipUser</returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            if ((RequiresUniqueEmail && (GetUserNameByEmail(email) != String.Empty)))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }

            MembershipUser membershipUser = GetUser(username, false);

            if (membershipUser == null)
            {
                IObjectScope    objScope   = ORM.GetNewObjectScope();
                System.DateTime createDate = DateTime.Now;
                objScope.Transaction.Begin();
                Employee e = new Employee();
                e.Name             = username;
                e.Password         = EncodePassword(password);
                e.Email            = email;
                e.PasswordQuestion = passwordQuestion;
                e.PasswordAnswer   = EncodePassword(passwordAnswer);
                e.IsApproved       = isApproved;

                objScope.Add(e);
                objScope.Transaction.Commit();

                status = MembershipCreateStatus.Success;
                return(GetUser(username, false));
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return(null);
        }
Пример #14
0
        private EmployeeProfile ResolveEmployeeProfileByName(IObjectScope objScope, string userName)
        {
            if (null == userName)
            {
                return(null);
            }
            EmployeeProfile ep = null;
            const string    queryEmployeeProfile =
                @"ELEMENT (SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.Name = $1)";
            IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeProfile);

            using (IQueryResult result = oqlQuery.Execute(userName))
                if (result.Count > 0)
                {
                    ep = result[0] as EmployeeProfile;
                }
            return(ep);
        }
Пример #15
0
        /// <summary>
        /// Update password and answer failure information.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="failureType">Type of failure</param>
        /// <remarks></remarks>
        private void UpdateFailureCount(IObjectScope objScope, Employee e, FailureType failureType)
        {
            int failureCount = 0;

            objScope.Transaction.Begin();
            if (failureType == FailureType.Password)
            {
                failureCount = e.FailedPasswordAttemptCount;
                if (failureCount == 0 ||
                    DateTime.Now > e.FailedPasswordAttemptWindowStart.AddMinutes(passwordAttemptWindow))
                {
                    e.FailedPasswordAttemptCount       = 1;
                    e.FailedPasswordAttemptWindowStart = DateTime.Now;
                }
            }
            else if (failureType == FailureType.PasswordAnswer)
            {
                failureCount = e.FailedPasswordAnswerAttemptCount;
                if (failureCount == 0 ||
                    DateTime.Now > e.FailedPasswordAnswerAttemptWindowStart.AddMinutes(passwordAttemptWindow))
                {
                    e.FailedPasswordAnswerAttemptCount       = 1;
                    e.FailedPasswordAnswerAttemptWindowStart = DateTime.Now;
                }
            }
            failureCount++;
            if (failureCount >= maxInvalidPasswordAttempts)
            {
                e.IsLockedOut       = true;
                e.LastLockedOutDate = DateTime.Now;
            }
            else
            {
                if (failureType == FailureType.Password)
                {
                    e.FailedPasswordAttemptCount = failureCount;
                }
                else if (failureType == FailureType.PasswordAnswer)
                {
                    e.FailedPasswordAnswerAttemptCount = failureCount;
                }
            }
            objScope.Transaction.Commit();
        }
Пример #16
0
        public static string GetProjects(string groupuid, string currentuseruid)
        {
            var outputTable = new DataTable();

            outputTable.Columns.Add("uid");
            outputTable.Columns.Add("name");
            try
            {
                // open access dynamic databse configuration
                string SiteUrl = HttpContext.Current.Request.UrlReferrer.Scheme + "://" +
                                 HttpContext.Current.Request.UrlReferrer.Host + ":" +
                                 HttpContext.Current.Request.UrlReferrer.Port + "/" +
                                 HttpContext.Current.Request.UrlReferrer.Segments[1];
                if (MyUtilities.DevelopMode)
                {
                    SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);
                }

                MyUtilities.ModifyConnectionString(SiteUrl);

                using (IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope())
                {
                    List <Groups> groups = (from c in scope.GetOqlQuery <Users>().ExecuteEnumerable()
                                            from d in c.groups
                                            where c.ResourceUID.Equals(currentuseruid) && d.UID.Equals(groupuid)
                                            select d).ToList();
                    if (groups.Count > 0)
                    {
                        foreach (var project in groups[0].projects)
                        {
                            var testrow = outputTable.NewRow();
                            testrow["uid"]  = project.uid;
                            testrow["name"] = project.name;
                            outputTable.Rows.Add(testrow);
                        }
                    }
                }
            }
            catch (Exception)
            {
                // error log here
            }
            return(MyUtilities.Serialize(outputTable));
        }
Пример #17
0
        private Role ResolveRoleByName(IObjectScope objScope, string roleName)
        {
            if (null == roleName)
            {
                return(null);
            }
            Role         r         = null;
            const string queryRole = @"ELEMENT (SELECT * FROM RoleExtent AS o WHERE o.Name = $1)";
            IQuery       oqlQuery  = objScope.GetOqlQuery(queryRole);

            using (IQueryResult result = oqlQuery.Execute(roleName))
            {
                if (result.Count > 0)
                {
                    r = result[0] as Role;
                }
            }
            return(r);
        }
Пример #18
0
        /// <summary>
        /// Get the property values for the user profile.
        /// </summary>
        /// <param name="context">Application context.</param>
        /// <param name="settingsProperties">Profile property settings.</param>
        /// <returns>Property setting values.</returns>
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection settingsProperties)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection();
            string          userName = GetUserName((string)context["UserName"]);
            EmployeeProfile ep       = ResolveEmployeeProfileByName(objScope, userName);

            if (null == ep)
            {
                ep = new EmployeeProfile();
            }
            foreach (SettingsProperty property in settingsProperties)
            {
                SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(property);
                switch (property.Name)
                {
                case "Language":
                    settingsPropertyValue.PropertyValue = ep.Language;
                    break;

                case "StyleTheme":
                    settingsPropertyValue.PropertyValue = ep.StyleTheme;
                    break;

                case "Factory_Name":
                    settingsPropertyValue.PropertyValue = ep.Factory_Name;
                    break;

                case "Operation_Name":
                    settingsPropertyValue.PropertyValue = ep.Operation_Name;
                    break;

                case "WorkCenter_Name":
                    settingsPropertyValue.PropertyValue = ep.WorkCenter_Name;
                    break;

                default:
                    throw new ProviderException("Unsupported property.");
                }
                settingsValues.Add(settingsPropertyValue);
            }
            return(settingsValues);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //return;
            string SiteUrl = MyUtilities.ProjectServerInstanceURL(SPContext.Current);

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (var Site = new SPSite(SiteUrl))
                {
                    string connstr = Utilities.GetProjectServerSQLDatabaseConnectionString(Site.ID, Utilities.DatabaseType.PublishedDatabase);
                    var builder    = new SqlConnectionStringBuilder(connstr);
                    ITXPGReportDataLayer.ObjectScopeProvider1.AdjustForDynamicLoad("ITXPGReportDataLayer", builder.DataSource);
                    using (IObjectScope scope = ITXPGReportDataLayer.ObjectScopeProvider1.GetNewObjectScope())
                    {
                    }
                }
            }
                                                 );
        }
Пример #20
0
        /// <summary>
        /// Delete profiles for an array of user names.
        /// </summary>
        /// <param name="userNames">Array of user names.</param>
        /// <returns>Number of profiles deleted.</returns>
        public override int DeleteProfiles(string[] userNames)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            int          deleted  = 0;

            objScope.Transaction.Begin();
            foreach (string userName in userNames)
            {
                string          shotUserName = GetUserName(userName);
                EmployeeProfile ep           = ResolveEmployeeProfileByName(objScope, shotUserName);
                if (ep != null)
                {
                    objScope.Remove(ep);
                    deleted++;
                }
            }
            objScope.Transaction.Commit();
            return(deleted);
        }
Пример #21
0
        public override string GetUserNameByEmail(string email)
        {
            const string queryEmployeeNameByEmail =
                @"ELEMENT (SELECT o.Name FROM EmployeeExtent AS o WHERE o.Email = $1)";
            IObjectScope objScope = ORM.GetNewObjectScope();
            IQuery       oqlQuery = objScope.GetOqlQuery(queryEmployeeNameByEmail);

            using (IQueryResult result = oqlQuery.Execute(email))
            {
                if (result.Count > 0)
                {
                    return(result[0].ToString());
                }
                else
                {
                    return(String.Empty);
                }
            }
        }
Пример #22
0
        private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
        {
            Employee     e = null;
            const string queryEmployeeByName =
                @"ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1 AND o.IsApproved = true AND o.isLockedOut = false)";
            IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeByName);

            using (IQueryResult result = oqlQuery.Execute(name))
            {
                if (result.Count > 0)
                {
                    e = result[0] as Employee;
                }
                else
                {
                    throw new ProviderException(string.Format(MSG.ProfileProvider_Employee_Not_Exist, name));
                }
            }
            return(e);
        }
Пример #23
0
        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            Role         role     = ResolveRoleByName(objScope, roleName);

            if (null == role)
            {
                throw new ProviderException(String.Format("Role: {0} is not exist", roleName));
            }

            const string queryFindUsersInRole =
                @"SELECT o.Name FROM EmployeeExtent AS o WHERE EXISTS r IN o.Roles : (r = $1) AND o.Name like $2";

            using (IQueryResult result = objScope.GetOqlQuery(queryFindUsersInRole).Execute(role, usernameToMatch + '*'))
            {
                string[] users = new string[result.Count];
                result.CopyTo(users, 0);
                return(users);
            }
        }
Пример #24
0
        public override void CreateRole(string roleName)
        {
            if (roleName.IndexOf(',') >= 0)
            {
                throw new ProviderException(String.Format("Role: {0} had comma inside", roleName));
            }

            IObjectScope objScope = ORM.GetNewObjectScope();
            Role         role     = ResolveRoleByName(objScope, roleName);

            if (null != role)
            {
                throw new ProviderException(String.Format("Role: {0} is already exist", roleName));
            }

            role      = new Role();
            role.Name = roleName;
            objScope.Transaction.Begin();
            objScope.Add(role);
            objScope.Transaction.Commit();
        }
Пример #25
0
        /// <summary>
        /// Deletes profiles that have been inactive since the specified date.
        /// </summary>
        /// <param name="authenticationOption">Current authentication option setting.</param>
        /// <param name="userInactiveSinceDate">Inactivity date for deletion.</param>
        /// <returns>Number of records deleted.</returns>
        public override int DeleteInactiveProfiles(System.Web.Profile.ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();

            objScope.Transaction.Begin();

            int          deleteCounter         = 0;
            const string queryInactiveProfiles =
                @"SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.LastActivityDate <= $1";
            IQuery oqlQuery = objScope.GetOqlQuery(queryInactiveProfiles);

            using (IQueryResult result = oqlQuery.Execute(userInactiveSinceDate))
            {
                foreach (object p in result)
                {
                    objScope.Remove(p);
                    deleteCounter++;
                }
            }
            objScope.Transaction.Commit();
            return(deleteCounter);
        }
Пример #26
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            Role         role     = ResolveRoleByName(objScope, roleName);

            if (null == role)
            {
                throw new ProviderException(String.Format("Role: {0} is not exist", roleName));
            }

            if (role.Employees.Count > 0 && true == throwOnPopulatedRole)
            {
                throw new ProviderException(String.Format("Role: {0} still has employee assigned", roleName));
            }
            else
            {
                objScope.Transaction.Begin();
                objScope.Remove(role);
                objScope.Transaction.Commit();
                return(true);
            }
        }
Пример #27
0
        private ProfileInfoCollection QueryProfileInfos(IObjectScope objScope, string oqlQuery, object oqlValue, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection pic = new ProfileInfoCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);

            IQueryResult result;

            if (oqlValue != null)
            {
                result = query.Execute(oqlValue);
            }
            else
            {
                result = query.Execute();
            }

            using (result)
            {
                totalRecords = result.Count;
                int counter    = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex   = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        EmployeeProfile ep = res as EmployeeProfile;
                        pic.Add(new ProfileInfo(ep.Employee.Name, false, ep.Employee.LastActivityDate, ep.LastUpdatedDate, 0));
                    }
                    if (counter >= endIndex)
                    {
                        break;
                    }
                    counter += 1;
                }
            }
            return(pic);
        }
Пример #28
0
        private MembershipUserCollection QueryMembershipUsers(IObjectScope objScope, string oqlQuery, string likeValue, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection users = new MembershipUserCollection();
            IQuery       query             = objScope.GetOqlQuery(oqlQuery);
            IQueryResult result;

            if (likeValue != null)
            {
                result = query.Execute(likeValue + '*'); // OQL use * as wildcard instead of %
            }
            else
            {
                result = query.Execute();
            }

            using (result)
            {
                totalRecords = result.Count;
                int counter    = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex   = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        Employee e = res as Employee;
                        users.Add(GetUserFromEmployee(e));
                    }
                    if (counter >= endIndex)
                    {
                        break;
                    }
                    counter += 1;
                }
            }
            return(users);
        }
Пример #29
0
        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();

            foreach (string u in usernames)
            {
                Employee emp = ResolveEmployeeByName(objScope, u);
                if (null == emp)
                {
                    throw new ArgumentNullException(String.Format("Employee: {0} is not exist", u));
                }
                foreach (string r in roleNames)
                {
                    Role role = ResolveRoleByName(objScope, r);
                    if (null == role)
                    {
                        throw new ArgumentNullException(String.Format("Role: {0} is not exist", r));
                    }
                    objScope.Transaction.Begin();
                    role.Employees.Remove(emp);
                    objScope.Transaction.Commit();
                }
            }
        }
Пример #30
0
        /// <summary>
        /// Get the password for a user.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="answer">Answer to security question.</param>
        /// <returns>Password for the user.</returns>
        public override string GetPassword(string username, string answer)
        {
            if (!EnablePasswordRetrieval)
            {
                throw new ProviderException("Password Retrieval Not Enabled.");
            }

            if (PasswordFormat == MembershipPasswordFormat.Hashed)
            {
                throw new ProviderException("Cannot retrieve Hashed passwords.");
            }

            IObjectScope objScope = ORM.GetNewObjectScope();
            Employee     e        = ResolveEmployeeByName(objScope, username);

            if (e.IsLockedOut == true)
            {
                throw new MembershipPasswordException("The supplied user is locked out.");
            }

            if (RequiresQuestionAndAnswer && !CheckPassword(answer, e.PasswordAnswer))
            {
                UpdateFailureCount(objScope, e, FailureType.PasswordAnswer);

                throw new MembershipPasswordException("Incorrect password answer.");
            }

            string password = e.Password;

            if (PasswordFormat == MembershipPasswordFormat.Encrypted)
            {
                password = UnEncodePassword(password);
            }

            return(password);
        }
 private static bool Checkauthorization(IObjectScope scope, string username)
 {
     List<User> users = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable()
                         where c.Username.ToLower().Equals(username.ToLower())
                         select c).ToList();
     if (users.Count > 0 && users[0].IsheAdmin)
         return true;
     return false;
 }
Пример #32
0
 private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
 {
     Employee e = null;
     const string queryEmployeeByName = "ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeByName);
     using (IQueryResult result = oqlQuery.Execute(name))
     {
         if (result.Count > 0)
             e = result[0] as Employee;
     }
     return e;
 }
Пример #33
0
        /// <summary>
        /// Update password and answer failure information.
        /// </summary>
        /// <param name="username">User name.</param>
        /// <param name="failureType">Type of failure</param>
        /// <remarks></remarks>
        private void UpdateFailureCount(IObjectScope objScope, Employee e, FailureType failureType)
        {
            int failureCount = 0;
            objScope.Transaction.Begin();
            if (failureType == FailureType.Password)
            {
                failureCount = e.FailedPasswordAttemptCount;
                if (failureCount == 0
                    || DateTime.Now > e.FailedPasswordAttemptWindowStart.AddMinutes(passwordAttemptWindow))
                {
                    e.FailedPasswordAttemptCount = 1;
                    e.FailedPasswordAttemptWindowStart = DateTime.Now;
                }

            }
            else if(failureType == FailureType.PasswordAnswer)
            {
                failureCount = e.FailedPasswordAnswerAttemptCount;
                if (failureCount == 0
                    || DateTime.Now > e.FailedPasswordAnswerAttemptWindowStart.AddMinutes(passwordAttemptWindow))
                {
                    e.FailedPasswordAnswerAttemptCount = 1;
                    e.FailedPasswordAnswerAttemptWindowStart = DateTime.Now;
                }
            }
            failureCount++;
            if (failureCount >= maxInvalidPasswordAttempts)
            {
                e.IsLockedOut = true;
                e.LastLockedOutDate = DateTime.Now;
            }
            else
            {
                if (failureType == FailureType.Password)
                    e.FailedPasswordAttemptCount = failureCount;
                else if (failureType == FailureType.PasswordAnswer)
                    e.FailedPasswordAnswerAttemptCount = failureCount;
            }
            objScope.Transaction.Commit();
        }
Пример #34
0
        private MembershipUser GetMembershipUser(IObjectScope objScope, bool userIsOnline, Employee e)
        {
            MembershipUser membershipUser = GetUserFromEmployee(e);

            if (userIsOnline)
            {
                objScope.Transaction.Begin();
                e.LastActivityDate = DateTime.Now;
                objScope.Transaction.Commit();
            }
            return membershipUser;
        }
Пример #35
0
        private MembershipUserCollection QueryMembershipUsers(IObjectScope objScope, string oqlQuery, string likeValue, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection users = new MembershipUserCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);
            IQueryResult result;
            if (likeValue != null)
                result = query.Execute(likeValue + '*'); // OQL use * as wildcard instead of %
            else
                result = query.Execute();

            using (result)
            {
                totalRecords = result.Count;
                int counter = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        Employee e = res as Employee;
                        users.Add(GetUserFromEmployee(e));
                    }
                    if (counter >= endIndex)
                        break;
                    counter += 1;
                }
            }
            return users;
        }
 private bool Checkauthorization(IObjectScope scope, string username)
 {
     List<User> users = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable()
                         where c.Username.ToLower().Equals(username.ToLower())
                         select c).ToList();
     if (users.Count > 0 && (users[0].IsheDonationReceiver || users[0].IsheAdmin))
     {
         ViewData["IsheAdmin"] = users[0].IsheAdmin;
         ViewData["IsheDonationReceiver"] = users[0].IsheDonationReceiver;
         return true;
     }
     ViewData["IsheAdmin"] = false;
     ViewData["IsheDonationReceiver"] = false;
     return false;
 }
        protected override void InitializeControls(Control controlContainer)
        {
            base.InitializeControls(controlContainer);
            this.DateFeed.ItemDataBound += new RepeaterItemEventHandler(this.DateFeed_ItemDataBound);

            //establish connection to database containing Brafton info...consider using GetObjectScope() (no "new")
            _objectScope = BraftonContext.GetNewObjectScope();

            //This following chunk, declaring "result", simply pulls all NewsItem objects (read: Articles) from "BraftonContext" (db holding Brafton articles?)
            var result = from n in _objectScope.Extent<NewsItem>()
                         //where n.NewsItems.Count() > 0
                         select n;

            //logic for determining number of months (with respective years), as well as number of posts per month
            //Concept: Iterate through articles, pushing months to a List as they come
            foreach (var item in result)
            {
                bool added = false;

                //if _dates is empty, add first month without checking
                if (_dates.Count < 1)
                {
                    var aDate = new ArtDate(item.PublishDate.Month, item.PublishDate.Year);
                    aDate.Iterate(item);
                    _dates.Add(aDate);
                    added = true;
                    continue;
                }

                //iterate the _dates list, comparing the month/year in each ArtDate in the list to item
                for (int i = 0; i < _dates.Count; i++)
                {
                    if (_dates[i].Month == item.PublishDate.Month && _dates[i].Year == item.PublishDate.Year)
                    {
                        _dates[i].Iterate(item);
                        added = true;

                        break;
                    }
                }
                if (added == false) //no ArtDate objects with article's Month/Year, add a new one!
                {
                    var aDate = new ArtDate(item.PublishDate.Month, item.PublishDate.Year);
                    aDate.Iterate(item);
                    _dates.Add(aDate);
                }
            }

            //check that at least one date has been added to _dates list, bind to DateFeed repeater if so
            if (_dates.Count > 0)
            {
                this.DateFeed.DataSource = _dates;
                this.DateFeed.DataBind();
            }
        }
Пример #38
0
 protected ShopFloor(IObjectScope existObjScope, HistoryMainLine reusedHML)
     : base(existObjScope)
 {
     historyMainLine = reusedHML;
 }
 private void LoadReceiptValuesFromDb(IObjectScope scope)
 {
     var modeofpayments = new List<string> { "Cash", "Cheque", "Online", "Mobile", "Goods" };
     ViewData["modeOfPayment"] = modeofpayments;
     var receivers = (from c in scope.GetOqlQuery<User>().ExecuteEnumerable()
                      where c.IsheDonationReceiver.Equals(true)
                      select c).ToList();
     var donationReceivers = receivers.Select(receiver => receiver.Username).ToList();
     ViewData["donationReceivers"] = donationReceivers;
 }
Пример #40
0
        protected override void InitializeControls(Control controlContainer)
        {
            base.InitializeControls(controlContainer);
            switch (this.DisplayMode)
            {
                case DisplayModes.DETAIL:
                    this.Controls.Clear();
                    this.Visible = false;
                    return;
                case DisplayModes.LIST:
                    this.NewsFeed.ItemDataBound += new RepeaterItemEventHandler(this.NewsFeed_ItemDataBound);
                    _objectScope = BraftonContext.GetNewObjectScope();
                    if (!string.IsNullOrEmpty(this._cat))
                    {
                        var result = from n in _objectScope.Extent<Category>()
                                     where n.Url == this._cat
                                     select n;
                        if (result.Count() > 0)
                        {
                            Category cat = result.First();
                            var items = cat.NewsItems.AsQueryable();
                            //if (!string.IsNullOrEmpty(this._sortExpression))
                                items = items.OrderByDescending(i => i.PublishDate);
                            this.NewsFeed.DataSource = items;
                            this.NewsFeed.DataBind();
                        }
                    }
                    else if (!string.IsNullOrEmpty(this._year)) //it's a date archive
                    {
                        var result = from n in _objectScope.Extent<NewsItem>()
                                     where n.PublishDate.Year.ToString() == this._year && n.PublishDate.Month.ToString() == this._month
                                     select n;
                        if (result.Count() > 0)
                        {
                            result = result.OrderByDescending(i => i.PublishDate);
                            this.NewsFeed.DataSource = result;
                            this.NewsFeed.DataBind();
                        }
                    }
                    else
                    {
                        var result = from n in _objectScope.Extent<NewsItem>()
                                     select n;
                        if (!string.IsNullOrEmpty(this._filter))
                            result = result.Where(this._filter);
                        result = result.OrderByDescending(i => i.PublishDate);
                        if (this._itemLimit > 0)
                            result = result.Take(3);

                        if (result.Count() > 0)
                        {
                            this.NewsFeed.DataSource = result;
                            this.NewsFeed.DataBind();
                        }

                        //Categories

                        //Pinnacle News Category
                        this.CatPinn.ItemDataBound += new RepeaterItemEventHandler(this.NewsFeed_ItemDataBound);
                        _objectScope = BraftonContext.GetNewObjectScope();
                        var result0 = from n in _objectScope.Extent<Category>()
                                      where n.Url == "pinnacle-news"
                                      select n;
                        if (result0.Count() > 0)
                        {
                            Category cat = result0.First();
                            var items = cat.NewsItems.AsQueryable();
                            //if (!string.IsNullOrEmpty(this._sortExpression))
                            items = items.OrderByDescending(i => i.PublishDate).Take(2);
                            this.CatPinn.Visible = true;
                            this.CatPinn.DataSource = items;
                            this.CatPinn.DataBind();
                        }

                        //IBM News Category
                        this.CatOne.ItemDataBound += new RepeaterItemEventHandler(this.NewsFeed_ItemDataBound);
                        _objectScope = BraftonContext.GetNewObjectScope();
                        var result1 = from n in _objectScope.Extent<Category>()
                                      where n.Url == "ibm-news"
                                      select n;
                        if (result1.Count() > 0)
                        {
                            Category cat = result1.First();
                            var items = cat.NewsItems.AsQueryable();
                            //if (!string.IsNullOrEmpty(this._sortExpression))
                            items = items.OrderByDescending(i => i.PublishDate).Take(2);
                            this.CatOne.Visible = true;
                            this.CatOne.DataSource = items;
                            this.CatOne.DataBind();
                        }

                        //EMC News Category
                        this.CatTwo.ItemDataBound += new RepeaterItemEventHandler(this.NewsFeed_ItemDataBound);
                        _objectScope = BraftonContext.GetNewObjectScope();
                        var result2 = from n in _objectScope.Extent<Category>()
                                      where n.Url == "emc-news"
                                      select n;
                        if (result2.Count() > 0)
                        {
                            Category cat = result2.First();
                            var items = cat.NewsItems.AsQueryable();
                            //if (!string.IsNullOrEmpty(this._sortExpression))
                            items = items.OrderByDescending(i => i.PublishDate).Take(2);
                            this.CatTwo.Visible = true;
                            this.CatTwo.DataSource = items;
                            this.CatTwo.DataBind();
                        }

                        //VM Ware News Category
                        this.CatThree.ItemDataBound += new RepeaterItemEventHandler(this.NewsFeed_ItemDataBound);
                        _objectScope = BraftonContext.GetNewObjectScope();
                        var result3 = from n in _objectScope.Extent<Category>()
                                      where n.Url == "vmware-news"
                                      select n;
                        if (result3.Count() > 0)
                        {
                            Category cat = result3.First();
                            var items = cat.NewsItems.AsQueryable();
                            //if (!string.IsNullOrEmpty(this._sortExpression))
                            items = items.OrderByDescending(i => i.PublishDate).Take(2);
                            this.CatThree.Visible = true;
                            this.CatThree.DataSource = items;
                            this.CatThree.DataBind();
                        }

                        //Cisco News Category
                        this.CatFour.ItemDataBound += new RepeaterItemEventHandler(this.NewsFeed_ItemDataBound);
                        _objectScope = BraftonContext.GetNewObjectScope();
                        var result4 = from n in _objectScope.Extent<Category>()
                                      where n.Url == "cisco-news"
                                      select n;
                        if (result4.Count() > 0)
                        {
                            Category cat = result4.First();
                            var items = cat.NewsItems.AsQueryable();
                            //if (!string.IsNullOrEmpty(this._sortExpression))
                            items = items.OrderByDescending(i => i.PublishDate).Take(2);
                            this.CatFour.Visible = true;
                            this.CatFour.DataSource = items;
                            this.CatFour.DataBind();
                        }
                    }
                    break;
                case DisplayModes.RSS:
                    OutputRSS();
                    break;
            }
        }
Пример #41
0
 private Employee ResolveEmployeeByName(IObjectScope objScope, string name)
 {
     Employee e = null;
     const string queryEmployeeByName =
     @"ELEMENT (SELECT o FROM EmployeeExtent AS o WHERE o.Name = $1 AND o.IsApproved = true AND o.isLockedOut = false)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeByName);
     using (IQueryResult result = oqlQuery.Execute(name))
     {
         if (result.Count > 0)
             e = result[0] as Employee;
         else
             throw new ProviderException(string.Format(MSG.ProfileProvider_Employee_Not_Exist,name));
     }
     return e;
 }
Пример #42
0
 private EmployeeProfile ResolveEmployeeProfileByName(IObjectScope objScope, string userName)
 {
     if (null == userName) return null;
     EmployeeProfile ep = null;
     const string queryEmployeeProfile =
     @"ELEMENT (SELECT * FROM EmployeeProfileExtent AS o WHERE o.Employee.Name = $1)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryEmployeeProfile);
     using (IQueryResult result = oqlQuery.Execute(userName))
         if (result.Count > 0)
             ep = result[0] as EmployeeProfile;
     return ep;
 }
Пример #43
0
 public void Dispose()
 {
     // Even CompoundTxn will reusing objScope, so only dispose here is enough
     // No need to further handle objScope dispose in subclass
     if (objScope != null)
     {
         objScope.Dispose();
         GC.SuppressFinalize(this);
         objScope = null;
     }
 }
Пример #44
0
 protected ContainerTxn(IObjectScope existObjScope, HistoryMainLine reusedHML)
     : base(existObjScope, reusedHML)
 {
 }
Пример #45
0
 protected Service()
 {
     // Always return New object scope ensure that not object access between different service.
     objScope = ORM.GetNewObjectScope();
 }
Пример #46
0
 protected Service(IObjectScope existObjScope)
 {
     objScope = existObjScope;
 }
Пример #47
0
 private Role ResolveRoleByName(IObjectScope objScope, string roleName)
 {
     if (null == roleName) return null;
     Role r = null;
     const string queryRole = @"ELEMENT (SELECT * FROM RoleExtent AS o WHERE o.Name = $1)";
     IQuery oqlQuery = objScope.GetOqlQuery(queryRole);
     using (IQueryResult result = oqlQuery.Execute(roleName))
     {
         if (result.Count > 0)
             r = result[0] as Role;
     }
     return r;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        ApiContext context = new ApiContext(new Guid("e5c5c78b-9e7a-4759-8dd6-ceaf46a2b855"), "http://api.brafton.com/");
        var news = context.News;
        var categories = context.Categories;
        //IList<newsItem> newsItems = new List<newsItem>();
        //IList<category> categoryItems = new List<category>();
        objectScope = BraftonContext.GetNewObjectScope();

        foreach (category item in categories)
        {
            bool isNew = false;
            objectScope.Transaction.Begin();
            Category cat = GetCategory(item, out isNew);
            cat = LoadCategoryItem(item, cat);
            if (isNew)
                objectScope.Add(cat);
            objectScope.Transaction.Commit();
        }

        foreach (newsItem item in news)
        {
            var cats = item.categories;
            objectScope.Transaction.Begin();
            bool isNew = false;
            NewsItem _item = GetNewsItem(item, out isNew);
            _item = LoadNewsItem(item, _item);
            if (isNew)
                objectScope.Add(_item);
            objectScope.Transaction.Commit();
        }

        string query = "select * from NewsItemExtent AS x";

        IQuery queryForExecution = objectScope.GetOqlQuery(query);
        queryForExecution.ForwardsOnly = false;
        IQueryResult res = queryForExecution.Execute();
        if (res.Count > 0)
        {
            for (int i = 0; i < res.Count; i++)
            {
                NewsItem item = (NewsItem)res[i];
                ltrlItems.Text += "<a href=\"news/" + item.Url + "\">" + item.Headline + "</a><br /><p>" + item.Extract + "</p>";
            }
        }
    }
Пример #49
0
        protected void OutputRSS()
        {
            IQueryable<NewsItem> res = Enumerable.Empty<NewsItem>().AsQueryable();
            _objectScope = BraftonContext.GetNewObjectScope();
            if (!string.IsNullOrEmpty(this._cat))
            {
                var result = from n in _objectScope.Extent<Category>()
                             where n.Url == this._cat
                             select n;
                if (result.Count() > 0)
                {

                    Category cat = result.First();
                    var items = cat.NewsItems.AsQueryable();
                    if (!string.IsNullOrEmpty(this._sortExpression))
                        items.OrderBy(this._sortExpression);
                    if (items.Count() > 0)
                    {
                        res = items;
                    }
                }
            }
            else
            {
                res = from n in _objectScope.Extent<NewsItem>()
                            select n;
                if (!string.IsNullOrEmpty(this._filter))
                    res.Where(this._filter);
                if (!string.IsNullOrEmpty(this._sortExpression))
                    res.OrderBy(this._sortExpression);
            }

            if (res.Count() > 0)
            {
                HttpResponse response = HttpContext.Current.Response;
                HttpRequest request = HttpContext.Current.Request;
                string url = GetPageUrl();
                response.Clear();
                response.ContentType = "text/xml";
                XmlTextWriter feedWriter
                  = new XmlTextWriter(response.OutputStream, Encoding.UTF8);

                feedWriter.WriteStartDocument();

                // These are RSS Tags
                feedWriter.WriteStartElement("rss");
                feedWriter.WriteAttributeString("version", "2.0");

                feedWriter.WriteStartElement("channel");
                feedWriter.WriteElementString("title", "Pinnacle Business Systems, Inc.");
                string feedUrl = request.Url.ToString();
                feedUrl = feedUrl.Replace("?" + request.QueryString.ToString(), "");
                feedWriter.WriteElementString("link", feedUrl);
                feedWriter.WriteElementString("description", "Pinnacle Business Systems, Inc.");
                feedWriter.WriteElementString("copyright", "Copyright 2010 pbsnow.com. All rights reserved.");

                url = request.Url.Scheme + "://" + request.Url.Host + this.Page.ResolveUrl(url);

                // Write all Posts in the rss feed
                foreach (NewsItem item in res)
                {
                    feedWriter.WriteStartElement("item");
                    feedWriter.WriteElementString("title", item.Headline);
                    feedWriter.WriteElementString("description", item.Extract);
                    feedWriter.WriteElementString("link", url + item.Url + UrlHelper.PageExtension);
                    feedWriter.WriteElementString("pubDate", item.PublishDate.ToString());
                    feedWriter.WriteEndElement();
                }

                // Close all open tags tags
                feedWriter.WriteEndElement();
                feedWriter.WriteEndElement();
                feedWriter.WriteEndDocument();
                feedWriter.Flush();
                feedWriter.Close();

                response.End();
            }
        }
Пример #50
0
        private ProfileInfoCollection QueryProfileInfos(IObjectScope objScope, string oqlQuery, object oqlValue, int pageIndex, int pageSize, out int totalRecords)
        {
            ProfileInfoCollection pic = new ProfileInfoCollection();
            IQuery query = objScope.GetOqlQuery(oqlQuery);

            IQueryResult result;
            if (oqlValue != null)
                result = query.Execute(oqlValue);
            else
                result = query.Execute();

            using (result)
            {
                totalRecords = result.Count;
                int counter = 0;
                int startIndex = pageSize * pageIndex;
                int endIndex = startIndex + pageSize - 1;

                foreach (object res in result)
                {
                    if (counter >= startIndex)
                    {
                        EmployeeProfile ep = res as EmployeeProfile;
                        pic.Add(new ProfileInfo(ep.Employee.Name, false, ep.Employee.LastActivityDate, ep.LastUpdatedDate, 0));
                    }
                    if (counter >= endIndex)
                        break;
                    counter += 1;
                }
            }
            return pic;
        }