Ejemplo n.º 1
0
        private async Task UpdateArticleContent(Article article, string articleContent)
        {
            var df = new DocumentFormatter(articleContent);

            // clean old images
            if (article.Id != 0)
            {
                await CleanArticleContentImage(article, df);
            }

            var imageSources = df.GetImageSources();
            var images       = imageSources.Select(imgSource =>
            {
                var image = new Image {
                    ArticleId = article.Id, Data = imgSource.Data, DataType = imgSource.DataType
                };
                imgSource.BindEntity(image);
                return(image);
            });

            await _db.Images.AddRangeAsync(images);

            await _db.SaveChangesAsync();

            imageSources.ForEach(ic => ic.UpdateHtmlSource("api/article/image/"));
            article.Content = df.Html;
            _db.Articles.Update(article);
            await _db.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public override void Write(DocumentFormatter output, OutputContext context)
        {
            if (Overloads.Count == 0)
            {
                base.Write(output, context);
                return;
            }

            output.Header(1, SharedTitle);
            WriteInfoBox(output, context);
            WriteOverloadsSummary(output, context);

            output.Table(new[] { "Overload", "Description" }, Overloads,
                         overload => overload.WriteLink(output, context),
                         overload => overload.WriteSummaryLine(output, context)
                         );

            foreach (var overload in Overloads)
            {
                output.Header(2, overload.Name);
                overload.WriteSummary(output, context);

                var syntax = overload.GetSyntax(context.Language);
                if (!string.IsNullOrEmpty(syntax))
                {
                    output.Header(3, "Syntax");
                    output.Code(syntax, context.Language.Name);
                }

                overload.WriteDetails(3, output, context);
            }
        }
Ejemplo n.º 3
0
 protected override void ToolExportClick(object sender, EventArgs e)
 {
     if (Procedure == null || Procedure.Data == null)
     {
         base.ToolExportClick(sender, e);
     }
     else
     {
         string fileName = Procedure.DataName.Replace(".", DateTime.Now.ToString("yyMMddHHmmss") + ".");
         using (var dialog = new SaveFileDialog()
         {
             InitialFileName = fileName
         })
         {
             if (dialog.Run(ParentWindow))
             {
                 DocumentFormatter.Execute(Procedure, new ExecuteArgs()
                 {
                     Parameters = parameters, Result = Query
                 });
                 System.Diagnostics.Process.Start(dialog.FileName);
             }
         }
     }
 }
Ejemplo n.º 4
0
        public virtual void WriteParametersSection(int level, DocumentFormatter output, OutputContext context, IEnumerable <ParameterInfo> parameters)
        {
            if (parameters == null || !parameters.Any())
            {
                return;
            }

            var doc = context.Document.Of(this);

            output.Header(level, "Parameters");
            output.DefinitionList(parameters,
                                  parameter =>
            {
                output.Text(parameter.Name, TextStyles.Teletype);
                output.Text(": ");
                if (parameter.ParameterType.IsGenericParameter)
                {
                    output.Text(parameter.ParameterType.GetDisplayName(), TextStyles.Emphasize);
                }
                else
                {
                    output.LinkCRef(parameter.ParameterType.GetCRef(), parameter.ParameterType.GetDisplayName());
                }
            },
                                  parameter => output.Section(() => doc?.Parameters.For(parameter.Name, output.Xml, name => Log.WarnMisisngParameterDoc(this, name))));
        }
Ejemplo n.º 5
0
        protected virtual void WriteThreadSafetySection(int level, DocumentFormatter output, IEnumerable <XmlThreadSafety> threadSafeties)
        {
            var threadSafety = threadSafeties?.FirstOrDefault();

            if (threadSafety == null)
            {
                return;
            }

            output.Header(level, "Thread Safety");
            if (threadSafety.Static && threadSafety.Instance)
            {
                output.Section("Any public member of this type, either static or instance, is thread-safe.");
            }
            else if (threadSafety.Static && !threadSafety.Instance)
            {
                output.Section("Any public static member of this type is thread-safe, but instance members are not guaranteed to be thread-safe.");
            }
            else if (!threadSafety.Static && threadSafety.Instance)
            {
                output.Section("Any public static member of this type is not guaranteed to be thread-safe, but instance members are thread-safe.");
            }
            else
            {
                output.Section("Neither public nor instance members of this type are guaranteed to be thread-safe.");
            }
        }
Ejemplo n.º 6
0
        private static bool FormatDocument()
        {
            var documentFormatter = new DocumentFormatter(
                new ClauserUnitStrategy(new ClauserUnitChecker()),
                new AdverbUnitStrategy(),
                new TimerUnitStrategy(),
                new ModifierStrategy(new ModifierFormatter()),
                new PrenStrategy());

            List <OpenXmlElement> shuffledXmlElements = new List <OpenXmlElement>();

            try
            {
                using (var document = WordprocessingDocument.Open(wordPath, true))
                {
                    var docPart = document.MainDocumentPart;
                    if (docPart?.Document != null)
                    {
                        shuffledXmlElements = documentFormatter.ProcessDocument(docPart);
                    }
                    CreateAndSaveShuffledDocument(shuffledXmlElements);
                }
            }
            catch (Exception ex)
            {
                DisplayException(ex);
                return(false);
            }

            return(true);
        }
 public static Task <Document> RefactorAsync(
     Document document,
     InitializerExpressionSyntax initializer,
     CancellationToken cancellationToken)
 {
     return(DocumentFormatter.ToSingleLineAsync(document, initializer, cancellationToken));
 }
        private static List <OpenXmlElement> GetDocument(string documentName)
        {
            List <OpenXmlElement> elements;

            using (WordprocessingDocument document =
                       DocumentContentHelper.GetMainDocumentPart(documentName))
            {
                // arrange
                var documentFormatter = new DocumentFormatter(
                    new ClauserUnitStrategy(new ClauserUnitChecker()),
                    new AdverbUnitStrategy(),
                    new TimerUnitStrategy(),
                    new ModifierStrategy(new ModifierFormatter()),
                    new PrenStrategy());

                var docPart = document.MainDocumentPart;
                if (docPart?.Document == null)
                {
                    throw new Exception();
                }

                // act
                elements = documentFormatter.ProcessDocument(docPart);
            }
            return(elements);
        }
Ejemplo n.º 9
0
        public static void ComputeRefactorings(RefactoringContext context, AccessorDeclarationSyntax accessor)
        {
            if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatAccessorBraces))
            {
                BlockSyntax body = accessor.Body;

                if (body?.Span.Contains(context.Span) == true &&
                    !body.OpenBraceToken.IsMissing &&
                    !body.CloseBraceToken.IsMissing)
                {
                    if (body.IsSingleLine())
                    {
                        if (accessor.Parent?.IsMultiLine() == true)
                        {
                            context.RegisterRefactoring(
                                "Format braces on separate lines",
                                cancellationToken => DocumentFormatter.ToMultiLineAsync(context.Document, accessor, cancellationToken));
                        }
                    }
                    else
                    {
                        SyntaxList <StatementSyntax> statements = body.Statements;

                        if (statements.Count == 1 &&
                            statements[0].IsSingleLine())
                        {
                            context.RegisterRefactoring(
                                "Format braces on a single line",
                                cancellationToken => DocumentFormatter.ToSingleLineAsync(context.Document, accessor, cancellationToken));
                        }
                    }
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseExpressionBodiedMember) &&
                context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(accessor) &&
                context.SupportsCSharp6 &&
                UseExpressionBodiedMemberRefactoring.CanRefactor(accessor))
            {
                SyntaxNode node = accessor;

                if (accessor.Parent is AccessorListSyntax accessorList)
                {
                    SyntaxList <AccessorDeclarationSyntax> accessors = accessorList.Accessors;

                    if (accessors.Count == 1 &&
                        accessors.First().IsKind(SyntaxKind.GetAccessorDeclaration) &&
                        (accessorList.Parent is MemberDeclarationSyntax parent))
                    {
                        node = parent;
                    }
                }

                context.RegisterRefactoring(
                    "Use expression-bodied member",
                    cancellationToken => UseExpressionBodiedMemberRefactoring.RefactorAsync(context.Document, node, cancellationToken));
            }
        }
