当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.SitecoreFieldConfiguration类代码示例

本文整理汇总了C#中Glass.Mapper.Sc.Configuration.SitecoreFieldConfiguration的典型用法代码示例。如果您正苦于以下问题:C# SitecoreFieldConfiguration类的具体用法?C# SitecoreFieldConfiguration怎么用?C# SitecoreFieldConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SitecoreFieldConfiguration类属于Glass.Mapper.Sc.Configuration命名空间,在下文中一共展示了SitecoreFieldConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetFieldValue

        /// <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)
        {
            Type type = config.PropertyInfo.PropertyType;
            //Get generic type
            Type pType = Glass.Mapper.Utilities.GetGenericArgument(type);

            //The enumerator only works with piped lists
            IEnumerable<string> parts = fieldValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            //replace any pipe encoding with an actual pipe
            parts = parts.Select(x => x.Replace(Global.PipeEncoding, "|")).ToArray();
            
            
            
            IEnumerable<object> items = parts.Select(x => Mapper.GetFieldValue(x, Mapper.Configuration as SitecoreFieldConfiguration, context)).ToArray();
            var list = Utilities.CreateGenericType(typeof (List<>), new Type[] {pType}) as IList;
            
            foreach (var item in items)
            {
                if(item != null)
                    list.Add(item);
            }

            return list;
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:32,代码来源:SitecoreFieldIEnumerableMapper.cs

示例2: GetField_FieldContainsId_ReturnsConcreteType

        public void GetField_FieldContainsId_ReturnsConcreteType()
        {
            //Assign
            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldTypeMapper/GetField");
            var targetId = Guid.Parse("{BB01B0A5-A3F0-410E-8A6D-07FF3A1E78C3}");
            var mapper = new SitecoreFieldTypeMapper();
            var field = item.Fields[FieldName];
            var config = new SitecoreFieldConfiguration();
            config.PropertyInfo = typeof (StubContaining).GetProperty("PropertyTrue");

            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
            var service = new SitecoreService(Database, context);


            var scContext = new SitecoreDataMappingContext(null, item, service);

            using (new ItemEditing(item, true))
            {
                field.Value = targetId.ToString();
            }

            //Act
            var result = mapper.GetField(field, config, scContext) as Stub;

            //Assert
            Assert.AreEqual(targetId, result.Id);

        }
开发者ID:smithc,项目名称:Glass.Mapper,代码行数:29,代码来源:SitecoreFieldTypeMapperFixture.cs

示例3: GetField

        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var data = field.GetBlobStream();

            MemoryStream stream = null;

            if (data.CanRead)
            {
                 stream = new MemoryStream();

                byte[] buffer = new byte[2048];
                int bytesRead;


                while ((bytesRead = data.Read(buffer, 0, buffer.Length)) > 0)
                {
                    stream.Write(buffer, 0, bytesRead);
                }

                data.Close();

                stream.Seek(0, SeekOrigin.Begin);
            }
            return stream;
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:32,代码来源:SitecoreFieldStreamMapper.cs

示例4: GetField

        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {

            Image img = new Image();
            ImageField scImg = new ImageField(field);

            int height = 0;
            int.TryParse(scImg.Height, out height);
            int width = 0;
            int.TryParse(scImg.Width, out width);
            int hSpace = 0;
            int.TryParse(scImg.HSpace, out hSpace);
            int vSpace = 0;
            int.TryParse(scImg.VSpace, out vSpace);

            img.Alt = scImg.Alt;
            img.Border = scImg.Border;
            img.Class = scImg.Class;
            img.Height = height;
            img.HSpace = hSpace;
            img.MediaId = scImg.MediaID.Guid;
            if (scImg.MediaItem != null)
                img.Src = MediaManager.GetMediaUrl(scImg.MediaItem);
            img.VSpace = vSpace;
            img.Width = width;

            return img;
        }
开发者ID:jelleovermars,项目名称:Glass.Mapper,代码行数:35,代码来源:SitecoreFieldImageMapper.cs

示例5: GetField_ForceRenderFieldPipeline_StringIsReturned

        public void GetField_ForceRenderFieldPipeline_StringIsReturned()
        {
            //Assign

            var fieldValue = "<p>hello world</p>";
            var expected = "&lt;p&gt;hello world&lt;/p&gt;";

            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetField");
            var field = item.Fields[FieldName];

            var mapper = new SitecoreFieldStringMapper();
            var config = new SitecoreFieldConfiguration();
            config.Setting = SitecoreFieldSettings.ForceRenderField;

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website");
            Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember);


            //Act
            var result = mapper.GetField(field, config, null) as string;

            //Assert

            Sitecore.Context.Site = null;

            Assert.AreEqual(expected, result);


        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:34,代码来源:SitecoreFieldStringMapperFixture.cs

示例6: SetFieldValue

        /// <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>
        /// <exception cref="System.NullReferenceException">Could not find item to save value {0}.Formatted(Configuration)</exception>
        public override string SetFieldValue(object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context", "The context was incorrectly set");
            
            if(context.Service == null)
                throw new NullReferenceException("The context's service property was null");

            if (context.Service.GlassContext == null)
                throw new NullReferenceException("The service glass context is null");
            
            if (context.Service.Database == null)
                throw new NullReferenceException("The database is not set for the service");

            if (value == null)
                return string.Empty;

            var type = value.GetType();

            var typeConfig = context.Service.GlassContext.GetTypeConfiguration<SitecoreTypeConfiguration>(value);

            if(typeConfig == null)
                throw new NullReferenceException("The type {0} has not been loaded into context {1}".Formatted(type.FullName, context.Service.GlassContext.Name));

            var item = typeConfig.ResolveItem(value, context.Service.Database);
            if(item == null)
                throw new NullReferenceException("Could not find item to save value {0}".Formatted(Configuration));

            return item.ID.ToString();
        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:38,代码来源:SitecoreFieldTypeMapper.cs

示例7: SetField

        /// <summary>
        /// Sets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="value">The value.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <exception cref="Glass.Mapper.MapperException">No item with ID {0}. Can not update File Item field.Formatted(newId)</exception>
        public override void SetField(Field field, object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            File file = value as File;

            var item = field.Item;

            FileField fileField = new FileField(field);

            if (file == null)
            {
                fileField.Clear();
                return;
            }

            if (fileField.MediaID.Guid != file.Id)
            {
                if (file.Id == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, fileField.InnerField.ID, fileField.MediaItem.Database.Name, fileField.MediaID, fileField.MediaItem.Paths.FullPath);
                    fileField.RemoveLink(link);
                }
                else
                {
                    ID newId = new ID(file.Id);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        fileField.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, fileField.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        fileField.UpdateLink(link);
                    }
                    else throw new MapperException("No item with ID {0}. Can not update File Item field".Formatted(newId));
                }
            }
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:43,代码来源:SitecoreFieldFileMapper.cs

示例8: GetField

        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Sitecore.Data.Fields.Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            if (field == null)
                return string.Empty;

            if (config.Setting == SitecoreFieldSettings.RichTextRaw)
            {
                return field.Value;
            }

            Guid fieldGuid = field.ID.Guid;

            // shortest route - we know whether or not its rich text
            if (isRichTextDictionary.ContainsKey(fieldGuid))
            {
                return GetResult(field, isRichTextDictionary[fieldGuid]);
            }

            // we don't know - it might still be rich text
            bool isRichText = field.TypeKey == _richTextKey;
            isRichTextDictionary.TryAdd(fieldGuid, isRichText);

            // now we know it isn't rich text - return the raw result.
            return GetResult(field, isRichText);
        }
