示例#1
0
        private void AddXmlDocumentation(ISymbol symbol, MetadataItems metadata)
        {
            string documentationCommentXml = symbol.GetDocumentationCommentXml(expandIncludes: true);
            XmlDocumentationParser xmlDocumentationParser
                = new XmlDocumentationParser(symbol, _commentIdToDocument, _cssClasses);
            IEnumerable <string> otherHtmlElementNames = xmlDocumentationParser.Parse(documentationCommentXml);

            // Add standard HTML elements
            metadata.AddRange(new []
            {
                new MetadataItem(CodeAnalysisKeys.CommentXml, documentationCommentXml),
                new MetadataItem(CodeAnalysisKeys.Example, (k, m) => xmlDocumentationParser.Process().Example),
                new MetadataItem(CodeAnalysisKeys.Remarks, (k, m) => xmlDocumentationParser.Process().Remarks),
                new MetadataItem(CodeAnalysisKeys.Summary, (k, m) => xmlDocumentationParser.Process().Summary),
                new MetadataItem(CodeAnalysisKeys.Returns, (k, m) => xmlDocumentationParser.Process().Returns),
                new MetadataItem(CodeAnalysisKeys.Value, (k, m) => xmlDocumentationParser.Process().Value),
                new MetadataItem(CodeAnalysisKeys.Exceptions, (k, m) => xmlDocumentationParser.Process().Exceptions),
                new MetadataItem(CodeAnalysisKeys.Permissions, (k, m) => xmlDocumentationParser.Process().Permissions),
                new MetadataItem(CodeAnalysisKeys.Params, (k, m) => xmlDocumentationParser.Process().Params),
                new MetadataItem(CodeAnalysisKeys.TypeParams, (k, m) => xmlDocumentationParser.Process().TypeParams),
                new MetadataItem(CodeAnalysisKeys.SeeAlso, (k, m) => xmlDocumentationParser.Process().SeeAlso)
            });

            // Add other HTML elements with keys of [ElementName]Html
            metadata.AddRange(otherHtmlElementNames.Select(x =>
                                                           new MetadataItem(FirstLetterToUpper(x) + "Comments",
                                                                            (k, m) => xmlDocumentationParser.Process().OtherComments[x])));
        }
示例#2
0
        private void AddDocument(ISymbol symbol, bool xmlDocumentation, MetadataItems items)
        {
            // Get universal metadata
            items.AddRange(new []
            {
                // In general, cache the values that need calculation and don't cache the ones that are just properties of ISymbol
                new MetadataItem(CodeAnalysisKeys.IsResult, !_finished),
                new MetadataItem(CodeAnalysisKeys.SymbolId, (k, m) => GetId(symbol), true),
                new MetadataItem(CodeAnalysisKeys.Symbol, symbol),
                new MetadataItem(CodeAnalysisKeys.Name, (k, m) => symbol.Name),
                new MetadataItem(CodeAnalysisKeys.FullName, (k, m) => GetFullName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.DisplayName, (k, m) => GetDisplayName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.QualifiedName, (k, m) => GetQualifiedName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.Kind, (k, m) => symbol.Kind.ToString()),
                new MetadataItem(CodeAnalysisKeys.ContainingNamespace, DocumentFor(symbol.ContainingNamespace)),
                new MetadataItem(CodeAnalysisKeys.Syntax, (k, m) => GetSyntax(symbol), true)
            });

            // Add metadata that's specific to initially-processed symbols
            if (!_finished)
            {
                items.AddRange(new[]
                {
                    new MetadataItem(Keys.WritePath, (k, m) => _writePath(m), true),
                    new MetadataItem(Keys.RelativeFilePath, (k, m) => m.FilePath(Keys.WritePath)),
                    new MetadataItem(Keys.RelativeFilePathBase, (k, m) =>
                    {
                        FilePath writePath = m.FilePath(Keys.WritePath);
                        return(writePath.Directory.CombineFile(writePath.FileNameWithoutExtension));
                    }),
                    new MetadataItem(Keys.RelativeFileDir, (k, m) => m.FilePath(Keys.WritePath).Directory)
                });
            }

            // XML Documentation
            if (xmlDocumentation && (!_finished || _docsForImplicitSymbols))
            {
                AddXmlDocumentation(symbol, items);
            }

            // Create the document and add it to the cache
            IDocument document = _context.GetDocument(new FilePath(NormalizedPath.AbstractProvider, symbol.ToDisplayString(), true), null, items);

            _symbolToDocument.GetOrAdd(symbol, _ => document);

            // Map the comment ID to the document
            if (!_finished)
            {
                string documentationCommentId = symbol.GetDocumentationCommentId();
                if (documentationCommentId != null)
                {
                    _commentIdToDocument.GetOrAdd(documentationCommentId, _ => document);
                }
            }
        }
