Beispiel #1
0
        private int ResetUserState(ResetUserStateMode mode, DateTime userInactiveSinceDate, string[] paths, string[] usernames)
        {
            var connection = new MySQLPersonalizationConnectionHelper(connectionString);

            connection.OpenConnection(true);

            try
            {
                if (ResetUserStateMode.PerInactiveDate == mode)
                {
                    return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate.ToUniversalTime(), null, null, connection));
                }
                if (ResetUserStateMode.PerPaths == mode)
                {
                    return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate, null, paths, connection));
                }
                else
                {
                    return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetUserState(ApplicationId, userInactiveSinceDate, usernames, paths, connection));
                }
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - ResetUserState");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Writes personalization state corresponding to a specified user and a specified page as an opaque blob to the database.
        /// </summary>
        /// <param name="webPartManager">The web part manager.</param>
        /// <param name="path">The path indicating where to save the data.</param>
        /// <param name="userName">The user name.</param>
        /// <param name="dataBlob">A byte array containing the data to be saved.</param>
        /// <remarks>If userName is <c>null</c>, then the personalization state is shared state and is not keyed by user name.</remarks>
        protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, Byte[] dataBlob)
        {
            MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                connection.OpenConnection(true);
                if (!string.IsNullOrEmpty(userName))
                {
                    PersonalizationProviderProcedures.my_aspnet_PersonalizationPerUser_SetPageSettings(ApplicationId, userName, path, dataBlob, DateTime.UtcNow, connection);
                }
                else
                {
                    PersonalizationProviderProcedures.my_aspnet_PersonalizationAllUsers_SetPageSettings(ApplicationId, path, dataBlob, DateTime.UtcNow, connection);
                }
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - SavePersonalizationBlob");
                }
                throw;
            }
        }