Ejemplo n.º 10
0
 public virtual void WriteInfoBox(DocumentFormatter output, OutputContext context)
 {
     output.Quote(GetInfoBoxWriters(context), info =>
     {
         output.Text(info.Label);
         output.Text(": ");
         info.Writer(output);
     });
 }
Ejemplo n.º 11
0
        protected void WriteTypesInCategory(DocumentFormatter output, OutputContext context, TypeCategory category, IEnumerable <ClrType> types)
        {
            output.Header(3, category.ToPluralString());

            output.Table(new[] { category.ToString(), "Description" }, types,
                         type => type.WriteLink(output, context),
                         type => type.WriteSummaryLine(output, context)
                         );
        }
Ejemplo n.º 12
0
        protected void WriteMembersInCategory(int level, DocumentFormatter output, OutputContext context, MemberCategory category, IEnumerable <ClrMember> members)
        {
            output.Header(level, category.ToPluralString());

            output.Table(new[] { category.ToString(), "Description" }, members,
                         member => member.WriteLink(output, context),
                         member => member.WriteSummaryLine(output, context)
                         );
        }
Ejemplo n.º 13
0
        public override void WriteMembers(int level, DocumentFormatter output, OutputContext context)
        {
            output.Header(level, "Members");

            output.Table(new[] { "Name", "Value", "Description" }, Info.GetEnumValues().Cast <Enum>(),
                         value => output.Text(Info.GetEnumName(value)),
                         value => output.Text((value as IFormattable)?.ToString("D", CultureInfo.InvariantCulture)),
                         value => context.Document.Members.For(value.GetCRef(), doc => output.Xml(doc.Summaries.FirstOrDefault()))
                         );
        }
