示例#1
0
 public override void Loading(LoadContentContext context) {
     var infosetPart = context.ContentItem.As<InfosetPart>();
     if (infosetPart != null) {
         infosetPart.Infoset = context.ContentItemRecord.Infoset;
         infosetPart.VersionInfoset = context.ContentItemVersionRecord.Infoset;
     }
 }
        protected override void Loaded(LoadContentContext context)
        {
            base.Loaded(context);

            if (_contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType) == null) return;

            var fields = context.ContentItem.Parts.SelectMany(x => x.Fields.OfType<MoneyField>());

            foreach (var field in fields)
            {
                field.ValueField.Loader(() =>
                {
                    if (field.Amount.HasValue)
                    {
                        Currency parsedCurrency;

                        Currency.TryParse(
                            string.IsNullOrEmpty(field.CurrencyIso3LetterCode)
                                ? field.PartFieldDefinition.Settings.GetModel<MoneyFieldSettings>().DefaultCurrency
                                : field.CurrencyIso3LetterCode,
                            out parsedCurrency);

                        return new Money(field.Amount.Value, parsedCurrency);
                    }
                    else
                    {
                        return null;
                    }
                });
            }
        }
 protected override void Loading(LoadContentContext context)
 {
     if (context.ContentType == "LocalizedTagCloud")
     {
         SetupTagCloudLoader(context.ContentItem);
     }
     base.Loading(context);
 }
 private IList<UserProviderEntry> OnLoader(LoadContentContext context) {
         return _userProviderRepository
             .Fetch(x => x.UserId == context.ContentItem.Id)
             .Select(x => new UserProviderEntry {
                 Id = x.Id,
                 ProviderUserId = x.ProviderUserId,
                 ProviderName = x.ProviderName
             })
             .ToList();
 }
        protected override void Loaded(LoadContentContext context)
        {
            base.Loaded(context);

            var fields = context.ContentItem.Parts.SelectMany(x => x.Fields.OfType<MediaLibraryUploadField>());

            if (_contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType) == null) return;

            foreach (var field in fields) field.MediaPartsField.Loader(() => _contentManager.GetMany<MediaPart>(field.Ids, VersionOptions.Published, QueryHints.Empty).ToList());
        }
示例#6
0
        private void LoadBids(LoadContentContext context, BidsPart part) {
            part._bidsFields.Loader(field => {

                var bids = _bidService.GetBidsForBidedContent(context.ContentItem.Id);
                return bids.List();
            });

            part._heighestBidField.Loader(field => part
                ._bidsFields
                .Value
                .OrderByDescending(b => b.BidPrice)
                .FirstOrDefault());
        }
