Inheritance: IContent
コード例 #1
0
ファイル: ReferenceHandler.cs プロジェクト: wezmag/Coevery
 protected void LazyLoadHandlers(ContentPart part) {
     // add handlers that will load content for id's just-in-time
     foreach (ReferenceField field in part.Fields.Where(f => f.FieldDefinition.Name.Equals("ReferenceField"))) {
         var field1 = field;
         field.ContentItemField.Loader(() => field1.Value.HasValue ? _contentManager.Get(field1.Value.Value) : null);   
     }
 }
コード例 #2
0
        public void NullCheckingCanBeDoneOnProperties() {
            var contentItem = new ContentItem();
            var contentPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("FooPart"), new SettingsDictionary()) };
            var contentField = new ContentField { PartFieldDefinition = new ContentPartFieldDefinition(new ContentFieldDefinition("FooType"), "FooField", new SettingsDictionary()) };

            dynamic item = contentItem;
            dynamic part = contentPart;

            Assert.That(item.FooPart == null, Is.True);
            Assert.That(item.FooPart != null, Is.False);

            contentItem.Weld(contentPart);

            Assert.That(item.FooPart == null, Is.False);
            Assert.That(item.FooPart != null, Is.True);
            Assert.That(item.FooPart, Is.SameAs(contentPart));

            Assert.That(part.FooField == null, Is.True);
            Assert.That(part.FooField != null, Is.False);
            Assert.That(item.FooPart.FooField == null, Is.True);
            Assert.That(item.FooPart.FooField != null, Is.False);

            contentPart.Weld(contentField);

            Assert.That(part.FooField == null, Is.False);
            Assert.That(part.FooField != null, Is.True);
            Assert.That(item.FooPart.FooField == null, Is.False);
            Assert.That(item.FooPart.FooField != null, Is.True);
            Assert.That(part.FooField, Is.SameAs(contentField));
            Assert.That(item.FooPart.FooField, Is.SameAs(contentField));
        }
コード例 #3
0
        private void SetSetting(XAttribute attribute, ContentPart contentPart) {
            var attributeName = attribute.Name.LocalName;
            var attributeValue = _settingRedactionService.GetSettingValue(contentPart.PartDefinition.Name, attributeName, attribute.Value);

            _realtimeFeedbackService.Info(T("Updating site settings for {0}.{1}. Value being set to {2} ({3} before redactions)", contentPart.PartDefinition.Name, attributeName, attributeValue, attribute.Value));
            var property = contentPart.GetType().GetProperty(attributeName);
            if (property == null) {
                _realtimeFeedbackService.Warn(T("Could not set setting {0} for part {1} because it was not found.", attributeName, contentPart.PartDefinition.Name));

                return;
            }
            var propertyType = property.PropertyType;
            if (propertyType == typeof(string))
            {
                property.SetValue(contentPart, attributeValue, null);
                _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue));
            }
            else if (propertyType == typeof(bool)) {
                property.SetValue(contentPart, Boolean.Parse(attributeValue), null);
                _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue));
            }
            else if (propertyType == typeof(int)) {
                property.SetValue(contentPart, Int32.Parse(attributeValue), null);
                _realtimeFeedbackService.Info(T("Setting {0} for part {1} has been set to {2}.", attributeName, contentPart.PartDefinition.Name, attributeValue));
            }
            else {
                _realtimeFeedbackService.Warn(T("Could not set setting {0} for part {1} because its type is not supported. Settings should be integer, boolean or string.", attributeName, contentPart.PartDefinition.Name));
            }
        }
 public OutputCachedContentShapeResult(string shapeType, Func<DriverResult> driverResultFactory, ICacheService cacheService, IOutputCachedPartsContext outputCachedPartsContext, ICacheKeyService cacheKeyService, ContentPart part, string cacheKey)
 {
     _cachedPartMetadata = new CachedPartMetadata(cacheKeyService.BuildFullCacheKey(part, cacheKey));
     _shapeType = shapeType;
     _driverResultFactory = driverResultFactory;
     _cacheService = cacheService;
     _outputCachedPartsContext = outputCachedPartsContext;
 }
