private bool CanReadPortalComment(EntityReference portalCommentReference) { var serviceContext = _dependencies.GetServiceContext(); var response = serviceContext.Execute <RetrieveResponse>(new RetrieveRequest { Target = portalCommentReference, ColumnSet = new ColumnSet("regardingobjectid"), }); var regarding = response.Entity.GetAttributeValue <EntityReference>("regardingobjectid"); return(regarding != null && new CrmEntityPermissionProvider().TryAssert( serviceContext, CrmEntityPermissionRight.Read, portalCommentReference, regarding: regarding)); }
private static CreateActionMetadata GetOpportunityProductCreateActionMetadata(EntityReference opportunity, IDataAdapterDependencies dataAdapterDependencies) { var serviceContext = dataAdapterDependencies.GetServiceContext(); var response = (RetrieveResponse)serviceContext.Execute(new RetrieveRequest { Target = opportunity, ColumnSet = new ColumnSet("pricelevelid") }); return(new CreateActionMetadata( response.Entity.GetAttributeValue <EntityReference>("pricelevelid") == null, ResourceManager.GetString("Opportunity_Product_Price_List_Required"))); }
protected EntityDirectoryFileSystem(IDataAdapterDependencies dependencies) { if (dependencies == null) { throw new ArgumentNullException("dependencies"); } Dependencies = dependencies; SecurityProvider = Dependencies.GetSecurityProvider(); ServiceContext = Dependencies.GetServiceContext(); UrlProvider = Dependencies.GetUrlProvider(); Website = Dependencies.GetWebsite(); }
private IEnumerable <IAttachment> RetrieveAttachments(Guid regardingId) { QueryExpression query = BuildActivityMimeAttachmentsQuery(regardingId); // Execute the query var serviceContext = _dependencies.GetServiceContext(); var retrieveMultipleResponse = (RetrieveMultipleResponse)serviceContext.Execute(new RetrieveMultipleRequest { Query = query }); // Project the response into Attachment object var attachmentCollection = retrieveMultipleResponse.EntityCollection.Entities.Select(attachment => GetAttachmentFile(attachment, attachment.Id)); return(attachmentCollection); }
protected Guid?GetPriceListId(IDataAdapterDependencies dependencies, Guid opportunityId) { var serviceContext = dependencies.GetServiceContext(); var opportunityRetrieveResponse = serviceContext.Execute <RetrieveResponse>(new RetrieveRequest { Target = new EntityReference("opportunity", opportunityId), ColumnSet = new ColumnSet("pricelevelid") }); var opportunityPriceLevel = opportunityRetrieveResponse.Entity.GetAttributeValue <EntityReference>("pricelevelid"); return(opportunityPriceLevel == null ? null : new Guid?(opportunityPriceLevel.Id)); }
private EntityReference GetExistingParent(EntityReference child, IDataAdapterDependencies dependencies) { var serviceContext = dependencies.GetServiceContext(); Tuple <string, string> parentSchema; if (ParentSchema.TryGetValue(child.LogicalName, out parentSchema)) { return(serviceContext.CreateQuery(child.LogicalName) .Where(e => e.GetAttributeValue <Guid>(parentSchema.Item1) == child.Id) .Select(e => e.GetAttributeValue <EntityReference>(parentSchema.Item2)) .FirstOrDefault()); } return(null); }
/// <summary>Try to apply the special case.</summary> /// <param name="configuration">The configuration.</param> /// <param name="dependencies">The dependencies.</param> /// <param name="customParameters">The custom parameters.</param> /// <param name="fetch">The fetch.</param> /// <returns>True if applied, false otherwise.</returns> public bool TryApply(IViewConfiguration configuration, IDataAdapterDependencies dependencies, IDictionary <string, string> customParameters, Fetch fetch) { if (!this.IsApplicable(configuration)) { return(false); } var contextLanguageInfo = dependencies.GetRequestContext()?.HttpContext?.GetContextLanguageInfo(); if (contextLanguageInfo == null || !contextLanguageInfo.IsCrmMultiLanguageEnabled) { return(false); } var serviceContext = dependencies.GetServiceContext(); var provisionedLanguages = ContextLanguageInfo.GetProvisionedLanugages(serviceContext as IOrganizationService); if (!provisionedLanguages.Any()) { return(false); } var languageCondition = new Condition { Attribute = "adx_systemlanguage", Operator = ConditionOperator.In, Values = provisionedLanguages.Cast <object>().ToArray() }; var filter = new Filter { Conditions = new[] { languageCondition } }; if (fetch.Entity.Filters == null) { fetch.Entity.Filters = new List <Filter> { filter }; } else { fetch.Entity.Filters.Add(filter); } return(true); }
public ActivityEnabledEntityDataAdapter(EntityReference recordReference, IDataAdapterDependencies dependencies) { if (recordReference == null) { throw new ArgumentNullException("recordReference"); } if (dependencies == null) { throw new ArgumentNullException("dependencies"); } RecordReference = recordReference; Dependencies = dependencies; var serviceContext = Dependencies.GetServiceContext(); }
public ForumDataAdapter(EntityReference forum, IDataAdapterDependencies dependencies, Func <OrganizationServiceContext, IQueryable <Entity> > selectThreadEntities) { if (forum == null) { throw new ArgumentNullException("forum"); } if (forum.LogicalName != "adx_communityforum") { throw new ArgumentException(string.Format("Value must have logical name {0}.", forum.LogicalName), "forum"); } if (dependencies == null) { throw new ArgumentNullException("dependencies"); } Forum = forum; Dependencies = dependencies; _helperDataAdapter = new ForumThreadAggregationDataAdapter( dependencies, false, serviceContext => SelectForumCounts(serviceContext, Forum), selectThreadEntities, serviceContext => serviceContext.FetchForumThreadTagInfo(Forum.Id), new ForumThreadAggregationDataAdapter.SingleForumThreadUrlProvider(dependencies.GetUrlProvider(), new Lazy <string>(() => { var serviceContext = dependencies.GetServiceContext(); var forumEntity = SelectForumEntity(serviceContext, forum); if (forumEntity == null) { return(null); } var urlProvider = dependencies.GetUrlProvider(); return(urlProvider.GetUrl(serviceContext, forumEntity)); }, LazyThreadSafetyMode.None))); }
protected virtual bool TryAssertCommentModerationPermission(IDataAdapterDependencies dependencies) { if (_hasCommentModerationPermission.HasValue) { return(_hasCommentModerationPermission.Value); } var serviceContext = dependencies.GetServiceContext(); var page = serviceContext.RetrieveSingle( WebPageReference.LogicalName, FetchAttribute.All, new Condition("adx_webpageid", ConditionOperator.Equal, WebPageReference.Id)); if (page == null) { throw new InvalidOperationException("Unable to load the adx_webpage {0}.".FormatWith(WebPageReference.Id)); } var security = Dependencies.GetSecurityProvider(); _hasCommentModerationPermission = security.TryAssert(serviceContext, page, CrmEntityRight.Change); return(_hasCommentModerationPermission.Value); }
public IEnumerable <IKnowledgeArticle> Create(IEnumerable <Entity> articleEntities) { var articles = articleEntities.ToArray(); var articleIds = articles.Select(e => e.Id).ToArray(); var commentCounts = _dependencies.GetServiceContext().FetchArticleCommentCounts(articleIds); var feedbackPolicyReader = new FeedbackPolicyReader(_dependencies, ArticleSiteMarker); var commentPolicy = feedbackPolicyReader.GetCommentPolicy(); var isRatingEnabled = feedbackPolicyReader.IsRatingEnabled(); if (commentCounts == null) { return(articles.Select(e => new KnowledgeArticle(e, 0, commentPolicy, isRatingEnabled, _httpContext)).ToArray()); } return(articles.Select(e => { int commentCountValue; var commentCount = commentCounts.TryGetValue(e.Id, out commentCountValue) ? commentCountValue : 0; return new KnowledgeArticle(e, commentCount, commentPolicy, isRatingEnabled, _httpContext); }).ToArray()); }
public static string BuildNoteSubject(IDataAdapterDependencies dependencies) { return(BuildNoteSubject(dependencies.GetServiceContext(), dependencies.GetPortalUser())); }
protected override bool TryGetQuoteAndReturnUrl(HttpRequest request, IDataAdapterDependencies dataAdapterDependencies, out Tuple <Guid, string> quoteAndReturnUrl) { quoteAndReturnUrl = null; var param = request.Form["order_id"]; if (string.IsNullOrEmpty(param)) { return(false); } var values = HttpUtility.ParseQueryString(param); var logicalName = values["LogicalName"]; if (string.IsNullOrEmpty(logicalName)) { return(false); } Guid id; if (!Guid.TryParse(values["Id"], out id)) { return(false); } var returnUrlParam = request.QueryString["ReturnUrl"]; if (string.IsNullOrEmpty(returnUrlParam)) { return(false); } var returnUrl = new UrlBuilder(returnUrlParam); if (string.Equals(logicalName, "quote", StringComparison.InvariantCultureIgnoreCase)) { quoteAndReturnUrl = new Tuple <Guid, string>(id, returnUrl.PathWithQueryString); return(true); } if (string.Equals(logicalName, "adx_webformsession", StringComparison.InvariantCultureIgnoreCase)) { var serviceContext = dataAdapterDependencies.GetServiceContext(); var webFormSession = serviceContext.CreateQuery("adx_webformsession") .FirstOrDefault(e => e.GetAttributeValue <Guid>("adx_webformsessionid") == id); if (webFormSession == null) { return(false); } var webFormSessionQuote = webFormSession.GetAttributeValue <EntityReference>("adx_quoteid"); if (webFormSessionQuote == null) { return(false); } quoteAndReturnUrl = new Tuple <Guid, string>(webFormSessionQuote.Id, returnUrl.PathWithQueryString); return(true); } return(false); }