public Response StoreInspectExpando(ExpandoObject theExpando, ContentItem theContentItem) { try { foreach (var kvp in theExpando) { string key = kvp.Key.ToString(); string valueType = kvp.Value.GetType().Name; object value = kvp.Value; if (kvp.Value is ExpandoObject) { StoreInspectExpando(kvp.Value as ExpandoObject, theContentItem); } _utilsServices.StoreInspectExpandoFields(theContentItem.Parts.ToList(), key, value); } } catch (Exception ex) { Log.Error("ContentExtension -> ContentExtensionService -> StoreInspectExpando : " + ex.Message + " <Stack> " + ex.StackTrace); return(_utilsServices.GetResponse(ResponseType.None, "Error:" + ex.Message)); } return(StoreInspectExpandoPart(theExpando, theContentItem)); }
public void StoreLikeDynamic(ContentItem item, string[] listProperty, object value) { dynamic subobject = item.Parts.Where(x => x.PartDefinition.Name == listProperty[0]).FirstOrDefault(); if (subobject == null) { throw new Exception("Part " + listProperty[0] + " not exist"); } Int32 numparole = listProperty.Count(); for (int i = 1; i < numparole; i++) { string property = listProperty[i]; if (i != numparole - 1) { subobject = subobject.GetType().GetProperty(property); } else { // prova a salvarlo come proprietà try { subobject.GetType().GetProperty(property).SetValue(subobject, Convert.ChangeType(value, subobject.GetType().GetProperty(property).PropertyType), null); // potrei ancora tentare di scrivere direttamente con // subobject.GetType().GetProperty(property).SetValue(subobject, value, null); } catch { // ignora volutamente eventuali errori } // prova a salvarlo come field try { List <ContentPart> lcp = new List <ContentPart>(); lcp.Add((ContentPart)subobject); _utilsServices.StoreInspectExpandoFields(lcp, property, value); } catch { // ignora volutamente eventuali errori } } } }
private void CopyProfilePart(ContentItem src, ContentItem dest) { if ((((dynamic)src).ProfilePart != null) && (((dynamic)dest).ProfilePart != null)) { List <ContentPart> Lcp = new List <ContentPart>(); ContentPart destProfile = (ContentPart)((dynamic)dest).ProfilePart; Lcp.Add(destProfile); foreach (dynamic cf in ((dynamic)src).ProfilePart.Fields) { if (cf is ICustomField) { // laser custom field type var valueList = ((ICustomField)cf).GetFieldValueList(); if (valueList != null) { var destField = (ICustomField)(destProfile.Fields.FirstOrDefault(x => x.Name == cf.Name)); foreach (var val in valueList) { destField.SetFieldValue(val.ValueName, val.Value); } } } else // orchard base field type { object myval; if (cf.FieldDefinition.Name == typeof(DateTimeField).Name) { myval = ((object)(((dynamic)cf).DateTime)); } else if (cf.FieldDefinition.Name == typeof(MediaLibraryPickerField).Name || cf.FieldDefinition.Name == typeof(ContentPickerField).Name) { myval = ((Int32[])cf.Ids).ToList().Select(x => (object)x).ToList(); } else if (cf.FieldDefinition.Name == typeof(TaxonomyField).Name) { List <TaxoVM> second = new List <TaxoVM>(); var selectedTerms = _taxonomyService.GetTermsForContentItem(src.Id, ((ContentField)cf).Name); foreach (TermPart tp in selectedTerms) { TaxoVM tv = new TaxoVM(); tv.Id = tp.Id; tv.flag = true; second.Add(tv); } myval = second; } else if (cf.FieldDefinition.Name == typeof(LinkField).Name) { LinkField linkField = (LinkField)cf; var second = new LinkVM(); second.Url = linkField.Value; second.Text = linkField.Text; myval = second; } else { myval = ((object)(((dynamic)cf).Value)); } _utilsServices.StoreInspectExpandoFields(Lcp, ((string)(cf.Name)), myval); } } } }