示例#7
0
        void LazyLoadHandlers(LoadContentContext context, SmtpSettingsPart part) {
            part.PasswordField.Getter(() => {
                try {
                    return String.IsNullOrWhiteSpace(part.Record.Password) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(part.Record.Password)));
                }
                catch {
                    Logger.Error("The email password could not be decrypted. It might be corrupted, try to reset it.");
                    return null;
                }
            });

            part.PasswordField.Setter(value => part.Record.Password = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value))));
        }
        protected override void Loading(LoadContentContext context) {
            base.Loading(context);

            var fields = context.ContentItem.Parts.SelectMany(x => x.Fields.Where(f => f.FieldDefinition.Name == typeof(MediaLibraryPickerField).Name)).Cast<MediaLibraryPickerField>();
            
            // define lazy initializer for ContentPickerField.ContentItems
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
            if (contentTypeDefinition == null) {
                return;
            }

            foreach (var field in fields) {
                var localField = field;
                field._contentItems.Loader(x => _contentManager.GetMany<MediaPart>(localField.Ids, VersionOptions.Published, QueryHints.Empty));
            }
        }
        protected override void Loading(LoadContentContext context) {
            base.Loading(context);

            var fields = context.ContentItem.Parts.SelectMany(x => x.Fields.Where(f => f.FieldDefinition.Name == typeof (MediaGalleryField).Name)).Cast<MediaGalleryField>();
            
            // define lazy initializer for MediaGalleryField.Items
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
            if (contentTypeDefinition == null) {
                return;
            }

            foreach (var field in fields) {
                var localField = field;
                field._mediaGalleryItems.Loader(x => _jsonConverter.Deserialize<MediaGalleryItem[]>(localField.SelectedItems ?? "[]") ?? new MediaGalleryItem[0]);
            }
        }
        public override void Loading(LoadContentContext context)
        {
            // This method is called on Get()
            // Adds all the missing parts to a content item based on the content type definition.

            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
            if (contentTypeDefinition == null)
                return;

            var partInfos = _partDrivers.Select(cpp => cpp.GetPartInfo()).ToArray();
            var fieldInfos = _fieldDrivers.Select(cpp => cpp.GetFieldInfo()).ToArray();

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName = typePartDefinition.PartDefinition.Name;
                if (!context.ContentItem.Has(partName))
                {
                    var partInfo = partInfos.FirstOrDefault(pi => pi.PartName == partName);
                    var part = partInfo != null
                        ? partInfo.Factory(typePartDefinition)
                        : new ContentPart();

                    context.ContentItem.Weld(partName, part);
                }

                foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields)
                {
                    var part = context.ContentItem.Get(partName);
                    var fieldName = partFieldDefinition.Name;

                    if (!part.Has(fieldName))
                    {

                        var fieldTypeName = partFieldDefinition.FieldDefinition.Name;
                        var fieldInfo = fieldInfos.FirstOrDefault(fi => fi.FieldTypeName == fieldTypeName);
                        var field = fieldInfo != null
                            ? fieldInfo.Factory(partFieldDefinition)
                            : new ContentField();

                        context.ContentItem.Get(partName).Weld(fieldName, field);
                    }
                }
            }
        }
示例#11
0
        void LazyLoadHandlers(LoadContentContext context, SmtpSettingsPart part) {
            part.PasswordField.Getter(() => {
                try {
                    var encryptedPassword = part.Retrieve(x => x.Password);
                    return String.IsNullOrWhiteSpace(encryptedPassword) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(encryptedPassword)));
                }
                catch {
                    Logger.Error("The email password could not be decrypted. It might be corrupted, try to reset it.");
                    return null;
                }
            });

            part.PasswordField.Setter(value => {
                var encryptedPassword = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value)));
                part.Store(x => x.Password, encryptedPassword);
            });

            part.AddressPlaceholderField.Loader(() => (string)((dynamic)ConfigurationManager.GetSection("system.net/mailSettings/smtp")).From);
        }
 private void LazyLoadHandlers(LoadContentContext context, FeaturedProductPart part) {
     part
         ._productField
         .Loader(prt => part.Record.Product == null ? null : _contentManager.Get(part.Record.Product.Id));
 }
 public void Loading(LoadContentContext context)
 {
 }
        protected void LazyLoadHandlers(LoadContentContext context, ExtendedMenuItemPart part)
        {
            part.MenuVersionField.Loader(() => {
                if (part.Record != null && part.Record.MenuVersionRecord != null) {
                    // Adding consistency check - the version loaded must be a version of the currently set menu
                    var menu = part.As<MenuPart>().Menu;
                    if (menu != null && menu.Id == part.Record.MenuVersionRecord.ContentItemRecord.Id) {
                        return context.ContentManager.Get(-1, VersionOptions.VersionRecord(part.Record.MenuVersionRecord.Id));
                    }

                    // if the version is not consistent with the menu item - must be nullified
                    part.MenuVersion = null;
                }

                return null;
            });

            part.IsChangedField.Loader(() => _versions.HasDraftVersion(part.Id));
            part.IsCurrentField.Loader(() => !part.IsDraft && part.HasPosition);
            part.IsDraftField.Loader(() => part.As<IVersionAspect>().Draft && !part.HasPosition && !part.HasPublished);
            part.IsNewField.Loader(() => !part.HasPublished);
            part.IsPublishedField.Loader(() => part.ContentItem.VersionRecord != null && part.As<IVersionAspect>().Published);
            part.PublishedVersionField.Loader(() => _versions.GetCurrent(part.ContentItem));
            part.IsRemovedField.Loader(() => part.As<IVersionAspect>().Removed);
            part.HasPublishedField.Loader(() => _versions.HasPublishedVersion(part.Id));
            part.HasLatestField.Loader(() => _versions.HasLatestVersion(part.Id));

            // Forcing parent position to update if it hasn't been updated yet
            var parent = part.ParentPosition;
        }
 void IContentHandler.Loading(LoadContentContext context)
 {
 }
 public void Loaded(LoadContentContext context)
 {
 }
        protected override void Loading(LoadContentContext context)
        {
            if (context.ContentItem.Is<ConnectorPart>()) {
 	            ConnectorPropertyGetHandlers(context.ContentItem.As<ConnectorPart>());
            }
        }
 void IContentHandler.Loaded(LoadContentContext context)
 {
 }
 void LazyLoadHandlers(LoadContentContext context, CommonAspect aspect) {
     // add handlers that will load content for id's just-in-time
     aspect.OwnerField.Loader(() => _contentManager.Get<IUser>(aspect.Record.OwnerId));
     aspect.ContainerField.Loader(() => aspect.Record.Container == null ? null : _contentManager.Get(aspect.Record.Container.Id));
 }
 public virtual void Loaded(LoadContentContext context)
 {
 }
 protected void LazyLoadHandlers(LoadContentContext context, UserProvidersPart part) {
     // Add handlers that will load content for id's just-in-time
     part.ProviderEntriesField.Loader(x => OnLoader(context));
 }
