Exemple #1
0
        private List <Models.Type> LoadTypes(string basePath, Namespace ns)
        {
            string             nsFolder = Path.Combine(basePath, ns.Name);
            List <Models.Type> types    = new List <Models.Type>();

            foreach (var typeFile in ListFiles(nsFolder, "*.xml"))
            {
                try
                {
                    var t = LoadType(typeFile);
                    if (t != null)
                    {
                        t.Parent = ns;
                        types.Add(t);
                        if (typeFile.IsVirtual)
                        {
                            FallbackFiles.Add(typeFile.AbsolutePath);
                        }
                    }
                }
                catch (Exception ex)
                {
                    OPSLogger.LogUserError(LogCode.ECMA2Yaml_InternalError, typeFile.AbsolutePath, ex.ToString());
                    _errorFiles.Add(typeFile.AbsolutePath);
                }
            }
            return(types);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var opt = new CommandLineOptions();

            try
            {
                if (opt.Parse(args))
                {
                    if (!string.IsNullOrEmpty(opt.RepoRootPath))
                    {
                        OPSLogger.PathTrimPrefix = opt.RepoRootPath;
                    }
                    if (!opt.SDPMode)
                    {
                        OPSLogger.LogUserError(LogCode.ECMA2Yaml_SDP_MigrationNeeded, ".openpublishing.publish.config.json");
                    }
                    else
                    {
                        LoadAndConvert(opt);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                OPSLogger.LogSystemError(LogCode.ECMA2Yaml_InternalError, null, ex.ToString());
            }
            finally
            {
                OPSLogger.Flush(opt.LogFilePath);
            }
        }
        public static void WriteCustomContentIfAny(string uid, Docs docs, string folder)
        {
            List <string> blocks = new List <string>();

            if (!string.IsNullOrEmpty(docs.ThreadSafety))
            {
                blocks.Add(GenerateOverwriteBlockForMarkup(uid, OPSMetadata.ThreadSafety, docs.ThreadSafety.TrimEnd()));
            }

            string fileName = null;

            if (blocks.Count > 0)
            {
                try
                {
                    fileName = Path.Combine(folder, TruncateUid(uid.Replace("*", "_")) + ".misc.md");
                    File.WriteAllLines(fileName, blocks);
                }
                catch (Exception ex)
                {
                    OPSLogger.LogUserError(LogCode.ECMA2Yaml_OverwriteMDFile_SaveFailed, null, $"{uid}: {ex}");
                    return;
                }
            }
        }
Exemple #4
0
        static Dictionary <string, Dictionary <string, object> > LoadFile(string path)
        {
            var rval    = new Dictionary <string, Dictionary <string, object> >();
            var text    = File.ReadAllText(path);
            var matches = YamlHeaderRegex.Matches(text);

            if (matches != null && matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    using (StringReader reader = new StringReader(match.Groups[1].Value))
                    {
                        Dictionary <string, object> result = null;
                        try
                        {
                            result = YamlUtility.Deserialize <Dictionary <string, object> >(reader);
                        }
                        catch (Exception ex)
                        {
                            OPSLogger.LogUserError(LogCode.ECMA2Yaml_YamlHeader_ParseFailed_WithException, path, ex);
                        }
                        if (result == null)
                        {
                            OPSLogger.LogUserError(LogCode.ECMA2Yaml_YamlHeader_ParseFailed, path, match.Value);
                        }
                        else if (!result.ContainsKey("uid"))
                        {
                            OPSLogger.LogUserError(LogCode.ECMA2Yaml_YamlHeader_ParseFailed, path, match.Value);
                        }
                        else
                        {
                            var uid = result["uid"].ToString();
                            result.Remove("uid");
                            if (rval.ContainsKey(uid))
                            {
                                OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_Uid_Duplicated, path, uid);
                            }
                            else
                            {
                                rval[uid] = result;
                            }
                        }
                    }
                }
            }

            return(rval);
        }
