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


C# Database.GetItem方法代码示例

本文整理汇总了C#中Database.GetItem方法的典型用法代码示例。如果您正苦于以下问题:C# Database.GetItem方法的具体用法?C# Database.GetItem怎么用?C# Database.GetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Database的用法示例。


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

示例1: Setup

        public void Setup()
        {
            var loader = new AttributeConfigurationLoader(
               new string[] { "Glass.Sitecore.Mapper.Tests.HtmlFixtureNS, Glass.Sitecore.Mapper.Tests" }
               );
            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });

            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _sitecore = new SitecoreService(_db);
            _itemId = new Guid("{5864308D-A91A-4E74-B8CA-7F27372CBB73}");
            _item = _db.GetItem(new ID(_itemId));
            _html = new GlassHtml(_sitecore);
            _sltTextOriginal = _item["SingleLineText"];
            _mltTextOriginal = _item["MultiLineText"];
            _intOriginal = _item["Integer"];
            _numberOriginal = _item["Number"];

            using (new SecurityDisabler())
            {
                _item.Editing.BeginEdit();
                _item["SingleLineText"] = _sltContent;
                _item["MultiLineText"] = _mltContent;
                _item["Integer"] = _intContent;
                _item["Number"] = _numberContent;
                _item.Editing.EndEdit();
            }

        }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:28,代码来源:HtmlFixture.cs

示例2: GetDatasourceFromControl

        ///<summary>
        ///	When working with the Presentation Layer for Sitecore, you can specify a Datasource as a property 
        ///	for a control.  However, accessing the item that is set brings a bit of a challenge.  Hopefully this fixes that.
        ///</summary>
        ///<param name = "database">Sitecore Database to Use.  Usually From Context.</param>
        ///<param name = "device">Sitecore Device to Use.  Usually from Context.</param>
        ///<param name = "item">Item to get the Layout Renderings from.</param>
        ///<param name = "sublayoutItem">
        ///	Item reference to the Sublayout or Webcontrol that you would like to use for getting the datasource from.
        ///</param>
        ///<returns>Datasource Item.  If no Datasource Item is listed in the layout properties, returns Null.</returns>
        ///<exception cref = "ItemNotFoundException">Thrown when Sitecore can't find a specified datasource item entry.</exception>
        public static Item GetDatasourceFromControl(Database database, DeviceItem device, Item item, Item sublayoutItem)
        {
            Item datasourceItem = null;

            // Get the Layout definition from the current item
            string rend = item.Fields["__renderings"].Value;
            LayoutDefinition layout = LayoutDefinition.Parse(rend);
            // Get the current device definition
            DeviceDefinition deviceDef = layout.GetDevice(device.ID.ToString());
            // Get the sublayout to find
            Item mySublayout = database.GetItem(sublayoutItem.ID);
            // Get the definition for the sublayout
            RenderingDefinition rendering = deviceDef.GetRendering(mySublayout.ID.ToString());

            if (!String.IsNullOrEmpty(rendering.Datasource))
            {
                datasourceItem = database.GetItem(rendering.Datasource);
                if (datasourceItem == null)
                {
                    throw new ItemNotFoundException("Could not find datasource item at " + rendering.Datasource);
                }
            }

            return datasourceItem;
        }
开发者ID:Velir,项目名称:Sitecore-Commons,代码行数:37,代码来源:LayoutUtil.cs

示例3: GetDateFolderDestination

 public static Item GetDateFolderDestination(Item originalDestination, Database databaseName)
 {
     var dateFolder = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/" + DateTime.Now.Hour + "/" + DateTime.Now.Minute;
     var newPath = originalDestination.Paths.FullPath + "/" + dateFolder;
     if (databaseName.GetItem(newPath) != null)
     {
         return databaseName.GetItem(newPath);
     }
     TemplateItem templateItem = databaseName.Templates[new TemplateID(Config.ContainerTemplateId)];
     return databaseName.CreateItemPath(newPath, templateItem, templateItem);
 }
开发者ID:udt1106,项目名称:Sitecore-Item-Buckets,代码行数:11,代码来源:CreateItems.aspx.cs

