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));
        }
        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
            });
        }