Example #1
0
 public FileUploadOrDownload(IHostService hostService, ShellStruct shellData, string sourceFilePath, string targetFilePath)
 {
     _hostService = hostService;
     _shellData = shellData;
     _sourceFilePath = sourceFilePath;
     _targetFilePath = targetFilePath;
 }
Example #2
0
 public static IEnumerable<OverwriteDocumentModel> ReadMarkdownAsOverwrite(IHostService host, FileAndType ft)
 {
     // Order the list from top to bottom
     var markdown = File.ReadAllText(ft.FullPath);
     var parts = MarkupMultiple(host, markdown, ft);
     return parts.Select(part => TransformModel(ft.FullPath, part));
 }
 private void BuildItem(IHostService host, ItemViewModel item, FileModel model)
 {
     item.Summary = Markup(host, item.Summary, model);
     item.Remarks = Markup(host, item.Remarks, model);
     item.Conceptual = Markup(host, item.Conceptual, model);
     if (item.Syntax?.Return?.Description != null)
     {
         item.Syntax.Return.Description = Markup(host, item.Syntax?.Return?.Description, model);
     }
     var parameters = item.Syntax?.Parameters;
     if (parameters != null)
     {
         foreach (var parameter in parameters)
         {
             parameter.Description = Markup(host, parameter.Description, model);
         }
     }
     if (item.Exceptions != null)
     {
         foreach (var exception in item.Exceptions)
         {
             exception.Description = Markup(host, exception.Description, model);
         }
     }
 }
Example #4
0
        /// <summary>
        /// 1. Expand the TOC reference
        /// 2. Resolve homepage
        /// </summary>
        /// <param name="models"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        public override IEnumerable<FileModel> Prebuild(ImmutableList<FileModel> models, IHostService host)
        {
            var tocModelCache = new Dictionary<string, TocItemInfo>();
            foreach (var model in models)
            {
                if (!tocModelCache.ContainsKey(model.OriginalFileAndType.FullPath))
                {
                    tocModelCache[model.OriginalFileAndType.FullPath] = new TocItemInfo(model.OriginalFileAndType, (TocItemViewModel)model.Content);
                }
            }
            var tocResolver = new TocResolver(host, tocModelCache);
            foreach (var key in tocModelCache.Keys.ToList())
            {
                tocModelCache[key] = tocResolver.Resolve(key);
            }

            foreach (var model in models)
            {
                var wrapper = tocModelCache[model.OriginalFileAndType.FullPath];

                // If the TOC file is referenced by other TOC, remove it from the collection
                if (!wrapper.IsReferenceToc)
                {
                    model.Content = wrapper.Content;
                    yield return model;
                }
            }
        }
Example #5
0
        private void BuildCore(TocItemViewModel item, FileModel model, IHostService hostService)
        {
            if (item == null)
            {
                return;
            }

            var linkToUids = new HashSet<string>();
            var linkToFiles = new HashSet<string>();
            if (Utility.IsSupportedRelativeHref(item.Href))
            {
                linkToFiles.Add(ParseFile(item.Href));
            }

            if (Utility.IsSupportedRelativeHref(item.Homepage))
            {
                linkToFiles.Add(ParseFile(item.Homepage));
            }

            if (!string.IsNullOrEmpty(item.TopicUid))
            {
                linkToUids.Add(item.TopicUid);
            }

            model.LinkToUids = model.LinkToUids.Union(linkToUids);
            model.LinkToFiles = model.LinkToFiles.Union(linkToFiles);

            if (item.Items != null)
            {
                foreach (var i in item.Items)
                {
                    BuildCore(i, model, hostService);
                }
            }
        }
Example #6
0
 private void FillCore(PageViewModel model, IHostService host)
 {
     if (model.References == null || model.References.Count == 0)
     {
         return;
     }
     foreach (var r in model.References)
     {
         var m = host.LookupByUid(r.Uid).Find(x => x.Type == DocumentType.Article);
         if (m == null)
         {
             continue;
         }
         var page = (PageViewModel)m.Content;
         var item = page.Items.Find(x => x.Uid == r.Uid);
         if (item == null)
         {
             continue;
         }
         r.Additional["summary"] = item.Summary;
         r.Additional["type"] = item.Type;
         r.Additional["syntax"] = item.Syntax;
         r.Additional["platform"] = item.Platform;
     }
 }
Example #7
0
 private static IEnumerable<YamlHtmlPart> MarkupMultiple(IHostService host, string markdown, FileAndType ft)
 {
     try
     {
         var html = host.Markup(markdown, ft, true);
         var parts = YamlHtmlPart.SplitYamlHtml(html);
         foreach (var part in parts)
         {
             var mr = host.Parse(part.ToMarkupResult(), ft);
             part.Conceptual = mr.Html;
             part.LinkToFiles = mr.LinkToFiles;
             part.LinkToUids = mr.LinkToUids;
             part.YamlHeader = mr.YamlHeader;
             part.FileLinkSources = mr.FileLinkSources;
             part.UidLinkSources = mr.UidLinkSources;
         }
         return parts;
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Fail("Markup failed!");
         var message = $"Markup failed: {ex.Message}.";
         Logger.LogError(message);
         throw new DocumentException(message, ex);
     }
 }
 public NewsletterController(INewsletterService newsletterService, IHostService hostService,
     ITripService tripService)
 {
     _newsletterService = newsletterService;
     _hostService = hostService;
     _tripService = tripService;
 }
