Esempio n. 1
0
        public static SharedPersonalization Load(Int32 personalizationPathId, bool useCache)
        {
            if (personalizationPathId == 0)
            {
                return(null);
            }
            SharedPersonalization sharedPersonalization = null;
            string key = "SharedPersonalization_" + personalizationPathId.ToString();

            if (useCache)
            {
                sharedPersonalization = ContextCache.GetObject(key) as SharedPersonalization;
                if (sharedPersonalization != null)
                {
                    return(sharedPersonalization);
                }
            }
            sharedPersonalization = new SharedPersonalization();
            if (sharedPersonalization.Load(personalizationPathId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, sharedPersonalization);
                }
                return(sharedPersonalization);
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the shared personalization record for the given path.
        /// </summary>
        /// <param name="path">The path to the file to load data for</param>
        /// <param name="create">If true, the personalization record is created if
        /// it does not exist.</param>
        /// <returns>Thje shared personalization record for the given path</returns>
        public static SharedPersonalization LoadForPath(string path, bool create)
        {
            SharedPersonalization sharedPersonalization = null;
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT " + SharedPersonalization.GetColumnNames("acSP"));
            selectQuery.Append(" FROM ac_SharedPersonalization acSP, ac_PersonalizationPaths acP");
            selectQuery.Append(" WHERE acSP.PersonalizationPathId = acP.PersonalizationPathId AND acP.Path = @path AND acP.StoreId = @storeId");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@path", System.Data.DbType.String, path);
            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            //EXECUTE THE COMMAND
            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                if (dr.Read())
                {
                    sharedPersonalization = new SharedPersonalization();
                    SharedPersonalization.LoadDataReader(sharedPersonalization, dr);
                }
                dr.Close();
            }
            if ((sharedPersonalization == null) && create)
            {
                sharedPersonalization = new SharedPersonalization(PersonalizationPathDataSource.LoadForPath(path, true));
            }
            return(sharedPersonalization);
        }
Esempio n. 3
0
        public static bool Delete(Int32 personalizationPathId)
        {
            SharedPersonalization sharedPersonalization = new SharedPersonalization();

            if (sharedPersonalization.Load(personalizationPathId))
            {
                return(sharedPersonalization.Delete());
            }
            return(false);
        }
