/// <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(); } }
/// <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; } }
/// <summary> /// Gets a collection of PersonalizationStateInfo objects for the given PersonalizationStateQuery /// </summary> /// <param name="scope">A PersonalizationScope with the personalization information to be queried. This value cannot be a null reference (Nothing in Visual Basic).</param> /// <param name="query">A PersonalizationStateQuery containing a query. This value can be a null reference (Nothing in Visual Basic).</param> /// <param name="pageIndex">The location where the query starts.</param> /// <param name="pageSize">The number of records to return.</param> /// <param name="totalRecords">The total number of records available.</param> /// <returns>A PersonalizationStateInfoCollection containing zero or more PersonalizationStateInfo-derived objects.</returns> public override System.Web.UI.WebControls.WebParts.PersonalizationStateInfoCollection FindState(System.Web.UI.WebControls.WebParts.PersonalizationScope scope, System.Web.UI.WebControls.WebParts.PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords) { if (pageIndex < 0) { throw new ArgumentException("pageIndex cannot be less than zero", "pageIndex"); } if (pageSize <= 0) { throw new ArgumentException("pageSize must be greater than zero", "pageSize"); } if (scope == System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared) { return(SharedPersonalizationDataSource.FindState(query, pageIndex, pageSize, out totalRecords)); } else { return(UserPersonalizationDataSource.FindState(query, pageIndex, pageSize, out totalRecords)); } }
/// <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(); } } }
/// <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); }