private static void EnsureCache(ContentItem item, string propertyName) { if (!s_Dictionary.ContainsKey(item.ID)) { lock (s_Lock) { if (!s_Dictionary.ContainsKey(item.ID)) { s_Dictionary.Add(item.ID, new Dictionary <string, LinkItemCollection>()); } } } if (!s_Dictionary[item.ID].ContainsKey(propertyName)) { lock (s_Lock) { if (!s_Dictionary[item.ID].ContainsKey(propertyName)) { string value = item.GetDetail <string>(propertyName, string.Empty); if (!string.IsNullOrEmpty(value)) { LinkItemCollection coll = Parse(value); s_Dictionary[item.ID].Add(propertyName, coll); } } } } }
public override void UpdateEditor(ContentItem item, Control editor) { LinkItemCollection coll = LinkItemCollection.FindByPageAndPropertyName(item, Name); List <ILinkItemCollectionPlugin> plugins = PluginTypesAvailable != null ? LinkItemCollection.PluginList.Where(x => PluginTypesAvailable.Contains(x.GetType())).ToList() : new List <ILinkItemCollectionPlugin>(); ((LinkEditorControl)editor).Initialize(item, coll.ToJSONString(), plugins, coll == null ? 0 : coll.Count, !DisableLinksOption, !DisableImageOption); }
public static bool TryParse(string json, out LinkItemCollection links) { try { links = Parse(json); return(true); } catch (Exception) { links = Empty; return(false); } }
public string Rebase(string value, string fromAppPath, string toAppPath) { //The value being passed in is the raw JSON value stored for the property //We need to identify all links that need to be rebased LinkItemCollection coll = LinkItemCollection.Empty; if (LinkItemCollection.TryParse(value, out coll)) { foreach (LinkItemBase item in coll) { item.RebaseLinkItem(fromAppPath, toAppPath); } } return(coll.ToJSONString()); }
private static LinkItemCollection Parse(string json) { LinkItemCollection coll = new LinkItemCollection(); Dictionary <string, object>[] jsonItems = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(json); LinkItemBase[] arrLinkItemBase = new LinkItemBase[jsonItems.Length]; //Execute this in parallel if possible to save time with json serialization/deserization for child items Parallel.ForEach(jsonItems, (x, state, index) => { Dictionary <string, object> dic = (Dictionary <string, object>)x; string linkType = dic["LinkTypeString"].ToString(); //HACK: Find a better way of doing this - we dont want to have to serialize/deserialize this again! //Need a good way of initially getting the array elements string json2 = JsonConvert.SerializeObject(dic); LinkItemBase itemBase = null; if (linkType == "Image") { itemBase = JsonConvert.DeserializeObject <ImageItem>(json2); } else if (linkType == "Internal") { itemBase = JsonConvert.DeserializeObject <InternalLinkItem>(json2); } else if (linkType == "External") { itemBase = JsonConvert.DeserializeObject <ExternalLinkItem>(json2); } else if (linkType == "Document") { itemBase = JsonConvert.DeserializeObject <DocumentItem>(json2); } else { if (PluginList != null) { ILinkItemCollectionPlugin plugin = PluginList.Find(y => y.Name == linkType); if (plugin != null) { itemBase = JsonConvert.DeserializeObject(json2, plugin.PluginType) as LinkItemBase; if (itemBase == null) { throw new Exception("The following json string for linkType " + linkType + " could not be parsed: " + json2); } } } } itemBase.SortOrder = (int)index; arrLinkItemBase[index] = itemBase; }); //Add the array items to the LinkItemCollection coll.AddRange(arrLinkItemBase); return(coll); }