Ejemplo n.º 14
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ConditionalExpressionSyntax conditionalExpression)
        {
            if (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(conditionalExpression))
            {
                if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatConditionalExpression))
                {
                    if (conditionalExpression.IsSingleLine())
                    {
                        context.RegisterRefactoring(
                            "Format ?: on separate lines",
                            cancellationToken =>
                        {
                            return(DocumentFormatter.ToMultiLineAsync(
                                       context.Document,
                                       conditionalExpression,
                                       cancellationToken));
                        });
                    }
                    else
                    {
                        context.RegisterRefactoring(
                            "Format ?: on a single line",
                            cancellationToken =>
                        {
                            return(DocumentFormatter.ToSingleLineAsync(
                                       context.Document,
                                       conditionalExpression,
                                       cancellationToken));
                        });
                    }
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.ReplaceConditionalExpressionWithIfElse))
                {
                    await ReplaceConditionalExpressionWithIfElseRefactoring.ComputeRefactoringAsync(context, conditionalExpression).ConfigureAwait(false);
                }
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.SwapExpressionsInConditionalExpression) &&
                (context.Span.IsBetweenSpans(conditionalExpression) ||
                 context.Span.IsEmptyAndContainedInSpan(conditionalExpression.QuestionToken) ||
                 context.Span.IsEmptyAndContainedInSpan(conditionalExpression.ColonToken)) &&
                SwapExpressionsInConditionalExpressionRefactoring.CanRefactor(conditionalExpression))
            {
                context.RegisterRefactoring(
                    "Swap expressions in ?:",
                    cancellationToken =>
                {
                    return(SwapExpressionsInConditionalExpressionRefactoring.RefactorAsync(
                               context.Document,
                               conditionalExpression,
                               cancellationToken));
                });
            }
        }
