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


C# ISitecoreService类代码示例

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


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

示例1: SetValue

        public override void SetValue(global::Sitecore.Data.Items.Item item, object value, ISitecoreService service)
        {
            
            switch (InfoType)
            {
                case SitecoreInfoType.DisplayName:
                    if (value is string || value == null)
                        item[Settings.DisplayNameFieldName] = (value ?? string.Empty).ToString();
                    else
                        throw new NotSupportedException("Can't set DisplayName. Value is not of type System.String");
                    break;
                case SitecoreInfoType.Name:
                    if (value is string || value == null)
                    {
                        //if the name is null or empty nothing should happen
                        if ((value ?? string.Empty).ToString().IsNullOrEmpty()) return;
                        
                        if (item.Name != value.ToString())
                        {
                            item.Name = value.ToString();
                        }
                        
                    }
                    else
                        throw new NotSupportedException("Can't set Name. Value is not of type System.String");
                    break;             
                default:
                    throw new NotSupportedException("You can not save SitecoreInfo {0}".Formatted(InfoType));
            }

        }
开发者ID:brianfeucht,项目名称:Glass.Sitecore.Mapper,代码行数:31,代码来源:SitecoreInfoHandler.cs

示例2: SetValue

        public override void SetValue( Item item, object value, ISitecoreService service)
        {
            var field = base.GetField(item);

            if (field == null)
            {
                return;
            }
            else if (field.Type.StartsWith("Rich Text") && Setting != SitecoreFieldSettings.RichTextRaw)
            {
                throw new NotSupportedException("It is not possible to save data from a rich text field when the data isn't raw."
                    + "Set the SitecoreFieldAttribute setting property to SitecoreFieldSettings.RichTextRaw for property {0} on type {1}".Formatted(Property.Name, Property.ReflectedType.FullName));
            }
            else
            {
                if (value != null)
                {
                    string fieldValue = value.ToString();
                    field.Value = fieldValue;
                }
                else
                {
                    field.Value = string.Empty;
                }
            }
        }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:26,代码来源:SitecoreFieldStringHandler.cs

示例3: SetValue

        public override void SetValue(global::Sitecore.Data.Items.Item item, object value, ISitecoreService service)
        {

            File  file = value as File;
            FileField field = new FileField(item.Fields[FieldName]);

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

            if (field.MediaID.Guid != file.Id)
            {
                if (file.Id == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, field.MediaItem.Database.Name, field.MediaID, field.MediaItem.Paths.FullPath);
                    field.RemoveLink(link);
                }
                else
                {
                    ID newId = new ID(file.Id);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        field.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        field.UpdateLink(link);
                    }
                    else throw new MapperException("No item with ID {0}. Can not update File Item field".Formatted(newId));
                }
            }

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

示例4: GetValue

        public override object GetValue(global::Sitecore.Data.Items.Item item,  ISitecoreService service)
        {
                int numChildren = item.Children.Count;
                Type genericType = Utility.GetGenericArgument(Property.PropertyType);


              
                    var getItems = new Func<IEnumerable<Item>>(() =>
                    {

                        switch (Options)
                        {
                            case SitecoreLinkedOptions.All:
                                var itemLinks1 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferences(item);
                                var itemLinks2 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferrers(item);
                                return itemLinks1.Select(x => x.GetTargetItem()).Union(itemLinks2.Select(x=>x.GetSourceItem()));
                                break;
                            case SitecoreLinkedOptions.References:
                                var itemLinks3 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferences(item);
                                return itemLinks3.Select(x => x.GetTargetItem());
                                break;
                            case SitecoreLinkedOptions.Referrers:
                                var itemLinks4 = global::Sitecore.Configuration.Factory.GetLinkDatabase().GetReferrers(item);
                                return itemLinks4.Select(x => x.GetSourceItem());
                                break;
                            default:
                                return new List<Item>();
                        }
                        
                    });

                return service.CreateClasses(IsLazy, InferType,  genericType, getItems);
        }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:33,代码来源:SitecoreLinkedHandler.cs

示例5: ReadFromItem

 public  void ReadFromItem(ISitecoreService service, object target, Item item, SitecoreClassConfig config)
 {
     foreach (var handler in config.DataHandlers)
     {
         handler.SetProperty(target, item, service);
     }
 }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:7,代码来源:ClassManager.cs

示例6: GetValue

        public override object GetValue(global::Sitecore.Data.Items.Item item,  ISitecoreService service)
        {

            var itemField = base.GetField(item);

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

            Link link = new Link();
            LinkField field = new LinkField(itemField);

            switch (field.LinkType)
            {
                case "anchor":
                    link.Url = field.Anchor;
                    link.Type = LinkType.Anchor;
                    break;
                case "external":
                    link.Url = field.Url;
                    link.Type = LinkType.External;
                    break;
                case "mailto":
                    link.Url = field.Url;
                    link.Type = LinkType.MailTo;
                    break;
                case "javascript":
                    link.Url = field.Url;
                    link.Type = LinkType.JavaScript;
                    break;
                case "media":
                    global::Sitecore.Data.Items.MediaItem media = new global::Sitecore.Data.Items.MediaItem(field.TargetItem);
                    link.Url = global::Sitecore.Resources.Media.MediaManager.GetMediaUrl(media);
                    link.Type = LinkType.Media;
                    link.TargetId = field.TargetID.Guid;

                    break;
                case "internal":
                    if (field.TargetItem == null) link.Url = string.Empty;
                    else link.Url = LinkManager.GetItemUrl(field.TargetItem);
                    link.Type = LinkType.Internal;
                    link.TargetId = field.TargetID.Guid;

                    break;
                default:
                    return null;
                    break;

            }
            

            link.Anchor = field.Anchor;
            link.Class = field.Class;
            link.Text = field.Text;
            link.Title = field.Title;
            link.Target = field.Target;
            link.Query = field.QueryString;

            return link;
        }