コード例 #5
0
        void AssignVersioningDates(VersionContentContext context, ContentPart<CommonVersionRecord> existing, ContentPart<CommonVersionRecord> building) {
            // assign create/modified dates for the new version
            building.Record.CreatedUtc = _clock.UtcNow;
            building.Record.ModifiedUtc = _clock.UtcNow;

            // publish date should be null until publish method called
            building.Record.PublishedUtc = null;
        }
コード例 #6
0
 void CreateIndexingTask(PublishContentContext context, ContentPart part) {
     // "Unpublish" case: Same as "remove"
     if (context.PublishingItemVersionRecord == null) {
         _indexingTaskManager.CreateDeleteIndexTask(context.ContentItem);
         return;
     }
     // "Publish" case: update index
     _indexingTaskManager.CreateUpdateIndexTask(context.ContentItem);
 }
コード例 #7
0
        private string BuildCachedPartMetadataKey(ContentPart part) 
        {
            if (part == null || part.TypePartDefinition == null || part.TypePartDefinition.PartDefinition == null) 
            {
                return null;
            }

            return string.Format("{0}-{1}", part.TypePartDefinition.PartDefinition.Name, part.Id);
        }
コード例 #8
0
        public void ContentItemProjectsPartNamesAsProperties() {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.TestingPart;

            Assert.That((object)testingPartDynamic, Is.SameAs(testingPart));
        }
コード例 #9
0
 private IContentQuery<ContentItem, CommonPartRecord> GetSeasonQuery(ContentPart<SeasonPartRecord> season, VersionOptions versionOptions)
 {
     int currentCultureId = _cultureManager.GetCultureByName(Services.WorkContext.CurrentCulture).Id;
     return
         _contentManager.Query(versionOptions, "Category")
         .Join<LocalizationPartRecord>().Where(lr => lr.CultureId == currentCultureId)
         .Join<CommonPartRecord>().Where(
             cr => cr.Container == season.Record.ContentItemRecord).OrderByDescending(cr => cr.CreatedUtc)
         .WithQueryHintsFor("Category");
 }