Example #9
0
        public ResolutionAgent()
        {
            hostService = new XenClientGuestHostService();

            SystemEvents.UserPreferenceChanging += new UserPreferenceChangingEventHandler(SystemEvents_UserPreferenceChanging);
            SystemEvents.PaletteChanged += new EventHandler(SystemEvents_PaletteChanged);
            SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged);
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);

            try
            {
                updateScreen();
            }
            catch (Exception ex)
            {
                MessageBox.Show("XenStore is unavailable, reboot needed",
                                "OpenXT Resolution Agent",
                                System.Windows.Forms.MessageBoxButtons.OK,
                                System.Windows.Forms.MessageBoxIcon.Information);
                Environment.Exit(0);
            }

            InitializeComponent();
            this.WindowState = FormWindowState.Minimized;
            this.ShowInTaskbar = false;
        }
Example #10
0
 public override void Build(FileModel model, IHostService host)
 {
     switch (model.Type)
     {
         case DocumentType.Article:
             var restApi = (RestApiRootItemViewModel)model.Content;
             BuildItem(host, restApi, model);
             if (restApi.Children != null)
             {
                 foreach (var item in restApi.Children)
                 {
                     BuildItem(host, item, model);
                 }
             }
             if (restApi.Tags != null)
             {
                 foreach (var tag in restApi.Tags)
                 {
                     BuildTag(host, tag, model);
                 }
             }
             break;
         case DocumentType.Overwrite:
             BuildItem(host, model);
             break;
         default:
             throw new NotSupportedException();
     }
 }
Example #11
0
        private void ValidateToc(TocItemViewModel item, FileModel model, IHostService hostService)
        {
            if (!PathUtility.IsRelativePath(item.Href)) return;
            var file = model.File;
            var originalFile = model.OriginalFileAndType.File;
            // Special handle for folder ends with '/'
            FileAndType originalTocFile = null;

            string fileName = Path.GetFileName(item.Href);
            if (string.IsNullOrEmpty(fileName))
            {
                var href = item.Href + "toc.yml";
                var absHref = (RelativePath)file + (RelativePath)href;
                string tocPath = absHref.GetPathFromWorkingFolder();
                if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
                {
                    href = item.Href + "toc.md";
                    absHref = (RelativePath)file + (RelativePath)href;
                    tocPath = absHref.GetPathFromWorkingFolder();
                    if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
                    {
                        var error = $"Unable to find either toc.yml or toc.md inside {item.Href}. Make sure the file is included in config file docfx.json!";
                        Logger.LogError(error, file: model.LocalPathFromRepoRoot);
                        throw new DocumentException(error);
                    }
                }

                Logger.LogInfo($"TOC file {href} inside {item.Href} is used", file: model.LocalPathFromRepoRoot);
                item.Href = href;
                item.OriginalHref = item.Href;
            }

            // Set default homepage
            SetDefaultHomepage(item, originalTocFile, model);
        }
 public IEnumerable<RestApiTagViewModel> GetTagsFromOverwriteDocument(FileModel overwriteModel, string uid, IHostService host)
 {
     return OverwriteDocumentReader.Transform<RestApiTagViewModel>(
         overwriteModel,
         uid,
         s => BuildRestApiDocument.BuildTag(host, s, overwriteModel, content => content != null && content.Trim() == Constants.ContentPlaceholder));
 }
Example #13
0
 protected override void OnStart(string[] args)
 {
     base.OnStart(args);
       var container = new Container();
       host = container.GetInstance<IHostService>();
       host.StartServices();
 }
Example #14
0
        private string _sourceCopyPath; //用于文件复制

        #endregion Fields

        #region Constructors

        public FileManagerControl(IHostService hostService, ShellStruct data)
        {
            InitializeComponent();
            this.Dock = System.Windows.Forms.DockStyle.Fill;
            treeView_Dirs.AfterSelect += treeView_File_AfterSelect;
            listView_File.DragEnter += listView_File_DragEnter;
            listView_File.DragDrop += listView_File_DragDrop;
            listView_File.DoubleClick += listView_File_DoubleClick;
            listView_File.AfterEditSubItem += listView_File_AfterEditSubItem;
            listView_File.EditSubItemCompleted += listView_File_EditSubItemCompleted;
            rightMenu_FileManager.Opening += rightMenu_FileManager_Opening;

            this._hostService = hostService;
            this._shellData = data;

            _fileManager = new FileManagerService(_hostService, _shellData);
            _fileManager.GetWwwRootPathCompletedToDo += fileManager_GetWwwRootPathCompletedToDo;
            _fileManager.DeleteFileOrDirCompletedToDo += fileManager_DeleteFileOrDirCompletedToDo;
            _fileManager.GetFileTreeCompletedToDo += fileManager_GetFileTreeCompletedToDo;
            _fileManager.RenameFileOrDirCompletedToDo += fileManager_RenameFileOrDirCompletedToDo;
            _fileManager.CopyFileOrDirCompletedToDo += fileManager_CopyFileOrDirCompletedToDo;
            _fileManager.ModifyFileOrDirTimeCompletedToDo += fileManager_ModifyFileOrDirTimeCompletedToDo;
            _fileManager.CreateDirCompletedToDo += fileManager_CreateDirCompletedToDo;
            _fileManager.WgetCompletedToDo += fileManager_WgetCompletedToDo;

            //获取根路径
            _fileManager.GetWwwRootPath();
        }
 public IEnumerable<ItemViewModel> GetItemsFromOverwriteDocument(FileModel fileModel, string uid, IHostService host)
 {
     return OverwriteDocumentReader.Transform<ItemViewModel>(
         fileModel,
         uid,
         s => BuildManagedReferenceDocument.BuildItem(host, s, fileModel, content => content != null && content.Trim() == Constants.ContentPlaceholder));
 }