示例#22
0
 protected override void Loading(LoadContentContext context)
 {
     base.Loading(context);
 }
示例#23
0
        public virtual ContentItem Get(int id, VersionOptions options)
        {
            ContentItem contentItem;

            ContentItemVersionRecord versionRecord = null;

            // obtain the root records based on version options
            if (options.VersionRecordId != 0) {
                // short-circuit if item held in session
                if (_contentManagerSession.RecallVersionRecordId(options.VersionRecordId, out contentItem)) {
                    return contentItem;
                }

                versionRecord = _contentItemStore.Get(id, options).VersionRecord;
            }
            else if (options.VersionNumber != 0) {
                // short-circuit if item held in session
                if (_contentManagerSession.RecallVersionNumber(id, options.VersionNumber, out contentItem)) {
                    return contentItem;
                }

                versionRecord = _contentItemStore.Get(id, options).VersionRecord;
            }
            else if (_contentManagerSession.RecallContentRecordId(id, out contentItem)) {
                // try to reload a previously loaded published content item

                if (options.IsPublished) {
                    return contentItem;
                }

                versionRecord = contentItem.VersionRecord;
            }

            // no record means content item is not in db
            if (versionRecord == null) {
                // check in memory
                var record = _contentItemStore.Get(id, options).VersionRecord;
                if (record == null) {
                    return null;
                }

                versionRecord = record;
            }

            // return item if obtained earlier in session
            if (_contentManagerSession.RecallVersionRecordId(versionRecord.Id, out contentItem)) {
                if (options.IsDraftRequired && versionRecord.Published) {
                    return BuildNewVersion(contentItem);
                }
                return contentItem;
            }

            // allocate instance and set record property
            contentItem = New(versionRecord.ContentItemRecord.ContentType.Name);
            contentItem.VersionRecord = versionRecord;

            // store in session prior to loading to avoid some problems with simple circular dependencies
            _contentManagerSession.Store(contentItem);

            // create a context with a new instance to load
            var context = new LoadContentContext(contentItem);

            // invoke handlers to acquire state, or at least establish lazy loading callbacks
            Handlers.Invoke(handler => handler.Loading(context), _logger);
            Handlers.Invoke(handler => handler.Loaded(context), _logger);

            // when draft is required and latest is published a new version is appended
            if (options.IsDraftRequired && versionRecord.Published) {
                contentItem = BuildNewVersion(context.ContentItem);
            }

            return contentItem;
        }
        public async Task<ContentItem> GetAsync(int contentItemId, VersionOptions options)
        {
            ContentItem contentItem;

            // obtain the root records based on version options
            if (options.VersionRecordId != 0)
            {
                if (_contentManagerSession.RecallVersionId(options.VersionRecordId, out contentItem))
                {
                    return contentItem;
                }

                contentItem = await _session.GetAsync<ContentItem>(options.VersionRecordId);
            }
            else if (options.VersionNumber != 0)
            {
                if (_contentManagerSession.RecallContentItemId(contentItemId, options.VersionNumber, out contentItem))
                {
                    return contentItem;
                }

                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x =>
                        x.ContentItemId == contentItemId &&
                        x.Number == options.VersionNumber
                    )
                    .FirstOrDefault();
            }
            else if (_contentManagerSession.RecallPublishedItemId(contentItemId, out contentItem))
            {
                if (options.IsPublished)
                {
                    return contentItem;
                }
            }
            else if (options.IsLatest)
            {
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x => x.ContentItemId == contentItemId && x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsDraft && !options.IsDraftRequired)
            {
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x =>
                        x.ContentItemId == contentItemId &&
                        x.Published == false &&
                        x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsDraft || options.IsDraftRequired)
            {
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x =>
                        x.ContentItemId == contentItemId &&
                        x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsPublished)
            {
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x => x.ContentItemId == contentItemId && x.Published == true)
                    .FirstOrDefault();
            }

            if (contentItem == null)
            {
                if (!options.IsDraftRequired)
                {
                    return null;
                }
            }

            // store in session prior to loading to avoid some problems with simple circular dependencies
            _contentManagerSession.Store(contentItem);

            // create a context with a new instance to load
            var context = new LoadContentContext(contentItem);

            // invoke handlers to acquire state, or at least establish lazy loading callbacks
            Handlers.Invoke(handler => handler.Loading(context), _logger);
            Handlers.Invoke(handler => handler.Loaded(context), _logger);

            // when draft is required and latest is published a new version is appended
            if (options.IsDraftRequired && contentItem.Published)
            {
                contentItem = await BuildNewVersionAsync(context.ContentItem);
            }

            return contentItem;
        }