Ejemplo n.º 15
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, InitializerExpressionSyntax initializer)
        {
            if (initializer.IsKind(SyntaxKind.ComplexElementInitializerExpression) &&
                initializer.IsParentKind(SyntaxKind.CollectionInitializerExpression))
            {
                initializer = (InitializerExpressionSyntax)initializer.Parent;
            }

            if (context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(initializer) ||
                context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(initializer.Expressions))
            {
                SeparatedSyntaxList <ExpressionSyntax> expressions = initializer.Expressions;

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatInitializer) &&
                    expressions.Any() &&
                    !initializer.IsKind(SyntaxKind.ComplexElementInitializerExpression) &&
                    initializer.IsParentKind(
                        SyntaxKind.ArrayCreationExpression,
                        SyntaxKind.ImplicitArrayCreationExpression,
                        SyntaxKind.ObjectCreationExpression,
                        SyntaxKind.CollectionInitializerExpression))
                {
                    if (initializer.IsSingleLine(includeExteriorTrivia: false))
                    {
                        context.RegisterRefactoring(
                            "Format initializer on multiple lines",
                            cancellationToken => DocumentFormatter.ToMultiLineAsync(
                                context.Document,
                                initializer,
                                cancellationToken));
                    }
                    else if (expressions.All(expression => expression.IsSingleLine()))
                    {
                        context.RegisterRefactoring(
                            "Format initializer on a single line",
                            cancellationToken => DocumentFormatter.ToSingleLineAsync(
                                context.Document,
                                initializer,
                                cancellationToken));
                    }
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.ExpandInitializer))
                {
                    await ExpandInitializerRefactoring.ComputeRefactoringsAsync(context, initializer).ConfigureAwait(false);
                }

                if (context.IsRefactoringEnabled(RefactoringIdentifiers.UseCSharp6DictionaryInitializer) &&
                    context.SupportsCSharp6)
                {
                    await UseCSharp6DictionaryInitializerRefactoring.ComputeRefactoringAsync(context, initializer).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 16
0
        public override void WriteDetails(int level, DocumentFormatter output, OutputContext context)
        {
            if (Info.IsIndexer())
            {
                WriteParametersSection(level, output, context, Info.GetIndexParameters());
            }

            WriteSection(output, level, "Property Value", context.Document.Of(this)?.PropertyValues);

            base.WriteDetails(level, output, context);
        }
Ejemplo n.º 17
0
        public override void Write(DocumentFormatter output, OutputContext context)
        {
            output.Header(2, Title);
            WriteSummaryLine(output, context);

            foreach (var typeCategory in TypeCategories.OrderBy(group => group.Key))
            {
                WriteTypesInCategory(output, context, typeCategory.Key, typeCategory);
                typeCategory.ForEach(context.Compose);
            }
        }
Ejemplo n.º 18
0
        public override void WriteDetails(int level, DocumentFormatter output, OutputContext context)
        {
            if (Info.IsGenericMethod)
            {
                WriteTypeParametersSection(level + 1, output, context, Info.GetGenericArguments().Where(arg => arg.IsGenericMethodParameter));
            }

            WriteParametersSection(level + 1, output, context, Info.GetParameters());
            WriteReturnValueSection(level + 1, output, context, (Info as MethodInfo)?.ReturnType);

            base.WriteDetails(level, output, context);
        }
Ejemplo n.º 19
0
 public virtual void WriteMembers(int level, DocumentFormatter output, OutputContext context)
 {
     foreach (var category in Members.Select(g => g.Key).OrderBy(c => c))
     {
         var categoryMembers = Members[category];
         if (categoryMembers.Any())
         {
             WriteMembersInCategory(level, output, context, category, categoryMembers);
             categoryMembers.Where(m => m.HasOwnDocFile).ForEach(context.Compose);
         }
     }
 }
Ejemplo n.º 20
0
        private async Task CleanArticleContentImage(Article article, DocumentFormatter df)
        {
            var articleImages = await _db.Images.Where(x => x.ArticleId == article.Id).ToListAsync();

            var htmlImagesIdList = df.GetInDocumentImagesList("api/article/image/");
            var needToDelete     = articleImages.Except(htmlImagesIdList.Select(id => new Image {
                Id = id
            }))
                                   .ToList();

            _db.Images.RemoveRange(needToDelete);
            await _db.SaveChangesAsync();
        }
Ejemplo n.º 21
0
        public override void WriteSummary(DocumentFormatter output, OutputContext context)
        {
            var summary = context.Document.Of(this)?.Summaries;

            if (summary != null && summary.Count != 0)
            {
                output.Section(() => output.Xml(summary));
            }
            else
            {
                output.Section(() => WriteDefaultSummary(output, context));
            }
        }
Ejemplo n.º 22
0
        public override void WriteDetails(int level, DocumentFormatter output, OutputContext context)
        {
            if (Info.IsGenericType)
            {
                WriteTypeParametersSection(level + 1, output, context, Info.GetGenericArguments());
            }

            WriteMembers(level, output, context);

            WriteThreadSafetySection(level, output, context.Document.Of(this)?.ThreadSafeties);

            base.WriteDetails(level, output, context);
        }
Ejemplo n.º 23
0
        public override void WriteSummaryLine(DocumentFormatter output, OutputContext context)
        {
            var summary = context.Document.Of(this)?.Summaries.FirstOrDefault();

            if (summary != null)
            {
                output.Xml(summary);
            }
            else
            {
                WriteDefaultSummary(output, context);
            }
        }
Ejemplo n.º 24
0
        protected virtual void WriteSection(DocumentFormatter output, int level, string header, IEnumerable <ICRef> items)
        {
            if (items == null || !items.Any())
            {
                return;
            }

            if (!string.IsNullOrEmpty(header))
            {
                output.Header(level, header);
            }

            output.List(items, item => output.LinkCRef(item.CRef, (item as ClrItem)?.Title));
        }
Ejemplo n.º 25
0
        protected virtual void WriteSection(DocumentFormatter output, int level, string header, IEnumerable <XmlNode> items)
        {
            if (items == null || !items.Any())
            {
                return;
            }

            if (!string.IsNullOrEmpty(header))
            {
                output.Header(level, header);
            }

            output.Xml(items);
        }
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, ArgumentListSyntax argumentList)
        {
            SeparatedSyntaxList <ArgumentSyntax> arguments = argumentList.Arguments;

            if (arguments.Count == 0)
            {
                return;
            }

            await AddOrRemoveParameterNameRefactoring.ComputeRefactoringsAsync(context, argumentList).ConfigureAwait(false);

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.DuplicateArgument))
            {
                var refactoring = new DuplicateArgumentRefactoring(argumentList);
                refactoring.ComputeRefactoring(context);
            }

            if (context.IsRefactoringEnabled(RefactoringIdentifiers.FormatArgumentList) &&
                (context.Span.IsEmpty || context.Span.IsBetweenSpans(argumentList)))
            {
                if (argumentList.IsSingleLine())
                {
                    if (arguments.Count > 1)
                    {
                        context.RegisterRefactoring(
                            "Format arguments on separate lines",
                            cancellationToken =>
                        {
                            return(DocumentFormatter.ToMultiLineAsync(
                                       context.Document,
                                       argumentList,
                                       cancellationToken));
                        });
                    }
                }
                else
                {
                    context.RegisterRefactoring(
                        "Format arguments on a single line",
                        cancellationToken =>
                    {
                        return(DocumentFormatter.ToSingleLineAsync(
                                   context.Document,
                                   argumentList,
                                   cancellationToken));
                    });
                }
            }
        }