Beispiel #3
0
        private int GetCountUserState(string path, DateTime userInactiveSinceDate, string userName)
        {
            MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                connection.OpenConnection(true);
                return(PersonalizationProviderProcedures.myaspnet_PersonalizationAdministration_GetCountOfState(
                           false, ApplicationName, ApplicationId, path,
                           userName, userInactiveSinceDate, connection));
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - GetCountUserState");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Deletes personalization state corresponding to a specified user and a specified page from the database.
        /// </summary>
        /// <param name="webPartManager">The web part manager.</param>
        /// <param name="path">The path indicating where to save the data.</param>
        /// <param name="userName">The user name.</param>
        protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
        {
            MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

            connection.OpenConnection(true);
            try
            {
                if (string.IsNullOrEmpty(userName))
                {
                    PersonalizationProviderProcedures.my_aspnet_PersonalizationAllUsers_ResetPageSettings(ApplicationId, path, connection);
                }
                else
                {
                    PersonalizationProviderProcedures.my_aspnet_PersonalizationPerUser_ResetPageSettings(ApplicationId, userName, path, DateTime.UtcNow, connection);
                }
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - ResetPersonalizationBlob");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Retrieves personalization state as opaque blobs from the data source.
        /// </summary>
        /// <param name="webPartManager">The web part manager.</param>
        /// <param name="path">The path indicating where to save the data.</param>
        /// <param name="userName">The user name.</param>
        /// <param name="sharedDataBlob">A byte array containing the user shared data to loaded.</param>
        /// <param name="userDataBlob">A byte array containing the user data to be loaded.</param>
        /// <remarks>Retrieves both shared and user personalization state corresponding to a specified user and a specified page.</remarks>
        protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref Byte[] sharedDataBlob, ref Byte[] userDataBlob)
        {
            sharedDataBlob = null;
            userDataBlob   = null;
            MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

            connection.OpenConnection(true);
            try
            {
                sharedDataBlob = PersonalizationProviderProcedures.my_aspnet_PersonalizationAllUsers_GetPageSettings(
                    ApplicationId, path, connection);
                if (!String.IsNullOrEmpty(userName))
                {
                    userDataBlob = PersonalizationProviderProcedures.my_aspnet_PersonalizationPerUser_GetPageSettings(
                        ApplicationId, path, userName, DateTime.UtcNow, connection);
                }

                connection.CloseConnection();
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - LoadPersonazalitionBlobs");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Deletes personalization state corresponding to the specified users and specified pages from the database.
        /// </summary>
        /// <param name="scope">The personalization scope.</param>
        /// <param name="paths">The paths indicating where to save the data.</param>
        /// <param name="usernames">The user names.</param>
        /// <returns></returns>
        public override int ResetState(PersonalizationScope scope, string[] paths, string[] usernames)
        {
            bool hasPaths = !(paths == null || paths.Length == 0);
            bool hasUsers = !(usernames == null || usernames.Length == 0);

            var count = 0;

            var connection = new MySQLPersonalizationConnectionHelper(connectionString);

            connection.OpenConnection(true);

            if (scope == PersonalizationScope.Shared)
            {
                try
                {
                    if (paths == null) // reset all state
                    {
                        return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_DeleteAllState(true, ApplicationId, connection));
                    }
                    else
                    {
                        return(PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_ResetSharedState(ApplicationId, paths, connection));
                    }
                }
                catch (Exception ex)
                {
                    if (writeExceptionsToEventLog)
                    {
                        WriteToEventLog(ex, "MySQLPersonalizationProvider - ResetState");
                    }
                    throw;
                }
                finally
                {
                    connection.CloseConnection();
                }
            }
            else
            {
                DateTime dateTime = Convert.ToDateTime("2038-01-19 03:14:07.999999"); // MySQL TimeStamp MaxValue

                if (!hasPaths && !hasUsers)
                {
                    count = PersonalizationProviderProcedures.my_aspnet_PersonalizationAdministration_DeleteAllState(true, ApplicationId, connection);
                }
                else if (!hasUsers)
                {
                    count = ResetUserState(ResetUserStateMode.PerPaths, dateTime, paths, null);
                }
                else
                {
                    count = ResetUserState(ResetUserStateMode.PerUsers, dateTime, paths, usernames);
                }
            }
            return(count);
        }
Beispiel #7
0
        private PersonalizationStateInfoCollection FindSharedState(string path, int pageIndex, int pageSize, out int totalRecords)
        {
            MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                connection.OpenConnection(true);
                totalRecords = PersonalizationProviderProcedures.myaspnet_PersonalizationAdministration_FindState(true, ApplicationId, ApplicationName, pageIndex, pageSize,
                                                                                                                  path, null, DateTime.MinValue, connection, ref cmd);

                PersonalizationStateInfoCollection sharedStateInfoCollection = new PersonalizationStateInfoCollection();

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string   pathQuery       = reader.GetString("Path");
                        DateTime lastUpdatedDate = (reader.IsDBNull(1)) ? DateTime.MinValue :
                                                   DateTime.SpecifyKind(reader.GetDateTime(1), DateTimeKind.Utc);
                        int size           = (reader.IsDBNull(2)) ? 0 : reader.GetInt32("SharedDataLength");
                        int userDataLength = (reader.IsDBNull(3)) ? 0 : reader.GetInt32("UserDataLength");
                        int userCount      = (reader.IsDBNull(4)) ? 0 : reader.GetInt32("UserCount");

                        sharedStateInfoCollection.Add(new SharedPersonalizationStateInfo(
                                                          pathQuery, lastUpdatedDate, size, userDataLength, userCount));
                    }
                }
                connection.CloseConnection();
                return(sharedStateInfoCollection);
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - FindSharedState");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }
Beispiel #8
0
        private PersonalizationStateInfoCollection FindUserState(string path, DateTime inactiveSinceDate, string userName, int pageIndex, int pageSize, out int totalRecords)
        {
            MySQLPersonalizationConnectionHelper connection = new MySQLPersonalizationConnectionHelper(connectionString);

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                connection.OpenConnection(true);
                totalRecords = PersonalizationProviderProcedures.myaspnet_PersonalizationAdministration_FindState(false, ApplicationId, ApplicationName, pageIndex, pageSize,
                                                                                                                  path, userName, inactiveSinceDate, connection, ref cmd);

                PersonalizationStateInfoCollection stateInfoCollection = new PersonalizationStateInfoCollection();

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string   pathQuery        = reader.GetString("Path");
                        DateTime lastUpdatedDate  = DateTime.SpecifyKind(reader.GetDateTime("LastUpdatedDate"), DateTimeKind.Utc);
                        int      size             = reader.GetInt32("Size");
                        string   usernameQuery    = reader.GetString("name");
                        DateTime lastActivityDate = DateTime.SpecifyKind(reader.GetDateTime("LastActivityDate"), DateTimeKind.Utc);
                        stateInfoCollection.Add(new UserPersonalizationStateInfo(pathQuery, lastActivityDate, size, usernameQuery, lastActivityDate));
                    }
                }
                connection.CloseConnection();

                return(stateInfoCollection);
            }
            catch (Exception ex)
            {
                if (writeExceptionsToEventLog)
                {
                    WriteToEventLog(ex, "MySQLPersonalizationProvider - FindUserState");
                }
                throw;
            }
            finally
            {
                connection.CloseConnection();
            }
        }