示例#3
0
        private IDocument AddDocumentCommon(ISymbol symbol, bool xmlDocumentation, MetadataItems items)
        {
            // Get universal metadata
            string commentId = symbol.GetDocumentationCommentId();

            items.AddRange(new[]
            {
                // In general, cache the values that need calculation and don't cache the ones that are just properties of ISymbol
                new MetadataItem(CodeAnalysisKeys.IsResult, !_finished),
                new MetadataItem(CodeAnalysisKeys.SymbolId, _ => GetId(symbol), true),
                new MetadataItem(CodeAnalysisKeys.CommentId, commentId),
                new MetadataItem(CodeAnalysisKeys.Name, metadata => string.IsNullOrEmpty(symbol.Name) ? metadata.String(CodeAnalysisKeys.FullName) : symbol.Name),
                new MetadataItem(CodeAnalysisKeys.FullName, _ => GetFullName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.DisplayName, _ => GetDisplayName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.QualifiedName, _ => GetQualifiedName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.Kind, _ => symbol.Kind.ToString()),
                new MetadataItem(CodeAnalysisKeys.ContainingNamespace, DocumentFor(symbol.ContainingNamespace)),
                new MetadataItem(CodeAnalysisKeys.Syntax, _ => GetSyntax(symbol), true),
                new MetadataItem(CodeAnalysisKeys.IsStatic, _ => symbol.IsStatic),
                new MetadataItem(CodeAnalysisKeys.IsAbstract, _ => symbol.IsAbstract),
                new MetadataItem(CodeAnalysisKeys.IsVirtual, _ => symbol.IsVirtual),
                new MetadataItem(CodeAnalysisKeys.IsOverride, _ => symbol.IsOverride),
                new MetadataItem(CodeAnalysisKeys.OriginalDefinition, DocumentFor(GetOriginalSymbolDefinition(symbol)))
            });

            // Add metadata that's specific to initially-processed symbols
            if (!_finished)
            {
                items.AddRange(new[]
                {
                    new MetadataItem(Keys.WritePath, x => _writePath(x), true),
                    new MetadataItem(Keys.RelativeFilePath, x => x.FilePath(Keys.WritePath)),
                    new MetadataItem(Keys.RelativeFilePathBase, x =>
                    {
                        FilePath writePath = x.FilePath(Keys.WritePath);
                        return(writePath.Directory.CombineFile(writePath.FileNameWithoutExtension));
                    }),
                    new MetadataItem(Keys.RelativeFileDir, x => x.FilePath(Keys.WritePath).Directory)
                });
            }

            // XML Documentation
            if (xmlDocumentation && (!_finished || _docsForImplicitSymbols))
            {
                AddXmlDocumentation(symbol, items);
            }

            // Create the document and add it to caches
            IDocument document = _symbolToDocument.GetOrAdd(
                symbol,
                _ => _context.GetDocument(new FilePath((Uri)null, symbol.ToDisplayString(), PathKind.Absolute), (Stream)null, items));

            return(document);
        }
示例#4
0
        private void AddXmlDocumentation(ISymbol symbol, MetadataItems metadata)
        {
            // Get the documentation comments
            INamespaceSymbol namespaceSymbol = symbol as INamespaceSymbol;
            string           documentationCommentXml;

            lock (XmlDocLock)
            {
                // Need to lock the XML comment access or it sometimes doesn't get generated when using external XML doc files
                documentationCommentXml = namespaceSymbol == null
                    ? symbol.GetDocumentationCommentXml(expandIncludes : true)
                    : GetNamespaceDocumentationCommentXml(namespaceSymbol);
            }

            // Should we assume inheritdoc?
            if (string.IsNullOrEmpty(documentationCommentXml) && _implicitInheritDoc)
            {
                documentationCommentXml = "<inheritdoc/>";
            }

            // Create and parse the documentation comments
            XmlDocumentationParser xmlDocumentationParser
                = new XmlDocumentationParser(_context, symbol, _compilation, _symbolToDocument, _cssClasses);
            IEnumerable <string> otherHtmlElementNames = xmlDocumentationParser.Parse(documentationCommentXml);

            // Add standard HTML elements
            metadata.AddRange(new []
            {
                new MetadataItem(CodeAnalysisKeys.CommentXml, documentationCommentXml),
                new MetadataItem(CodeAnalysisKeys.Example, _ => xmlDocumentationParser.Process().Example),
                new MetadataItem(CodeAnalysisKeys.Remarks, _ => xmlDocumentationParser.Process().Remarks),
                new MetadataItem(CodeAnalysisKeys.Summary, _ => xmlDocumentationParser.Process().Summary),
                new MetadataItem(CodeAnalysisKeys.Returns, _ => xmlDocumentationParser.Process().Returns),
                new MetadataItem(CodeAnalysisKeys.Value, _ => xmlDocumentationParser.Process().Value),
                new MetadataItem(CodeAnalysisKeys.Exceptions, _ => xmlDocumentationParser.Process().Exceptions),
                new MetadataItem(CodeAnalysisKeys.Permissions, _ => xmlDocumentationParser.Process().Permissions),
                new MetadataItem(CodeAnalysisKeys.Params, _ => xmlDocumentationParser.Process().Params),
                new MetadataItem(CodeAnalysisKeys.TypeParams, _ => xmlDocumentationParser.Process().TypeParams),
                new MetadataItem(CodeAnalysisKeys.SeeAlso, _ => xmlDocumentationParser.Process().SeeAlso)
            });

            // Add other HTML elements with keys of [ElementName]Html
            metadata.AddRange(otherHtmlElementNames.Select(x =>
                                                           new MetadataItem(
                                                               FirstLetterToUpper(x) + "Comments",
                                                               _ => xmlDocumentationParser.Process().OtherComments[x])));
        }
