本文整理汇总了C#中IContentManager.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IContentManager.Get方法的具体用法?C# IContentManager.Get怎么用?C# IContentManager.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContentManager
的用法示例。
在下文中一共展示了IContentManager.Get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TermsPartHandler
public TermsPartHandler(
IContentDefinitionManager contentDefinitionManager,
IRepository<TermsPartRecord> repository,
ITaxonomyService taxonomyService,
IContentManager contentManager) {
_contentDefinitionManager = contentDefinitionManager;
_contentManager = contentManager;
Filters.Add(StorageFilter.For(repository));
OnPublished<TermsPart>((context, part) => RecalculateCount(contentManager, taxonomyService, part));
OnUnpublished<TermsPart>((context, part) => RecalculateCount(contentManager, taxonomyService, part));
OnRemoved<TermsPart>((context, part) => RecalculateCount(contentManager, taxonomyService, part));
// tells how to load the field terms on demand
OnLoaded<TermsPart>((context, part) => {
foreach(var field in part.ContentItem.Parts.SelectMany(p => p.Fields).OfType<TaxonomyField>()) {
var tempField = field.Name;
var fieldTermRecordIds = part.Record.Terms.Where(t => t.Field == tempField).Select(tci => tci.TermRecord.Id);
field.Terms.Loader(value => fieldTermRecordIds.Select(id => _contentManager.Get<TermPart>(id)));
}
});
OnIndexing<TermsPart>(
(context, part) => {
foreach (var term in part.Terms) {
var value = context.ContentManager.Get(term.TermRecord.Id).As<TitlePart>().Title;
context.DocumentIndex.Add(term.Field, value).Analyze();
context.DocumentIndex.Add(term.Field + "-id", term.Id).Store();
}
});
}
示例2: CommentPartHandler
public CommentPartHandler(
IRepository<CommentPartRecord> commentsRepository,
IContentManager contentManager,
ICommentService commentService
) {
Filters.Add(StorageFilter.For(commentsRepository));
OnLoading<CommentPart>((context, comment) => {
comment.CommentedOnContentItemField.Loader(
item => contentManager.Get(comment.CommentedOn)
);
comment.CommentedOnContentItemMetadataField.Loader(
item => contentManager.GetItemMetadata(comment.CommentedOnContentItem)
);
});
OnRemoving<CommentPart>((context, comment) => {
foreach(var response in contentManager.Query<CommentPart, CommentPartRecord>().Where(x => x.RepliedOn == comment.Id).List()) {
contentManager.Remove(response.ContentItem);
}
});
// keep CommentsPart.Count in sync
OnPublished<CommentPart>((context, part) => commentService.ProcessCommentsCount(part.CommentedOn));
OnUnpublished<CommentPart>((context, part) => commentService.ProcessCommentsCount(part.CommentedOn));
OnVersioned<CommentPart>((context, part, newVersionPart) => commentService.ProcessCommentsCount(newVersionPart.CommentedOn));
OnRemoved<CommentPart>((context, part) => commentService.ProcessCommentsCount(part.CommentedOn));
OnIndexing<CommentPart>((context, commentPart) => context.DocumentIndex
.Add("commentText", commentPart.Record.CommentText));
}
示例3: ContentMenuItemPartHandler
public ContentMenuItemPartHandler(IContentManager contentManager, IRepository<ContentMenuItemPartRecord> repository) {
_contentManager = contentManager;
Filters.Add(new ActivatingFilter<ContentMenuItemPart>("ContentMenuItem"));
Filters.Add(StorageFilter.For(repository));
OnLoading<ContentMenuItemPart>((context, part) => part._content.Loader(p => contentManager.Get(part.Record.ContentMenuItemRecord.Id)));
}
示例4: CustomerPartHandler
public CustomerPartHandler(
IContentManager contentManager,
ICustomersService customersService,
IRepository<CustomerPartRecord> repository
)
{
Filters.Add(StorageFilter.For(repository));
OnActivated<CustomerPart>((context, part) => {
// User field
part._user.Loader(user => contentManager.Get<IUser>(part.UserId));
part._user.Setter(user => {
part.UserId = (user != null ? user.Id : 0);
return user;
});
// Default address field
part._defaultAddress.Loader(address => customersService.GetAddress(part.DefaultAddressId));
part._defaultAddress.Setter(address => {
part.DefaultAddressId = (address != null ? address.Id : 0);
return address;
});
// Addresses field
part._addresses.Loader(addresses => customersService.GetAddressesForCustomer(part));
});
OnRemoving<CustomerPart>((context, part) => {
foreach (var address in part.Addresses) {
contentManager.Remove(address.ContentItem);
}
});
}
示例5: CommentPartHandler
public CommentPartHandler(
IRepository<CommentPartRecord> commentsRepository,
IContentManager contentManager) {
Filters.Add(StorageFilter.For(commentsRepository));
OnLoading<CommentPart>((context, comment) => {
comment.CommentedOnContentItemField.Loader(
item => contentManager.Get(comment.CommentedOn)
);
comment.CommentedOnContentItemMetadataField.Loader(
item => contentManager.GetItemMetadata(comment.CommentedOnContentItem)
);
});
OnRemoving<CommentPart>((context, comment) => {
foreach(var response in contentManager.Query<CommentPart, CommentPartRecord>().Where(x => x.RepliedOn == comment.Id).List()) {
contentManager.Remove(response.ContentItem);
}
});
OnIndexing<CommentPart>((context, commentPart) => context.DocumentIndex
.Add("commentText", commentPart.Record.CommentText));
}
示例6: NotificationBatchPartHandler
public NotificationBatchPartHandler(
IContentManager contentManager,
Lazy<IRoleService> roleServiceLazy,
Lazy<IRepository<UserRolesPartRecord>> userRolesRepositoryLazy)
{
OnActivated<NotificationBatchPart>((context, part) =>
{
part.RecipientsTypeField.Loader(() =>
{
var recipientsType = part.Retrieve<string>("RecipientsType");
if (string.IsNullOrEmpty(recipientsType)) return NotificationBatchRecipientsType.Role;
return (NotificationBatchRecipientsType)Enum.Parse(typeof(NotificationBatchRecipientsType), recipientsType);
});
part.RecipientsTypeField.Setter(recipientsType =>
{
part.Store("RecipientsType", recipientsType.ToString());
return recipientsType;
});
part.AvailableRolesField.Loader(() => roleServiceLazy.Value.GetRoles());
part.RecipientListField.Loader(() => contentManager.Get(part.RecipientListId));
part.AvailableRecipientListsField.Loader(() => contentManager.Query(Constants.RecipientListContentType).List());
part.RecipientListField.Setter(recipientsList =>
{
part.RecipientListId = recipientsList != null ? recipientsList.ContentItem.Id : 0;
return recipientsList;
});
part.ActualRecipientIdsField.Loader(() =>
{
IEnumerable<int> recipientIds;
switch (part.RecipientsType)
{
case NotificationBatchRecipientsType.Role:
recipientIds = userRolesRepositoryLazy.Value.Table
.Where(record => record.Role.Id == part.RecipientsRoleId)
.Select(record => record.UserId);
break;
case NotificationBatchRecipientsType.RecipientList:
recipientIds = part.RecipientList.As<NotificationRecipientsPart>().RecipientIds;
break;
case NotificationBatchRecipientsType.AdhocRecipients:
recipientIds = part.As<NotificationRecipientsPart>().RecipientIds;
break;
default:
throw new InvalidOperationException("Not supported recipient type.");
}
return recipientIds;
});
part.ActualRecipientsField.Loader(() => contentManager.GetMany<IUser>(part.ActualRecipientIds, VersionOptions.Published, new QueryHints().ExpandParts<UserPart>()));
});
}
示例7: ContentMenuItemPartHandler
public ContentMenuItemPartHandler(IContentManager contentManager, IRepository<ContentMenuItemPartRecord> repository) {
_contentManager = contentManager;
Filters.Add(new ActivatingFilter<ContentMenuItemPart>("ContentMenuItem"));
Filters.Add(StorageFilter.For(repository));
OnLoading<ContentMenuItemPart>((context, part) => part._content.Loader(p => {
if (part.ContentItemId != null) {
return contentManager.Get(part.ContentItemId.Value);
}
return null;
}));
}
示例8: OfflinePaymentSettingsPartHandler
public OfflinePaymentSettingsPartHandler(IContentManager contentManager)
{
_contentManager = contentManager;
Filters.Add(new ActivatingFilter<OfflinePaymentSettingsPart>("Site"));
OnLoading<OfflinePaymentSettingsPart>((context, part) => part._content.Loader(p => {
if (part.ContentItemId != null) {
return contentManager.Get(part.ContentItemId.Value);
}
return null;
}));
}
示例9: RoutePartHandler
public RoutePartHandler(
IOrchardServices services,
IRepository<RoutePartRecord> repository,
IRoutablePathConstraint routablePathConstraint,
IRoutableService routableService,
IContentManager contentManager,
IWorkContextAccessor workContextAccessor,
IEnumerable<IHomePageProvider> homePageProviders) {
_services = services;
_routablePathConstraint = routablePathConstraint;
_routableService = routableService;
_contentManager = contentManager;
_workContextAccessor = workContextAccessor;
_routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
T = NullLocalizer.Instance;
Filters.Add(StorageFilter.For(repository));
Action<RoutePart> processSlug = (
routable => {
if (!_routableService.ProcessSlug(routable))
_services.Notifier.Warning(T("Permalinks in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
routable.Slug, routable.GetEffectiveSlug(), routable.ContentItem.ContentType));
});
OnGetDisplayShape<RoutePart>(SetModelProperties);
OnGetEditorShape<RoutePart>(SetModelProperties);
OnUpdateEditorShape<RoutePart>(SetModelProperties);
Action<PublishContentContext, RoutePart> handler = (context, route) => {
FinalizePath(route, context, processSlug);
if (_routableHomePageProvider == null)
return;
var homePageSetting = _workContextAccessor.GetContext().CurrentSite.HomePage;
var currentHomePageId = !string.IsNullOrWhiteSpace(homePageSetting)
? _routableHomePageProvider.GetHomePageId(homePageSetting)
: 0;
if (route.Id != 0 && (route.Id == currentHomePageId || route.PromoteToHomePage)) {
if (currentHomePageId != route.Id) {
// reset the path on the current home page
var currentHomePage = _contentManager.Get(currentHomePageId);
if (currentHomePage != null)
FinalizePath(currentHomePage.As<RoutePart>(), context, processSlug);
// set the new home page
_services.WorkContext.CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(route.ContentItem.Id);
}
// readjust the constraints of the current current home page
_routablePathConstraint.RemovePath(route.Path);
route.Path = "";
_routableService.FixContainedPaths(route);
_routablePathConstraint.AddPath(route.Path);
}
};
OnPublished<RoutePart>(handler);
OnUnpublished<RoutePart>(handler);
OnRemoved<RoutePart>((context, route) => {
if (!string.IsNullOrWhiteSpace(route.Path))
_routablePathConstraint.RemovePath(route.Path);
});
OnIndexing<RoutePart>((context, part) => context.DocumentIndex.Add("title", part.Record.Title).RemoveTags().Analyze());
}
示例10: CaptchaService
public CaptchaService(IContentManager contentManager, ISiteService siteService)
{
CaptchaPart = contentManager.Get<CaptchaSettingsPart>(1);
CurrentCulture = siteService.GetSiteSettings().SiteCulture;
T = NullLocalizer.Instance;
}