Beispiel #1
0
        private static string BuildOutput(CopyContext context)
        {
            MarkdownBuilder builder = new MarkdownBuilder();

            builder.Header("Copy");
            builder.Link(context.Destination, ActionBuilder.PathOpenUri(context.Destination));
            bool empty = true;

            if (context.CopiedFiles.Count > 0)
            {
                builder.Header("Copied", 2);
                builder.WritePathList(context.CopiedFiles, context.Destination);
                empty = false;
            }

            if (context.OverwritenFiles.Count > 0)
            {
                builder.Header("Overwriten");
                builder.WritePathList(context.OverwritenFiles, context.Destination);
                empty = false;
            }

            if (empty)
            {
                builder.WriteLine();
                builder.WriteLine();
                builder.Italic("Nothing copied.");
            }

            return(builder.ToString());
        }
Beispiel #2
0
 public override void WriteToMarkdown(MarkdownBuilder builder, int intent)
 {
     builder.Bullet(intent);
     builder.Write("**");
     builder.Link(Name, ActionBuilder.PathOpenUri(file.FilePath));
     builder.Write("** *(file)*");
 }
Beispiel #3
0
        private static LinksModel BuildLinks(IEnumerable <string> paths, string relatedTo)
        {
            LinksModel result = new LinksModel();

            foreach (string path in paths)
            {
                PathTypeEnum type = path.GetPathType();

                switch (type)
                {
                case PathTypeEnum.Directory:
                    result.Directories.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathOpenUri(path)));
                    break;

                case PathTypeEnum.File:
                    result.Files.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathOpenUri(path)));
                    break;

                case PathTypeEnum.NonExistent:
                    result.NonExists.Add(new Link(path.GetFriendlyPath(relatedTo), ActionBuilder.PathUri(path)));
                    break;
                }
            }

            return(result);
        }
Beispiel #4
0
 public override void WriteToMarkdown(MarkdownBuilder builder, int intent)
 {
     builder.Bullet(intent);
     builder.Write("*");
     builder.Link(Name, ActionBuilder.PathOpenUri(project.FilePath));
     builder.Write("* ");
     builder.Italic($"(project)");
 }
Beispiel #5
0
        private static ModeledItem BuildOutput(ZipContext context)
        {
            Document document = new Document(
                new Header(context.DestinationZipFile.GetFileNameOrDirectoryName()),
                new Paragraph(new Core.Model.Text.Link(
                                  context.DestinationZipFile.GetFullPath(),
                                  ActionBuilder.PathOpenUri(context.DestinationZipFile.GetFullPath()))),
                new Section(
                    new Header(2, "Content"),
                    context.FileOutputList));

            return(new ModeledItem(document));
        }
Beispiel #6
0
        private void SearchFile(string filePath, SearchContext context)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                context.FilesCount++;
                context.LineNumber   = 0;
                context.MatchesCount = 0;
                context.MatchResults = new Span();

                using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    using (TextReader reader = new StreamReader(stream))
                    {
                        while ((context.Line = reader.ReadLine()) != null)
                        {
                            context.LineNumber++;
                            SearchLine(context, filePath);
                        }
                    }

                if (context.MatchesCount < 1)
                {
                    return;
                }

                Document fileDocument = new Document(
                    new Header($"{filePath.GetFileNameOrDirectoryName()} ({context.MatchesCount})"),
                    new Paragraph(
                        new Core.Model.Text.Link(
                            filePath.GetFriendlyPath(context.SourceLobby),
                            ActionBuilder.PathOpenUri(filePath.GetFullPath()))),
                    new Paragraph(context.MatchResults));

                context.Result.Add(new ModeledItem(fileDocument));
                context.PositiveFilesCount++;
                context.TotalMatchesCount += context.MatchesCount;
            }
            catch (Exception exception)
            {
                logger.Error("Error during search in file: " + filePath, exception);
            }
        }
Beispiel #7
0
        protected string GetLinkUrl()
        {
            Location location = syntaxNode.GetLocation();
            string   filePath = syntaxNode.SyntaxTree.FilePath;

            if (!location.IsInSource)
            {
                return(ActionBuilder.PathOpenUri(filePath));
            }

            return(ActionBuilder.BuildActionUri(
                       ActionNames.PATH_OPEN,
                       new Dictionary <string, string>
            {
                { ActionParameters.PATH, filePath },
                { "line", (location.GetLineSpan().StartLinePosition.Line + 1).ToString() }
            }));
        }
Beispiel #8
0
        private static Item BuildStageItem(string lobbyPath, IEnumerable <string> paths, string header)
        {
            MarkdownBuilder builder = new MarkdownBuilder();

            builder.Header(header);

            if (string.IsNullOrEmpty(lobbyPath))
            {
                builder.Italic("No lobby directory.");
            }
            else
            {
                builder.Link(lobbyPath, ActionBuilder.PathOpenUri(lobbyPath));
            }

            builder.WriteLine();
            builder.WritePathLists(paths, lobbyPath);

            return(Item.AsMarkdown(builder.ToString()));
        }
Beispiel #9
0
        private static void AddFile(string filePath, ZipArchive archive, ZipContext context)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            bool   flatten         = context.Flat || !filePath.IsSubPathOf(context.SourceLobby);
            string destinationPath = flatten
                ? filePath.GetFileNameOrDirectoryName()
                : filePath.GetFriendlyPath(context.SourceLobby);

            ZipArchiveEntry fileEntry = archive.GetEntry(destinationPath);

            if (fileEntry != null &&
                !context.Override)
            {
                return;
            }

            if (fileEntry == null)
            {
                if (context.ZipAlreadyExists && !context.Add)
                {
                    return;
                }

                fileEntry = archive.CreateEntry(destinationPath);
            }

            context.FileOutputList = context.FileOutputList.AddItem(
                new ListItem(new Core.Model.Text.Link(
                                 destinationPath,
                                 ActionBuilder.PathOpenUri(filePath.GetFullPath()))));

            using (FileStream originalStream = new FileStream(filePath, FileMode.Open))
                using (Stream targetStream = fileEntry.Open())
                {
                    originalStream.CopyTo(targetStream);
                }
        }