private static IMarketingDataAdapter GetMarketingDataAdapter() { var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); var dependencies = new PortalContextDataAdapterDependencies(portalContext); return(new MarketingDataAdapter(dependencies)); }
private IEnumerable <ForumThreadDrop> GetForumThreadSubscriptions(IPortalLiquidContext portalLiquidContext) { var user = Entity; if (user == null || user.LogicalName != "contact") { return(Enumerable.Empty <ForumThreadDrop>()); } var portal = PortalViewContext.CreatePortalContext(); var forumDependencies = new PortalContextDataAdapterDependencies(portal, new PaginatedLatestPostUrlProvider("page", portalLiquidContext.Html.IntegerSetting("Forums/PostsPerPage").GetValueOrDefault(20))); var dataAdapter = new ForumThreadAggregationDataAdapter(forumDependencies, true, serviceContext => serviceContext.FetchForumCountsForWebsite(PortalViewContext.Website.EntityReference.Id), serviceContext => (from thread in serviceContext.CreateQuery("adx_communityforumthread") join alert in serviceContext.CreateQuery("adx_communityforumalert") on thread.GetAttributeValue <Guid>("adx_communityforumthreadid") equals alert.GetAttributeValue <EntityReference>("adx_threadid").Id join forum in serviceContext.CreateQuery("adx_communityforum") on thread.GetAttributeValue <EntityReference>("adx_forumid").Id equals forum.GetAttributeValue <Guid>("adx_communityforumid") where forum.GetAttributeValue <EntityReference>("adx_websiteid") != null && forum.GetAttributeValue <EntityReference>("adx_websiteid").Id == PortalViewContext.Website.EntityReference.Id where alert.GetAttributeValue <EntityReference>("adx_subscriberid") != null && alert.GetAttributeValue <EntityReference>("adx_subscriberid").Id == user.Id orderby thread.GetAttributeValue <DateTime>("adx_lastpostdate") descending orderby thread.GetAttributeValue <string>("adx_name") select thread), serviceContext => serviceContext.FetchForumThreadTagInfoForWebsite(PortalViewContext.Website.EntityReference.Id), new ForumThreadAggregationDataAdapter.ForumThreadUrlProvider(forumDependencies.GetUrlProvider())); var forumThreads = dataAdapter.SelectThreads(0).ToList(); return(!forumThreads.Any() ? Enumerable.Empty <ForumThreadDrop>() : forumThreads.Select(e => new ForumThreadDrop(portalLiquidContext, forumDependencies, e))); }
private static LiquidEnvironment GetLiquidEnvironment(this HtmlHelper html) { const string environmentKey = "Adxstudio.Xrm.Web.Mvc.LiquidExtensions.GetLiquidEnvironment:Data"; LiquidEnvironment environment; object data; if (html.ViewContext.TempData.TryGetValue(environmentKey, out data)) { environment = data as LiquidEnvironment; if (environment != null) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Reusing Liquid environment."); return(environment); } } ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Creating new Liquid environment."); var portal = PortalCrmConfigurationManager.CreatePortalContext(); var portalViewContext = PortalExtensions.GetPortalViewContext(html); var portalLiquidContext = new PortalLiquidContext(html, portalViewContext); var forumDependencies = new PortalContextDataAdapterDependencies( portal, new PaginatedLatestPostUrlProvider("page", html.IntegerSetting("Forums/PostsPerPage").GetValueOrDefault(20))); var blogDependencies = new Blogs.PortalConfigurationDataAdapterDependencies(); var knowledgeDependencies = new KnowledgeArticles.PortalConfigurationDataAdapterDependencies(); var contextDrop = new PortalViewContextDrop(portalLiquidContext, forumDependencies); var requestDrop = RequestDrop.FromHtmlHelper(portalLiquidContext, html); var siteMapDrop = new SiteMapDrop(portalLiquidContext, portalViewContext.SiteMapProvider); var globals = new Hash { { "context", contextDrop }, { "entities", new EntitiesDrop(portalLiquidContext) }, { "now", DateTime.UtcNow }, { "params", requestDrop == null ? null : requestDrop.Params }, { "request", requestDrop }, { "settings", new SettingsDrop(portalViewContext.Settings) }, { "sharepoint", new SharePointDrop(portalLiquidContext) }, { "sitemap", siteMapDrop }, { "sitemarkers", new SiteMarkersDrop(portalLiquidContext, portalViewContext.SiteMarkers) }, { "snippets", new SnippetsDrop(portalLiquidContext, portalViewContext.Snippets) }, { "user", contextDrop.User }, { "weblinks", new WebLinkSetsDrop(portalLiquidContext, portalViewContext.WebLinks) }, { "ads", new AdsDrop(portalLiquidContext, portalViewContext.Ads) }, { "polls", new PollsDrop(portalLiquidContext, portalViewContext.Polls) }, { "forums", new ForumsDrop(portalLiquidContext, forumDependencies) }, { "events", new EventsDrop(portalLiquidContext, forumDependencies) }, { "blogs", new BlogsDrop(portalLiquidContext, blogDependencies) }, { "website", contextDrop.Website }, { "resx", new ResourceManagerDrop(portalLiquidContext) }, { "knowledge", new KnowledgeDrop(portalLiquidContext, knowledgeDependencies) }, { "uniqueId", new UniqueDrop() } }; if (portalViewContext.Entity != null && siteMapDrop.Current != null) { globals["page"] = new PageDrop(portalLiquidContext, portalViewContext.Entity, siteMapDrop.Current); } foreach (var factory in _globalVariableFactories) { globals[factory.Key] = factory.Value(html); } environment = new LiquidEnvironment(globals, new Hash { { "htmlHelper", html }, { "file_system", new CompositeFileSystem( new EntityFileSystem(portalViewContext, "adx_webtemplate", "adx_name", "adx_source"), new EmbeddedResourceFileSystem(typeof(LiquidExtensions).Assembly, "Adxstudio.Xrm.Liquid")) }, { "portalLiquidContext", portalLiquidContext } }); html.ViewContext.TempData[environmentKey] = environment; return(environment); }