示例#5
0
 private IDocument AddMemberDocument(ISymbol symbol, bool xmlDocumentation, MetadataItems items)
 {
     items.AddRange(new[]
     {
         new MetadataItem(CodeAnalysisKeys.ContainingType, DocumentFor(symbol.ContainingType))
     });
     return(AddDocument(symbol, xmlDocumentation, items));
 }
示例#6
0
        private IDocument Write(IDocument input, IExecutionContext context, FilePath outputPath)
        {
            IFile output = context.FileSystem.GetOutputFile(outputPath);

            if (output != null)
            {
                using (Stream inputStream = input.GetStream())
                {
                    if (_ignoreEmptyContent && inputStream.Length == 0)
                    {
                        return(input);
                    }
                    if (!_onlyMetadata)
                    {
                        using (Stream outputStream = _append ? output.OpenAppend() : output.OpenWrite())
                        {
                            inputStream.CopyTo(outputStream);
                            if (!_append)
                            {
                                outputStream.SetLength(inputStream.Length);
                            }
                        }
                    }
                }
                Trace.Verbose($"{(_onlyMetadata ? "Set metadata for" : "Wrote")} file {output.Path.FullPath} from {input.SourceString()}");
                FilePath      relativePath             = context.FileSystem.GetOutputPath().GetRelativePath(output.Path) ?? output.Path.FileName;
                FilePath      fileNameWithoutExtension = output.Path.FileNameWithoutExtension;
                MetadataItems metadata = new MetadataItems
                {
                    { Keys.RelativeFilePath, relativePath },
                    { Keys.RelativeFilePathBase, fileNameWithoutExtension == null
                        ? null : relativePath.Directory.CombineFile(output.Path.FileNameWithoutExtension) },
                    { Keys.RelativeFileDir, relativePath.Directory }
                };
                if (_onlyMetadata)
                {
                    metadata.Add(Keys.WritePath, outputPath);
                }
                else
                {
                    metadata.AddRange(new MetadataItems
                    {
                        { Keys.DestinationFileBase, fileNameWithoutExtension },
                        { Keys.DestinationFileExt, output.Path.Extension },
                        { Keys.DestinationFileName, output.Path.FileName },
                        { Keys.DestinationFileDir, output.Path.Directory },
                        { Keys.DestinationFilePath, output.Path },
                        { Keys.DestinationFilePathBase, fileNameWithoutExtension == null
                            ? null : output.Path.Directory.CombineFile(output.Path.FileNameWithoutExtension) },
                    });
                }
                return(_onlyMetadata
                    ? context.GetDocument(input, metadata)
                    : context.GetDocument(input, output.OpenRead(), metadata));
            }
            return(input);
        }
        public override void VisitNamedType(INamedTypeSymbol symbol)
        {
            // Only visit the original definition until we're finished
            INamedTypeSymbol originalDefinition = GetOriginalSymbolDefinition(symbol);

            if (!_finished && !SymbolEqualityComparer.Default.Equals(originalDefinition, symbol))
            {
                VisitNamedType(originalDefinition);
                return;
            }

            if (ShouldIncludeSymbol(symbol))
            {
                MetadataItems metadata = new MetadataItems
                {
                    { CodeAnalysisKeys.SpecificKind, _ => symbol.TypeKind.ToString() },
                    { CodeAnalysisKeys.ContainingType, DocumentFor(symbol.ContainingType) },
                    { CodeAnalysisKeys.MemberTypes, DocumentsFor(symbol.GetTypeMembers()) },
                    { CodeAnalysisKeys.BaseTypes, DocumentsFor(GetBaseTypes(symbol)) },
                    { CodeAnalysisKeys.AllInterfaces, DocumentsFor(symbol.AllInterfaces) },
                    { CodeAnalysisKeys.Members, DocumentsFor(GetAccessibleMembersInThisAndBaseTypes(symbol, symbol).Where(MemberPredicate)) },
                    { CodeAnalysisKeys.Operators, DocumentsFor(GetAccessibleMembersInThisAndBaseTypes(symbol, symbol).Where(OperatorPredicate)) },
                    { CodeAnalysisKeys.ExtensionMethods, _ => DocumentsFor(_extensionMethods.Where(x => x.ReduceExtensionMethod(symbol) != null)) },
                    { CodeAnalysisKeys.Constructors, DocumentsFor(symbol.Constructors.Where(x => !x.IsImplicitlyDeclared)) },
                    { CodeAnalysisKeys.TypeParameters, DocumentsFor(symbol.TypeParameters) },
                    { CodeAnalysisKeys.TypeArguments, DocumentsFor(symbol.TypeArguments) },
                    { CodeAnalysisKeys.Accessibility, _ => symbol.DeclaredAccessibility.ToString() },
                    { CodeAnalysisKeys.Attributes, GetAttributeDocuments(symbol) }
                };
                if (!_finished)
                {
                    metadata.AddRange(new[]
                    {
                        new MetadataItem(CodeAnalysisKeys.DerivedTypes, _ => GetDerivedTypes(symbol), true),
                        new MetadataItem(CodeAnalysisKeys.ImplementingTypes, _ => GetImplementingTypes(symbol), true)
                    });
                }
                AddDocumentCommon(symbol, true, metadata);

                // Descend if not finished, and only if this type was included
                if (!_finished)
                {
                    Parallel.ForEach(
                        symbol.GetMembers()
                        .Where(MemberPredicate)
                        .Concat(symbol.Constructors.Where(x => !x.IsImplicitlyDeclared)),
                        s => s.Accept(this));
                }
            }
        }