Example #16
0
 private void ApplyOverrides(ImmutableList<FileModel> models, IHostService host)
 {
     foreach (var uid in host.GetAllUids())
     {
         var ms = host.LookupByUid(uid);
         var od = ms.SingleOrDefault(m => m.Type == DocumentType.Override);
         if (od != null)
         {
             var ovm = ((List<ItemViewModel>)od.Content).Single(vm => vm.Uid == uid);
             foreach (
                 var pair in
                     from model in ms
                     where model.Type == DocumentType.Article
                     from item in ((PageViewModel)model.Content).Items
                     where item.Uid == uid
                     select new { model, item })
             {
                 var vm = pair.item;
                 // todo : fix file path
                 Merger.Merge(ref vm, ovm);
                 ((HashSet<string>)pair.model.Properties.LinkToUids).UnionWith((HashSet<string>)od.Properties.LinkToUids);
                 ((HashSet<string>)pair.model.Properties.LinkToFiles).UnionWith((HashSet<string>)od.Properties.LinkToFiles);
             }
         }
     }
 }
Example #17
0
        public override void Build(FileModel model, IHostService host)
        {
            var toc = (TocItemViewModel)model.Content;
            BuildCore(toc, model, host);

            // todo : metadata.
        }
Example #18
0
 public override void Build(FileModel model, IHostService host)
 {
     if (model.Type != DocumentType.Article && model.Type != DocumentType.Resource)
     {
         throw new NotSupportedException();
     }
     // todo : metadata.
 }
Example #19
0
 public override IEnumerable<FileModel> Postbuild(ImmutableList<FileModel> models, IHostService host)
 {
     if (models.Count > 0)
     {
         ApplyOverrides(models, host);
     }
     return models;
 }
Example #20
0
 public VMListController(
     IHostService hostService, 
     IMonitoringService monitoringService, 
     IRememberService rememberService)
 {
     this.hostService = hostService;
     this.monitoringService = monitoringService;
     this.rememberService = rememberService;
 }
Example #21
0
        private void UpdateRelativePathAndAddTocMap(TocViewModel toc, FileModel model, HashSet<string> links, Dictionary<string, HashSet<string>> tocMap, IHostService hostService)
        {
            if (toc == null) return;
            var file = model.File;
            var originalFile = model.OriginalFileAndType.File;
            foreach (var item in toc)
            {
                if (PathUtility.IsRelativePath(item.Href))
                {
                    // Special handle for folder ends with '/'
                    FileAndType originalTocFile = null;

                    string fileName = Path.GetFileName(item.Href);
                    if (string.IsNullOrEmpty(fileName))
                    {
                        var href = item.Href + "toc.yml";
                        var absHref = (RelativePath)file + (RelativePath)href;
                        string tocPath = absHref.GetPathFromWorkingFolder();
                        if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
                        {
                            href = item.Href + "toc.md";
                            absHref = (RelativePath)file + (RelativePath)href;
                            tocPath = absHref.GetPathFromWorkingFolder();
                            if (!hostService.SourceFiles.TryGetValue(tocPath, out originalTocFile))
                            {
                                var error = $"Unable to find either toc.yml or toc.md inside {item.Href}. Make sure the file is included in config file docfx.json!";
                                Logger.LogError(error, file: model.LocalPathFromRepoRoot);
                                throw new DocumentException(error);
                            }
                        }

                        Logger.LogInfo($"TOC file {href} inside {item.Href} is used", file: model.LocalPathFromRepoRoot);
                        item.Href = href;
                        item.OriginalHref = item.Href;
                    }

                    // Add toc.yml to tocMap before change item.Href to home page
                    item.Href = ((RelativePath)file + (RelativePath)item.Href).GetPathFromWorkingFolder();
                    if (item.OriginalHref != null) item.OriginalHref = ((RelativePath)file + (RelativePath)item.OriginalHref).GetPathFromWorkingFolder();

                    HashSet<string> value;
                    if (tocMap.TryGetValue(item.Href, out value))
                    {
                        value.Add(originalFile);
                    }
                    else
                    {
                        tocMap[item.Href] = new HashSet<string>(FilePathComparer.OSPlatformSensitiveComparer) { originalFile };
                    }
                    links.Add(item.Href);

                    SetHomepage(item, originalTocFile, model);
                }

                UpdateRelativePathAndAddTocMap(item.Items, model, links, tocMap, hostService);
            }
        }
Example #22
0
        public MyFirstPlugin(IHostService host, ShellStruct data)
        {
            InitializeComponent();
            this.Dock = System.Windows.Forms.DockStyle.Fill;

            _host = host;
            _shellData = data;

            ShowShellTypeDataInLable(_shellData);
        }
Example #23
0
        public TrayIcon()
        {
            InitializeComponent();
            hostService = Program.GetHostService();
            alertList = Program.GetAlertList();
            initRunOnStartup();

            //Event handlers
            notifyIcon1.BalloonTipClicked += new EventHandler(notifyIcon1_BalloonTipClicked);
        }