Esempio n. 4
0
 /// <summary>
 /// Saves raw personalization data to the underlying data store.
 /// </summary>
 /// <param name="webPartManager">The WebPartManager managing the personalization data.</param>
 /// <param name="path">The path for personalization information to be used as the data store key.</param>
 /// <param name="userName">The user name for personalization information to be used as the key.</param>
 /// <param name="dataBlob">The byte array of data to be saved.</param>
 protected override void SavePersonalizationBlob(System.Web.UI.WebControls.WebParts.WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
 {
     if (userName == null)
     {
         SharedPersonalization sharedPersonalization = SharedPersonalizationDataSource.LoadForPath(path, true);
         sharedPersonalization.PageSettings = dataBlob;
         sharedPersonalization.Save();
     }
     else
     {
         UserPersonalization userPersonalization = UserPersonalizationDataSource.LoadForPath(path, userName, true);
         userPersonalization.PageSettings = dataBlob;
         userPersonalization.Save();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Loads raw personalization data from the underlying data store.
        /// </summary>
        /// <param name="webPartManager">The WebPartManager managing the personalization data.</param>
        /// <param name="path">The path for personalization information to be used as the retrieval key.</param>
        /// <param name="userName">The user name for personalization information to be used as the retrieval key.</param>
        /// <param name="sharedDataBlob">The returned data for the Shared scope.</param>
        /// <param name="userDataBlob">The returned data for the User scope.</param>
        protected override void LoadPersonalizationBlobs(System.Web.UI.WebControls.WebParts.WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
        {
            sharedDataBlob = null;
            userDataBlob   = null;
            SharedPersonalization sharedPersonalization = SharedPersonalizationDataSource.LoadForPath(path, false);

            if (sharedPersonalization != null)
            {
                sharedDataBlob = sharedPersonalization.PageSettings;
            }
            UserPersonalization UserPersonalization = UserPersonalizationDataSource.LoadForPath(path, userName, false);

            if (UserPersonalization != null)
            {
                userDataBlob = UserPersonalization.PageSettings;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Deletes raw personalization data from the underlying data store.
 /// </summary>
 /// <param name="webPartManager">The WebPartManager managing the personalization data.</param>
 /// <param name="path">The path for personalization information to be used as the data store key.</param>
 /// <param name="userName">The user name for personalization information to be used as the data store key.</param>
 protected override void ResetPersonalizationBlob(System.Web.UI.WebControls.WebParts.WebPartManager webPartManager, string path, string userName)
 {
     if (string.IsNullOrEmpty(userName))
     {
         SharedPersonalization sharedPersonalization = SharedPersonalizationDataSource.LoadForPath(path, false);
         if (sharedPersonalization != null)
         {
             sharedPersonalization.Delete();
         }
     }
     else
     {
         UserPersonalization userPersonalization = UserPersonalizationDataSource.LoadForPath(path, userName, false);
         if (userPersonalization != null)
         {
             userPersonalization.Delete();
         }
     }
 }
Esempio n. 7
0
        public static SharedPersonalizationCollection  LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression)
        {
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            selectQuery.Append("SELECT");
            if (maximumRows > 0)
            {
                selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString());
            }
            selectQuery.Append(" " + SharedPersonalization.GetColumnNames(string.Empty));
            selectQuery.Append(" FROM ac_SharedPersonalization");
            string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria;

            selectQuery.Append(whereClause);
            if (!string.IsNullOrEmpty(sortExpression))
            {
                selectQuery.Append(" ORDER BY " + sortExpression);
            }
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());
            //EXECUTE THE COMMAND
            SharedPersonalizationCollection results = new SharedPersonalizationCollection();
            int thisIndex = 0;
            int rowCount  = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        SharedPersonalization sharedPersonalization = new SharedPersonalization();
                        SharedPersonalization.LoadDataReader(sharedPersonalization, dr);
                        results.Add(sharedPersonalization);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            return(results);
        }
Esempio n. 8
0
 public static SaveResult Insert(SharedPersonalization sharedPersonalization)
 {
     return(sharedPersonalization.Save());
 }
Esempio n. 9
0
 public static bool Delete(SharedPersonalization sharedPersonalization)
 {
     return(sharedPersonalization.Delete());
 }
Esempio n. 10
0
 public static SaveResult Update(SharedPersonalization sharedPersonalization)
 {
     return(sharedPersonalization.Save());
 }
Esempio n. 11
0
        /// <summary>
        /// Returns a collection containing zero or more PersonalizationStateInfo-derived objects based
        /// on scope and specific query parameters.
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecords"></param>
        /// <returns></returns>
        public static PersonalizationStateInfoCollection FindState(PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords)
        {
            PersonalizationStateInfoCollection tempResults = new PersonalizationStateInfoCollection();

            //USERNAMES ARE NOT ASSOCIATED WITH SHARED DATA
            //IF A USERNAME WAS SPECIFIED, RETURN AN EMPTY COLLECTION
            totalRecords = 0;
            if (!string.IsNullOrEmpty(query.UsernameToMatch))
            {
                return(tempResults);
            }
            //CREATE THE DYNAMIC SQL TO LOAD OBJECT
            StringBuilder selectQuery = new StringBuilder();

            //CHECK WHETHER TO LOAD ALL PATHS, OR TO FILTER
            selectQuery.Append("SELECT " + SharedPersonalization.GetColumnNames("S") + ",P.Path");
            selectQuery.Append(" FROM ac_SharedPersonalization S, ac_PersonalizationPaths P");
            selectQuery.Append(" WHERE S.PersonalizationPathId = P.PersonalizationPathId AND P.StoreId = @storeId");
            if (!string.IsNullOrEmpty(query.PathToMatch))
            {
                selectQuery.Append(" AND P.Path LIKE @pathToMatch");
            }
            selectQuery.Append(" ORDER BY P.Path");
            Database  database      = Token.Instance.Database;
            DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString());

            database.AddInParameter(selectCommand, "@storeId", System.Data.DbType.Int32, Token.Instance.StoreId);
            if (!string.IsNullOrEmpty(query.PathToMatch))
            {
                database.AddInParameter(selectCommand, "@pathToMatch", System.Data.DbType.String, query.PathToMatch);
            }
            //EXECUTE THE COMMAND
            int startRowIndex = (pageIndex * pageSize);
            int thisIndex     = 0;
            int rowCount      = 0;

            using (IDataReader dr = database.ExecuteReader(selectCommand))
            {
                while (dr.Read() && ((rowCount < pageSize)))
                {
                    if (thisIndex >= startRowIndex)
                    {
                        SharedPersonalization p = new SharedPersonalization();
                        SharedPersonalization.LoadDataReader(p, dr);
                        SharedPersonalizationStateInfo i = new SharedPersonalizationStateInfo(dr.GetString(5), p.LastUpdatedDate, p.PageSettings.Length, 0, 0);
                        tempResults.Add(i);
                        rowCount++;
                    }
                    thisIndex++;
                }
                dr.Close();
            }
            totalRecords = rowCount;
            //LOOP RESULTS AND COMPILE USER STATISICS
            int size, count;
            PersonalizationStateInfoCollection results = new PersonalizationStateInfoCollection();

            foreach (SharedPersonalizationStateInfo i in tempResults)
            {
                UserPersonalizationDataSource.CountForPath(i.Path, out size, out count);
                results.Add(new SharedPersonalizationStateInfo(i.Path, i.LastUpdatedDate, i.Size, size, count));
            }
            return(results);
        }