示例#8
0
        // Used for everything but namespace documents
        private IDocument AddDocument(ISymbol symbol, bool xmlDocumentation, MetadataItems items)
        {
            items.AddRange(new[]
            {
                new MetadataItem(CodeAnalysisKeys.Symbol, symbol)
            });

            // Add the containing assembly, but only if it's not the code analysis compilation
            if (symbol.ContainingAssembly?.Name != AnalyzeCSharp.CompilationAssemblyName && _assemblySymbols)
            {
                items.Add(new MetadataItem(CodeAnalysisKeys.ContainingAssembly, DocumentFor(symbol.ContainingAssembly)));
            }

            return(AddDocumentCommon(symbol, xmlDocumentation, items));
        }
示例#9
0
        public override void VisitNamedType(INamedTypeSymbol symbol)
        {
            if (_finished || _symbolPredicate == null || _symbolPredicate(symbol))
            {
                MetadataItems metadata = new MetadataItems
                {
                    { CodeAnalysisKeys.SpecificKind, _ => symbol.TypeKind.ToString() },
                    { CodeAnalysisKeys.ContainingType, DocumentFor(symbol.ContainingType) },
                    { CodeAnalysisKeys.MemberTypes, DocumentsFor(symbol.GetTypeMembers()) },
                    { CodeAnalysisKeys.BaseTypes, DocumentsFor(GetBaseTypes(symbol)) },
                    { CodeAnalysisKeys.AllInterfaces, DocumentsFor(symbol.AllInterfaces) },
                    { CodeAnalysisKeys.Members, DocumentsFor(GetAccessibleMembersInThisAndBaseTypes(symbol, symbol).Where(MemberPredicate)) },
                    { CodeAnalysisKeys.Operators, DocumentsFor(GetAccessibleMembersInThisAndBaseTypes(symbol, symbol).Where(OperatorPredicate)) },
                    { CodeAnalysisKeys.ExtensionMethods, _ => DocumentsFor(_extensionMethods.Where(x => x.ReduceExtensionMethod(symbol) != null)) },
                    { CodeAnalysisKeys.Constructors, DocumentsFor(symbol.Constructors.Where(x => !x.IsImplicitlyDeclared)) },
                    { CodeAnalysisKeys.TypeParameters, DocumentsFor(symbol.TypeParameters) },
                    { CodeAnalysisKeys.Accessibility, _ => symbol.DeclaredAccessibility.ToString() },
                    { CodeAnalysisKeys.Attributes, GetAttributeDocuments(symbol) }
                };
                if (!_finished)
                {
                    metadata.AddRange(new[]
                    {
                        new MetadataItem(CodeAnalysisKeys.DerivedTypes, _ => GetDerivedTypes(symbol), true),
                        new MetadataItem(CodeAnalysisKeys.ImplementingTypes, _ => GetImplementingTypes(symbol), true)
                    });
                }
                AddDocument(symbol, true, metadata);

                // Descend if not finished, and only if this type was included
                if (!_finished)
                {
                    Parallel.ForEach(
                        symbol.GetMembers()
                        .Where(MemberPredicate)
                        .Concat(symbol.Constructors.Where(x => !x.IsImplicitlyDeclared)),
                        s => s.Accept(this));
                }
            }
        }