Example #24
0
        public ShellCmderControl(IHostService hostService, ShellStruct data)
        {
            InitializeComponent();
            this.Dock = System.Windows.Forms.DockStyle.Fill;
            this._hostService = hostService;
            this._shellData = data;

            shellTextBox_Cmder.CommandEntered+=shellTextBox_Cmder_CommandEntered;
            shellTextBox_Cmder.Prompt = "SECTools";
            ConnectOneShell();
        }
 private static MergeItem CreateMergeItem(string majorUid, FileModel model, IHostService host)
 {
     var vm = (PageViewModel)model.Content;
     var majorItem = vm.Items.Find(item => item.Uid == majorUid);
     if (majorItem == null)
     {
         host.LogError("Cannot find uid in model.", file: model.File);
         return null;
     }
     return CreateMergeItemCore(majorItem, vm);
 }
 private string Markup(IHostService host, string markdown, FileModel model)
 {
     if (string.IsNullOrEmpty(markdown))
     {
         return markdown;
     }
     var mr = host.Markup(markdown, model.FileAndType);
     ((HashSet<string>)model.Properties.LinkToFiles).UnionWith(mr.LinkToFiles);
     ((HashSet<string>)model.Properties.LinkToUids).UnionWith(mr.LinkToUids);
     return mr.Html;
 }
Example #27
0
 public void Build(FileModel model, IHostService host)
 {
     model.File = Path.ChangeExtension(model.File, ".json");
     var toc = (TocViewModel)model.Content;
     HashSet<string> links = new HashSet<string>();
     Dictionary<string, HashSet<string>> tocMap = new Dictionary<string, HashSet<string>>();
     UpdateRelativePathAndAddTocMap(toc, model, links, tocMap, host);
     model.Properties.LinkToFiles = links.ToImmutableArray();
     model.Properties.TocMap = tocMap.ToImmutableDictionary();
     // todo : metadata.
 }
Example #28
0
 public override IEnumerable<FileModel> Postbuild(ImmutableList<FileModel> models, IHostService host)
 {
     foreach (var model in models)
     {
         if (model.Type == DocumentType.Article)
         {
             var content = (Dictionary<string, object>)model.Content;
             content["wordCount"] = WordCounter.CountWord((string)content["conceptual"]);
         }
     }
     return models;
 }
        public override void Build(FileModel model, IHostService host)
        {
            if (model.Type != DocumentType.Article)
            {
                return;
            }
            var content = (Dictionary<string, object>)model.Content;
            var markdown = (string)content[ConceputalKey];
            var result = host.Markup(markdown, model.FileAndType);

            var htmlInfo = SeperateHtml(result.Html);
            content["title"] = htmlInfo.Title;
            content["rawTitle"] = htmlInfo.RawTitle;
            content[ConceputalKey] = htmlInfo.Content;

            if (result.YamlHeader != null && result.YamlHeader.Count > 0)
            {
                foreach (var item in result.YamlHeader)
                {
                    if (item.Key == "uid")
                    {
                        var uid = item.Value as string;
                        if (!string.IsNullOrWhiteSpace(uid))
                        {
                            model.Uids = new[] { uid }.ToImmutableArray();
                            content["uid"] = item.Value;
                        }
                    }
                    else
                    {
                        content[item.Key] = item.Value;
                        if (item.Key == DocumentTypeKey)
                        {
                            model.DocumentType = item.Value as string;
                        }
                    }
                }
            }
            model.Properties.LinkToFiles = result.LinkToFiles;
            model.Properties.LinkToUids = result.LinkToUids;
            model.Properties.XrefSpec = null;
            if (model.Uids.Length > 0)
            {
                model.Properties.XrefSpec = new XRefSpec
                {
                    Uid = model.Uids[0],
                    Name = TitleThumbnail(content["title"].ToString() ?? model.Uids[0], TitleThumbnailMaxLength),
                    Href = ((RelativePath)model.File).GetPathFromWorkingFolder()
                };
            }
            model.File = Path.ChangeExtension(model.File, ".json");
        }
Example #30
0
 public override void Build(FileModel model, IHostService host)
 {
     if (model.Type != DocumentType.Article)
     {
         return;
     }
     if (!host.HasMetadataValidation)
     {
         return;
     }
     host.ValidateInputMetadata(
         model.OriginalFileAndType.File,
         ((Dictionary <string, object>)model.Content).ToImmutableDictionary().Remove(ConceptualKey));
 }
        protected override void BuildArticle(IHostService host, FileModel model)
        {
            var pageViewModel = (PageViewModel)model.Content;

            BuildArticleCore(host, model, shouldSkipMarkup: pageViewModel?.ShouldSkipMarkup ?? false);

            foreach (var r in pageViewModel.References)
            {
                if (r.IsExternal == false)
                {
                    host.ReportDependencyTo(model, r.Uid, DependencyItemSourceType.Uid, DependencyTypeName.Reference);
                }
            }
        }
        private static void BuildItem(IHostService host, FileModel model)
        {
            var file       = model.FileAndType;
            var overwrites = MarkdownReader.ReadMarkdownAsOverwrite(host, model.FileAndType).ToList();

            model.Content     = overwrites;
            model.LinkToFiles = overwrites.SelectMany(o => o.LinkToFiles).ToImmutableHashSet();
            model.LinkToUids  = overwrites.SelectMany(o => o.LinkToUids).ToImmutableHashSet();
            model.Uids        = (from item in overwrites
                                 select new UidDefinition(
                                     item.Uid,
                                     model.LocalPathFromRoot,
                                     item.Documentation.StartLine + 1)).ToImmutableArray();
        }
 public virtual void ReportUidDependency(FileModel model, IHostService host, TocItemViewModel item)
 {
     if (item.TopicUid != null)
     {
         host.ReportDependencyFrom(model, item.TopicUid, DependencyItemSourceType.Uid, DependencyTypeName.Metadata);
     }
     if (item.Items != null && item.Items.Count > 0)
     {
         foreach (var i in item.Items)
         {
             ReportUidDependency(model, host, i);
         }
     }
 }
