public override void DeleteValue(string cUid) { CustomPageEntity cpe = Mediachase.IBN.Business.WidgetEngine.CustomPageManager.GetCustomPage(pageUid, profileId, userId); if (cpe == null) { throw new ArgumentException(string.Format("Page not found for pageUid: {0} profileId: {1} userId: {2}", pageUid, profileId, userId)); } XmlDocument doc = new XmlDocument(); if (String.IsNullOrEmpty(cpe.PropertyJsonData)) { doc.AppendChild(doc.CreateElement("ControlProperties")); cpe.PropertyJsonData = doc.OuterXml; } else { doc.LoadXml(cpe.PropertyJsonData); } XmlNode controlNode = doc.DocumentElement.SelectSingleNode(cUid); if (controlNode != null) { doc.DocumentElement.RemoveChild(controlNode); } //todo: to debug Mediachase.IBN.Business.WidgetEngine.CustomPageManager.UpdateCustomPageProperty(pageUid, doc.OuterXml, profileId, userId); }
private int CustomPageEntitySort(EntityObject x, EntityObject y) { CustomPageEntity xPage = x as CustomPageEntity; CustomPageEntity yPage = y as CustomPageEntity; // Global if (xPage == null && yPage == null) { return(0); } if (xPage == null) { return(1); } if (yPage == null) { return(-1); } // User if (xPage.UserId == null && yPage.UserId == null) { // Profile if (xPage.ProfileId == null && yPage.ProfileId == null) { // Global if (xPage.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName)) { return(1); } if (yPage.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName)) { return(-1); } } if (xPage.ProfileId == null) { return(1); } if (yPage.ProfileId == null) { return(-1); } } if (xPage.UserId == null) { return(1); } if (yPage.UserId == null) { return(-1); } return(0); }
/// <summary> /// Updates the custom page. /// </summary> /// <param name="uid">The page uid.</param> /// <param name="jsonData">The json data.</param> /// <param name="templateUid">The template uid.</param> /// <param name="profileId">The profile id.</param> /// <param name="userId">The user id.</param> public static void UpdateCustomPage(Guid uid, string jsonData, Guid templateUid, int?profileId, int?userId) { CustomPageEntity page = GetCustomPage(uid, profileId, userId); if (page == null) { throw new ArgumentException("The page is not found", "uid"); } CustomPageEntity updatedPage = page; bool isNew = false; if (userId.HasValue) { if (!(page.UserId.HasValue && page.UserId.Value == userId.Value)) // create new user page { updatedPage = BusinessManager.InitializeEntity <CustomPageEntity>(CustomPageEntity.ClassName); updatedPage.UserId = userId.Value; isNew = true; } } else if (profileId.HasValue) { if (!(page.ProfileId.HasValue && page.ProfileId.Value == profileId.Value)) // create new profile page { updatedPage = BusinessManager.InitializeEntity <CustomPageEntity>(CustomPageEntity.ClassName); updatedPage.ProfileId = profileId.Value; isNew = true; } } else { if (page.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName)) // create new site page { updatedPage = BusinessManager.InitializeEntity <CustomPageEntity>(CustomPageEntity.ClassName); isNew = true; } } updatedPage.TemplateId = templateUid; updatedPage.JsonData = jsonData; if (isNew) { updatedPage.Uid = page.Uid; updatedPage.Title = page.Title; updatedPage.Description = page.Description; updatedPage.Icon = page.Icon; updatedPage.PropertyJsonData = page.PropertyJsonData; BusinessManager.Create(updatedPage); } else { BusinessManager.Update(updatedPage); } }
/// <summary> /// Creates the entity object. /// </summary> /// <param name="metaClassName">Name of the meta class.</param> /// <param name="primaryKeyId">The primary key id.</param> /// <returns></returns> protected override EntityObject CreateEntityObject(string metaClassName, PrimaryKeyId?primaryKeyId) { if (metaClassName == CustomPageEntity.ClassName) { CustomPageEntity retVal = new CustomPageEntity(); retVal.PrimaryKeyId = primaryKeyId; return(retVal); } return(base.CreateEntityObject(metaClassName, primaryKeyId)); }
public override object GetValue(string cUid, string key) { string uid = GetKey(cUid, key); CustomPageEntity cpe = Mediachase.IBN.Business.WidgetEngine.CustomPageManager.GetCustomPage(pageUid, profileId, userId); if (cpe == null) { throw new ArgumentException(string.Format("Page not found for pageUid: {0} profileId: {1} userId: {2}", pageUid, profileId, userId)); } XmlDocument doc = new XmlDocument(); if (String.IsNullOrEmpty(cpe.PropertyJsonData)) { doc.AppendChild(doc.CreateElement("ControlProperties")); cpe.PropertyJsonData = doc.OuterXml; } else { doc.LoadXml(cpe.PropertyJsonData); } string value = string.Empty; XmlNode valNode = doc.DocumentElement.SelectSingleNode(string.Format("{0}/{1}", cUid, key)); if (valNode != null) { value = valNode.InnerText; } //else //{ // value = PortalConfig.GetValue(uid); //} if (String.IsNullOrEmpty(value)) { return(null); } // Step 1. String to XmlSerializedItem value = value.Trim(); XmlSerializedItem item = McXmlSerializer.GetObject <XmlSerializedItem>(value); // Step 2. XmlSerializedItem to object return(McXmlSerializer.GetObject(item.Type, item.Data)); }
public void Execute(BusinessContext context) { if (context.Request.Parameters.Contains("CustomPageNormalizationPlugin") && !(bool)context.Request.Parameters["CustomPageNormalizationPlugin"].Value) { return; } ListResponse response = context.Response as ListResponse; if (response != null) { List <EntityObject> items = new List <EntityObject>(response.EntityObjects); if (items.Count > 0) { items.Sort(CustomPageEntitySort); } Hashtable uidHash = new Hashtable(); List <EntityObject> resultItem = new List <EntityObject>(); foreach (CustomPageEntity item in items) { if (uidHash.ContainsKey(item.Uid)) { CustomPageEntity topElement = (CustomPageEntity)uidHash[item.Uid]; topElement[FieldNameCreatedLevel] = GetLevel(item); } else { resultItem.Add(item); uidHash.Add(item.Uid, item); item[FieldNameCreatedLevel] = GetLevel(item); item[FieldNameModifiedLevel] = GetLevel(item); } } response.EntityObjects = resultItem.ToArray(); } }
/// <summary> /// Gets the level. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private CustomPageLevel GetLevel(CustomPageEntity item) { if (item.UserId.HasValue) { return(CustomPageLevel.User); } if (item.ProfileId.HasValue) { return(CustomPageLevel.Profile); } if (item.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName)) { return(CustomPageLevel.Disk); } return(CustomPageLevel.Global); }
/// <summary> /// Gets the level. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private CustomPageLevel GetLevel(CustomPageEntity item) { if (item.UserId.HasValue) return CustomPageLevel.User; if (item.ProfileId.HasValue) return CustomPageLevel.Profile; if (item.Properties.Contains(LocalDiskEntityObjectPlugin.IsLoadDiskEntityPropertyName)) return CustomPageLevel.Disk; return CustomPageLevel.Global; }
/// <summary> /// Gets the custom page. /// </summary> /// <param name="uid">The page uid.</param> /// <param name="profileId">The profile id.</param> /// <param name="userId">The user id.</param> /// <returns></returns> public static CustomPageEntity GetCustomPage(Guid uid, int?profileId, int?userId) { FilterElementCollection filters = new FilterElementCollection(); filters.Add(FilterElement.EqualElement(CustomPageEntity.FieldUid, uid)); if (userId.HasValue) // User layer { if (!profileId.HasValue) { profileId = ProfileManager.GetProfileIdByUser(userId.Value); } // ProfileId is null AND UserId is null AndBlockFilterElement andBlock1 = new AndBlockFilterElement(); andBlock1.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId)); andBlock1.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId)); // ProfileId = value AND UserId is null AndBlockFilterElement andBlock2 = new AndBlockFilterElement(); andBlock2.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldProfileId, profileId.Value)); andBlock2.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId)); // ProfileId is null AND UserId = value AndBlockFilterElement andBlock3 = new AndBlockFilterElement(); andBlock3.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId)); andBlock3.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldUserId, userId.Value)); OrBlockFilterElement orBlock = new OrBlockFilterElement(); orBlock.ChildElements.Add(andBlock1); orBlock.ChildElements.Add(andBlock2); orBlock.ChildElements.Add(andBlock3); filters.Add(orBlock); } else if (profileId.HasValue) // Profile layer { filters.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId)); OrBlockFilterElement orBlock = new OrBlockFilterElement(); orBlock.ChildElements.Add(FilterElement.EqualElement(CustomPageEntity.FieldProfileId, profileId.Value)); orBlock.ChildElements.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId)); filters.Add(orBlock); } else // Site layer { filters.Add(FilterElement.IsNullElement(CustomPageEntity.FieldProfileId)); filters.Add(FilterElement.IsNullElement(CustomPageEntity.FieldUserId)); } EntityObject[] pages = BusinessManager.List(CustomPageEntity.ClassName, filters.ToArray()); CustomPageEntity retval = null; if (pages.Length > 0) { retval = (CustomPageEntity)pages[0]; } return(retval); }
public override void SaveValue(string cUid, string key, object value) { string uid = GetKey(cUid, key); CustomPageEntity cpe = Mediachase.IBN.Business.WidgetEngine.CustomPageManager.GetCustomPage(pageUid, profileId, userId); if (cpe == null) { throw new ArgumentException(string.Format("Page not found for pageUid: {0} profileId: {1} userId: {2}", pageUid, profileId, userId)); } XmlDocument doc = new XmlDocument(); if (String.IsNullOrEmpty(cpe.PropertyJsonData)) { doc.AppendChild(doc.CreateElement("ControlProperties")); cpe.PropertyJsonData = doc.OuterXml; } else { doc.LoadXml(cpe.PropertyJsonData); } XmlNode controlNode = doc.DocumentElement.SelectSingleNode(cUid); if (controlNode == null) { controlNode = doc.CreateElement(cUid); doc.DocumentElement.AppendChild(controlNode); } XmlNode keyNode = controlNode.SelectSingleNode(key); if (keyNode == null) { keyNode = doc.CreateElement(key); controlNode.AppendChild(keyNode); } if (value == null) { keyNode.InnerText = ControlProperties._nullValueKey; } else if (value is string && string.Empty == ((string)value)) { keyNode.InnerText = string.Empty; } else { // Step 1. Object to XmlSerializedItem string typeName = null; if (value.GetType().IsGenericType) { typeName = AssemblyUtil.GetTypeString(value.GetType().FullName, value.GetType().Assembly.GetName().Name); } else { typeName = AssemblyUtil.GetTypeString(value.GetType().ToString(), value.GetType().Assembly.GetName().Name); } XmlSerializedItem item = new XmlSerializedItem(typeName, McXmlSerializer.GetString(value.GetType(), value)); // Step 2. XmlSerializedItem to string keyNode.InnerText = McXmlSerializer.GetString <XmlSerializedItem>(item); } //todo: to debug Mediachase.IBN.Business.WidgetEngine.CustomPageManager.UpdateCustomPageProperty(pageUid, doc.OuterXml, profileId, userId); }
/// <summary> /// Templates the change. /// </summary> /// <param name="page">The page.</param> private void TemplateChange(CustomPageEntity page) { string userSettings = page.JsonData; List<CpInfo> list = UtilHelper.JsonDeserialize<List<CpInfo>>(userSettings); WorkspaceTemplateInfo wti = WorkspaceTemplateFactory.GetTemplateInfo(this.selectedUid.ToString()); if (wti == null) throw new NullReferenceException(String.Format("Cant find template: {0}", this.selectedUid)); List<ColumnInfo> templateColumn = UtilHelper.JsonDeserialize<List<ColumnInfo>>(wti.ColumnInfo); if (templateColumn.Count == 0) throw new ArgumentException("Template must contain minumum 1 column"); if (list.Count == 0) throw new ArgumentException("Invalid workspace personalize data"); int counter = 0; ArrayList deletedItems = new ArrayList(); foreach (CpInfo info in list) { if (!templateColumn.Contains(new ColumnInfo(info.Id))) { info.Id = templateColumn[0].Id; if (counter > 0) { foreach (CpInfoItem item in info.Items) { list[0].Items.Add(item); } deletedItems.Add(info); } } counter++; } if (deletedItems.Count > 0) { foreach (CpInfo info in deletedItems) { list.Remove(info); } } string jsonData = UtilHelper.JsonSerialize(list); if (!this.IsAdmin) CustomPageManager.UpdateCustomPage(PageUid, jsonData, this.selectedUid, null, Mediachase.IBN.Business.Security.UserID); else CustomPageManager.UpdateCustomPage(PageUid, jsonData, this.selectedUid, ProfileId, UserId); }
/// <summary> /// Performs the save data. /// </summary> /// <param name="page">The page.</param> private void PerformSaveData(CustomPageEntity page) { string userData = page.JsonData; Guid templateUid = page.TemplateId; List<CpInfo> userList = UtilHelper.JsonDeserialize<List<CpInfo>>(userData.Replace("\\", "")); string jsonData = UtilHelper.JsonSerialize(userList); //Perform save to storage if (!IsAdmin) CustomPageManager.UpdateCustomPage(PageUid, jsonData, templateUid, null, Mediachase.IBN.Business.Security.UserID); else CustomPageManager.UpdateCustomPage(PageUid, jsonData, templateUid, ProfileId, UserId); }