public int Compare(OThinker.H3.Site.SiteWebPartInstanceValue x, OThinker.H3.Site.SiteWebPartInstanceValue y) { if (x == null) { if (y == null) { return(0); } else { return(-1); } } else { if (y == null) { return(1); } else { int value = x.SortKey.CompareTo(y.SortKey); if (value == 0) { value = x.AttributeName.CompareTo(y.AttributeName); } return(value); } } }
/// <summary> /// 添加插件到页面,保存时 /// </summary> /// <param name="webpartId">部件id,唯一部件</param> /// <param name="pageId">00000000-0000-0000-0000-000000000000 Guid.NewGuid().ToString()</param> /// <param name="part">部件显示区域</param> /// <param name="webpartname"></param> public Dictionary <string, string> AddWebPartToPage(string webpartId, string pageId, string part, string webpartname) { Dictionary <string, string> result = new Dictionary <string, string>(); OThinker.H3.Site.SitePage page = this.Engine.SiteManager.GetPage(pageId); if (page == null || page == default(OThinker.H3.Site.SitePage)) { result.Add("Error", "页面不存在"); return(result); } SiteWebPartInstance inst = new SiteWebPartInstance(); int recordCount = 0; int pageCount = 0; SiteWebPartInstance[] webparts = this.Engine.SiteManager.GetAllWebPartInsts(); if (webparts != null && webparts.Length > 0) { int i = 0; foreach (SiteWebPartInstance webpart in webparts) { if (webpart.PagePart == part && webpart.PageId == pageId) { i++; } } recordCount = i; pageCount = recordCount % 1 > 0 ? recordCount / 1 + 1 : recordCount / 1; } inst.CreatedTime = DateTime.Now; inst.CreatedBy = UserValidatorFactory.CurrentUser.UserID; inst.PageId = pageId; inst.PagePart = part; inst.SortKey = recordCount + 1; inst.WebPartId = webpartId; List <SiteWebPartInstanceValue> source = new List <SiteWebPartInstanceValue>(); OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue(); obj.AttributeName = "Title"; obj.AttributeType = AttributeType.PublicAttribute; obj.AttributeValue = webpartname; obj.InstanceId = webpartId; obj.ParentIndex = 1; source.Add(obj); inst.Attributes = source.ToArray(); this.Engine.SiteManager.AddWebPartInst(inst); result.Add("Success", inst.ObjectID); this.InstId = inst.ObjectID; return(result); }
/// <summary> /// 统一保存配置 /// </summary> /// <param name="dict"></param> private void SaveConfigs(Dictionary <string, object> dict, AttributeType AttrType) { string instId = this.InstId; if (string.IsNullOrEmpty(instId)) { return; } //先找到PluginInstVal 对象,先删除再重新添加 SiteWebPartInstance instance = Engine.SiteManager.GetWebPartInst(instId); if (instance != null) { List <SiteWebPartInstanceValue> source = new List <SiteWebPartInstanceValue>(); if (instance.Attributes != null) { source = instance.Attributes.ToList(); var values = source.Where(e => e.AttributeType == AttrType).ToList(); if (values != null) { foreach (var value in values) { source.Remove((SiteWebPartInstanceValue)value); } } } //移除缓存,如果有的话 //PortalCache<string, string, string>.Instance.FindItem(PortalConst.CacheName_WebPartInstContent).Remove(instId); List <string> attrinfo = null; foreach (var pv in dict) { //如果不存在,就不保存了,确保属性一定要定义 if (!IsAttribteExists(pv.Key, AttrType)) { continue; } attrinfo = GetAttributeTypeAndFormat(pv.Key, AttrType); //多值状态,一个属性多个值,用List<string>传进来,其余的都用string if (pv.Value is List <string> ) { List <string> multiattrs = pv.Value as List <string>; int ix = 1;//给多值保存一个顺序 foreach (string str in multiattrs) { OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue(); obj.AttributeName = pv.Key; obj.AttributeType = AttrType; obj.AttributeValue = str; // obj.BindType = attrinfo[0]; obj.Format = attrinfo[1]; obj.InstanceId = instId; obj.ParentIndex = ix; ix++; source.Add(obj); } } else { OThinker.H3.Site.SiteWebPartInstanceValue obj = new OThinker.H3.Site.SiteWebPartInstanceValue(); obj.AttributeName = pv.Key; obj.AttributeType = AttrType; obj.AttributeValue = pv.Value.ToString(); // obj.BindType = attrinfo[0]; obj.Format = attrinfo[1]; obj.InstanceId = instId; source.Add(obj); } } instance.Attributes = source.ToArray(); Engine.SiteManager.UpdateWebPartInst(instance); } }