示例#10
0
        public override void VisitNamedType(INamedTypeSymbol symbol)
        {
            if (_finished || _symbolPredicate == null || _symbolPredicate(symbol))
            {
                MetadataItems metadata = new MetadataItems
                {
                    { CodeAnalysisKeys.SpecificKind, (k, m) => symbol.TypeKind.ToString() },
                    { CodeAnalysisKeys.ContainingType, DocumentFor(symbol.ContainingType) },
                    { CodeAnalysisKeys.MemberTypes, DocumentsFor(symbol.GetTypeMembers()) },
                    { CodeAnalysisKeys.BaseType, DocumentFor(symbol.BaseType) },
                    { CodeAnalysisKeys.AllInterfaces, DocumentsFor(symbol.AllInterfaces) },
                    { CodeAnalysisKeys.Members, DocumentsFor(symbol.GetMembers().Where(MemberPredicate)) },
                    { CodeAnalysisKeys.Constructors,
                        DocumentsFor(symbol.Constructors.Where(x => !x.IsImplicitlyDeclared)) },
                    { CodeAnalysisKeys.TypeParameters, DocumentsFor(symbol.TypeParameters) },
                    { CodeAnalysisKeys.Accessibility, (k, m) => symbol.DeclaredAccessibility.ToString() }
                };
                if (!_finished)
                {
                    metadata.AddRange(new []
                    {
                        new MetadataItem(CodeAnalysisKeys.DerivedTypes, (k, m) => GetDerivedTypes(symbol), true),
                        new MetadataItem(CodeAnalysisKeys.ImplementingTypes, (k, m) => GetImplementingTypes(symbol), true)
                    });
                }
                AddDocument(symbol, true, metadata);

                // Descend if not finished, and only if this type was included
                if (!_finished)
                {
                    Parallel.ForEach(symbol.GetMembers()
                        .Where(MemberPredicate)
                        .Concat(symbol.Constructors.Where(x => !x.IsImplicitlyDeclared)),
                        s => s.Accept(this));
                }
            }
        }
示例#11
0
        private void AddXmlDocumentation(ISymbol symbol, MetadataItems metadata)
        {
            string documentationCommentXml = symbol.GetDocumentationCommentXml(expandIncludes: true);
            XmlDocumentationParser xmlDocumentationParser
                = new XmlDocumentationParser(symbol, _commentIdToDocument, _cssClasses, _context.Trace);
            IEnumerable<string> otherHtmlElementNames = xmlDocumentationParser.Parse(documentationCommentXml);

            // Add standard HTML elements
            metadata.AddRange(new []
            {
                new MetadataItem(CodeAnalysisKeys.CommentXml, documentationCommentXml),
                new MetadataItem(CodeAnalysisKeys.Example, (k, m) => xmlDocumentationParser.Process().Example),
                new MetadataItem(CodeAnalysisKeys.Remarks, (k, m) => xmlDocumentationParser.Process().Remarks),
                new MetadataItem(CodeAnalysisKeys.Summary, (k, m) => xmlDocumentationParser.Process().Summary),
                new MetadataItem(CodeAnalysisKeys.Returns, (k, m) => xmlDocumentationParser.Process().Returns),
                new MetadataItem(CodeAnalysisKeys.Value, (k, m) => xmlDocumentationParser.Process().Value),
                new MetadataItem(CodeAnalysisKeys.Exceptions, (k, m) => xmlDocumentationParser.Process().Exceptions),
                new MetadataItem(CodeAnalysisKeys.Permissions, (k, m) => xmlDocumentationParser.Process().Permissions),
                new MetadataItem(CodeAnalysisKeys.Params, (k, m) => xmlDocumentationParser.Process().Params),
                new MetadataItem(CodeAnalysisKeys.TypeParams, (k, m) => xmlDocumentationParser.Process().TypeParams),
                new MetadataItem(CodeAnalysisKeys.SeeAlso, (k, m) => xmlDocumentationParser.Process().SeeAlso)
            });

            // Add other HTML elements with keys of [ElementName]Html
            metadata.AddRange(otherHtmlElementNames.Select(x => 
                new MetadataItem(FirstLetterToUpper(x) + "Comments",
                    (k, m) => xmlDocumentationParser.Process().OtherComments[x])));
        }
示例#12
0
        private void AddDocument(ISymbol symbol, bool xmlDocumentation, MetadataItems items)
        {
            // Get universal metadata
            items.AddRange(new []
            {
                // In general, cache the values that need calculation and don't cache the ones that are just properties of ISymbol
                new MetadataItem(CodeAnalysisKeys.IsResult, !_finished),
                new MetadataItem(CodeAnalysisKeys.SymbolId, (k, m) => GetId(symbol), true),
                new MetadataItem(CodeAnalysisKeys.Symbol, symbol),
                new MetadataItem(CodeAnalysisKeys.Name, (k, m) => symbol.Name),
                new MetadataItem(CodeAnalysisKeys.FullName, (k, m) => GetFullName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.DisplayName, (k, m) => GetDisplayName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.QualifiedName, (k, m) => GetQualifiedName(symbol), true),
                new MetadataItem(CodeAnalysisKeys.Kind, (k, m) => symbol.Kind.ToString()),
                new MetadataItem(CodeAnalysisKeys.ContainingNamespace, DocumentFor(symbol.ContainingNamespace)),
                new MetadataItem(CodeAnalysisKeys.Syntax, (k, m) => GetSyntax(symbol), true)
            });

            // Add metadata that's specific to initially-processed symbols
            if (!_finished)
            {
                items.AddRange(new[]
                {
                    new MetadataItem(Keys.WritePath, (k, m) => _writePath(m), true),
                    new MetadataItem(Keys.RelativeFilePath, 
                        (k, m) => m.String(Keys.WritePath)),
                    new MetadataItem(Keys.RelativeFilePathBase, 
                        (k, m) => PathHelper.RemoveExtension(m.String(Keys.WritePath))),
                    new MetadataItem(Keys.RelativeFileDir, 
                        (k, m) => Path.GetDirectoryName(m.String(Keys.WritePath)))
                });
            }

            // XML Documentation
            if (xmlDocumentation && (!_finished || _docsForImplicitSymbols))
            {
                AddXmlDocumentation(symbol, items);
            }

            // Create the document and add it to the cache
            IDocument document = _context.GetNewDocument(symbol.ToDisplayString(), null, items);
            _symbolToDocument.GetOrAdd(symbol, _ => document);

            // Map the comment ID to the document
            if (!_finished)
            {
                string documentationCommentId = symbol.GetDocumentationCommentId();
                if (documentationCommentId != null)
                {
                    _commentIdToDocument.GetOrAdd(documentationCommentId, _ => document);
                }
            }
        }