示例#25
0
        public async Task<ContentItem> Get(int id, VersionOptions options) {
            ContentItem contentItem;

            ContentItemVersionRecord versionRecord = null;

            // obtain the root records based on version options
            if (options.VersionRecordId != 0) {

                if (_contentManagerSession.RecallVersionRecordId(options.VersionRecordId, out contentItem))
                {
                    return contentItem;
                }

                versionRecord = await _session
                    .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>()
                    .Where(x => x.Id == options.VersionRecordId)
                    .FirstOrDefault();
            }
            else if (options.VersionNumber != 0) {
                if (_contentManagerSession.RecallVersionNumber(id, options.VersionNumber, out contentItem))
                {
                    return contentItem;
                }

                versionRecord = await _session
                    .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>()
                    .Where(x =>
                        x.ContentItemId == id &&
                        x.Number == options.VersionNumber
                    )
                    .FirstOrDefault();

            }
            else if (_contentManagerSession.RecallContentRecordId(id, out contentItem))
            {
                // try to reload a previously loaded published content item

                if (options.IsPublished)
                {
                    return contentItem;
                }

                versionRecord = contentItem.VersionRecord;
            }
            else if (options.IsLatest)
            {
                versionRecord = await _session
                    .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>()
                    .Where(x => x.ContentItemId == id && x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsDraft && !options.IsDraftRequired)
            {
                versionRecord = await _session
                    .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>()
                    .Where(x =>
                        x.ContentItemId == id &&
                        x.Published == false &&
                        x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsDraft || options.IsDraftRequired)
            {
                versionRecord = await _session
                    .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>()
                    .Where(x => x.ContentItemId == id && x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsPublished)
            {
                versionRecord = await _session
                    .QueryAsync<ContentItemVersionRecord, ContentItemVersionRecordIndex>()
                    .Where(x => x.ContentItemId == id && x.Published == true)
                    .FirstOrDefault();
            }
                
            if(versionRecord == null && !options.IsDraftRequired)
            {
                return null;
            }
            
            var record = await _session.GetAsync<ContentItemRecord>(id);

            // allocate instance and set record property
            contentItem = New(versionRecord.ContentType);
            contentItem.Record = record;
            contentItem.VersionRecord = versionRecord;

            // store in session prior to loading to avoid some problems with simple circular dependencies
            _contentManagerSession.Store(contentItem);

            // create a context with a new instance to load            
            var context = new LoadContentContext(contentItem);

            // invoke handlers to acquire state, or at least establish lazy loading callbacks
            Handlers.Invoke(handler => handler.Loading(context), _logger);
            Handlers.Invoke(handler => handler.Loaded(context), _logger);

            // when draft is required and latest is published a new version is appended 
            if (options.IsDraftRequired && versionRecord.Published) {
                contentItem = await BuildNewVersionAsync(context.ContentItem);
            }

            return contentItem;
        }
示例#26
0
 protected virtual void Loaded(LoadContentContext context)
 {
 }
 protected override void Loaded(LoadContentContext context) {
     base.Loading(context);
     InitilizeLoader(context.ContentItem);
 }
示例#28
0
        public async Task<ContentItem> GetAsync(int contentItemId, VersionOptions options)
        {
            ContentItem contentItem = null;

            // obtain the root records based on version options
            if (options.VersionRecordId != 0)
            {
                if (_contentManagerSession.RecallVersionId(options.VersionRecordId, out contentItem))
                {
                    return contentItem;
                }

                contentItem = await _session.GetAsync<ContentItem>(options.VersionRecordId);
            }
            else if (options.VersionNumber != 0)
            {
                if (_contentManagerSession.RecallContentItemId(contentItemId, options.VersionNumber, out contentItem))
                {
                    return contentItem;
                }

                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x =>
                        x.ContentItemId == contentItemId &&
                        x.Number == options.VersionNumber
                    )
                    .FirstOrDefault();
            }
            else if (options.IsLatest)
            {
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x => x.ContentItemId == contentItemId && x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsDraft && !options.IsDraftRequired)
            {
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x =>
                        x.ContentItemId == contentItemId &&
                        x.Published == false &&
                        x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsDraft || options.IsDraftRequired)
            {
                // Loaded whatever is the latest as it will be cloned
                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x =>
                        x.ContentItemId == contentItemId &&
                        x.Latest == true)
                    .FirstOrDefault();
            }
            else if (options.IsPublished)
            {
                // If the published version is requested and is already loaded, we can
                // return it right away
                if(_contentManagerSession.RecallPublishedItemId(contentItemId, out contentItem))
                {
                    return contentItem;
                }

                contentItem = await _session
                    .QueryAsync<ContentItem, ContentItemIndex>()
                    .Where(x => x.ContentItemId == contentItemId && x.Published == true)
                    .FirstOrDefault();
            }

            if (contentItem == null)
            {
                if (!options.IsDraftRequired)
                {
                    return null;
                }
            }

            // Return item if obtained earlier in session
            // If IsPublished is required then the test has already been checked before
            ContentItem recalled = null;
            if (!_contentManagerSession.RecallVersionId(contentItem.Id, out recalled))
            {
                // store in session prior to loading to avoid some problems with simple circular dependencies
                _contentManagerSession.Store(contentItem);

                // create a context with a new instance to load
                var context = new LoadContentContext(contentItem);

                // invoke handlers to acquire state, or at least establish lazy loading callbacks
                Handlers.Invoke(handler => handler.Loading(context), _logger);
                Handlers.Invoke(handler => handler.Loaded(context), _logger);

                contentItem = context.ContentItem;
            }
            else
            {
                contentItem = recalled;
            }

            if (options.IsDraftRequired)
            {
                // When draft is required and latest is published a new version is added
                if (contentItem.Published)
                {
                    // Save the previous version
                    _session.Save(contentItem);

                    contentItem = await BuildNewVersionAsync(contentItem);
                }

                // Save the new version
                _session.Save(contentItem);
            }

            return contentItem;
        }
示例#29
0
 protected override void Loading(LoadContentContext context) {
     foreach (var part in context.ContentItem.Parts) {
         LazyLoadHandlers(part);
     }
 }
 void LazyLoadHandlers(LoadContentContext context, SmtpSettingsPart part) {
     part.PasswordField.Getter(() => String.IsNullOrWhiteSpace(part.Record.Password) ? String.Empty : Encoding.UTF8.GetString(_encryptionService.Decode(Convert.FromBase64String(part.Record.Password))));
     part.PasswordField.Setter(value => part.Record.Password = String.IsNullOrWhiteSpace(value) ? String.Empty : Convert.ToBase64String(_encryptionService.Encode(Encoding.UTF8.GetBytes(value))));
 }
示例#31
0
 public virtual void Loaded(LoadContentContext context, TPart instance)
 {
 }