Example #34
0
        public static ItemViewModel BuildItem(IHostService host, ItemViewModel item, FileModel model, Func <string, bool> filter = null)
        {
            var linkToUids = new HashSet <string>();

            item.Summary    = Markup(host, item.Summary, model, filter);
            item.Remarks    = Markup(host, item.Remarks, model, filter);
            item.Conceptual = Markup(host, item.Conceptual, model, filter);
            linkToUids.UnionWith(item.Inheritance ?? EmptyEnumerable);
            linkToUids.UnionWith(item.InheritedMembers ?? EmptyEnumerable);
            linkToUids.UnionWith(item.Implements ?? EmptyEnumerable);
            linkToUids.UnionWith(item.SeeAlsos?.Select(s => s.Type) ?? EmptyEnumerable);
            linkToUids.UnionWith(item.Sees?.Select(s => s.Type) ?? EmptyEnumerable);

            if (item.Overridden != null)
            {
                linkToUids.Add(item.Overridden);
            }

            if (item.Syntax?.Return != null)
            {
                if (item.Syntax.Return.Description != null)
                {
                    item.Syntax.Return.Description = Markup(host, item.Syntax?.Return?.Description, model, filter);
                }

                linkToUids.Add(item.Syntax.Return.Type);
            }

            var parameters = item.Syntax?.Parameters;

            if (parameters != null)
            {
                foreach (var parameter in parameters)
                {
                    parameter.Description = Markup(host, parameter.Description, model, filter);
                    linkToUids.Add(parameter.Type);
                }
            }
            if (item.Exceptions != null)
            {
                foreach (var exception in item.Exceptions)
                {
                    exception.Description = Markup(host, exception.Description, model, filter);
                    linkToUids.Add(exception.Type);
                }
            }

            ((HashSet <string>)model.Properties.LinkToUids).UnionWith(linkToUids);
            return(item);
        }
Example #35
0
        private void UpdateNearestTocCore(IHostService host, string item, FileModel toc, ConcurrentDictionary <string, RelativeInfo> nearest)
        {
            if (!host.SourceFiles.TryGetValue(item, out var itemSource))
            {
                return;
            }

            var tocInfo = new RelativeInfo(toc, itemSource);

            nearest.AddOrUpdate(
                item,
                k => tocInfo,
                (k, v) => Compare(tocInfo, v) < 0 ? tocInfo : v);
        }
 public void Postbuild(ImmutableList <FileModel> models, IHostService host)
 {
     foreach (var model in models)
     {
         if (Path.GetFileNameWithoutExtension(model.File) == "page1")
         {
             ((dynamic)model.Properties.Metadata).postMeta = "postbuild1";
         }
         else
         {
             ((dynamic)model.Properties.Metadata).postMeta = "postbuild2";
         }
     }
 }
Example #37
0
        public override void Postbuild(ImmutableList <FileModel> models, IHostService host)
        {
            if (TagInterpreters == null)
            {
                return;
            }

            var schemaProcessor = new SchemaProcessor(new TagsInterpreter(TagInterpreters.ToList()));

            foreach (var model in models)
            {
                model.Content = schemaProcessor.Process(model.Content, model.Properties.Schema, new ProcessContext(host, model));
            }
        }
Example #38
0
 private void ReportUidDependency(IHostService host, TocItemViewModel item, FileModel toc)
 {
     if (item.TopicUid != null)
     {
         host.ReportDependencyFrom(toc, item.TopicUid, DependencyItemSourceType.Uid, DependencyTypeName.Metadata);
     }
     if (item.Items != null && item.Items.Count > 0)
     {
         foreach (var i in item.Items)
         {
             ReportUidDependency(host, i, toc);
         }
     }
 }
Example #39
0
        public override void Postbuild(ImmutableList <FileModel> models, IHostService host)
        {
            if (TagInterpreters == null)
            {
                return;
            }

            var schemaProcessor = new SchemaProcessor(new TagsInterpreter(TagInterpreters.ToList()));

            models.Where(s => s.Type == DocumentType.Article).RunAll(model =>
            {
                model.Content = schemaProcessor.Process(model.Content, model.Properties.Schema, new ProcessContext(host, model));
            });
        }
Example #40
0
        internal override void CreateAllStyle()
        {
            Invariant.Assert(App != null, "RootBrowserWindow must be created in an Application");

            IHostService ihs = (IHostService)App.GetService(typeof(IHostService));

            Invariant.Assert(ihs != null, "IHostService in RootBrowserWindow cannot be null");
            Invariant.Assert(ihs.HostWindowHandle != IntPtr.Zero, "IHostService.HostWindowHandle in RootBrowserWindow cannot be null");

            //This sets the _ownerHandle correctly and will be used to create the _sourceWindow
            //with the correct parent
            this.OwnerHandle = ihs.HostWindowHandle;
            this.Win32Style  = NativeMethods.WS_CHILD | NativeMethods.WS_CLIPCHILDREN | NativeMethods.WS_CLIPSIBLINGS;
        }
Example #41
0
 public override void Postbuild(ImmutableList <FileModel> models, IHostService host)
 {
     if (models.Count > 0)
     {
         foreach (var model in models)
         {
             if (model.Type != DocumentType.Article)
             {
                 continue;
             }
             FillCore((PageViewModel)model.Content, host);
         }
     }
 }
