Пример #1
0
 public override int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query)
 {
     PersonalizationProviderHelper.CheckPersonalizationScope(scope);
     if (scope == PersonalizationScope.Shared)
     {
         string pathToMatch = null;
         if (query != null)
         {
             pathToMatch = PersonalizationProviderHelper.CheckAndTrimString(query.PathToMatch, "query.PathToMatch", false, MaxStringLength);
         }
         return(GetCountOfSharedState(pathToMatch));
     }
     else
     {
         string   pathToMatch           = null;
         DateTime userInactiveSinceDate = DateTime.MinValue;
         string   usernameToMatch       = null;
         if (query != null)
         {
             pathToMatch           = PersonalizationProviderHelper.CheckAndTrimString(query.PathToMatch, "query.PathToMatch", false, MaxStringLength);
             userInactiveSinceDate = query.UserInactiveSinceDate;
             usernameToMatch       = PersonalizationProviderHelper.CheckAndTrimString(
                 query.UsernameToMatch, "query.UsernameToMatch", false, MaxStringLength);
         }
         return(GetCountOfUserState(pathToMatch, userInactiveSinceDate, usernameToMatch));
     }
 }
Пример #2
0
        public override PersonalizationStateInfoCollection FindState(PersonalizationScope scope,
                                                                     PersonalizationStateQuery query,
                                                                     int pageIndex,
                                                                     int pageSize,
                                                                     out int totalRecords)
        {
            PersonalizationProviderHelper.CheckPersonalizationScope(scope);
            PersonalizationProviderHelper.CheckPageIndexAndSize(pageIndex, pageSize);

            if (scope == PersonalizationScope.Shared)
            {
                string pathToMatch = null;
                if (query != null)
                {
                    pathToMatch = PersonalizationProviderHelper.CheckAndTrimString(query.PathToMatch, "query.PathToMatch", false, MaxStringLength);
                }
                return(FindSharedState(pathToMatch, pageIndex, pageSize, out totalRecords));
            }
            else
            {
                string   pathToMatch       = null;
                DateTime inactiveSinceDate = DateTime.MinValue;
                string   usernameToMatch   = null;
                if (query != null)
                {
                    pathToMatch       = PersonalizationProviderHelper.CheckAndTrimString(query.PathToMatch, "query.PathToMatch", false, MaxStringLength);
                    inactiveSinceDate = query.UserInactiveSinceDate;
                    usernameToMatch   = PersonalizationProviderHelper.CheckAndTrimString(
                        query.UsernameToMatch, "query.UsernameToMatch", false, MaxStringLength);
                }

                return(FindUserState(pathToMatch, inactiveSinceDate, usernameToMatch,
                                     pageIndex, pageSize, out totalRecords));
            }
        }
Пример #3
0
        public override int ResetUserState(string path, DateTime userInactiveSinceDate)
        {
            path = PersonalizationProviderHelper.CheckAndTrimString(path, "path", false, MaxStringLength);

            AccessConnectionHolder connectionHolder = null;
            OleDbConnection        connection       = null;
            int count = 0;


            try {
                try {
                    connectionHolder = GetConnectionHolder();
                    connection       = connectionHolder.Connection;

                    // Special note: OleDbProvider requires the parameters to be added
                    // in the same order as appearing in the query text.

                    string getDeleteUserStateCount =
                        "SELECT COUNT(*)" +
                        " FROM aspnet_PagePersonalizationPerUser PerUser, aspnet_Users Users, aspnet_Paths Paths" +
                        " WHERE PerUser.UserId = Users.UserId AND PerUser.PathId = Paths.PathId" +
                        " AND Paths.ApplicationId = @ApplicationId" +
                        " AND Users.LastActivityDate <= @InactiveSinceDate";

                    string deleteUserState =
                        "DELETE FROM aspnet_PagePersonalizationPerUser" +
                        " WHERE Id IN (SELECT PerUser.Id " +
                        " FROM aspnet_PagePersonalizationPerUser PerUser, aspnet_Users Users, aspnet_Paths Paths" +
                        " WHERE PerUser.UserId = Users.UserId AND PerUser.PathId = Paths.PathId" +
                        " AND Paths.ApplicationId = @ApplicationId" +
                        " AND Users.LastActivityDate <= @InactiveSinceDate";

                    // Get the count of records that would be deleted
                    OleDbCommand command = new OleDbCommand();
                    command.Connection = connection;
                    OleDbParameterCollection parameters = command.Parameters;
                    OleDbParameter           parameter;

                    int appId = GetApplicationID(connectionHolder);
                    parameters.AddWithValue("ApplicationId", appId);

                    // Note: OleDb provider does not handle datetime that has non-
                    // zero millisecond, so it needs to be rounded up.
                    parameter       = parameters.Add("InactiveSinceDate", OleDbType.DBTimeStamp);
                    parameter.Value = new DateTime(userInactiveSinceDate.Year, userInactiveSinceDate.Month, userInactiveSinceDate.Day,
                                                   userInactiveSinceDate.Hour, userInactiveSinceDate.Minute, userInactiveSinceDate.Second);

                    if (path != null)
                    {
                        const string pathParamQueryText = " AND Paths.Path = @Path";
                        getDeleteUserStateCount += pathParamQueryText;
                        deleteUserState         += pathParamQueryText;
                        parameters.AddWithValue("Path", path);
                    }
                    deleteUserState += ")";

                    command.CommandText = getDeleteUserStateCount;

                    object lookupResult = command.ExecuteScalar();
                    if ((lookupResult != null) && (lookupResult is Int32))
                    {
                        count = (Int32)lookupResult;
                        if (count > 0)
                        {
                            // Do the actual deletion
                            command.CommandText = deleteUserState;
                            command.ExecuteNonQuery();
                        }
                    }
                }
                finally {
                    if (connectionHolder != null)
                    {
                        connectionHolder.Close();
                        connectionHolder = null;
                    }
                }
            }
            catch {
                throw;
            }

            return(count);
        }