/// <summary> /// The convert data to source. /// </summary> /// <param name="propertyType"> /// The property type. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="preview"> /// The preview. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { var merchello = new MerchelloHelper(); if (source == null) return null; var collectionKey = source.ToString(); if (collectionKey.IsNullOrWhiteSpace()) { var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(10).OrderBy(ProductSortField.Name); //var defaultCollection = merchello.Query.Product.TypedProductContentSearch(1, 10); return new ProductContentListView(Guid.Empty, query.Execute().Items); } try { var key = new Guid(collectionKey); var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(long.MaxValue).ConstrainByCollectionKey(key); return new ProductContentListView(key, query.Execute().Items); } catch (Exception ex) { MultiLogHelper.Error<ProductListViewValueConverter>("Failed to Convert Merchello.ProductListView property", ex); return null; } }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { // in xml a string is: string // in the database a string is: string // default value is: null return source; }
public XmlPublishedProperty(PublishedPropertyType propertyType, bool isPreviewing, string propertyData) : this(propertyType, isPreviewing) { if (propertyData == null) throw new ArgumentNullException("propertyData"); _xmlValue = propertyData; }
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { if (source == null) return null; return Umbraco.TypedMedia(source); }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null) return null; var sourceString = source.ToString(); var links = JsonConvert.DeserializeObject<IEnumerable<LinksPickerItem>>(sourceString); foreach (var link in links) { try { link.Content = ( link.IsMedia ? umbHelper.TypedMedia(link.Id) : umbHelper.TypedContent(link.Id) ); link.Url = link.Content.Url; } catch (Exception) { } } return links; }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { try { if (source != null && !source.ToString().IsNullOrWhiteSpace()) { var oh = JsonConvert.DeserializeObject<Dictionary<DayOfWeek, WeekdayOpeningHours>>(source.ToString()); return oh; } } catch (Exception e) { LogHelper.Error<OpeningHoursValueConverter>("Error converting value", e); } // Create default model var dict = new Dictionary<DayOfWeek, WeekdayOpeningHours>(); for (var i = 0; i < 7; i++) { dict.Add((DayOfWeek)i, new WeekdayOpeningHours()); } return dict; }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { // data is (both in database and xml): // <keyFeatureList> // <values> // <value>Strong</value> // <value>Flexible</value> // <value>Efficient</value> // </values> // </keyFeatureList> var sourceString = source.ToString(); if (string.IsNullOrWhiteSpace(sourceString)) return Enumerable.Empty<string>(); var values = new List<string>(); var pos = sourceString.IndexOf("<value>", StringComparison.Ordinal); while (pos >= 0) { pos += "<value>".Length; var npos = sourceString.IndexOf("<", pos, StringComparison.Ordinal); var value = sourceString.Substring(pos, npos - pos); values.Add(value); pos = sourceString.IndexOf("<value>", pos, StringComparison.Ordinal); } return values.ToArray(); }
public XmlPublishedProperty(PublishedPropertyType propertyType, bool isPreviewing, XmlNode propertyXmlData) : this(propertyType, isPreviewing) { if (propertyXmlData == null) throw new ArgumentNullException("propertyXmlData", "Property xml source is null"); _xmlValue = XmlHelper.GetNodeValue(propertyXmlData); }
/// <summary> /// This is a generic converter for all nuPicker Picker PropertyEditors /// this may be subclassed for specific types (eg. Enum collection properties, or Xml and Content / Media / Members) /// </summary> /// <param name="propertyType"></param> /// <returns></returns> public override bool IsConverter(PublishedPropertyType propertyType) { return new string[] { PropertyEditorConstants.JsonCheckBoxPickerAlias, PropertyEditorConstants.JsonDropDownPickerAlias, PropertyEditorConstants.JsonPrefetchListPickerAlias, PropertyEditorConstants.JsonRadioButtonPickerAlias, PropertyEditorConstants.JsonTypeaheadListPickerAlias, PropertyEditorConstants.LuceneCheckBoxPickerAlias, PropertyEditorConstants.LuceneDropDownPickerAlias, PropertyEditorConstants.LucenePrefetchListPickerAlias, PropertyEditorConstants.LuceneRadioButtonPickerAlias, PropertyEditorConstants.LuceneTypeaheadListPickerAlias, PropertyEditorConstants.SqlCheckBoxPickerAlias, PropertyEditorConstants.SqlDropDownPickerAlias, PropertyEditorConstants.SqlPrefetchListPickerAlias, PropertyEditorConstants.SqlRadioButtonPickerAlias, PropertyEditorConstants.SqlTypeaheadListPickerAlias, PropertyEditorConstants.XmlCheckBoxPickerAlias, PropertyEditorConstants.XmlDropDownPickerAlias, PropertyEditorConstants.XmlPrefetchListPickerAlias, PropertyEditorConstants.XmlRadioButtonPickerAlias, PropertyEditorConstants.XmlTypeaheadListPickerAlias, PropertyEditorConstants.EnumCheckBoxPickerAlias, PropertyEditorConstants.EnumDropDownPickerAlias, PropertyEditorConstants.EnumPrefetchListPickerAlias, PropertyEditorConstants.EnumRadioButtonPickerAlias } .Contains(propertyType.PropertyEditorAlias); }
/// <summary> /// The convert data to source. /// </summary> /// <param name="propertyType"> /// The property type. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="preview"> /// The preview. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { var merchello = new MerchelloHelper(); if (source == null) return null; var collectionKey = source.ToString(); if (collectionKey.IsNullOrWhiteSpace()) { var defaultCollection = merchello.Query.Product.Search(1, 10) .Items.Select(x => merchello.TypedProductContent(((ProductDisplay)x).Key)); return new ProductContentListView(Guid.Empty, defaultCollection); } try { var key = new Guid(collectionKey); return new ProductContentListView(key, merchello.TypedProductContentFromCollection(key)); } catch (Exception ex) { MultiLogHelper.Error<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex); return null; } }
/// <summary> /// Method to convert a property value to an instance /// of the ColorPalette class. /// </summary> /// <param name="propertyType">The current published property /// type to convert.</param> /// <param name="source">The original property data.</param> /// <param name="preview">True if in preview mode.</param> /// <returns>An instance of the ColorPalette class.</returns> public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null) return null; if (UmbracoContext.Current == null) return null; var retval = new ColorPalette(); var palette = JsonConvert.DeserializeObject<ColorPalette>(source.ToString()); if (palette == null || palette.Colors.Count < 0) return retval; var colors = new List<Color>(); foreach (var color in palette.Colors) { colors.Add(color); } retval.Name = palette.Name; retval.Alias = palette.Alias; retval.Colors = colors; return retval; }
public bool IsConverter(PublishedPropertyType propertyType) { return ( propertyType.PropertyEditorAlias == "Skybrud.SelfService.Categories" || propertyType.PropertyEditorAlias == "Skybrud.SelfService.List" ); }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null) return null; var sourceString = source.ToString(); return UmbracoContext.Current != null ? new MultiUrls(sourceString) : null; }
public Type GetPropertyValueType(PublishedPropertyType propertyType) { if (IsMultipleDataType(propertyType.DataTypeId)) { return !IsConverterDefault(propertyType) ? typeof(IEnumerable<Image>) : typeof(IEnumerable<IPublishedContent>); } return !IsConverterDefault(propertyType) ? typeof(Image) : typeof(IPublishedContent); }
public object ConvertDataToSource(PublishedPropertyType propertyType, object data, bool preview) { switch (propertyType.PropertyEditorAlias) { case "Skybrud.SelfService.Categories": return SelfServiceContext.Current.Categories.GetCategoryByIds(data as string); default: return null; } }
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { if (source == null) { return null; } var nodeIds = source.ToString() .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(x => { int id = int.TryParse(x, out id) ? id : -1; return id; }) .ToList(); if (IsMultipleDataType(propertyType.DataTypeId)) { if (!IsConverterDefault(propertyType)) { return nodeIds.Select(x => { var image = x < 0 ? null : UmbracoContext.Current.MediaCache.GetById(x) as Image; if (image != null) { return image.AsValid(); } return null; }).Where(x => x != null).ToList(); } return nodeIds.Select(x => { var media = x < 0 ? null : UmbracoContext.Current.MediaCache.GetById(x); return media; }).Where(x => x != null).ToList(); } if (nodeIds.Any()) { var id = nodeIds.First(); if (!IsConverterDefault(propertyType)) { var image = id < 0 ? null : UmbracoContext.Current.MediaCache.GetById(id) as Image; if (image != null) { return image.AsValid(); } } var media = id < 0 ? null : UmbracoContext.Current.MediaCache.GetById(id); return media; } return null; }
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { if (source == null || UmbracoContext.Current == null) { return null; } return JsonConvert.DeserializeObject<PersonalisationGroupDefinition>(source.ToString()); }
/// <summary> /// Converts property source value to Grid object /// </summary> /// <param name="propertyType">Property type</param> /// <param name="source">Source object</param> /// <param name="preview">Is preview</param> /// <returns>Converted object</returns> public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null || string.IsNullOrWhiteSpace(source.ToString())) { return null; } return JsonHelper.Deserialize<Grid>(source.ToString()); }
public object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { // Get the value as a string string str = source as string; // Deserialize the string return GridDataModel.Deserialize(str, propertyType.PropertyTypeAlias) ?? GridDataModel.GetEmptyModel(propertyType.PropertyTypeAlias); }
/// <summary> /// Initializes a new instance of the <see cref="DetachedPublishedProperty"/> class. /// </summary> /// <param name="propertyType"> /// The property type. /// </param> /// <param name="value"> /// The value. /// </param> /// <param name="isPreview"> /// The is preview. /// </param> public DetachedPublishedProperty(PublishedPropertyType propertyType, object value, bool isPreview) { this._propertyType = propertyType; this._isPreview = isPreview; this._rawValue = value; this._sourceValue = new Lazy<object>(() => this._propertyType.ConvertDataToSource(this._rawValue, this._isPreview)); this._objectValue = new Lazy<object>(() => this._propertyType.ConvertSourceToObject(this._sourceValue.Value, this._isPreview)); this._xpathValue = new Lazy<object>(() => this._propertyType.ConvertSourceToXPath(this._sourceValue.Value, this._isPreview)); }
public object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview) { // Get the value as a string string str = source as string; // Deserialize the string return String.IsNullOrWhiteSpace(str) ? null : GoogleOAuthData.Deserialize(str); }
/// <summary> /// Determines whether the specified property type is converter for Archetype. /// </summary> /// <param name="propertyType">Type of the property.</param> /// <returns></returns> public override bool IsConverter(PublishedPropertyType propertyType) { var isArcheTypePropertyEditor = !String.IsNullOrEmpty(propertyType.PropertyEditorAlias) && propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditorAlias); if (!isArcheTypePropertyEditor) return false; return !ArchetypeHelper.Instance.IsPropertyValueConverterOverridden(propertyType.DataTypeId); }
/// <summary> /// Convert the raw string into a nodeId integer array /// </summary> /// <param name="propertyType"> /// The published property type. /// </param> /// <param name="source"> /// The value of the property /// </param> /// <param name="preview"> /// The preview. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { var nodeIds = source.ToString() .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); return nodeIds; }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null || string.IsNullOrWhiteSpace(source.ToString())) return null; var coordinates = source.ToString().Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries); var loc = new GMapsLocation(); loc.Lat = decimal.Parse(coordinates[0]); loc.Lng = decimal.Parse(coordinates[1]); return loc; }
public XmlPublishedProperty(PublishedPropertyType propertyType, bool isPreviewing) : base(propertyType) { _xmlValue = string.Empty; _isPreviewing = isPreviewing; _sourceValue = new Lazy<object>(() => PropertyType.ConvertDataToSource(_xmlValue, _isPreviewing)); _objectValue = new Lazy<object>(() => PropertyType.ConvertSourceToObject(_sourceValue.Value, _isPreviewing)); _xpathValue = new Lazy<object>(() => PropertyType.ConvertSourceToXPath(_sourceValue.Value, _isPreviewing)); }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null || string.IsNullOrWhiteSpace(source.ToString())) { return new FormModel(); } var model = SerializationHelper.DeserializeFormModel(source.ToString()); return model; }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { if (source == null) return null; var sourceString = source.ToString(); // ensures string is parsed for {localLink} and urls are resolved correctly sourceString = TemplateUtilities.ParseInternalLinks(sourceString, preview); sourceString = TemplateUtilities.ResolveUrlsFromTextString(sourceString); return sourceString; }
public DetachedPublishedProperty(PublishedPropertyType propertyType, object value, bool isPreview) { _propertyType = propertyType; _isPreview = isPreview; _rawValue = value; _sourceValue = new Lazy<object>(() => _propertyType.ConvertDataToSource(_rawValue, _isPreview)); _objectValue = new Lazy<object>(() => _propertyType.ConvertSourceToObject(_sourceValue.Value, _isPreview)); _xpathValue = new Lazy<object>(() => _propertyType.ConvertSourceToXPath(_sourceValue.Value, _isPreview)); }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { // in xml a boolean is: string // in the database a boolean is: string "1" or "0" or empty // the converter does not need to handle anything else ("true"...) // default value is: false var sourceString = source as string; if (sourceString == null) return false; return sourceString == "1"; }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { var defaultValue = new Models.Archetype(); if (source == null) return defaultValue; var sourceString = source.ToString(); if (sourceString.DetectIsJson()) { try { // Deserialize value to archetype model var archetype = JsonConvert.DeserializeObject<Models.Archetype>(sourceString, _jsonSettings); try { // Get list of configured properties and their types // and map them to the deserialized archetype model var dataTypeCache = new Dictionary<Guid, IDataTypeDefinition>(); var preValue = GetArchetypePreValueFromDataTypeId(propertyType.DataTypeId, dataTypeCache); foreach (var fieldset in preValue.Fieldsets) { var fieldsetAlias = fieldset.Alias; foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias)) { foreach (var property in fieldset.Properties) { var propertyAlias = property.Alias; foreach (var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias)) { propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id; propertyInst.PropertyEditorAlias = property.PropertyEditorAlias; } } } } } catch (Exception ex) { } return archetype; } catch (Exception ex) { return defaultValue; } } return defaultValue; }
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) { // NOTE: ignore preview, because IPropertyEditorValueConverter does not support it return(_converter.ConvertPropertyValue(source).Result); }
public override bool IsConverter(PublishedPropertyType propertyType) { return(true); }