Example #42
0
 public override void Postbuild(ImmutableList<FileModel> models, IHostService host)
 {
     if (models.Count > 0)
     {
         foreach (var model in models)
         {
             if (model.Type != DocumentType.Article)
             {
                 continue;
             }
             FillCore((PageViewModel)model.Content, host);
         }
     }
 }
Example #43
0
        protected void ApplyOverwrite <T>(
            IHostService host,
            List <FileModel> overwrites,
            string uid,
            List <FileModel> articles,
            Func <FileModel, string, IHostService, IEnumerable <T> > getItemsFromOverwriteDocument,
            Func <FileModel, string, IHostService, IEnumerable <T> > getItemsToOverwrite)
            where T : class, IOverwriteDocumentViewModel
        {
            // Multiple UID in overwrite documents is allowed now
            var ovms = (from fm in overwrites
                        from content in getItemsFromOverwriteDocument(fm, uid, host)
                        select new
            {
                model = content,
                fileModel = fm
            }).ToList();

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

            // 1. merge all the overwrite document into one overwrite view model
            var ovm = ovms.Skip(1).Aggregate(ovms[0].model, (accum, item) => Merge(accum, item.model, item.fileModel));

            // 2. apply the view model to articles matching the uid
            foreach (
                var pair in
                from model in articles
                from item in getItemsToOverwrite(model, uid, host)
                select new { model, item })
            {
                var vm = pair.item;
                Merge(vm, ovm, ovms[0].fileModel);

                foreach (var overwriteDocumentModel in overwrites.Select(overwrite => GetOverwriteDocumentModelsByUid(overwrite, uid)).SelectMany(o => o))
                {
                    pair.model.LinkToUids      = pair.model.LinkToUids.Union(overwriteDocumentModel.LinkToUids);
                    pair.model.LinkToFiles     = pair.model.LinkToFiles.Union(overwriteDocumentModel.LinkToFiles);
                    pair.model.FileLinkSources = pair.model.FileLinkSources.ToDictionary(i => i.Key, i => i.Value.ToList())
                                                 .Merge(overwriteDocumentModel.FileLinkSources.Select(i => new KeyValuePair <string, IEnumerable <LinkSourceInfo> >(i.Key, i.Value)))
                                                 .ToImmutableDictionary(p => p.Key, p => p.Value.ToImmutableList());
                    pair.model.UidLinkSources = pair.model.UidLinkSources.ToDictionary(i => i.Key, i => i.Value.ToList())
                                                .Merge(overwriteDocumentModel.UidLinkSources.Select(i => new KeyValuePair <string, IEnumerable <LinkSourceInfo> >(i.Key, i.Value)))
                                                .ToImmutableDictionary(p => p.Key, p => p.Value.ToImmutableList());
                }
            }
        }
Example #44
0
        public static RestApiItemViewModelBase BuildItem(IHostService host, RestApiItemViewModelBase item, FileModel model, Func <string, bool> filter = null)
        {
            item.Summary     = Markup(host, item.Summary, model, filter);
            item.Description = Markup(host, item.Description, model, filter);
            if (model.Type != DocumentType.Overwrite)
            {
                item.Conceptual = Markup(host, item.Conceptual, model, filter);
                item.Remarks    = Markup(host, item.Remarks, model, filter);
            }

            var rootModel = item as RestApiRootItemViewModel;

            if (rootModel != null)
            {
                // Mark up recursively for swagger root except for children and tags
                foreach (var jToken in rootModel.Metadata.Values.OfType <JToken>())
                {
                    MarkupRecursive(jToken, host, model, filter);
                }
            }

            var childModel = item as RestApiChildItemViewModel;

            if (childModel?.Parameters != null)
            {
                foreach (var param in childModel.Parameters)
                {
                    param.Description = Markup(host, param.Description, model, filter);

                    foreach (var jToken in param.Metadata.Values.OfType <JToken>())
                    {
                        MarkupRecursive(jToken, host, model, filter);
                    }
                }
            }
            if (childModel?.Responses != null)
            {
                foreach (var response in childModel.Responses)
                {
                    response.Description = Markup(host, response.Description, model, filter);

                    foreach (var jToken in response.Metadata.Values.OfType <JToken>())
                    {
                        MarkupRecursive(jToken, host, model, filter);
                    }
                }
            }
            return(item);
        }
        private static string Markup(IHostService host, string markdown, FileModel model, Func <string, bool> filter = null)
        {
            if (string.IsNullOrEmpty(markdown))
            {
                return(markdown);
            }

            if (filter != null && filter(markdown))
            {
                return(markdown);
            }

            var mr = host.Markup(markdown, model.OriginalFileAndType);

            model.LinkToFiles = model.LinkToFiles.Union(mr.LinkToFiles);
            model.LinkToUids  = model.LinkToUids.Union(mr.LinkToUids);

            var fls = model.FileLinkSources.ToDictionary(p => p.Key, p => p.Value);

            foreach (var pair in mr.FileLinkSources)
            {
                if (fls.TryGetValue(pair.Key, out ImmutableList <LinkSourceInfo> list))
                {
                    fls[pair.Key] = list.AddRange(pair.Value);
                }
                else
                {
                    fls[pair.Key] = pair.Value;
                }
            }
            model.FileLinkSources = fls.ToImmutableDictionary();

            var uls = model.UidLinkSources.ToDictionary(p => p.Key, p => p.Value);

            foreach (var pair in mr.UidLinkSources)
            {
                if (uls.TryGetValue(pair.Key, out ImmutableList <LinkSourceInfo> list))
                {
                    uls[pair.Key] = list.AddRange(pair.Value);
                }
                else
                {
                    uls[pair.Key] = pair.Value;
                }
            }
            model.UidLinkSources = uls.ToImmutableDictionary();

            return(mr.Html);
        }
