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


C# SitecoreDataMappingContext类代码示例

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


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

示例1: 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

示例2: MapToProperty_ItemIdAsGuid_ReturnsIdAsGuid

        public void MapToProperty_ItemIdAsGuid_ReturnsIdAsGuid()
        {
            //Assign
            string targetPath = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
            })
            {
                var mapper = new SitecoreIdMapper();
                var config = new SitecoreIdConfiguration();
                var property = typeof(Stub).GetProperty("GuidId");
                var item = database.GetItem("/sitecore/content/target");

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");

                config.PropertyInfo = property;

                mapper.Setup(new DataMapperResolverArgs(null, config));

                var dataContext = new SitecoreDataMappingContext(null, item, null);
                var expected = item.ID.Guid;

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:31,代码来源:SitecoreIdMapperFixture.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(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

示例4: 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

示例5: 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

示例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: MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService

        public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var item = database.GetItem("/sitecore/content/TestItem");
                var service = Substitute.For<ISitecoreService>();
                var scContext = new SitecoreDataMappingContext(null, item, service);

                var config = new SitecoreParentConfiguration();
                config.PropertyInfo = typeof(Stub).GetProperty("Property");

                var mapper = new SitecoreParentMapper();
                mapper.Setup(new DataMapperResolverArgs(null, config));

                //Act
                var result = mapper.MapToProperty(scContext);

                //Assert

                //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails.
                service.Received()
                    .CreateType(config.PropertyInfo.PropertyType, Arg.Is<Item>(x => x.ID == item.Parent.ID), true, false,
                        null);
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:29,代码来源:SitecoreParentMapperFixture.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: MapCmsToProperty_DoesNotAlterObject

        public void MapCmsToProperty_DoesNotAlterObject()
        {
            //Assign
            var fieldValue = "hello world";
            var propertyValue = "goodbye world";

            var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreIgnoreMapper/Target");
            var field = item.Fields["Field"];

            var mapper = new SitecoreIgnoreMapper();
            var config = new SitecoreIgnoreMapper();

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

            var stub = new StubClass();
            stub.Field = propertyValue;
            var context = new SitecoreDataMappingContext(stub, item, null);

            //Act
            mapper.MapCmsToProperty(context);


            //Assert
            Assert.AreEqual(stub.Field, propertyValue);
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:28,代码来源:SitecoreIgnoreMapperFixture.cs

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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>
        public override void SetField(Sitecore.Data.Fields.Field field, object value, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {

            if (value == null)
            {
                return;
            }
            field.SetBlobStream(value as Stream);
        }
开发者ID:rootix,项目名称:Glass.Mapper,代码行数:16,代码来源:SitecoreFieldStreamMapper.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


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