protected virtual bool TryCreateHandler(AnnotationNode annotation, WebFileNode webfileNode, IPortalContext portal, out IHttpHandler handler) { if (annotation != null) { // convert to Entity object and populate the documentbody attribute value var portalOrgService = HttpContext.Current.GetOrganizationService(); var entity = annotation.ToEntity(); var body = portalOrgService.RetrieveSingle("annotation", new[] { "documentbody" }, new Condition("annotationid", ConditionOperator.Equal, annotation.Id)); entity.SetAttributeValue("documentbody", body); var webfile = webfileNode != null ? portalOrgService.RetrieveSingle("adx_webfile", FetchAttribute.All, new Condition("adx_webfileid", ConditionOperator.Equal, webfileNode.Id)) : null; handler = CreateAnnotationHandler(entity, webfile); return(true); } handler = CreateAnnotationHandler(null); return(true); }
private ApplicationPath GetApplicationPath(WebFileNode file) { var websiteRelativeUrl = InternalGetApplicationPath(file); var path = websiteRelativeUrl.PartialPath; var appPath = ApplicationPath.FromPartialPath(path); return(appPath); }
protected CrmSiteMapNode GetAccessibleNodeOrAccessDeniedNode(ContentMap map, WebFileNode file, IContentMapEntityUrlProvider provider, bool excludeFromSecurityValidation = false) { if (excludeFromSecurityValidation) { return(GetNode(map, file, provider) ?? GetAccessDeniedNodeInternal()); } return(ReturnNodeIfAccessible(GetNode(map, file, provider), GetAccessDeniedNodeInternal)); }
protected virtual string GetUrl(WebFileNode file) { var applicationPath = GetApplicationPath(file); if (applicationPath != null) { return(applicationPath.ExternalUrl ?? applicationPath.AbsolutePath); } return(null); }
protected virtual CrmSiteMapNode GetNode(ContentMap map, WebFileNode file, HttpStatusCode statusCode, IContentMapEntityUrlProvider provider) { var entity = file.ToEntity(GetEntityType("adx_webfile")); var url = provider.GetUrl(map, file); return(new CrmSiteMapNode( this, url, url, file.Name, file.Summary, string.Empty, file.ModifiedOn.GetValueOrDefault(DateTime.UtcNow), entity, statusCode)); }
private ApplicationPath InternalGetApplicationPath(WebFileNode file) { var partialUrl = file.PartialUrl; if (file.Parent != null) { var parentUrl = InternalGetApplicationPath(file.Parent); if (parentUrl == null) { return(null); } return(JoinApplicationPath(parentUrl.PartialPath, partialUrl)); } if (file.BlogPost != null) { var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(PortalName); var blogPost = serviceContext.CreateQuery("adx_blogpost") .FirstOrDefault(e => e.GetAttributeValue <Guid>("adx_blogpostid") == file.BlogPost.Id); if (blogPost == null) { return(null); } var parentUrl = GetApplicationPath(serviceContext, blogPost); if (parentUrl == null) { return(null); } return(JoinApplicationPath(parentUrl.PartialPath, partialUrl)); } return(ApplicationPath.FromPartialPath(partialUrl)); }
protected virtual CrmSiteMapNode GetNode(ContentMap map, WebFileNode file, IContentMapEntityUrlProvider provider) { return(GetNode(map, file, HttpStatusCode.OK, provider)); }
protected virtual DirectoryContent GetDirectoryContent(WebFileNode node) { if (node == null) { return(null); } var fileNote = node.Annotations .Where(e => e.IsDocument.GetValueOrDefault()) .OrderByDescending(e => e.CreatedOn) .FirstOrDefault(); if (fileNote == null) { return(null); } string url; try { url = ContentMapUrlProvider.GetUrl(ContentMap, node); } catch (Exception e) { ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Error getting URL for entity [adx_webfile:{0}]: {1}", Node.Id, e.ToString())); return(null); } if (url == null) { return(null); } var entity = node.ToEntity(); if (!ServiceContext.IsAttached(entity)) { entity = ServiceContext.MergeClone(entity); } bool canWrite; try { if (!SecurityProvider.TryAssert(ServiceContext, entity, CrmEntityRight.Read)) { return(null); } canWrite = SecurityProvider.TryAssert(ServiceContext, entity, CrmEntityRight.Change); } catch (InvalidOperationException e) { ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Error validating security for entity [adx_webfile:{0}]: {1}", Node.Id, e.ToString())); return(null); } var azure = new Regex(@"\.azure\.txt$").IsMatch(fileNote.FileName); return(new DirectoryContent { hash = new DirectoryContentHash(entity).ToString(), name = node.Name, mime = azure ? "application/x-azure-blob" : fileNote.MimeType, size = azure ? 0 : fileNote.FileSize.GetValueOrDefault(), url = url, date = FormatDateTime(node.ModifiedOn), read = true, write = canWrite, rm = canWrite }); }