Example #46
0
        public InputAggregator(
            IHostService host,
            IKeyboardDevice[] keyboards,
            IMouseDevice[] mouses,
            IJoystickDevice[] joysticks)
        {
            m_hostKeyboard = host.Keyboard;
            m_hostMouse    = host.Mouse;
            m_hostJoystick = host.Joystick;

            m_keyboards = keyboards;
            m_mouses    = mouses;
            m_joysticks = joysticks;
            Capture();
        }
Example #47
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     try
     {
         NativeMethods.TimeBeginPeriod(1);
         renderVideo.InitWnd();
         _host = CreateHost();
         OnViewOpened();
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
     }
 }
Example #48
0
        public ResolutionAgent()
        {
            hostService = new XenClientGuestHostService();

            SystemEvents.UserPreferenceChanging += new UserPreferenceChangingEventHandler(SystemEvents_UserPreferenceChanging);
            SystemEvents.PaletteChanged         += new EventHandler(SystemEvents_PaletteChanged);
            SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged);
            SystemEvents.PowerModeChanged       += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);

            updateScreen();

            InitializeComponent();
            this.WindowState   = FormWindowState.Minimized;
            this.ShowInTaskbar = false;
        }
Example #49
0
        protected virtual void ApplyOverwrites(ImmutableList <FileModel> models, IHostService host)
        {
            foreach (var uid in host.GetAllUids())
            {
                var ms       = host.LookupByUid(uid);
                var od       = ms.Where(m => m.Type == DocumentType.Overwrite).ToList();
                var articles = ms.Except(od).ToList();
                if (articles.Count == 0 || od.Count == 0)
                {
                    continue;
                }

                ApplyOverwrite(host, od, uid, articles);
            }
        }
Example #50
0
        private static UserControl CreateGenericScreenControl(BusManager workBus, IHostService host, BusDeviceBase device)
        {
            var control = new CtlSettingsGenericDevice();

            try
            {
                control.Init(workBus, host, device);
                return(control);
            }
            catch
            {
                control.Dispose();
                throw;
            }
        }
        protected virtual void BuildOverwrite(IHostService host, FileModel model)
        {
            var overwrites = MarkdownReader.ReadMarkdownAsOverwrite(host, model.FileAndType).ToList();

            model.Content         = overwrites;
            model.LinkToFiles     = overwrites.SelectMany(o => o.LinkToFiles).ToImmutableHashSet();
            model.LinkToUids      = overwrites.SelectMany(o => o.LinkToUids).ToImmutableHashSet();
            model.FileLinkSources = overwrites.SelectMany(o => o.FileLinkSources).GroupBy(i => i.Key, i => i.Value).ToImmutableDictionary(i => i.Key, i => i.SelectMany(l => l).ToImmutableList());
            model.UidLinkSources  = overwrites.SelectMany(o => o.UidLinkSources).GroupBy(i => i.Key, i => i.Value).ToImmutableDictionary(i => i.Key, i => i.SelectMany(l => l).ToImmutableList());
            model.Uids            = (from item in overwrites
                                     select new UidDefinition(
                                         item.Uid,
                                         model.LocalPathFromRoot,
                                         item.Documentation.StartLine + 1)).ToImmutableArray();
        }
Example #52
0
        public override void Build(FileModel model, IHostService host)
        {
            if (!host.HasMetadataValidation)
            {
                return;
            }
            var metadata = (Dictionary <string, object>)model.Content;

            if (metadata != null)
            {
                host.ValidateInputMetadata(
                    model.OriginalFileAndType.File,
                    metadata.ToImmutableDictionary());
            }
        }
Example #53
0
        private static void BuildItem(IHostService host, FileModel model)
        {
            var file       = model.FileAndType;
            var overwrites = MarkdownReader.ReadMarkdownAsOverwrite(host, model.FileAndType).ToList();

            model.Content               = overwrites;
            model.LinkToFiles           = overwrites.SelectMany(o => o.LinkToFiles).ToImmutableHashSet();
            model.LinkToUids            = overwrites.SelectMany(o => o.LinkToUids).ToImmutableHashSet();
            model.LocalPathFromRepoRoot = overwrites.FirstOrDefault()?.Documentation?.Remote?.RelativePath ?? Path.Combine(file.BaseDir, file.File).ToDisplayPath();
            model.Uids = (from item in overwrites
                          select new UidDefinition(
                              item.Uid,
                              model.LocalPathFromRoot,
                              item.Documentation.StartLine + 1)).ToImmutableArray();
        }
Example #54
0
 protected override void ApplyOverwrite(IHostService host, List <FileModel> overwrites, string uid, List <FileModel> articles)
 {
     if (articles.Any(a => uid == ((RestApiRootItemViewModel)a.Content).Uid))
     {
         ApplyOverwrite(host, overwrites, uid, articles, GetRootItemsFromOverwriteDocument, GetRootItemsToOverwrite);
     }
     else if (articles.Any(a => ((RestApiRootItemViewModel)a.Content).Children.Any(c => uid == c.Uid)))
     {
         ApplyOverwrite(host, overwrites, uid, articles, GetChildItemsFromOverwriteDocument, GetChildItemsToOverwrite);
     }
     else if (articles.Any(a => ((RestApiRootItemViewModel)a.Content).Tags.Any(t => uid == t.Uid)))
     {
         ApplyOverwrite(host, overwrites, uid, articles, GetTagsFromOverwriteDocument, GetTagItemsToOverwrite);
     }
 }