コード例 #10
0
        public void ActualPropertiesTakePriority() {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("Parts"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.Parts;


            Assert.That((object)testingPartDynamic, Is.AssignableTo<IEnumerable<ContentPart>>());
        }
コード例 #11
0
ファイル: ContentPartDisplay.cs プロジェクト: anycall/Orchard
        public dynamic BuildEditor(ContentPart part, string groupId) {
            var context = BuildEditorContext(part, groupId);
            var drivers = GetPartDrivers(part.PartDefinition.Name);

            drivers.Invoke(driver => {
                var result = driver.BuildEditor(context);
                if (result != null)
                    result.Apply(context);
            }, Logger);

            return context.Shape;
        }
コード例 #12
0
ファイル: ContentPartDisplay.cs プロジェクト: anycall/Orchard
        public dynamic UpdateEditor(ContentPart part, IUpdateModel updater, string groupInfoId) {
            var context = UpdateEditorContext(part, updater, groupInfoId);
            var drivers = GetPartDrivers(part.PartDefinition.Name);

            drivers.Invoke(driver => {
                var result = driver.UpdateEditor(context);
                if (result != null)
                    result.Apply(context);
            }, Logger);
            
            return context.Shape;
        }
コード例 #13
0
ファイル: ReferenceHandler.cs プロジェクト: wezmag/Coevery
        protected static void PropertySetHandlers(ActivatedContentContext context, ContentPart part) {
            // add handlers that will update ID when ContentItem is assigned
            foreach (ReferenceField field in part.Fields.Where(f => f.FieldDefinition.Name.Equals("ReferenceField"))) {
                var field1 = field;
                field1.ContentItemField.Setter(contentItem => {
                    field1.Value = contentItem == null ? new int?() : contentItem.Id;
                    return contentItem;
                });

                // Force call to setter if we had already set a value
                if (field1.ContentItemField.Value != null)
                    field1.ContentItemField.Value = field1.ContentItemField.Value;
            }
        }
コード例 #14
0
        public CachedPartMetadata GetCachedPartMetadata(ContentPart part) 
        {
            var dictionaryKey = BuildCachedPartMetadataKey(part);

            if (dictionaryKey == null) 
            {
                return null;
            }

            if (CachedPartMetadata.ContainsKey(dictionaryKey)) 
            {
                return CachedPartMetadata[dictionaryKey];
            }

            return null;
        }
コード例 #15
0
        protected JObject SerializePart(ContentPart part) {
            var partObject = new JObject();

            // see if we have a Record property...
            var recordPropertyInfo = part.GetType().GetProperty("Record");
            if (recordPropertyInfo != null) {

                // get the value and serialize it...
                object val = recordPropertyInfo.GetValue(part, BindingFlags.GetProperty, null, null, null);
                if (val != null) {
                    var serializer = new JsonSerializer { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
                    JObject recordObject = JObject.FromObject(val,
                    serializer);
                    partObject.Add("Record", recordObject);
                }
            }

            // now add the fields to the json object....
            var fieldsArray = new JArray();

            foreach (var contentField in part.Fields) {
                var fieldObject = SerializeField(contentField);
                fieldsArray.Add(fieldObject);
            }

            partObject.Add("Fields", fieldsArray);

            // add the settings...
            var settingsObject = new JObject();

            foreach ( var key in part.Settings.Keys) {
                settingsObject.Add(new JProperty(key, part.Settings[key]));
            }

            partObject.Add("Settings", settingsObject);

            // add the part settings...
            var partSettingsObject = new JObject();

            foreach (string key in part.TypePartDefinition.Settings.Keys) {
                partSettingsObject.Add(new JProperty(key, part.TypePartDefinition.Settings[key]));
            }

            partObject.Add("TypePartDefinition.Settings", partSettingsObject);

            return partObject;
        }
コード例 #16
0
        public void ContentItemPropertyOnPartRootsYou() {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            var anotherPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("AnotherPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);
            contentItem.Weld(anotherPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.TestingPart;
            dynamic anotherPartDynamic  = contentItemDynamic.AnotherPart;

            dynamic contentItemDynamic1  = testingPartDynamic.ContentItem;
            dynamic contentItemDynamic2  = anotherPartDynamic.ContentItem;

            Assert.That((object)contentItemDynamic1, Is.SameAs(contentItem));
            Assert.That((object)contentItemDynamic2, Is.SameAs(contentItem));
        }
コード例 #17
0
ファイル: SettingsStep.cs プロジェクト: Higea/Orchard
        private IEnumerable<XAttribute> ExportSettingsPartAttributes(ContentPart sitePart) {
            foreach (var property in sitePart.GetType().GetProperties().OrderBy(x => x.Name)) {
                var propertyType = property.PropertyType;

                // Supported types (we also know they are not indexed properties).
                if (propertyType == typeof(string) || propertyType == typeof(bool) || propertyType == typeof(int)) {
                    // Exclude read-only properties.
                    if (property.GetSetMethod() != null) {
                        var value = property.GetValue(sitePart, null);
                        if (value == null)
                            continue;

                        yield return new XAttribute(property.Name, value);
                    }
                }
            }
        }
        public IHtmlString BuildAndCacheOutput(Func<IHtmlString> htmlStringFactory, ContentPart part)
        {
            var cachedPartMetadata = _outputCachedPartsContext.GetCachedPartMetadata(part);

            if (cachedPartMetadata == null) 
            {
                return htmlStringFactory();
            }

            var cachedModel = _outputCachedPartsContext.GetCacheModel(() => htmlStringFactory().ToHtmlString());

            if (string.IsNullOrEmpty(cachedModel.Html)
                && !cachedModel.FootScripts.Any()
                && !cachedModel.HeadScripts.Any()
                && !cachedModel.IncludedResources.Any()
                && !cachedModel.RequiredResources.Any())
            {
                return new HtmlString(string.Empty);
            }

            if (cachedPartMetadata.Timespan.HasValue)
            {
                _cacheService.Put(cachedPartMetadata.CacheKey, cachedModel, cachedPartMetadata.Timespan.Value);
            }
            else
            {
                _cacheService.Put(cachedPartMetadata.CacheKey, cachedModel);
            }

            var currentRecords = _cacheKeyRepository.Fetch(r => r.CacheKey == cachedPartMetadata.CacheKey);

            foreach (var currentRecord in currentRecords)
            {
                _cacheKeyRepository.Delete(currentRecord);
            }

            _cacheKeyRepository.Create(new CacheKeyRecord {
                CacheKey = cachedPartMetadata.CacheKey,
                ContentId = part.Id,
                PartName = part.PartDefinition.Name
            });

            return new HtmlString(cachedModel.Html);
        }
 private ContentPart CreateContentItemPart() {
     var partDefinition = FooPartDefinition();
     var typeDefinition = new ContentTypeDefinitionBuilder()
         .WithPart(partDefinition, part => { })
         .Build();
     var contentItem = new ContentItem {
         VersionRecord = new ContentItemVersionRecord {
             ContentItemRecord = new ContentItemRecord()
         }
     };
     var contentPart = new ContentPart {
         TypePartDefinition = typeDefinition.Parts.Single()
     };
     contentItem.Weld(contentPart);
     contentItem.Weld(new InfosetPart {
         Infoset = contentItem.Record.Infoset,
         VersionInfoset = contentItem.VersionRecord.Infoset
     });
     return contentPart;
 }
コード例 #20
0
 private static void SetSetting(XAttribute attribute, ContentPart contentPart) {
     var attributeName = attribute.Name.LocalName;
     var attributeValue = attribute.Value;
     var property = contentPart.GetType().GetProperty(attributeName);
     if (property == null) {
         throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because it was not found.", attributeName, contentPart.PartDefinition.Name));
     }
     var propertyType = property.PropertyType;
     if (propertyType == typeof(string)) {
         property.SetValue(contentPart, attributeValue, null);
     }
     else if (propertyType == typeof(bool)) {
         property.SetValue(contentPart, Boolean.Parse(attributeValue), null);
     }
     else if (propertyType == typeof(int)) {
         property.SetValue(contentPart, Int32.Parse(attributeValue), null);
     }
     else {
         throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because its type is not supported. Settings should be integer,boolean or string.", attributeName, contentPart.PartDefinition.Name));
     }
 }
コード例 #21
0
        private void ImportSettingPart(ContentPart sitePart, XElement element) {

            foreach (var attribute in element.Attributes()) {
                var attributeName = attribute.Name.LocalName;
                var attributeValue = attribute.Value;

                var property = sitePart.GetType().GetProperty(attributeName);
                if (property == null) {
                    throw new InvalidOperationException(string.Format("Could set setting {0} for part {1} because it was not found.", attributeName, sitePart.PartDefinition.Name));
                }

                var propertyType = property.PropertyType;
                if (propertyType == typeof(string)) {
                    property.SetValue(sitePart, attributeValue, null);
                }
                else if (propertyType == typeof(bool)) {
                    property.SetValue(sitePart, Boolean.Parse(attributeValue), null);
                }
                else if (propertyType == typeof(int)) {
                    property.SetValue(sitePart, Int32.Parse(attributeValue), null);
                }
            }
        }
コード例 #22
0
        private void ImportSettingPart(ContentPart sitePart, XElement element) {

            foreach (var attribute in element.Attributes()) {
                var attributeName = attribute.Name.LocalName;
                var attributeValue = attribute.Value;

                var property = sitePart.GetType().GetProperty(attributeName);
                if (property == null) {
                    continue;
                }

                var propertyType = property.PropertyType;
                if (propertyType == typeof(string)) {
                    property.SetValue(sitePart, attributeValue, null);
                }
                else if (propertyType == typeof(bool)) {
                    property.SetValue(sitePart, Boolean.Parse(attributeValue), null);
                }
                else if (propertyType == typeof(int)) {
                    property.SetValue(sitePart, Int32.Parse(attributeValue), null);
                }
            }
        }
コード例 #23
0
 public void Weld(ContentPart part) {
     part.ContentItem = this;
     _parts.Add(part);
 }
コード例 #24
0
 public IFieldStorage BindStorage(ContentPart contentPart, ContentPartFieldDefinition partFieldDefinition) {
     return new DefaultCotentPartFieldStorage(contentPart, partFieldDefinition);
 }
コード例 #25
0
 private IContentQuery<ContentItem, CommonPartRecord> GetForumQuery(ContentPart<ForumPartRecord> forum, VersionOptions versionOptions)
 {
     return
         _contentManager.Query(versionOptions, ContentPartConstants.Thread).Join<CommonPartRecord>().Where(
             cr => cr.Container == forum.Record.ContentItemRecord).OrderByDescending(cr => cr.CreatedUtc);
 }
コード例 #26
0
ファイル: BlogPostService.cs プロジェクト: kanujhun/orchard
 private IContentQuery<ContentItem, CommonPartRecord> GetBlogQuery(ContentPart<BlogPartRecord> blog, VersionOptions versionOptions) {
     return
         _contentManager.Query(versionOptions, "BlogPost")
         .Join<CommonPartRecord>().Where(
             cr => cr.Container == blog.Record.ContentItemRecord).OrderByDescending(cr => cr.CreatedUtc)
         .WithQueryHintsFor("BlogPost")
             ;
 }
コード例 #27
0
 void Generate(PublishContentContext context, ContentPart part) {
     if(_orchardServices.WorkContext.CurrentSite.As<WarmupSettingsPart>().OnPublish) {
         _warmupScheduler.Schedule(true);
     }
 }
コード例 #28
0
        public void DumpContentItem_DepthSix() {
            var contentItem = new ContentItem { ContentType = "TestContentType" };
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            var objectDumper = new ObjectDumper(6);
            var xElement = objectDumper.Dump(contentItem, "Model");

            var stringBuilder = new StringBuilder();
            ObjectDumper.ConvertToJSon(xElement, stringBuilder);
            var json = stringBuilder.ToString();

            var jObject = new JObject(
                new JProperty("name", "Model"),
                new JProperty("value", "ContentItem"),
                new JProperty("children", new JArray(
                    new JObject(
                        new JProperty("name", "Id"),
                        new JProperty("value", "0")),
                    new JObject(
                        new JProperty("name", "Version"),
                        new JProperty("value", "0")),
                    new JObject(
                        new JProperty("name", "ContentType"),
                        new JProperty("value", "&quot;TestContentType&quot;")),
                    new JObject(
                        new JProperty("name", "TestingPart"),
                        new JProperty("value", "ContentPart"),
                        new JProperty("children", new JArray(
                            new JObject(
                                new JProperty("name", "Id"),
                                new JProperty("value", "0")),
                            new JObject(
                                new JProperty("name", "TypeDefinition"),
                                new JProperty("value", "null")),
                            new JObject(
                                new JProperty("name", "TypePartDefinition"),
                                new JProperty("value", "ContentTypePartDefinition"),
                                new JProperty("children", new JArray(
                                    new JObject(
                                        new JProperty("name", "PartDefinition"),
                                        new JProperty("value", "ContentPartDefinition"),
                                        new JProperty("children", new JArray(
                                                new JObject(
                                                    new JProperty("name", "Name"),
                                                    new JProperty("value", "&quot;TestingPart&quot;")),
                                                new JObject(
                                                    new JProperty("name", "Fields"),
                                                    new JProperty("value", "ContentPartFieldDefinition[]")),
                                                new JObject(
                                                    new JProperty("name", "Settings"),
                                                    new JProperty("value", "SettingsDictionary"))))),
                                    new JObject(
                                        new JProperty("name", "Settings"),
                                        new JProperty("value", "SettingsDictionary")),
                                    new JObject(
                                        new JProperty("name", "ContentTypeDefinition"),
                                        new JProperty("value", "null"))))),
                            new JObject(
                                new JProperty("name", "PartDefinition"),
                                new JProperty("value", "ContentPartDefinition"),
                                new JProperty("children", new JArray(
                                    new JObject(
                                        new JProperty("name", "Name"),
                                        new JProperty("value", "&quot;TestingPart&quot;")),
                                    new JObject(
                                        new JProperty("name", "Fields"),
                                        new JProperty("value", "ContentPartFieldDefinition[]")),
                                    new JObject(
                                        new JProperty("name", "Settings"),
                                        new JProperty("value", "SettingsDictionary"))))),
                            new JObject(
                                new JProperty("name", "Settings"),
                                new JProperty("value", "SettingsDictionary")),
                            new JObject(
                                new JProperty("name", "Fields"),
                                new JProperty("value", "List&lt;ContentField&gt;"))))))));

            ComparareJsonObject(jObject, json);
        }
コード例 #29
0
 void RemoveIndexingTask(RemoveContentContext context, ContentPart part) {
     _indexingTaskManager.CreateDeleteIndexTask(context.ContentItem);
 }
コード例 #30
0
ファイル: ContentPartBehavior.cs プロジェクト: dioptre/nkd
 public ContentPartBehavior(ContentPart contentPart)
     : base(contentPart)
 {
     _contentPart = contentPart;
 }
コード例 #31
0
 public void Weld(ContentPart part)
 {
     part.ContentItem = this;
     _parts.Add(part);
 }