/// <summary> /// Constructor. /// </summary> /// <param name="dependencies">The dependencies to use for getting data.</param> public WebsiteDataAdapter(IDataAdapterDependencies dependencies) { dependencies.ThrowOnNull("dependencies"); var website = dependencies.GetWebsite(); website.ThrowOnNull("dependencies", ResourceManager.GetString("Website_Reference_Retrieval_Exception")); website.AssertLogicalName("adx_website"); Website = website; Dependencies = dependencies; }
public WebsiteForumDataAdapter(IDataAdapterDependencies dependencies) : base(dependencies) { var website = dependencies.GetWebsite(); _helperDataAdapter = new ForumThreadAggregationDataAdapter( dependencies, true, serviceContext => serviceContext.FetchForumCountsForWebsite(website.Id), serviceContext => CreateThreadEntityQuery(serviceContext, website), serviceContext => serviceContext.FetchForumThreadTagInfoForWebsite(website.Id), new ForumThreadAggregationDataAdapter.ForumThreadUrlProvider(dependencies.GetUrlProvider())); }
public WebsiteForumDataAdapter(IDataAdapterDependencies dependencies, Func <OrganizationServiceContext, IQueryable <Entity> > selectThreadEntities) : base(dependencies) { var website = dependencies.GetWebsite(); _helperDataAdapter = new ForumThreadAggregationDataAdapter( dependencies, true, serviceContext => serviceContext.FetchForumCountsForWebsite(website.Id), selectThreadEntities, serviceContext => serviceContext.FetchForumThreadTagInfoForWebsite(website.Id), new ForumThreadAggregationDataAdapter.ForumThreadUrlProvider(dependencies.GetUrlProvider())); }
/// <summary> /// Constructor. /// </summary> /// <param name="userId">The unique identifier of the portal user to aggregate data for.</param> /// <param name="dependencies">The dependencies to use for getting data.</param> public WebsiteForumPostUserAggregationDataAdapter(Guid userId, IDataAdapterDependencies dependencies) { dependencies.ThrowOnNull("dependencies"); var website = dependencies.GetWebsite(); website.ThrowOnNull("dependencies", ResourceManager.GetString("Website_Reference_Retrieval_Exception")); website.AssertLogicalName("adx_website"); Website = website; Dependencies = dependencies; UserId = userId; }
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(); }
public WebsiteBlogAggregationDataAdapter(IDataAdapterDependencies dependencies) { if (dependencies == null) { throw new ArgumentNullException("dependencies"); } Website = dependencies.GetWebsite(); if (Website == null) { throw new ArgumentException("Unable to get website reference.", "dependencies"); } Dependencies = dependencies; }
public TagWebsiteForumThreadDataAdapter(string tag, IDataAdapterDependencies dependencies) { if (string.IsNullOrWhiteSpace(tag)) { throw new ArgumentException("Value can't be null or whitespace.", "tag"); } if (dependencies == null) { throw new ArgumentNullException("dependencies"); } Dependencies = dependencies; var website = dependencies.GetWebsite(); _helperDataAdapter = new ForumThreadAggregationDataAdapter( dependencies, true, serviceContext => serviceContext.FetchForumCountsForWebsiteWithTag(website.Id, tag), serviceContext => CreateThreadEntityQuery(serviceContext, website, tag), serviceContext => serviceContext.FetchForumThreadTagInfoForWebsite(website.Id), new ForumThreadAggregationDataAdapter.ForumThreadUrlProvider(dependencies.GetUrlProvider())); }
private IAttachment GetAttachmentFile(Entity activityMimeAttachment, Guid id) { ulong fileSize; if (!ulong.TryParse(activityMimeAttachment.GetAttributeValue <int>("filesize").ToString(), out fileSize)) { fileSize = 0; } FileSize attachmentSize = new FileSize(fileSize); Entity attachment = null; if (activityMimeAttachment.Attributes.ContainsKey("attachmentid")) { attachment = new Entity("activitymimeattachment", activityMimeAttachment.GetAttributeValue <EntityReference>("attachmentid").Id); } return(new Attachment { AttachmentContentType = activityMimeAttachment.GetAttributeValue <string>("mimetype"), AttachmentFileName = activityMimeAttachment.GetAttributeValue <string>("filename"), AttachmentIsImage = (new List <string> { "image/jpeg", "image/gif", "image/png" }).Contains( activityMimeAttachment.GetAttributeValue <string>("mimetype")), AttachmentSize = attachmentSize, AttachmentSizeDisplay = attachmentSize.ToString(), AttachmentUrl = attachment == null ? string.Empty : attachment.GetFileAttachmentUrl(_dependencies.GetWebsite()), AttachmentBody = GetAttachmentBody(activityMimeAttachment, activityMimeAttachment.Id), Entity = activityMimeAttachment }); }
private IEnumerable <IAttachment> GetAnnotationsAsAttachmentCollection(EntityReference regarding, bool respectPermissions = true) { // Retrieve attachments var annotationDataAdapter = new AnnotationDataAdapter(_dependencies); var annotationCollection = annotationDataAdapter.GetAnnotations(regarding, respectPermissions: respectPermissions, privacy: AnnotationPrivacy.Any); // Filter and project into Attachment object return(annotationCollection.Where(annotation => EntityContainsRequiredAnnotationFields(annotation.Entity.Attributes)).Select(annotation => { var entity = annotation.Entity; var fileName = GetFieldValue(entity, "filename"); var fileType = GetFieldValue(entity, "mimetype"); ulong fileSize; if (!ulong.TryParse(GetFieldValue(entity, "filesize"), out fileSize)) { fileSize = 0; } FileSize attachmentSize = new FileSize(fileSize); // Create CrmAnnotationFile for URL generation var crmAnnotationFile = new CrmAnnotationFile(fileName, fileType, new byte[0]); crmAnnotationFile.Annotation = new Entity("annotation") { Id = Guid.Parse(GetFieldValue(entity, "annotationid")) }; var activityAttachment = new Attachment { AttachmentContentType = fileType, AttachmentFileName = fileName, AttachmentIsImage = (new List <string> { "image/jpeg", "image/gif", "image/png" }).Contains(fileType), AttachmentSize = attachmentSize, AttachmentSizeDisplay = attachmentSize.ToString(), AttachmentUrl = crmAnnotationFile.Annotation.GetFileAttachmentUrl(_dependencies.GetWebsite()) }; return activityAttachment; })); }
public ISharePointCollection GetFoldersAndFiles(EntityReference regarding, string sortExpression = DefaultSortExpression, int page = 1, int pageSize = DefaultPageSize, string pagingInfo = null, string folderPath = null) { var context = _dependencies.GetServiceContextForWrite(); var website = _dependencies.GetWebsite(); var entityPermissionProvider = new CrmEntityPermissionProvider(); var result = new SharePointResult(regarding, entityPermissionProvider, context); // assert permission to create the sharepointdocumentlocation entity if (!result.PermissionsExist || !result.CanCreate || !result.CanAppend || !result.CanAppendTo) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Permission Denied. You do not have the appropriate Entity Permissions to Create or Append document locations or AppendTo the regarding entity."); return(SharePointCollection.Empty(true)); } var entityMetadata = context.GetEntityMetadata(regarding.LogicalName); var entity = context.CreateQuery(regarding.LogicalName).First(e => e.GetAttributeValue <Guid>(entityMetadata.PrimaryIdAttribute) == regarding.Id); var spConnection = new SharePointConnection(SharePointConnectionStringName); var spSite = context.GetSharePointSiteFromUrl(spConnection.Url); var location = GetDocumentLocation(context, entity, entityMetadata, spSite); if (!entityPermissionProvider.TryAssert(context, CrmEntityPermissionRight.Read, location)) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Permission Denied. You do not have the appropriate Entity Permissions to Read document locations."); return(SharePointCollection.Empty(true)); } ADXTrace.Instance.TraceInfo(TraceCategory.Application, "Read SharePoint Document Location Permission Granted."); var factory = new ClientFactory(); using (var client = factory.CreateClientContext(spConnection)) { // retrieve the SharePoint list and folder names for the document location string listUrl, folderUrl; context.GetDocumentLocationListAndFolder(location, out listUrl, out folderUrl); var sharePointFolder = client.AddOrGetExistingFolder(listUrl, folderUrl + folderPath); var list = client.GetListByUrl(listUrl); if (!sharePointFolder.IsPropertyAvailable("ServerRelativeUrl")) { client.Load(sharePointFolder, folder => folder.ServerRelativeUrl); } if (!sharePointFolder.IsPropertyAvailable("ItemCount")) { client.Load(sharePointFolder, folder => folder.ItemCount); } var camlQuery = new CamlQuery { FolderServerRelativeUrl = sharePointFolder.ServerRelativeUrl, ViewXml = @" <View> <Query> <OrderBy> <FieldRef {0}></FieldRef> </OrderBy> <Where></Where> </Query> <RowLimit>{1}</RowLimit> </View>" .FormatWith( ConvertSortExpressionToCaml(sortExpression), pageSize) }; if (page > 1) { camlQuery.ListItemCollectionPosition = new ListItemCollectionPosition { PagingInfo = pagingInfo }; } var folderItems = list.GetItems(camlQuery); client.Load(folderItems, items => items.ListItemCollectionPosition, items => items.Include( item => item.ContentType, item => item["ID"], item => item["FileLeafRef"], item => item["Created"], item => item["Modified"], item => item["FileSizeDisplay"])); client.ExecuteQuery(); var sharePointItems = new List <SharePointItem>(); if (!string.IsNullOrEmpty(folderPath) && folderPath.Contains("/")) { var relativePaths = folderPath.Split('/'); var parentFolderName = relativePaths.Length > 2 ? relativePaths.Skip(relativePaths.Length - 2).First() : "/"; sharePointItems.Add(new SharePointItem() { Name = @"""{0}""".FormatWith(parentFolderName), IsFolder = true, FolderPath = folderPath.Substring(0, folderPath.LastIndexOf('/')), IsParent = true }); } if (folderItems.Count < 1) { return(new SharePointCollection(sharePointItems, null, sharePointItems.Count())); } foreach (var item in folderItems) { var id = item["ID"] as int?; var name = item["FileLeafRef"] as string; var created = item["Created"] as DateTime?; var modified = item["Modified"] as DateTime?; long longFileSize; var fileSize = long.TryParse(item["FileSizeDisplay"] as string, out longFileSize) ? longFileSize : null as long?; if (string.Equals(item.ContentType.Name, "Folder", StringComparison.InvariantCultureIgnoreCase)) { sharePointItems.Add(new SharePointItem { Id = id, Name = name, IsFolder = true, CreatedOn = created, ModifiedOn = modified, FolderPath = "{0}/{1}".FormatWith(folderPath, name) }); } else { sharePointItems.Add(new SharePointItem { Id = id, Name = name, CreatedOn = created, ModifiedOn = modified, FileSize = fileSize, Url = GetAbsolutePath(website, location, name, folderPath) }); } } var pageInfo = folderItems.ListItemCollectionPosition != null ? folderItems.ListItemCollectionPosition.PagingInfo : null; return(new SharePointCollection(sharePointItems, pageInfo, sharePointFolder.ItemCount)); } }