示例4: WarmDb

        /// <summary>
        /// Warms the db.
        /// </summary>
        /// <param name="db">The db.</param>
        protected void WarmDb(Database db)
        {
            

            var behind = db.GetItem(SitecoreIds.GlassBehindRazorId);
            var typed = db.GetItem(SitecoreIds.GlassTypedRazorId);
            var dynamic = db.GetItem(SitecoreIds.GlassDynamicRazorId);

            WarmType(behind);
            WarmType(typed);
            WarmType(dynamic);
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:16,代码来源:CacheWarmer.cs

示例5: Setup

        public void Setup()
        {
            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");
            Context context = new Context(
                  new AttributeConfigurationLoader(
                      "Glass.Sitecore.Mapper.Tests.Domain,  Glass.Sitecore.Mapper.Tests"));

            _service = new SitecoreService(_db);

            _handler = new SitecoreQueryHandler();

            _item = _db.GetItem("/sitecore/content/Data/SitecoreQueryHandler");
            _langItem = _db.GetItem("/sitecore/content/Data/SitecoreQueryHandler", Language.Parse("af-ZA"));
        }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:14,代码来源:SitecoreQueryHandlerFixture.cs

示例6: Setup

        public void Setup()
        {
            if (_hasRun)
            {
                return;
            }
            else
                _hasRun = true;

            _glassWatch = new Stopwatch();
            _rawWatch= new Stopwatch();
            

            _expected = "hello world";
            _id = new Guid("{59784F74-F830-4BCD-B1F0-1A08616EF726}");

            _context = Context.Create(Utilities.CreateStandardResolver());


            _context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

            _db = Factory.GetDatabase("master");

            //       service.Profiler = new SimpleProfiler();

            _service = new SitecoreService(_db);

            var item = _db.GetItem(new ID(_id));
            using (new ItemEditing(item, true))
            {
                item["Field"] = _expected;
            }
        }
开发者ID:neilduncan,项目名称:Glass.Mapper,代码行数:33,代码来源:PerformanceTests.cs

示例7: GetFieldsOfASublayoutItem

        public static List<Item> GetFieldsOfASublayoutItem(Item item, Database database)
        {
            List<Item> sourceField = new List<Item>();
            if (!string.IsNullOrEmpty(item["Datasource Template"]))
            {
                var firstTemplateID = database.GetItem(item["Datasource Template"]).ID;
                if (!firstTemplateID.IsNull)
                {
                    List<TemplateItem> templateItems = new List<TemplateItem>();
                    var firstTemplate = database.GetTemplate(firstTemplateID);
                    if (firstTemplate != null)
                    {
                        templateItems.Add(firstTemplate);
                        templateItems.AddRange(firstTemplate.BaseTemplates);

                        foreach (Item template in templateItems)
                        {
                            var sections =
                                template.Children.Where(
                                    o => o.TemplateID.Equals(new ID("{E269FBB5-3750-427A-9149-7AA950B49301}")));

                            foreach (var section in sections.Distinct(new ItemEqualityComparer()))
                            {
                                foreach (Item fieldItem in section.Children.Where(o => !o.Name.StartsWith("__")))
                                {
                                    sourceField.Add(fieldItem);
                                }
                            }
                        }
                    }
                }

            }
            return sourceField;
        }
开发者ID:JobiJoba,项目名称:PageAnalyze,代码行数:35,代码来源:DatasourceIndexerHelper.cs

示例8: CheckReferences

        /// <summary>
        /// Verified that the references exist in the specified database
        /// </summary>
        /// <param name="type"></param>
        /// <param name="database"></param>
        /// <returns></returns>
        public static List<ItemReferenceObject> CheckReferences(Type type, Database database)
        {
            if (type == null || database == null)
            {
                return new List<ItemReferenceObject>();
            }

            //use reflection to bring back all item references
            List<ItemReferenceObject> failedItems = new List<ItemReferenceObject>();
            PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
            foreach (PropertyInfo property in properties)
            {
                ItemReferenceObject itemReferenceObject = (ItemReferenceObject)property.GetValue(type, null);
                if (itemReferenceObject == null)
                {
                    continue;
                }

                //verification item exists
                Item item = database.GetItem(itemReferenceObject.Guid);
                if (item.IsNull())
                {
                    //item does not exist, flag to be returned
                    failedItems.Add(itemReferenceObject);
                }
            }

            return failedItems;
        }
开发者ID:Velir,项目名称:Sitecore-Commons,代码行数:35,代码来源:ItemReferenceObject.static.cs

示例9: Repository

 public Repository(ID repositoryID, Database database)
 {
     Assert.IsNotNull(database, "Database cannot be null");
     _item = database.GetItem(repositoryID);
     Assert.IsTrue(_item.IsDerived(Templates.Repository.ID), 
         string.Format("'{0}' must be derrived from '{1}'", nameof(repositoryID), Templates.Repository.ID));
 }
开发者ID:blacktambourine,项目名称:DiversusHackathon2016,代码行数:7,代码来源:Repository.cs

示例10: Setup

        public void Setup()
        {
            _context = new Context(
                new AttributeConfigurationLoader(
                    "Glass.Sitecore.Mapper.Tests.InterfaceFixtureNS, Glass.Sitecore.Mapper.Tests"), null);

            global::Sitecore.Context.Site = global::Sitecore.Configuration.Factory.GetSite("website");

            _sitecore = new SitecoreService("master");

            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");

            _test1 = _db.GetItem("/sitecore/content/Glass/Test1");
            _test2 = _db.GetItem("/sitecore/content/Glass/Test2");
            _test3 = _db.GetItem("/sitecore/content/Glass/Test1/Test3");
        }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:16,代码来源:InterfaceFixture.cs

示例11: TransferPath

 public static void TransferPath(string itemPath, Database sourceDatabase, Database targetDatabase, Action<string> callback)
 {
     var item = sourceDatabase.GetItem(itemPath);
     var dataProvider = targetDatabase.GetDataProviders().First() as DataProviderWrapper;
     TransferAncestors(item.Parent, dataProvider, callback);
     TransferItemAndDescendants(item, dataProvider, callback);
 }
开发者ID:dsolovay,项目名称:SitecoreData,代码行数:7,代码来源:TransferUtil.cs

示例12: Setup

        public void Setup()
        {
            _handler = new SitecoreLinkedHandler();
            _database = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _target = _database.GetItem("/sitecore/content/Glass/ItemLinksTest");

            SitecoreProperty idProperty =  new SitecoreProperty(){
                            Attribute = new SitecoreIdAttribute(),
                            Property = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass).GetProperty("Id")
                        };
            SitecoreIdDataHandler idHandler = new SitecoreIdDataHandler();
            idHandler.ConfigureDataHandler(idProperty);
                 

            var context = new InstanceContext(
              (new SitecoreClassConfig[]{
                   new SitecoreClassConfig(){
                       ClassAttribute = new SitecoreClassAttribute(),
                       Properties = new SitecoreProperty[]{
                           idProperty                       
                       },
                       Type = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass),
                       DataHandlers = new AbstractSitecoreDataHandler []{
                            idHandler
                       }
                   }
               }).ToDictionary(), new AbstractSitecoreDataHandler[] { });


        

            _service = new SitecoreService(_database, context);

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

