private bool TryAssert(CrmEntityRight right) { using (var serviceContext = PortalViewContext.CreateServiceContext()) { var attachedEntity = serviceContext.MergeClone(Entity); return(PortalViewContext.CreateCrmEntitySecurityProvider().TryAssert(serviceContext, attachedEntity, right)); } }
private EntityDrop GetRelatedEntity(Relationship relationship) { using (var serviceContext = PortalViewContext.CreateServiceContext()) { var clone = serviceContext.MergeClone(Entity); var entity = serviceContext.RetrieveRelatedEntity(clone, relationship); return(this.CreateEntityDropWithPermission(entity)); } }
private EntityNoteDrop[] GetNotes() { using (var serviceContext = PortalViewContext.CreateServiceContext()) { var filter = new FilterExpression(LogicalOperator.And); filter.AddCondition("objecttypecode", ConditionOperator.Equal, EntityReference.LogicalName); filter.AddCondition("objectid", ConditionOperator.Equal, EntityReference.Id); var query = new QueryExpression("annotation") { // When we get notes, we want to get most attributes, but NOT documentbody, to avoid having // to load large file contents. We want people to use the handler URL on the note drop if // possible. If not, the note drop can lazy-load the documentbody attribute if requested. ColumnSet = new ColumnSet(new[] { "annotationid", "createdby", "createdon", "createdonbehalfby", "filename", "filesize", "isdocument", "langid", "mimetype", "modifiedby", "modifiedon", "modifiedonbehalfby", "notetext", "objectid", "objecttypecode", "ownerid", "owningbusinessunit", "owningteam", "owninguser", "stepid", "subject", "versionnumber" }), Criteria = filter }; query.AddOrder("createdon", OrderType.Ascending); var response = (RetrieveMultipleResponse)serviceContext.Execute(new RetrieveMultipleRequest { Query = query }); return(response.EntityCollection.Entities .Select(e => new EntityNoteDrop(this, e)).ToArray()); } }
private EntityDrop[] GetRelatedEntities(Relationship relationship) { using (var serviceContext = PortalViewContext.CreateServiceContext()) { var clone = serviceContext.MergeClone(Entity); var drops = serviceContext.RetrieveRelatedEntities(clone, relationship).Entities .Select(e => this.CreateEntityDropWithPermission(e)) .ToArray(); return(drops); } }
private string GetDocumentBody() { using (var serviceContext = PortalViewContext.CreateServiceContext()) { var response = (RetrieveResponse)serviceContext.Execute(new RetrieveRequest { Target = EntityReference, ColumnSet = new ColumnSet("documentbody") }); return(response.Entity.GetAttributeValue <string>("documentbody")); } }
private EntityCollectionDrop GetResults() { if (_permissionRightResult != null && !(_permissionRightResult.GlobalPermissionGranted || _permissionRightResult.PermissionGranted)) { return(new EntityCollectionDrop(this, new EntityCollection())); } using (var serviceContext = PortalViewContext.CreateServiceContext()) { var response = (RetrieveMultipleResponse)serviceContext.Execute(_fetch.Value.ToRetrieveMultipleRequest()); return(new EntityCollectionDrop(this, response.EntityCollection)); } }
private string GetUrl() { if (FullEntity == null) { return(null); } using (var serviceContext = PortalViewContext.CreateServiceContext()) { var clone = serviceContext.MergeClone(FullEntity); return(PortalViewContext.UrlProvider.GetUrl(serviceContext, clone)); } }
private string GetLabel() { try { using (var serviceContext = PortalViewContext.CreateServiceContext()) { return(_languageCode != null && _languageCode.Value != 0 ? serviceContext.GetOptionSetValueLabel(_entityLogicalName, _attributeLogicalName, _value.Value, _languageCode.Value) : serviceContext.GetOptionSetValueLabel(_entityLogicalName, _attributeLogicalName, _value.Value)); } } catch { return(null); } }
protected override void OnPreRender(EventArgs args) { if (!string.IsNullOrEmpty(SiteMarkerName)) { var portalViewContext = new PortalViewContext( new PortalContextDataAdapterDependencies( PortalCrmConfigurationManager.CreatePortalContext(PortalName), PortalName, Context.Request.RequestContext)); var target = portalViewContext.SiteMarkers.Select(SiteMarkerName); if (target != null) { NavigateUrl = new UrlBuilder(target.Url); if (string.IsNullOrEmpty(Text) && Controls.Count == 0) { var contentFormatter = PortalCrmConfigurationManager.CreateDependencyProvider(PortalName).GetDependency <ICrmEntityContentFormatter>(GetType().FullName) ?? new PassthroughCrmEntityContentFormatter(); Text = contentFormatter.Format(target.Entity.GetAttributeValue <string>("adx_name"), target.Entity, this); } } else if (AutoHiddenIfAbsent ?? true) { Visible = false; } } if (!string.IsNullOrEmpty(QueryString)) { // we need to append these querystring parameters if (!NavigateUrl.Contains("?")) { NavigateUrl += "?"; } if (!NavigateUrl.EndsWith("?")) { NavigateUrl += "&"; } NavigateUrl += QueryString; } }
internal static HtmlHelper GetHtmlHelper(string portalName, RequestContext requestContext, HttpResponse response) { var portal = PortalCrmConfigurationManager.CreatePortalContext(portalName, requestContext); var controllerContext = new ControllerContext(requestContext, new MockController()); var portalViewContext = new PortalViewContext(new PortalContextDataAdapterDependencies(portal)); var htmlHelper = new HtmlHelper(new ViewContext(controllerContext, new MockView(), new ViewDataDictionary(), new TempDataDictionary(), response.Output) { ViewData = new ViewDataDictionary { { PortalExtensions.PortalViewContextKey, portalViewContext } } }, new ViewPage()); htmlHelper.ViewData[PortalExtensions.PortalViewContextKey] = portalViewContext; return(htmlHelper); }
public bool TryReadTemplateFile(string templateName, out string template) { var website = PortalViewContext.Website.EntityReference; var fetch = new Fetch { PageSize = 1, Entity = new FetchEntity(EntityLogicalName, new[] { SourceAttributeLogicalName }) { Filters = new [] { new Filter { Type = LogicalOperator.And, Conditions = new [] { new Condition("statecode", ConditionOperator.Equal, 0), new Condition("adx_websiteid", ConditionOperator.Equal, website.Id), new Condition(NameAttributeLogicalName, ConditionOperator.Equal, templateName) } } } } }; using (var serviceContext = PortalViewContext.CreateServiceContext()) { var response = (RetrieveMultipleResponse)serviceContext.Execute(fetch.ToRetrieveMultipleRequest()); var entity = response.EntityCollection.Entities.FirstOrDefault(); if (entity == null) { template = null; return(false); } template = entity.GetAttributeValue <string>(SourceAttributeLogicalName) ?? string.Empty; return(true); } }
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))); }
public virtual string GetEditable(Context context, string key, EditableOptions options) { if (context == null) { throw new ArgumentNullException("context"); } if (key == null) { throw new ArgumentNullException("key"); } if (options == null) { throw new ArgumentNullException("options"); } using (var serviceContext = PortalViewContext.CreateServiceContext()) { var attachedEntity = serviceContext.MergeClone(Entity.Attributes.ContainsKey(key) ? Entity : FullEntity); var portalViewEntity = PortalViewContext.GetEntity(serviceContext, attachedEntity); IHtmlString html = null; context.Stack(() => { html = Html.AttributeInternal( portalViewEntity.GetAttribute(key), options.Type ?? "html", options.Title, options.Escape.GetValueOrDefault(false), options.Tag ?? "div", options.CssClass, options.Liquid.GetValueOrDefault(true), context, options.Default); }); return(html == null ? null : html.ToString()); } }
private EntityPermissionsDrop GetPermissions() { if (!AdxstudioCrmConfigurationManager.GetCrmSection().ContentMap.Enabled) { return(null); } if (FullEntity == null) { return(null); } using (var serviceContext = PortalViewContext.CreateServiceContext()) { var clone = serviceContext.MergeClone(FullEntity); var permissionResult = new CrmEntityPermissionProvider(PortalViewContext.PortalName) .TryAssert(serviceContext, clone); return(permissionResult == null ? null : new EntityPermissionsDrop(permissionResult)); } }
protected PortalUrlDrop(IPortalLiquidContext portalLiquidContext) : base(portalLiquidContext) { _isSitemapAncestor = new Lazy <bool>(() => PortalViewContext.IsAncestorSiteMapNode(Url), LazyThreadSafetyMode.None); _isSitemapCurrent = new Lazy <bool>(() => PortalViewContext.IsCurrentSiteMapNode(Url), LazyThreadSafetyMode.None); }
public override object BeforeMethod(string method) { if (method == null) { return(null); } using (var serviceContext = PortalViewContext.CreateServiceContext()) { try { Entity location; Guid id; if (!Guid.TryParse(method, out id)) { return(null); } if (!string.IsNullOrWhiteSpace(_folderName)) { // Get documents based on provided folder name. var entity = new Entity(LogicalName) { Id = id }; location = GetDocumentLocation(serviceContext, entity, _folderName); } else { // Get documents based on "primary attribute_id" folder. var metadata = serviceContext.GetEntityMetadata(LogicalName, EntityFilters.Attributes); location = GetDocumentLocation(serviceContext, metadata, id); } if (location == null) { return(null); } var crmEntityPermissionProvider = new CrmEntityPermissionProvider(); if (!crmEntityPermissionProvider.TryAssert(serviceContext, CrmEntityPermissionRight.Read, location)) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Permission Denied. You do not have the appropriate Entity Permissions to Read document locations."); return(null); } ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Read SharePoint Document Location Permission Granted."); var spConnection = new SharePointConnection("SharePoint"); var factory = new ClientFactory(); using (var client = factory.CreateClientContext(spConnection)) { // retrieve the SharePoint list and folder names for the document location string listName, folderName; serviceContext.GetDocumentLocationListAndFolder(location, out listName, out folderName); var folder = client.AddOrGetExistingFolder(listName, folderName); var fileCollection = folder.Files; client.Load(folder.Files); client.ExecuteQuery(); var files = fileCollection.ToArray().OrderBy(file => file.Name); if (!files.Any()) { return(null); } return(files.Select(file => new SharePointDocumentDrop(this, file, location))); } } catch (FaultException <OrganizationServiceFault> ) { return(null); } } }