public void MapContentTypeToContentPart(string contentType, string contentPart)
        {
            // Create content type if needed
            var contentTypeRecord = GetContentTypeRecord(contentType);
            if (contentTypeRecord == null) {
                contentTypeRecord = new ContentTypeRecord { Name = contentType };
                _contentTypeRepository.Create(contentTypeRecord);
            }

            // Create part name if needed
            var contentTypePartNameRecord = GetContentPartNameRecord(contentPart);
            if (contentTypePartNameRecord == null) {
                contentTypePartNameRecord = new ContentTypePartNameRecord { PartName = contentPart };
                _contentTypePartNameRepository.Create(contentTypePartNameRecord);
            }

            // Add part name to content type
            var contentTypePartRecord = new ContentTypePartRecord { PartName = contentTypePartNameRecord };
            contentTypeRecord.ContentParts.Add(contentTypePartRecord);
        }
Example #2
0
 private ContentTypeRecord AcquireContentTypeRecord(string contentType)
 {
     var contentTypeRecord = _contentTypeRepository.Get(x => x.Name == contentType);
     if (contentTypeRecord == null)
     {
         //TEMP: this is not safe... ContentItem types could be created concurrently?
         contentTypeRecord = new ContentTypeRecord { Name = contentType };
         _contentTypeRepository.Create(contentTypeRecord);
     }
     return contentTypeRecord;
 }
Example #3
0
        private ContentTypeRecord AcquireContentTypeRecord(string contentType)
        {
            var contentTypeRecord = _contentStorageManager
                .Query<ContentTypeRecord>(x => x.Name == contentType)
                .SingleOrDefault();

            if (contentTypeRecord == null) {
                //TEMP: this is not safe... ContentItem types could be created concurrently?
                contentTypeRecord = new ContentTypeRecord { Name = contentType };
                _contentStorageManager.Store(contentTypeRecord);
            }

            var contentTypeId = contentTypeRecord.Id;

            // There is a case when a content type record is created locally but the transaction is actually
            // cancelled. In this case we are caching an Id which is none existent, or might represent another
            // content type. Thus we need to ensure that the cache is valid, or invalidate it and retrieve it
            // another time.

            var result = _contentStorageManager
                .Get<ContentTypeRecord>(contentTypeId);

            if (result != null && result.Name.Equals(contentType, StringComparison.OrdinalIgnoreCase)) {
                return result;
            }

            // invalidate the cache entry and load it again
            return AcquireContentTypeRecord(contentType);
        }