static MarkProxy() { var provider = new DfmJsonTokenTreeServiceProvider(); _markdown = provider.CreateMarkdownService(new MarkdownServiceParameters { }); }
public TrelloControllerService(Settings config, ITrelloWorldService service, IMarkdownService md, ICommitParser parser) { _config = config; _service = service; _md = md; _parser = parser; }
public virtual HostService CreateHostService( DocumentBuildParameters parameters, TemplateProcessor templateProcessor, IMarkdownService markdownService, IEnumerable <IInputMetadataValidator> metadataValidator, IDocumentProcessor processor, IEnumerable <FileAndType> files) { var hostService = new HostService( parameters.Files.DefaultBaseDir, files == null ? Enumerable.Empty <FileModel>() : from file in files select Load(processor, parameters.Metadata, parameters.FileMetadata, file) into model where model != null select model, parameters.VersionName, parameters.VersionDir, parameters.LruSize, parameters.GroupInfo) { MarkdownService = markdownService, Processor = processor, Template = templateProcessor, Validators = metadataValidator?.ToImmutableList(), ShouldTraceIncrementalInfo = ShouldProcessorTraceInfo(processor), CanIncrementalBuild = CanProcessorIncremental(processor), }; return(hostService); }
private static void JsonMarkupReceiveContent(IMarkdownService dfmMarkdownService) { string markdownContent = GetMarkdownContent(); var result = JsonMarkup(dfmMarkdownService, markdownContent.ToString()); SendWithEndCode(result); }
private string JsonRenderer(string content) { JsonTokenTreeServiceProvider jsonServiceProvider = new JsonTokenTreeServiceProvider(); IMarkdownService jsonService = jsonServiceProvider.CreateMarkdownService(new MarkdownServiceParameters()); return(jsonService.Markup(content, null).Html); }
static void Main(string[] args) { DfmJsonTokenTreeServiceProvider dfmJsonTokenTreeServiceProvider = new DfmJsonTokenTreeServiceProvider(); IMarkdownService dfmMarkdownService = dfmJsonTokenTreeServiceProvider.CreateMarkdownService(new MarkdownServiceParameters()); while (true) { try { string command = Console.ReadLine(); switch (command.ToLower().Trim()) { case "exit": return; case "dfmmarkup": DfmMarkupReceiveContent(); break; case "jsonmarkup": JsonMarkupReceiveContent(dfmMarkdownService); break; default: SendWithEndCode("Undefined Command"); continue; } } catch (Exception e) { SendWithEndCode($"error:{e.Message}"); } } }
public DetailsModel(IMarkdownService markdownService, GetOEmbedVideoService getOEmbedVideoService, GetVideoService getVideoService, IRepository <ArchiveVideo> repository) { _markdownService = markdownService; _getVideoService = getVideoService; _repository = repository; _getOEmbedVideoService = getOEmbedVideoService; }
public async Task <IActionResult> Edit( int nid, NewsEditModel model, [FromServices] IMarkdownService markdownService) { if (model.NewsId != nid) { return(BadRequest()); } var news = await DbContext.News .Where(n => n.NewsId == nid) .FirstOrDefaultAsync(); if (news is null) { return(NotFound()); } markdownService.Render(model.MarkdownSource, out var html, out var tree); news.Source = Encoding.UTF8.GetBytes(model.MarkdownSource); news.Title = model.Title; news.Active = model.Active; news.Content = Encoding.UTF8.GetBytes(html); news.Tree = Encoding.UTF8.GetBytes(tree); news.LastUpdate = DateTimeOffset.Now; await DbContext.SaveChangesAsync(); StatusMessage = "News updated successfully."; return(RedirectToAction(nameof(Edit), new { nid })); }
private static void JsonMarkupReceiveContent(IMarkdownService dfmMarkdownService) { string markdownContent = GetMarkdownContent(); var result = JsonMarkup(dfmMarkdownService, markdownContent.ToString()); SendWithEndCode(result); }
public GistCommentView(IMarkdownService markdownService) : base(markdownService) { this.WhenAnyValue(x => x.ViewModel.SaveCommand) .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Save)) .Subscribe(x => NavigationItem.RightBarButtonItem = x); }
public virtual HostService CreateHostService( DocumentBuildParameters parameters, TemplateProcessor templateProcessor, IMarkdownService markdownService, IEnumerable <IInputMetadataValidator> metadataValidator, IDocumentProcessor processor, IEnumerable <FileAndType> files) { var(models, invalidFiles) = LoadModels(files, parameters, processor); var hostService = new HostService( parameters.Files.DefaultBaseDir, models, parameters.VersionName, parameters.VersionDir, parameters.LruSize, parameters.GroupInfo, new BuildParameters(parameters.TagParameters)) { MarkdownService = markdownService, Processor = processor, Template = templateProcessor, Validators = metadataValidator?.ToImmutableList(), ShouldTraceIncrementalInfo = ShouldProcessorTraceInfo(processor), CanIncrementalBuild = CanProcessorIncremental(processor), InvalidSourceFiles = invalidFiles.ToImmutableList(), }; return(hostService); }
public PagesController(IPolicyService policies, IPageService pages, IGroupService groups, IMarkdownService markdown) { Pages = pages; Groups = groups; Markdown = markdown; Policies = policies; }
public virtual HostService CreateHostService( DocumentBuildParameters parameters, TemplateProcessor templateProcessor, IMarkdownService markdownService, IEnumerable<IInputMetadataValidator> metadataValidator, IDocumentProcessor processor, IEnumerable<FileAndType> files) { var hostService = new HostService( parameters.Files.DefaultBaseDir, files == null ? new FileModel[0] : from file in files select Load(processor, parameters.Metadata, parameters.FileMetadata, file) into model where model != null select model) { MarkdownService = markdownService, Processor = processor, Template = templateProcessor, Validators = metadataValidator?.ToImmutableList(), ShouldTraceIncrementalInfo = ShouldProcessorTraceInfo(processor), CanIncrementalBuild = CanProcessorIncremental(processor), }; return hostService; }
public VideosController(IMapper mapper, IRepository <ArchiveVideo> repository, IOptions <ApiSettings> apiSettings, GetOEmbedVideoService getOEmbedVideoService, GetVideoService getVideoService, DeleteVideoService deleteVideoService, UploadSubtitleToVideoService uploadSubtitleToVideoService, IMarkdownService markdownService, CreateAnimatedThumbnailsService createAnimatedThumbnailsService, GetAllAnimatedThumbnailService getAllAnimatedThumbnailService, IVideosService videosService, UserManager <ApplicationUser> userManager, IRepository <Member> memberRepository) { _mapper = mapper; _getOEmbedVideoService = getOEmbedVideoService; _getVideoService = getVideoService; _deleteVideoService = deleteVideoService; _uploadSubtitleToVideoService = uploadSubtitleToVideoService; _repository = repository; _expectedApiKey = apiSettings.Value.ApiKey; _markdownService = markdownService; _createAnimatedThumbnailsService = createAnimatedThumbnailsService; _getAllAnimatedThumbnailService = getAllAnimatedThumbnailService; _videosService = videosService; _userManager = userManager; _memberRepository = memberRepository; }
public IssueViewModel( IApplicationService applicationService = null, IFeaturesService featuresService = null, IMessageService messageService = null, IMarkdownService markdownService = null) { _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); _featuresService = featuresService ?? Locator.Current.GetService <IFeaturesService>(); _messageService = messageService ?? Locator.Current.GetService <IMessageService>(); _markdownService = markdownService ?? Locator.Current.GetService <IMarkdownService>(); this.Bind(x => x.Issue, true) .Where(x => x != null) .Select(x => string.Equals(x.State, "closed")) .Subscribe(x => IsClosed = x); this.Bind(x => x.Issue, true) .SelectMany(issue => _markdownService.Convert(issue?.Body).ToObservable()) .Subscribe(x => MarkdownDescription = x); GoToOwner = ReactiveUI.ReactiveCommand.Create( () => ShowViewModel <UserViewModel>(new UserViewModel.NavObject { Username = Issue?.User?.Login }), this.Bind(x => x.Issue, true).Select(x => x != null)); }
public PullRequestViewModel( string username, string repository, PullRequest pullRequest, IMarkdownService markdownService = null, IApplicationService applicationService = null, IActionMenuService actionMenuService = null) : this(username, repository, pullRequest.Id, markdownService, applicationService) { PullRequest = pullRequest; }
public DfmPreviewHandler(string workspacePath, bool isDfmLatest) { DfmServiceProvider provider = isDfmLatest ? new DfmServiceProvider() : new DfmLegacyServiceProvider(); _service = provider.CreateMarkdownService(new MarkdownServiceParameters { BasePath = workspacePath }); }
public IssueViewModel( string username, string repository, Issue issue, IApplicationService applicationService = null, IMarkdownService markdownService = null, IMessageService messageService = null) : this(username, repository, issue.LocalId, applicationService, markdownService, messageService) { Issue = issue; }
public DfmTokenTreeHandler(string workspacePath) { DfmJsonTokenTreeServiceProvider provider = new DfmJsonTokenTreeServiceProvider(); _service = provider.CreateMarkdownService(new MarkdownServiceParameters { BasePath = workspacePath }); }
private void TestDfmJsonTokenTreeJsonRender(string source, string expected) { DfmJsonTokenTreeServiceProvider dfmJsonTokenTreeServiceProvider = new DfmJsonTokenTreeServiceProvider(); IMarkdownService dfmMarkdownService = dfmJsonTokenTreeServiceProvider.CreateMarkdownService(new MarkdownServiceParameters()); Assert.Equal(expected, dfmMarkdownService.Markup(source, null).Html); }
public QueriesHandler(IMarkdownService markdownService, IBlogRepository blogRepository, ITagMapper tagMapper, IMapper <BlogPostHeader, BlogPostHeaderDto> headerMapper, IUserRepository userRepository) { _markdownService = markdownService; _blogRepository = blogRepository; _tagMapper = tagMapper; _headerMapper = headerMapper; _userRepository = userRepository; }
public MarkdownProblemViewProvider( IMarkdownService markdownService, HtmlEncoder encoder, IStaticFileRepository io2) { Markdown = markdownService; Encoder = encoder; StaticFiles = io2; }
public ReadMeService( IPackageFileService packageFileService, IEntitiesContext entitiesContext, IMarkdownService markdownService) { _packageFileService = packageFileService ?? throw new ArgumentNullException(nameof(packageFileService)); _entitiesContext = entitiesContext ?? throw new ArgumentNullException(nameof(entitiesContext)); _markdownService = markdownService ?? throw new ArgumentNullException(nameof(markdownService)); }
private static string DfmMarkup(string basedir, string filename, string markdownContent) { DfmServiceProvider dfmServiceProvider = new DfmServiceProvider(); IMarkdownService dfmService = dfmServiceProvider.CreateMarkdownService(new MarkdownServiceParameters { BasePath = basedir }); return(dfmService.Markup(markdownContent, filename).Html); }
public DetailsModel(IMarkdownService markdownService, GetOEmbedVideoService getOEmbedVideoService, GetVideoService getVideoService, IRepository <ArchiveVideo> repository, UserManager <ApplicationUser> userManager, IRepository <Member> memberRepository) { _markdownService = markdownService; _getVideoService = getVideoService; _repository = repository; _getOEmbedVideoService = getOEmbedVideoService; _userManager = userManager; _memberRepository = memberRepository; }
public ReadmeViewController( string owner, string repository, Octokit.Readme readme = null, IApplicationService applicationService = null, IMarkdownService markdownService = null) : base(false, false) { _owner = owner; _repository = repository; _applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); _markdownService = markdownService ?? Locator.Current.GetService <IMarkdownService>(); Title = "Readme"; var loadCommand = ReactiveCommand.CreateFromTask(() => { if (readme != null) { return(Task.FromResult(readme)); } return(_applicationService.GitHubClient.Repository.Content.GetReadme(owner, repository)); }); loadCommand .ThrownExceptions .Do(_ => SetErrorView()) .Select(error => new UserError(LoadErrorMessage, error)) .SelectMany(Interactions.Errors.Handle) .Subscribe(); loadCommand .ToProperty(this, x => x.Readme, out _readme); Appearing .Take(1) .Select(_ => Unit.Default) .InvokeReactiveCommand(loadCommand); this.WhenAnyValue(x => x.Readme) .Where(x => x != null) .SelectMany(ConvertToWebView) .Subscribe(LoadContent); this.WhenAnyValue(x => x.Readme) .Select(x => x != null) .Subscribe(x => _actionButton.Enabled = x); NavigationItem.RightBarButtonItem = _actionButton; this.WhenActivated(d => { d(_actionButton.GetClickedObservable() .Subscribe(ShareButtonPress)); }); }
public ComposerViewController(IMarkdownService markdownService) : base(markdownService) { OnActivation(d => { d(this.WhenAnyValue(x => x.ViewModel.SaveCommand) .ToBarButtonItem(UIBarButtonSystemItem.Save, x => NavigationItem.RightBarButtonItem = x)); d(this.WhenAnyValue(x => x.ViewModel.DismissCommand) .ToBarButtonItem(Images.Cancel, x => NavigationItem.LeftBarButtonItem = x)); }); }
private static string DfmMarkup(string basedir, string filename, string markdownContent) { // TODO: different editor use different child process so there is no need to create dfm service each time DfmServiceProvider dfmServiceProvider = new DfmServiceProvider(); IMarkdownService dfmService = dfmServiceProvider.CreateMarkdownService(new MarkdownServiceParameters { BasePath = basedir }); return(dfmService.Markup(markdownContent, filename).Html); }
public void Dispose() { foreach (var processor in Processors) { Logger.LogVerbose($"Disposing processor {processor.Name} ..."); (processor as IDisposable)?.Dispose(); } (MarkdownService as IDisposable)?.Dispose(); MarkdownService = null; }
public ParseCommand(IMarkdownService markdownService, IOptions <GistEmbedConfig> gistConfig, ILogger logger) { _markdownService = markdownService; _gistConfig = gistConfig; _logger = logger; this.IsCommand("parse", "Parse markdown codes with embeded gist code"); this.HasOption("f|file=", "markdown file path", v => _filePath = v); this.HasOption("t|token=", "github auth token", v => _token = v); }
public PullRequestViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory) : base(applicationService, markdownService, actionMenuService, alertDialogFactory) { this.WhenAnyValue(x => x.Id) .Subscribe(x => Title = "Pull Request #" + x); this.WhenAnyValue(x => x.PullRequest.HtmlUrl) .ToProperty(this, x => x.HtmlUrl, out _htmlUrl); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); _canMerge = canMergeObservable.CombineLatest( this.WhenAnyValue(x => x.PushAccess), (x, y) => x && y) .ToProperty(this, x => x.CanMerge); _commentsCount = this.WhenAnyValue(x => x.Issue.Comments, x => x.Comments.Count, (x, y) => x + y) .ToProperty(this, x => x.CommentCount); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { using (alertDialogFactory.Activate("Merging...")) { var req = new MergePullRequest { Message = MergeComment }; var response = await applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) { throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); } await LoadCommand.ExecuteAsync(); } }); var canGoToCommits = this.WhenAnyValue(x => x.PullRequest.Commits).Select(x => x > 0); GoToCommitsCommand = ReactiveCommand.Create(canGoToCommits); GoToCommitsCommand .Select(x => this.CreateViewModel <PullRequestCommitsViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName, Id)) .Subscribe(NavigateTo); var canGoToFiles = this.WhenAnyValue(x => x.PullRequest.ChangedFiles).Select(x => x > 0); GoToFilesCommand = ReactiveCommand.Create(canGoToFiles); GoToFilesCommand .Select(x => this.CreateViewModel <PullRequestFilesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName, Id, PullRequest.Head.Sha)) .Do(x => x.CommentCreated.Subscribe(AddComment)) .Subscribe(NavigateTo); }
public ComposerViewController(IMarkdownService markdownService) : base(markdownService) { this.WhenAnyValue(x => x.ViewModel.SaveCommand) .Select(x => x.ToBarButtonItem(UIBarButtonSystemItem.Save)) .Subscribe(x => NavigationItem.RightBarButtonItem = x); this.WhenAnyValue(x => x.ViewModel.DismissCommand) .Select(x => x.ToBarButtonItem(Images.Cancel)) .Subscribe(x => NavigationItem.LeftBarButtonItem = x); }
public GistFileViewModel(ISessionService sessionService, ISessionService applicationService, IFilesystemService filesystemService, IActionMenuFactory actionMenuService, IMarkdownService markdownService) : base(sessionService) { this.WhenAnyValue(x => x.Filename) .Select(x => x == null ? "Gist" : x.Substring(x.LastIndexOf('/') + 1)) .Subscribe(x => Title = x); _isMarkdown = this.WhenAnyValue(x => x.GistFile) .IsNotNull() .Select(x => string.Equals(x.Language, MarkdownLanguage, StringComparison.OrdinalIgnoreCase)) .ToProperty(this, x => x.IsMarkdown); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.SourceItem).Select(x => x != null), sender => { var menu = actionMenuService.Create(); menu.AddButton("Open With", OpenWithCommand); return menu.Show(sender); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { if (GistFile == null) { var data = await applicationService.Client.ExecuteAsync(applicationService.Client.Gists[_id].Get()); GistFile = data.Data.Files[_filename]; } //Check to make sure... if (GistFile == null || GistFile.Content == null) { throw new Exception("Unable to retreive gist!"); } var content = GistFile.Content; if (MarkdownLanguage.Equals(GistFile.Language, StringComparison.OrdinalIgnoreCase)) content = await applicationService.Client.Markdown.GetMarkdown(content); var gistFileName = System.IO.Path.GetFileName(GistFile.Filename).Trim(); string filePath; using (var stream = filesystemService.CreateTempFile(out filePath, gistFileName)) { using (var fs = new System.IO.StreamWriter(stream)) { fs.Write(content); } } var fileUri = new Uri(filePath); SourceItem = new FileSourceItemViewModel(fileUri, false); }); }
public IssueViewModel( ISessionService applicationService, IActionMenuFactory actionMenuFactory, IMarkdownService markdownService, IAlertDialogFactory alertDialogFactory) : base(applicationService, markdownService, actionMenuFactory, alertDialogFactory) { this.WhenAnyValue(x => x.Id) .Subscribe(x => Title = "Issue #" + x); _htmlUrl = this.WhenAnyValue(x => x.Issue.HtmlUrl) .ToProperty(this, x => x.HtmlUrl); }
public PullRequestViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory) : base(applicationService, markdownService, actionMenuService, alertDialogFactory) { this.WhenAnyValue(x => x.Id) .Subscribe(x => Title = "Pull Request #" + x); this.WhenAnyValue(x => x.PullRequest.HtmlUrl) .ToProperty(this, x => x.HtmlUrl, out _htmlUrl); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); _canMerge = canMergeObservable.CombineLatest( this.WhenAnyValue(x => x.PushAccess), (x, y) => x && y) .ToProperty(this, x => x.CanMerge); _commentsCount = this.WhenAnyValue(x => x.Issue.Comments, x => x.Comments.Count, (x, y) => x + y) .ToProperty(this, x => x.CommentCount); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { using (alertDialogFactory.Activate("Merging...")) { var req = new MergePullRequest { CommitMessage = MergeComment }; var response = await applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); await LoadCommand.ExecuteAsync(); } }); var canGoToCommits = this.WhenAnyValue(x => x.PullRequest.Commits).Select(x => x > 0); GoToCommitsCommand = ReactiveCommand.Create(canGoToCommits); GoToCommitsCommand .Select(x => this.CreateViewModel<PullRequestCommitsViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName, Id)) .Subscribe(NavigateTo); var canGoToFiles = this.WhenAnyValue(x => x.PullRequest.ChangedFiles).Select(x => x > 0); GoToFilesCommand = ReactiveCommand.Create(canGoToFiles); GoToFilesCommand .Select(x => this.CreateViewModel<PullRequestFilesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName, Id, PullRequest.Head.Sha)) .Do(x => x.CommentCreated.Subscribe(AddComment)) .Subscribe(NavigateTo); }
public override HostService CreateHostService( DocumentBuildParameters parameters, TemplateProcessor templateProcessor, IMarkdownService markdownService, IEnumerable<IInputMetadataValidator> metadataValidator, IDocumentProcessor processor, IEnumerable<FileAndType> files) { if (ShouldProcessorTraceInfo(processor)) { IncrementalContext.CreateProcessorInfo(processor); } var hs = base.CreateHostService(parameters, templateProcessor, markdownService, metadataValidator, processor, files); PostCreate(hs, files); return hs; }
public ReadmeViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService) { ShareCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ContentModel, x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ContentModel.HtmlUrl)); GoToGitHubCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ContentModel, x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(ContentModel.HtmlUrl)); GoToLinkCommand = new ReactiveCommand(); GoToLinkCommand.OfType<string>().Subscribe(x => GoToUrlCommand.ExecuteIfCan(x)); LoadCommand.RegisterAsyncTask(x => this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme(), x as bool?, r => { ContentModel = r.Data; ContentText = markdownService.Convert(Encoding.UTF8.GetString(Convert.FromBase64String(ContentModel.Content))); })); }
public static ImmutableList<FileModel> Build(IDocumentProcessor processor, DocumentBuildParameters parameters, IMarkdownService markdownService) { var hostServiceCreator = new HostServiceCreator(null); var hostService = hostServiceCreator.CreateHostService( parameters, null, markdownService, null, processor, parameters.Files.EnumerateFiles()); var phaseProcessor = new PhaseProcessor { Handlers = { new PrebuildBuildPhaseHandler(null), new PostbuildPhaseHandler(null, null), } }; phaseProcessor.Process(new List<HostService> { hostService }, parameters.MaxParallelism); return hostService.Models; }
private static string JsonMarkup(IMarkdownService dfmMarkdownService, string markdownContent) { return dfmMarkdownService.Markup(markdownContent, null).Html; }
private IEnumerable<HostService> GetInnerContexts( DocumentBuildParameters parameters, IEnumerable<IDocumentProcessor> processors, TemplateProcessor templateProcessor, IMarkdownService markdownService, DocumentBuildContext context) { var k = from fileItem in ( from file in parameters.Files.EnumerateFiles() from p in (from processor in processors let priority = processor.GetProcessingPriority(file) where priority != ProcessingPriority.NotSupported group processor by priority into ps orderby ps.Key descending select ps.ToList()).FirstOrDefault() ?? new List<IDocumentProcessor> { null } select new { file, p }) group fileItem by fileItem.p; var toHandleItems = k.Where(s => s.Key != null); var notToHandleItems = k.Where(s => s.Key == null); foreach (var item in notToHandleItems) { var sb = new StringBuilder(); sb.AppendLine("Cannot handle following file:"); foreach (var f in item) { sb.Append("\t"); sb.AppendLine(f.file.File); } Logger.LogWarning(sb.ToString()); } // todo : revert until PreProcessor ready foreach (var pair in (from processor in processors join item in toHandleItems on processor equals item.Key into g from item in g.DefaultIfEmpty() select new { processor, item, }).AsParallel().WithDegreeOfParallelism(parameters.MaxParallelism)) { var incrementalContext = context.IncrementalBuildContext; var processorSupportIncremental = IsProcessorSupportIncremental(pair.processor); bool processorCanIncremental = processorSupportIncremental; if (processorSupportIncremental) { incrementalContext.CreateProcessorInfo(pair.processor); processorCanIncremental = incrementalContext.CanProcessorIncremental(pair.processor); } var hostService = new HostService( parameters.Files.DefaultBaseDir, pair.item == null ? new FileModel[0] : from file in pair.item select Load(pair.processor, parameters.Metadata, parameters.FileMetadata, file.file, processorCanIncremental, context) into model where model != null select model) { MarkdownService = markdownService, Processor = pair.processor, Template = templateProcessor, Validators = MetadataValidators.ToImmutableList(), ShouldTraceIncrementalInfo = processorSupportIncremental, CanIncrementalBuild = processorCanIncremental, }; if (ShouldTraceIncrementalInfo) { using (new LoggerPhaseScope("ReportModelLoadInfo", true)) { var allFiles = pair.item?.Select(f => f.file.File) ?? new string[0]; var loadedFiles = hostService.Models.Select(m => m.FileAndType.File); incrementalContext.ReportModelLoadInfo(hostService, allFiles.Except(loadedFiles), null); incrementalContext.ReportModelLoadInfo(hostService, loadedFiles, BuildPhase.PreBuild); } } yield return hostService; } }
public MarkdownView(IMarkdownService markdown, IResourceProviderService resourceProvider) { _markdown = markdown; _resourceProvider = resourceProvider; }
public PullRequestViewModel(IMarkdownService markdownService) { _markdownService = markdownService; }
public EfPostRepository(IBlogContext context, IMarkdownService markdown) { Context = context; Markdown = markdown; }
public ReadmeViewModel(IMarkdownService markdownService) { _markdownService = markdownService; }
private Manifest BuildCore(DocumentBuildParameters parameters) { using (new LoggerPhaseScope(PhaseName, true)) { Logger.LogInfo($"Max parallelism is {parameters.MaxParallelism}."); Directory.CreateDirectory(parameters.OutputBaseDir); var context = new DocumentBuildContext( Path.Combine(Directory.GetCurrentDirectory(), parameters.OutputBaseDir), parameters.Files.EnumerateFiles(), parameters.ExternalReferencePackages, parameters.XRefMaps, parameters.MaxParallelism, parameters.Files.DefaultBaseDir, parameters.VersionName, parameters.ApplyTemplateSettings, parameters.RootTocPath); Logger.LogVerbose("Start building document..."); // Start building document... List<HostService> hostServices = null; IHostServiceCreator hostServiceCreator = null; PhaseProcessor phaseProcessor = null; try { using (var templateProcessor = parameters.TemplateManager?.GetTemplateProcessor(context, parameters.MaxParallelism) ?? TemplateProcessor.DefaultProcessor) { using (new LoggerPhaseScope("Prepare", true)) { if (MarkdownService == null) { MarkdownService = CreateMarkdownService(parameters, templateProcessor.Tokens.ToImmutableDictionary()); } Prepare( parameters, context, templateProcessor, (MarkdownService as IHasIncrementalContext)?.GetIncrementalContextHash(), out hostServiceCreator, out phaseProcessor); } using (new LoggerPhaseScope("Load", true)) { hostServices = GetInnerContexts(parameters, Processors, templateProcessor, hostServiceCreator).ToList(); } BuildCore(phaseProcessor, hostServices, context); return new Manifest { Files = context.ManifestItems.ToList(), Homepages = GetHomepages(context), XRefMap = ExportXRefMap(parameters, context), SourceBasePath = StringExtension.ToNormalizedPath(EnvironmentContext.BaseDirectory) }; } } finally { if (hostServices != null) { foreach (var item in hostServices) { Cleanup(item); item.Dispose(); } } } } }
public static ImmutableList<FileModel> Build(IDocumentProcessor processor, DocumentBuildParameters parameters, IMarkdownService markdownService) { var hostService = new HostService( parameters.Files.DefaultBaseDir, from file in parameters.Files.EnumerateFiles() select Load(processor, parameters.Metadata, parameters.FileMetadata, file, false, null) into model where model != null select model) { Processor = processor, MarkdownService = markdownService, DependencyGraph = new DependencyGraph(), }; BuildCore(new List<HostService> { hostService }, parameters.MaxParallelism, null, null, null); return hostService.Models; }
protected BaseIssueViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; _markdownService = markdownService; _alertDialogFactory = alertDialogFactory; _assigneesCache = new Lazy<Task<IReadOnlyList<Octokit.User>>>(() => _applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName)); _milestonesCache = new Lazy<Task<IReadOnlyList<Octokit.Milestone>>>(() => _applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName)); _labelsCache = new Lazy<Task<IReadOnlyList<Octokit.Label>>>(() => _applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName)); IssueUpdated.Subscribe(x => Issue = x); var issuePresenceObservable = this.WhenAnyValue(x => x.Issue, x => x.CanModify) .Select(x => x.Item1 != null && x.Item2); Events = InternalEvents.CreateDerivedCollection(x => x); this.WhenAnyValue(x => x.Issue.Comments) .ToProperty(this, x => x.CommentCount, out _commentsCount); _participants = Events.Changed .Select(_ => Events.Select(y => y.Actor).Distinct().Count()) .Select(x => x == 0 ? 1 : x) .ToProperty(this, x => x.Participants); GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable); GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable); GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable); _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee) .ToProperty(this, x => x.AssignedUser); _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone) .ToProperty(this, x => x.AssignedMilestone); _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels) .ToProperty(this, x => x.AssignedLabels); _isClosed = this.WhenAnyValue(x => x.Issue.State) .Select(x => x == Octokit.ItemState.Closed) .ToProperty(this, x => x.IsClosed); _markdownDescription = this.WhenAnyValue(x => x.Issue) .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : x.Body)) .Where(x => x != null) .Select(x => GetMarkdownDescription().ToObservable()) .Switch() .ToProperty(this, x => x.MarkdownDescription, null, RxApp.MainThreadScheduler); LoadCommand = ReactiveCommand.CreateAsyncTask(t => Load(applicationService)); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToOwnerCommand .Select(_ => this.CreateViewModel<UserViewModel>()) .Select(x => x.Init(Issue.User.Login)) .Subscribe(NavigateTo); ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => { try { var updatedIssue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate { State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open }); _issueUpdatedObservable.OnNext(updatedIssue); } catch (Exception e) { var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open"; throw new Exception("Unable to " + close + " the item. " + e.Message, e); } RetrieveEvents().ToBackground(x => InternalEvents.Reset(x)); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(s); var comment = (await applicationService.Client.ExecuteAsync(request)).Data; InternalEvents.Add(new IssueCommentItemViewModel(comment)); }, alertDialogFactory); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Issue).Select(x => x != null), sender => { var menu = actionMenuFactory.Create(); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(Issue.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", AddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return menu.Show(sender); }); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel<IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.Issue = Issue; vm.SaveCommand.Subscribe(_issueUpdatedObservable.OnNext); NavigateTo(vm); }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType<string>().Subscribe(GoToUrl); GoToUrlCommand.OfType<Uri>().Subscribe(x => GoToUrl(x.AbsoluteUri)); var hasHtmlObservable = this.WhenAnyValue(x => x.HtmlUrl).Select(x => x != null); ShareCommand = ReactiveCommand.Create(hasHtmlObservable); ShareCommand.Subscribe(sender => actionMenuFactory.ShareUrl(sender, HtmlUrl)); GoToHtmlUrlCommand = ReactiveCommand.Create(hasHtmlObservable); GoToHtmlUrlCommand.Subscribe(_ => GoToUrl(HtmlUrl.AbsoluteUri)); }
public PullRequestViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService) { _applicationService = applicationService; _markdownService = markdownService; Comments = new ReactiveList<IssueCommentModel>(); Events = new ReactiveList<IssueEventModel>(); MergeCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && x.Merged.HasValue && !x.Merged.Value && x.Mergable.HasValue && x.Mergable.Value), async t => { try { var response = await _applicationService.Client.ExecuteAsync(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].Merge()); if (!response.Data.Merged) throw new Exception(response.Data.Message); var pullRequest = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].Get(); await this.RequestModel(pullRequest, true, r => PullRequest = r.Data); } catch (Exception e) { throw new Exception("Unable to Merge: " + e.Message, e); } }); ToggleStateCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), async t => { var close = string.Equals(PullRequest.State, "open", StringComparison.OrdinalIgnoreCase); try { var data = await _applicationService.Client.ExecuteAsync( _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].UpdateState(close ? "closed" : "open")); PullRequest = data.Data; } catch (Exception e) { throw new Exception("Unable to " + (close ? "close" : "open") + " the item. " + e.Message, e); } }); GoToCommitsCommand = ReactiveCommand.Create(); GoToCommitsCommand.Subscribe(_ => { var vm = CreateViewModel<PullRequestCommitsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.PullRequestId = PullRequestId; ShowViewModel(vm); }); GoToFilesCommand = ReactiveCommand.Create(); GoToFilesCommand.Subscribe(_ => { var vm = CreateViewModel<PullRequestFilesViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.PullRequestId = PullRequestId; ShowViewModel(vm); }); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); ShareCommand.Subscribe(_ => shareService.ShareUrl(PullRequest.HtmlUrl)); GoToEditCommand = ReactiveCommand.Create(); GoToEditCommand.Subscribe(_ => { var vm = CreateViewModel<IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = PullRequestId; vm.Issue = Issue; vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x); ShowViewModel(vm); }); GoToLabelsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToLabelsCommand.Subscribe(_ => { var vm = CreateViewModel<IssueLabelsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.IssueId = PullRequestId; vm.SaveOnSelect = true; vm.SelectedLabels.Reset(Issue.Labels); vm.WhenAnyValue(x => x.Labels).Skip(1).Subscribe(x => { Issue.Labels = x.ToList(); this.RaisePropertyChanged("Issue"); }); ShowViewModel(vm); }); GoToMilestoneCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToMilestoneCommand.Subscribe(_ => { var vm = CreateViewModel<IssueMilestonesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.IssueId = PullRequestId; vm.SaveOnSelect = true; vm.SelectedMilestone = Issue.Milestone; vm.WhenAnyValue(x => x.SelectedMilestone).Skip(1).Subscribe(x => { Issue.Milestone = x; this.RaisePropertyChanged("Issue"); }); ShowViewModel(vm); }); GoToAssigneeCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToAssigneeCommand.Subscribe(_ => { var vm = CreateViewModel<IssueAssignedToViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.IssueId = PullRequestId; vm.SaveOnSelect = true; vm.SelectedUser = Issue.Assignee; vm.WhenAnyValue(x => x.SelectedUser).Skip(1).Subscribe(x => { Issue.Assignee = x; this.RaisePropertyChanged("Issue"); }); ShowViewModel(vm); }); GoToAddCommentCommand = ReactiveCommand.Create(); GoToAddCommentCommand.Subscribe(_ => { var vm = CreateViewModel<CommentViewModel>(); ReactiveUI.Legacy.ReactiveCommandMixins.RegisterAsyncTask(vm.SaveCommand, async t => { var req = _applicationService.Client.Users[RepositoryOwner] .Repositories[RepositoryName].Issues[PullRequestId].CreateComment(vm.Comment); var comment = await _applicationService.Client.ExecuteAsync(req); Comments.Add(comment.Data); vm.DismissCommand.ExecuteIfCan(); }); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var pullRequest = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests[PullRequestId].Get(); var t1 = this.RequestModel(pullRequest, forceCacheInvalidation, response => PullRequest = response.Data); Events.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[PullRequestId].GetEvents(), forceCacheInvalidation).FireAndForget(); Comments.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[PullRequestId].GetComments(), forceCacheInvalidation).FireAndForget(); this.RequestModel(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[PullRequestId].Get(), forceCacheInvalidation, response => Issue = response.Data).FireAndForget(); return t1; }); }