示例13: RegisterGermanLanaguage

 public static Item RegisterGermanLanaguage(Database database)
 {
   using (new SecurityDisabler())
   {
     var languageRoot = database.GetItem(ItemIDs.LanguageRoot);
     return TestUtil.CreateContentFromFile("test data\\German Language.xml", languageRoot);
   }
 }
开发者ID:KerwinMa,项目名称:WeBlog,代码行数:8,代码来源:TestUtil.cs

示例14: Setup

        public void Setup()
        {
            AttributeConfigurationLoader loader = new AttributeConfigurationLoader(
               new string[] { "Glass.Sitecore.Mapper.Tests.MiscFixtureNS, Glass.Sitecore.Mapper.Tests" }
               );

            _context = new Context(loader, new AbstractSitecoreDataHandler[] {});
            global::Sitecore.Context.Site = global::Sitecore.Configuration.Factory.GetSite("website");

            _sitecore = new SitecoreService("master");
            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");

            _test1 = _db.GetItem("/sitecore/content/Glass/Test1");
            _test2 = _db.GetItem("/sitecore/content/Glass/Test2");
            _test3 = _db.GetItem("/sitecore/content/Glass/Test1/Test3");
            _demo = _db.GetItem("/sitecore/content/Glass/Demo");
        }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:17,代码来源:MiscFixture.cs

示例15: GetTemplateSubitems

        /// <summary>
        /// Gets the subitems below a root item taht are Sitecore templates 
        /// </summary>
        /// <param name="rootItem">The root item.</param>
        /// <param name="database">The database.</param>
        /// <returns></returns>
        public static List<Item> GetTemplateSubitems(Item rootItem, Database database)
        {
            TemplateItem sitecoreTemplateItem = database.GetItem("{AB86861A-6030-46C5-B394-E8F99E8B87DB}");

            return (from Item child in rootItem.Axes.GetDescendants()
                            where child.Template.ID == sitecoreTemplateItem.ID
                            select child).OrderBy(i => i.Name).ToList();
        }
开发者ID:kmazzoni,项目名称:Custom-Item-Generator,代码行数:14,代码来源:TemplateUtil.cs


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