Exemple #5
0
        private PackageInformationMapping LoadPackageInformationMapping(string folder)
        {
            var pkgInfoDir     = Path.Combine(folder, "PackageInformation");
            var pkgInfoMapping = new PackageInformationMapping();

            foreach (var file in ListFiles(pkgInfoDir, "*.json"))
            {
                try
                {
                    var mapping = JsonConvert.DeserializeObject <PackageInformationMapping>(_fileAccessor.ReadAllText(file.AbsolutePath));
                    pkgInfoMapping.Merge(mapping);
                }
                catch (Exception ex)
                {
                    OPSLogger.LogUserError(LogCode.ECMA2Yaml_PackageInformation_LoadFailed, file.AbsolutePath, ex);
                }
            }
            return(pkgInfoMapping);
        }
        public static void WriteOverload(Member overload, string folder)
        {
            var model = new Overload
            {
                Uid = overload.Uid
            };

            if (!string.IsNullOrEmpty(overload.Docs.Summary))
            {
                model.Summary = overload.Docs.Summary;
            }
            if (!string.IsNullOrEmpty(overload.Docs.Remarks))
            {
                model.Remarks = overload.Docs.Remarks;
            }
            if (!string.IsNullOrEmpty(overload.Docs.Examples))
            {
                model.Examples = new List <string> {
                    overload.Docs.Examples
                };
            }
            var fileContent = GenerateOverwriteBlock(model);

            string fileName = null;

            try
            {
                fileName = Path.Combine(folder, TruncateUid(overload.Uid.Replace("*", "_")) + ".md");
                File.WriteAllText(fileName, fileContent);
            }
            catch (Exception ex)
            {
                OPSLogger.LogUserError(LogCode.ECMA2Yaml_OverloadMDFile_SaveFailed, null, $"{overload.Uid}: {ex}");
                return;
            }
        }
Exemple #7
0
        public ECMAStore LoadFolder(string sourcePath, bool isUWPMode = false)
        {
            //if (!System.IO.Directory.Exists(sourcePath))
            //{
            //    OPSLogger.LogUserWarning(string.Format("Source folder does not exist: {0}", sourcePath));
            //    return null;
            //}

            var filterStore      = LoadFilters(sourcePath);
            var typeMappingStore = LoadTypeMap(sourcePath);
            var pkgInfoMapping   = LoadPackageInformationMapping(sourcePath);

            ConcurrentBag <Namespace> namespaces = new ConcurrentBag <Namespace>();
            ParallelOptions           opt        = new ParallelOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            };

            //foreach(var nsFile in ListFiles(sourcePath, "ns-*.xml"))
            Parallel.ForEach(ListFiles(sourcePath, "ns-*.xml"), opt, nsFile =>
            {
                var ns = LoadNamespace(sourcePath, nsFile);
                if (ns == null)
                {
                    OPSLogger.LogUserError(LogCode.ECMA2Yaml_Namespace_LoadFailed, nsFile.AbsolutePath);
                }
                else if (ns.Types == null)
                {
                    OPSLogger.LogUserWarning(LogCode.ECMA2Yaml_Namespace_NoTypes, nsFile.AbsolutePath);
                }
                else
                {
                    namespaces.Add(ns);
                    if (nsFile.IsVirtual)
                    {
                        FallbackFiles.Add(nsFile.AbsolutePath);
                    }
                }
            });

            if (namespaces.Count == 0)
            {
                return(null);
            }

            if (_errorFiles.Count > 0)
            {
                OPSLogger.LogUserError(LogCode.ECMA2Yaml_File_LoadFailed, null, _errorFiles.Count);
                return(null);
            }

            var frameworks = LoadFrameworks(sourcePath);

            if (frameworks == null || frameworks.DocIdToFrameworkDict.Count == 0)
            {
                OPSLogger.LogUserError(LogCode.ECMA2Yaml_Framework_NotFound, null, "any API, please check your FrameworkIndex folder");
                return(null);
            }

            var filteredNS = Filter(namespaces, filterStore, frameworks);
            var store      = new ECMAStore(filteredNS.OrderBy(ns => ns.Name).ToArray(), frameworks)
            {
                FilterStore      = filterStore,
                TypeMappingStore = isUWPMode ? typeMappingStore : null,
                PkgInfoMapping   = pkgInfoMapping,
                UWPMode          = isUWPMode
            };

            return(store);
        }
Exemple #8
0
 private void PrintUsage()
 {
     OPSLogger.LogUserError(LogCode.ECMA2Yaml_Command_Invalid, null);
     Console.WriteLine("Usage: ECMA2Yaml.exe <Options>");
     _options.WriteOptionDescriptions(Console.Out);
 }