Example #55
0
        public static DockerEnginePlatform GetDockerEnginePlatform()
        {
            IHostService docker = DockerHelper.GetDockerHost();

            if (docker.Host.IsLinuxEngine())
            {
                return(DockerEnginePlatform.Linux);
            }

            if (docker.Host.IsWindowsEngine())
            {
                return(DockerEnginePlatform.Windows);
            }
            throw new Exception("Unknown Engine Type");
        }
Example #56
0
        private void BuildCore(TocItemViewModel item, FileModel model, IHostService hostService, string includedFrom = null)
        {
            if (item == null)
            {
                return;
            }

            var linkToUids      = new HashSet <string>();
            var linkToFiles     = new HashSet <string>();
            var uidLinkSources  = new Dictionary <string, ImmutableList <LinkSourceInfo> >();
            var fileLinkSources = new Dictionary <string, ImmutableList <LinkSourceInfo> >();

            if (Utility.IsSupportedRelativeHref(item.Href))
            {
                UpdateDependencies(linkToFiles, fileLinkSources, item.Href);
            }
            if (Utility.IsSupportedRelativeHref(item.Homepage))
            {
                UpdateDependencies(linkToFiles, fileLinkSources, item.Homepage);
            }
            if (!string.IsNullOrEmpty(item.TopicUid))
            {
                UpdateDependencies(linkToUids, uidLinkSources, item.TopicUid);
            }

            model.LinkToUids      = model.LinkToUids.Union(linkToUids);
            model.LinkToFiles     = model.LinkToFiles.Union(linkToFiles);
            model.UidLinkSources  = model.UidLinkSources.Merge(uidLinkSources);
            model.FileLinkSources = model.FileLinkSources.Merge(fileLinkSources);

            includedFrom = item.IncludedFrom ?? includedFrom;
            if (item.Items != null)
            {
                foreach (var i in item.Items)
                {
                    BuildCore(i, model, hostService, includedFrom);
                }
            }

            void UpdateDependencies(HashSet <string> linkTos, Dictionary <string, ImmutableList <LinkSourceInfo> > linkSources, string link)
            {
                var path   = UriUtility.GetPath(link);
                var anchor = UriUtility.GetFragment(link);

                linkTos.Add(path);
                AddOrUpdate(linkSources, path, GetLinkSourceInfo(path, anchor, model.File, includedFrom));
            }
        }
Example #57
0
        /// <summary>
        /// Executes the reference.
        /// </summary>
        /// <param name="reference">The IAssetReference that will be execute.</param>
        private void ExecuteReference(IAssetReference reference)
        {
            if (reference == null)
            {
                return;
            }

            try
            {
                IHostService host = (IHostService)ServiceHelper.GetService(this, typeof(IHostService));

                bool execute = false;
                if (reference is IBoundAssetReference)
                {
                    IBoundAssetReference boundReferece = reference as IBoundAssetReference;
                    if (boundReferece.Target == null)
                    {
                        // this is a stale bound reference: tell the user and refresh the list of available guidance
                        MessageBox.Show(Properties.Resources.Navigator_StaleReference, Properties.Resources.Navigator_StaleReferenceTitle);
                        // invalidate the cache to remove stale references
                        this.UpdateAvailableGuidance(true);
                        return;
                    }
                    execute = host.SelectTarget(((IBoundAssetReference)reference).Target);
                }
                else if (reference is IUnboundAssetReference)
                {
                    execute = host.SelectTarget(this, (IUnboundAssetReference)reference);
                }

                if (execute)
                {
                    selectedGuidancePackage.TurnOnOutput();
                    reference.Execute();
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), ex);
            }
            finally
            {
                if (selectedGuidancePackage != null)
                {
                    selectedGuidancePackage.TurnOffOutput();
                }
            }
        }
        private void EnsureDockerHost()
        {
            if (Host?.State == ServiceRunningState.Running)
            {
                return;
            }

            var hosts = new Hosts().Discover();

            Host = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");

            if (null != Host)
            {
                if (Host.State != ServiceRunningState.Running)
                {
                    Host.Start();
                    Host.Host.LinuxMode(Host.Certificates);
                }

                return;
            }

            if (hosts.Count > 0)
            {
                Host = hosts.First();
            }

            if (null != Host)
            {
                return;
            }

            if (_createdHost)
            {
                throw new Exception("Failed to initialize the test class, tried to create a docker host but failed");
            }

            var res = "test-machine".Create(1024, 20000, 1);

            Assert.AreEqual(true, res.Success);

            var start = "test-machine".Start();

            Assert.AreEqual(true, start.Success);

            _createdHost = true;
            EnsureDockerHost();
        }
        public override void Build(FileModel model, IHostService host)
        {
            switch (model.Type)
            {
            case DocumentType.Article:
                BuildArticle(host, model);
                break;

            case DocumentType.Overwrite:
                BuildOverwrite(host, model);
                break;

            default:
                throw new NotSupportedException();
            }
        }
 private void CheckMarkdownService(IHostService host)
 {
     if (IsUsingMarkdigMarkdownService == null)
     {
         lock (SyncRoot)
         {
             if (IsUsingMarkdigMarkdownService == null)
             {
                 if (host.MarkdownServiceName != "markdig")
                 {
                     Logger.LogWarning("Markdownfragments depend on Markdig Markdown Engine. To avoid markup result inconsistency, please set `\"markdownEngineName\": \"markdig\"` in docfx.json's build section.");
                 }
             }
         }
     }
 }