Class SitecoreDataMappingContext
Наследование: AbstractDataMappingContext
Пример #1
0
        public override object GetFieldValue(string fieldValue, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var settings = context.Service.GetItem<TwitterSettings>(TweetCommand.SettingsPath);
            TwitterService twitterService = new TwitterService(settings.ConsumerKey, settings.ConsumerSecret);
            twitterService.AuthenticateWith(settings.AccessToken, settings.AccessTokenSecret);

            return twitterService.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions() { ScreenName = fieldValue });
        }
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {

            if (field == null || string.IsNullOrEmpty(field.Value.Trim())) return null;

            List<Link> links = new List<Link>();
            Monoco.CMS.Fields.LinkListField linksField = new Monoco.CMS.Fields.LinkListField(field);

            foreach (var link in linksField.Links)
            {
                links.Add(link);
            }

            LinkList linkList = new LinkList(links);

            return linkList;
        }
        /// <summary>
        /// Gets the field value.
        /// </summary>
        /// <param name="fieldValue">The field value.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetFieldValue(string fieldValue, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var collection = HttpUtility.ParseQueryString(fieldValue);

            Type[] genericArguments = config.PropertyInfo.PropertyType.GetGenericArguments();

            IDictionary dictionary = Utilities.CreateGenericType(typeof(Dictionary<,>), genericArguments, new object[0]) as IDictionary;

            foreach (var k in collection.AllKeys)
            {
                var key = this.KeyMapper.GetFieldValue(k, this.KeyMapper.Configuration as SitecoreFieldConfiguration, context);

                var value = this.ValueMapper.GetFieldValue(collection[k], this.ValueMapper.Configuration as SitecoreFieldConfiguration, context);

                dictionary.Add(key, value);
            }

            return dictionary;
        }
        /// <summary>
        /// Creates the data mapping context.
        /// </summary>
        public override AbstractDataMappingContext CreateDataMappingContext(object obj)
        {
            var mappingContext = new SitecoreDataMappingContext(obj, Item, SitecoreService, Options as GetItemOptions);

            return(mappingContext);
        }
Пример #5
0
 public override string SetFieldValue(object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Sets the field value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.String.</returns>
        public override string SetFieldValue(object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var dictionary = value as IDictionary;
            
            if (dictionary == null)
            {
                return (string)null;
            }

            var parameters = new NameValueCollection();

            foreach (DictionaryEntry obj in dictionary)
            {
                string dictionaryKey = this.KeyMapper.SetFieldValue(obj.Key, config, context);

                string dictionaryValue = this.ValueMapper.SetFieldValue(obj.Value, config, context);

                if (!dictionaryKey.IsNullOrEmpty() || !dictionaryValue.IsNullOrEmpty())
                {
                    parameters.Add(dictionaryKey, dictionaryValue);
                }
            }

            return Utilities.ConstructQueryString(parameters);
        }
        public override AbstractDataMappingContext CreateDataMappingContext(IAbstractService service)
        {
            var mappingContext = new SitecoreDataMappingContext(Object, Item, service as ISitecoreService, null);

            return(mappingContext);
        }