Ejemplo n.º 27
0
        protected virtual void WriteSection(DocumentFormatter output, int level, string header, string label, IEnumerable <XmlReferenceNode> items)
        {
            if (items == null || !items.Any())
            {
                return;
            }

            if (!string.IsNullOrEmpty(header))
            {
                output.Header(level, header);
            }

            output.Table(new[] { label, "Description" }, items,
                         item => output.LinkCRef(item.CRef, Utils.FormatCRef(item.CRef)),
                         item => output.Xml(item));
        }
Ejemplo n.º 28
0
        protected virtual void WriteOverloadsSummary(DocumentFormatter output, OutputContext context)
        {
            var doc = Overloads.Select(o => context.Document.Of(o)?.Overloads.FirstOrDefault()).FirstOrDefault(o => o != null);

            if (doc != null)
            {
                if (doc.Summaries.Any())
                {
                    output.Xml(doc.Summaries);
                }
                else
                {
                    output.Section(() => output.Xml(doc));
                }
            }
        }
Ejemplo n.º 29
0
        public override void Write(DocumentFormatter output, OutputContext context)
        {
            output.Header(1, Title);
            WriteInfoBox(output, context);
            WriteSummary(output, context);

            var syntax = GetSyntax(context.Language);

            if (!string.IsNullOrEmpty(syntax))
            {
                output.Header(2, "Syntax");
                output.Code(syntax, context.Language.Name);
            }

            WriteDetails(2, output, context);
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            ReportPrinter test1 = new ReportPrinter();

            test1.data = "Przykład";
            test1.PrintReport();
            test1.FormatDocument();

            Report test2 = new Report();
            ReportPrinterBetter printer = new ReportPrinterBetter();
            DocumentFormatter   format  = new DocumentFormatter();

            test2.data = "Drugi przykład";
            format.FormatDocument(test2);
            printer.PrintReport(test2);
        }
Ejemplo n.º 31
0
 public MasterControl()
 {
     InitializeComponent();
     this.formatter = new DocumentFormatter();
     this.ctrlPreview.Master = this;
     this.bIsAscending = Properties.Settings.Default.DEFAULT_IS_SORTDIRECTION_ASCENDING;
 }