开发者ID:photomoose,项目名称:Glass.Sitecore.Mapper,代码行数:60,代码来源:SitecoreFieldLinkHandler.cs

示例7: GetFieldValue

 public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return 0d;
     double dValue = 0;
     if (double.TryParse(fieldValue, out dValue)) return dValue;
     else throw new MapperException("Could not convert value to double");
 }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:7,代码来源:SitecoreFieldDoubleHandler.cs

示例8: GetFieldValue

        public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
        {
            Type type = Property.PropertyType;
            //Get generic type
            Type pType = Utility.GetGenericArgument(type);

            if (EnumSubHandler == null) EnumSubHandler = GetSubHandler(pType, service);
            
            //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(Settings.PipeEncoding, "|")).ToArray();

                      

            IEnumerable<object> items = parts.Select(x => EnumSubHandler.GetFieldValue(x, item, service)).ToArray();
            var list = Utility.CreateGenericType(typeof(List<>), new Type[] { pType }) ;
            Utility.CallAddMethod(items, list);

            return list;
            


        }
开发者ID:photomoose,项目名称:Glass.Sitecore.Mapper,代码行数:25,代码来源:SitecoreFieldIEnumerableHandler.cs

示例9: GetFieldValue

 public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return 0;
     long lValue = 0;
     if (long.TryParse(fieldValue, NumberStyles.Any, CultureInfo.InvariantCulture, out lValue)) return lValue;
     throw new MapperException("Could not convert value to long.");
 }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:7,代码来源:SitecoreFieldLongHandler.cs

示例10: SetFieldValue

        public override string SetFieldValue(object value, ISitecoreService service)
        {
            Type pType = Utility.GetGenericArgument(Property.PropertyType);


            if (EnumSubHandler == null)
                EnumSubHandler = GetSubHandler(pType, service);

            IEnumerable list = value as IEnumerable;

            if (list == null) return "";

            List<string> sList = new List<string>();
                       

            foreach (object obj in list)
            {
                string result = EnumSubHandler.SetFieldValue(obj, service);
                if (!result.IsNullOrEmpty())
                    sList.Add(result);
            }

            StringBuilder sb = new StringBuilder();
            sList.ForEach(x => sb.AppendFormat("{0}|", x.Replace("|", Settings.PipeEncoding)));
            if (sb.Length > 1) 
                sb.Remove(sb.Length - 1, 1);

            return sb.ToString();
        }
开发者ID:photomoose,项目名称:Glass.Sitecore.Mapper,代码行数:29,代码来源:SitecoreFieldIEnumerableHandler.cs

示例11: GetFieldValue

 public override object GetFieldValue(string fieldValue, Item item,  ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return 0;
     int iValue = 0;
     if (int.TryParse(fieldValue, out iValue)) return iValue;
     else throw new MapperException("Could not convert value to integer.");
 }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:7,代码来源:SitecoreFieldIntegerHandler.cs

示例12: GetFieldValue

 public override object GetFieldValue(string fieldValue, Item item, ISitecoreService service)
 {
     if (fieldValue.IsNullOrEmpty()) return (float)0.0;
     float fValue = 0.0f;
     if (float.TryParse(fieldValue, out fValue)) return fValue;
     else throw new MapperException("Could not convert value to float");
 }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:7,代码来源:SitecoreFieldFloatHandler.cs

示例13: CommentsController

 public CommentsController(
     ISitecoreContext context,
     ISitecoreService master)
 {
     _context = context;
     _master = master;
 }
开发者ID:bplasmeijer,项目名称:Glass.Mapper.Sc.Demo,代码行数:7,代码来源:CommentsController.cs

示例14: SitecoreDataMappingContext

        /// <summary>
        /// Initializes a new instance of the <see cref="SitecoreDataMappingContext"/> class.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="item">The item.</param>
        /// <param name="service">The service.</param>
        public SitecoreDataMappingContext(object obj, Item item, ISitecoreService service):base(obj)
        {

            //TODO: ME - should we assert that these are not null
            this.Item = item;
            Service = service;
        }
开发者ID:kgkostadinov,项目名称:TdsTesting,代码行数:13,代码来源:SitecoreDataMappingContext.cs

示例15: GetValue

        public override object GetValue(global::Sitecore.Data.Items.Item item,  ISitecoreService service)
        {
            var itemField = item.Fields[FieldName];

            if (itemField == null) return null;

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

            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:simonproctor,项目名称:Glass.Sitecore.Mapper,代码行数:31,代码来源:SitecoreFieldImageHandler.cs


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