示例#13
0
 private void AddDocumentForMember(ISymbol symbol, bool xmlDocumentation, MetadataItems items)
 {
     items.AddRange(new[]
     {
         new MetadataItem(CodeAnalysisKeys.ContainingType, DocumentFor(symbol.ContainingType))
     });
     AddDocument(symbol, xmlDocumentation, items);
 }
示例#14
0
        /// <summary>
        /// Initializes a new instance of an <see cref="Video" /> object.
        /// </summary>
        /// <param name="id">The ID that uniquely identifies this object. Specify int.MinValue for a new object.</param>
        /// <param name="parentAlbum">The album that contains this object. This is a required parameter.</param>
        /// <param name="title">The title of this image.</param>
        /// <param name="hashKey">The hash key that uniquely identifies the original image file.</param>
        /// <param name="thumbnailFilename">The filename of the thumbnail image.</param>
        /// <param name="thumbnailWidth">The width (px) of the thumbnail image.</param>
        /// <param name="thumbnailHeight">The height (px) of the thumbnail image.</param>
        /// <param name="thumbnailSizeKb">The size (KB) of the thumbnail image.</param>
        /// <param name="originalFilename">The filename of the original image.</param>
        /// <param name="originalWidth">The width (px) of the original image.</param>
        /// <param name="originalHeight">The height (px) of the original image.</param>
        /// <param name="originalSizeKb">The size (KB) of the original image.</param>
        /// <param name="sequence">An integer that represents the order in which this image should appear when displayed.</param>
        /// <param name="createdByUsername">The user name of the account that originally added this object to the data store.</param>
        /// <param name="dateAdded">The date this image was added to the data store.</param>
        /// <param name="lastModifiedByUsername">The user name of the account that last modified this object.</param>
        /// <param name="dateLastModified">The date this object was last modified.</param>
        /// <param name="isPrivate">Indicates whether this object should be hidden from un-authenticated (anonymous) users.</param>
        /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
        /// <param name="videoFile">A <see cref="FileInfo"/> object containing the original video file for this object. This is intended to be
        /// specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        /// record.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// <paramref name="videoFile"/> is specified (not null) and the file it refers to is not in the same directory
        /// as the parent album's directory.</exception>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException">Thrown when
        /// <paramref name="videoFile"/> is specified (not null) and its file extension does not correspond to an video MIME
        /// type, as determined by the MIME type definition in the configuration file.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        /// <remarks>This constructor does not verify that <paramref name="videoFile"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal Video(int id, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename, int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string originalFilename, int originalWidth, int originalHeight, int originalSizeKb, int sequence, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, bool isPrivate, bool isInflated, FileInfo videoFile)
        {
            if (parentAlbum == null)
            {
                throw new ArgumentNullException("parentAlbum");
            }

            System.Diagnostics.Debug.Assert(((originalFilename.Length > 0) || (videoFile != null)), "Invalid Video constructor arguments: The original filename or a FileInfo reference to the original file must be passed to the Video constructor.");

            this.Id                     = id;
            this.Parent                 = parentAlbum;
            this.GalleryId              = this.Parent.GalleryId;
            this.Title                  = title;
            this.Sequence               = sequence;
            this.Hashkey                = hashKey;
            this.CreatedByUserName      = createdByUsername;
            this.DateAdded              = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this.DateLastModified       = dateLastModified;
            this.IsPrivate              = isPrivate;

            string parentPhysicalPath = this.Parent.FullPhysicalPathOnDisk;

            IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId);

            // Thumbnail image
            this.Thumbnail            = DisplayObject.CreateInstance(this, thumbnailFilename, thumbnailWidth, thumbnailHeight, DisplayObjectType.Thumbnail, new VideoThumbnailCreator(this));
            this.Thumbnail.FileSizeKB = thumbnailSizeKb;
            if (thumbnailFilename.Length > 0)
            {
                // The thumbnail is stored in either the album's physical path or an alternate location (if thumbnailPath config setting is specified) .
                string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, gallerySetting.FullThumbnailPath, gallerySetting.FullMediaObjectPath);
                this.Thumbnail.FileNamePhysicalPath = System.IO.Path.Combine(thumbnailPath, thumbnailFilename);
            }

            // Videos do not have an optimized version.
            this.Optimized = new NullObjects.NullDisplayObject();

            // Original video file
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new NullObjects.NullDisplayObjectCreator());
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (videoFile != null)
            {
                this.Hashkey           = HelperFunctions.GetHashKeyUnique(videoFile);
                this.Original.FileInfo = videoFile;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (this.MimeType.TypeCategory != MimeTypeCategory.Video)
                {
                    throw new GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException(this.Original.FileInfo);
                }

                this.Original.Width  = gallerySetting.DefaultVideoPlayerWidth;
                this.Original.Height = gallerySetting.DefaultVideoPlayerHeight;

                int fileSize = (int)(videoFile.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.

                if (gallerySetting.ExtractMetadata)
                {
                    // Get the metadata found in the original file.
                    MediaObjectMetadataExtractor metadata = new MediaObjectMetadataExtractor(videoFile.FullName, this.GalleryId);
                    MetadataItems.AddRange(metadata.GetGalleryObjectMetadataItemCollection());
                }

                // Assign the title based on the template, resorting to the filename if necessary.
                if (String.IsNullOrEmpty(title))
                {
                    SetTitle(gallerySetting.MediaObjectCaptionTemplate);

                    if (String.IsNullOrEmpty(this.Title))
                    {
                        this.Title = videoFile.Name;
                    }
                }
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            this.SaveBehavior   = Factory.GetMediaObjectSaveBehavior(this);
            this.DeleteBehavior = Factory.GetMediaObjectDeleteBehavior(this);

            this.IsInflated = isInflated;

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            // Set up our event handlers.
            //this.Saving += new EventHandler(Image_Saving); // Don't need
            this.Saved += Image_Saved;
        }
示例#15
0
        /// <summary>
        /// Initializes a new instance of a <see cref="GenericMediaObject" /> object.
        /// </summary>
        /// <param name="id">The ID that uniquely identifies this object. Specify int.MinValue for a new object.</param>
        /// <param name="parentAlbum">The album that contains this object. This is a required parameter.</param>
        /// <param name="title">The title of this image.</param>
        /// <param name="hashKey">The hash key that uniquely identifies the original file.</param>
        /// <param name="thumbnailFilename">The filename of the thumbnail image.</param>
        /// <param name="thumbnailWidth">The width (px) of the thumbnail image.</param>
        /// <param name="thumbnailHeight">The height (px) of the thumbnail image.</param>
        /// <param name="thumbnailSizeKb">The size (KB) of the thumbnail image.</param>
        /// <param name="originalFilename">The filename of the original image.</param>
        /// <param name="originalWidth">The width (px) of the original image.</param>
        /// <param name="originalHeight">The height (px) of the original image.</param>
        /// <param name="originalSizeKb">The size (KB) of the original image.</param>
        /// <param name="sequence">An integer that represents the order in which this image should appear when displayed.</param>
        /// <param name="createdByUsername">The user name of the account that originally added this object to the data store.</param>
        /// <param name="dateAdded">The date this image was added to the data store.</param>
        /// <param name="lastModifiedByUsername">The user name of the account that last modified this object.</param>
        /// <param name="dateLastModified">The date this object was last modified.</param>
        /// <param name="isPrivate">Indicates whether this object should be hidden from un-authenticated (anonymous) users.</param>
        /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
        /// <param name="file">A <see cref="FileInfo"/> object containing the original file for this object. This is intended to be
        /// specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        /// record.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// the <paramref name="file"/> parameter is specified (not null) and the file it refers to is not in the same directory
        /// as the parent album's directory.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        /// <remarks>This constructor does not verify that <paramref name="file"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal GenericMediaObject(int id, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename,
                                    int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string originalFilename,
                                    int originalWidth, int originalHeight, int originalSizeKb, int sequence,
                                    string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified,
                                    bool isPrivate, bool isInflated, System.IO.FileInfo file)
        {
            if (parentAlbum == null)
            {
                throw new ArgumentNullException("parentAlbum");
            }

            System.Diagnostics.Debug.Assert(((originalFilename.Length > 0) || (file != null)), "Invalid GenericMediaObject constructor arguments: The original filename or a FileInfo reference to the original file must be passed to the GenericMediaObject constructor.");

            this.Id                     = id;
            this.Parent                 = parentAlbum;
            this.GalleryId              = this.Parent.GalleryId;
            this.Title                  = title;
            this.Sequence               = sequence;
            this.Hashkey                = hashKey;
            this.CreatedByUserName      = createdByUsername;
            this.DateAdded              = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this.DateLastModified       = dateLastModified;
            this.IsPrivate              = isPrivate;

            string parentPhysicalPath = this.Parent.FullPhysicalPathOnDisk;

            IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId);

            // Thumbnail image
            this.Thumbnail            = DisplayObject.CreateInstance(this, thumbnailFilename, thumbnailWidth, thumbnailHeight, DisplayObjectType.Thumbnail, new GenericThumbnailCreator(this));
            this.Thumbnail.FileSizeKB = thumbnailSizeKb;
            if (thumbnailFilename.Length > 0)
            {
                // The thumbnail is stored in either the album's physical path or an alternate location (if thumbnailPath config setting is specified) .
                string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, gallerySetting.FullThumbnailPath, gallerySetting.FullMediaObjectPath);
                this.Thumbnail.FileNamePhysicalPath = System.IO.Path.Combine(thumbnailPath, thumbnailFilename);
            }

            // GenericMediaObject instances do not have an optimized version.
            this.Optimized = new NullObjects.NullDisplayObject();

            // Original file
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new NullObjects.NullDisplayObjectCreator());
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (file != null)
            {
                this.Hashkey           = HelperFunctions.GetHashKeyUnique(file);
                this.Original.FileInfo = file;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (this.MimeType.TypeCategory == MimeTypeCategory.Other)
                {
                    // Specify a default width and height for any object other than audio, video, and image. We leave those to their default
                    // value of int.MinValue because we do not accurately know their real width and height. For example, a corrupt image file
                    // will be rejected by the Image class (an UnsupportedImageTypeException is thrown) and will be routed to this class instead.
                    // In this case, we don't know it's real width and height. Similarly, audio and video files are normally handled by the
                    // Audio and Video classes. If one of them ends up here, we need to treat it generically and not assign a width and height.
                    this.Original.Width  = gallerySetting.DefaultGenericObjectWidth;
                    this.Original.Height = gallerySetting.DefaultGenericObjectHeight;
                }

                int fileSize = (int)(file.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.

                if (gallerySetting.ExtractMetadata)
                {
                    // Get the metadata found in the original file.
                    MediaObjectMetadataExtractor metadata = new MediaObjectMetadataExtractor(file.FullName, this.GalleryId);
                    MetadataItems.AddRange(metadata.GetGalleryObjectMetadataItemCollection());
                }

                // Assign the title based on the template, resorting to the filename if necessary.
                if (String.IsNullOrEmpty(title))
                {
                    SetTitle(gallerySetting.MediaObjectCaptionTemplate);

                    if (String.IsNullOrEmpty(this.Title))
                    {
                        this.Title = file.Name;
                    }
                }
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            this.SaveBehavior   = Factory.GetMediaObjectSaveBehavior(this);
            this.DeleteBehavior = Factory.GetMediaObjectDeleteBehavior(this);

            this.IsInflated = isInflated;

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            // Set up our event handlers.
            //this.Saving += new EventHandler(Image_Saving); // Don't need
            this.Saved += Image_Saved;
        }
示例#16
0
文件: WriteFiles.cs 项目: ibebbs/Wyam
 private IDocument Write(IDocument input, IExecutionContext context, FilePath outputPath)
 {
     IFile output = context.FileSystem.GetOutputFile(outputPath);
     if (output != null)
     {
         using (Stream inputStream = input.GetStream())
         {
             if (_ignoreEmptyContent && inputStream.Length == 0)
             {
                 return input;
             }
             if (!_onlyMetadata)
             {
                 using (Stream outputStream = _append ? output.OpenAppend() : output.OpenWrite())
                 {
                     inputStream.CopyTo(outputStream);
                 }
             }
         }
         Trace.Verbose($"{(_onlyMetadata ? "Set metadata for" : "Wrote")} file {output.Path.FullPath} from {input.SourceString()}");
         FilePath relativePath = context.FileSystem.GetOutputPath().GetRelativePath(output.Path) ?? output.Path.FileName;
         FilePath fileNameWithoutExtension = output.Path.FileNameWithoutExtension;
         MetadataItems metadata = new MetadataItems
         {
             { Keys.RelativeFilePath, relativePath },
             { Keys.RelativeFilePathBase, fileNameWithoutExtension == null
                 ? null : relativePath.Directory.CombineFile(output.Path.FileNameWithoutExtension) },
             { Keys.RelativeFileDir, relativePath.Directory }
         };
         if (_onlyMetadata)
         {
             metadata.Add(Keys.WritePath, outputPath);
         }
         else
         {
             metadata.AddRange(new MetadataItems
             {
                 { Keys.DestinationFileBase, fileNameWithoutExtension },
                 { Keys.DestinationFileExt, output.Path.Extension },
                 { Keys.DestinationFileName, output.Path.FileName },
                 { Keys.DestinationFileDir, output.Path.Directory },
                 { Keys.DestinationFilePath, output.Path },
                 { Keys.DestinationFilePathBase, fileNameWithoutExtension == null
                     ? null : output.Path.Directory.CombineFile(output.Path.FileNameWithoutExtension) },
             });
         }
         return _onlyMetadata
             ? context.GetDocument(input, metadata)
             : context.GetDocument(input, output.OpenRead(), metadata);
     }
     return input;
 }