开发者ID:rootix,项目名称:Glass.Mapper,代码行数:32,代码来源:SitecoreFieldStringMapper.cs

示例9: GetField_RichText_StringIsReturnedWithScapedUrl

        public void GetField_RichText_StringIsReturnedWithScapedUrl()
        {
            //Assign
            var fieldValue = "<p>Test with <a href=\"~/link.aspx?_id=BFD7975DF42F41E19DDA9A38E971555F&amp;_z=z\">link</a></p>";
            var expected = "<p>Test with <a href=\"/en/Tests/DataMappers/SitecoreFieldStringMapper/GetField.aspx\">link</a></p>";
            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldStringMapper/GetFieldRichText");
            var field = item.Fields[FieldName];

            var mapper = new SitecoreFieldStringMapper();
            var config = new SitecoreFieldConfiguration();

            Sitecore.Context.Site = Sitecore.Configuration.Factory.GetSite("website");
            Sitecore.Context.Site.SetDisplayMode(DisplayMode.Preview, DisplayModeDuration.Remember);
            
            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }



            //Act
            var result = mapper.GetField(field, config, null) as string;

            Sitecore.Context.Site = null;

            //Assert
            Assert.AreEqual(expected, result);
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:29,代码来源:SitecoreFieldStringMapperFixture.cs

示例10: GetFieldValue

        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 });
        }
开发者ID:simonproctor,项目名称:VirtualSummit,代码行数:8,代码来源:TweetDataMapper.cs

示例11: GetFieldValue

 /// <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>
 /// <exception cref="Glass.Mapper.MapperException">Could not convert value to double</exception>
 public override object GetFieldValue(string fieldValue, SitecoreFieldConfiguration config,
                                      SitecoreDataMappingContext context)
 {
     if (fieldValue.IsNullOrEmpty()) return 0;
     int dValue = 0;
     if (int.TryParse(fieldValue, NumberStyles.Any, CultureInfo.InvariantCulture, out dValue)) return dValue;
     else throw new MapperException("Could not convert value to Integer");
 }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:16,代码来源:SitecoreFieldIntegerMapper.cs

示例12: GetFieldValue

        /// <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)
        {
            if (fieldValue.IsNullOrEmpty()) return Guid.Empty;


            return Guid.Parse(fieldValue);
        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:15,代码来源:SitecoreFieldGuidMapper.cs

示例13: SetFieldValue

 /// <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>
 /// <exception cref="Glass.Mapper.MapperException">The value is not of type System.Guid</exception>
 public override string SetFieldValue(object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
 {
     if (value is Guid)
     {
         return ((Guid)value).ToString("B").ToUpper();
     }
     else throw new MapperException("The value is not of type System.Guid");
 }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:16,代码来源:SitecoreFieldGuidMapper.cs

示例14: SetFieldValue

 /// <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>
 /// <exception cref="Glass.Mapper.MapperException">The value is not of type System.Guid</exception>
 public override string SetFieldValue(object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
 {
     if (value is ID)
     {
         return ((ID)value).ToString();
     }
     else throw new MapperException("The value is not of type Sitecore.Data.ID");
 }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:16,代码来源:SitecoreFieldIdMapper.cs

示例15: GetField

        /// <summary>
        /// Gets the field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="config">The config.</param>
        /// <param name="context">The context.</param>
        /// <returns>System.Object.</returns>
        public override object GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            Image img = new Image();
            ImageField scImg = new ImageField(field);

            MapToImage(img, scImg);

            return img;
        }
开发者ID:seanmolam,项目名称:Glass.Mapper,代码行数:16,代码来源:SitecoreFieldImageMapper.cs


注:本文中的Glass.Mapper.Sc.Configuration.SitecoreFieldConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。