Example #1
0
        /// <summary>
        /// Checks whether extension is available and enabled for a given language definition.
        /// </summary>
        /// <param name="languageSet">Language reference.</param>
        /// <param name="extension">Extension.</param>
        /// <returns>Extension availability status.</returns>
        public bool IsValidExtension(LanguageSettings languageSet, string extension)
        {
            if (languageSet == null)
            {
                throw new ArgumentNullException(nameof(languageSet));
            }

            if (string.IsNullOrEmpty(extension))
            {
                return(false);
            }

            if (extension.StartsWith(".", StringComparison.OrdinalIgnoreCase))
            {
                extension = extension.Substring(1, extension.Length - 1);
            }

            var extensions = languageSet.Extensions;

            if (extensions.ContainsKey(extension))
            {
                return(extensions[extension]);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Returns all registered languages.
        /// </summary>
        /// <returns>Languages.</returns>
        public ICollection <LanguageSettings> GetLanguages()
        {
            List <LanguageSettings> languages = new List <LanguageSettings>(10);

            RegistryKey dpackKey;

            try
            {
                dpackKey = _packageService.GetAppRegistryRootKey(LANGUAGES_KEY);
            }
            catch
            {
                dpackKey = null;
            }
            if (dpackKey == null)
            {
                throw new ApplicationException(
                          $"Language definitions registry key {LANGUAGES_KEY} is missing. {_packageService.ProductName} must be re-installed.");
            }

            using (dpackKey)
            {
                var languageKeys = dpackKey.GetSubKeyNames();

                for (var index = 0; index < languageKeys.Length; index++)
                {
                    var id = languageKeys[index];

                    var friendlyName        = string.Empty;
                    var webName             = string.Empty;
                    var webLanguage         = string.Empty;
                    var smartFormat         = true;
                    var xmlDoc              = (string)null;
                    var xmlDocSurround      = false;
                    var ignoreCodeType      = false;
                    var checkDuplicateNames = false;
                    var parentlessFullName  = false;
                    var designerFiles       = LanguageDesignerFiles.NotSupported;
                    var imports             = LanguageImports.NotSupported;
                    var surroundWith        = false;

                    var langKey = dpackKey.OpenSubKey(id);
                    if (langKey != null)
                    {
                        using (langKey)
                        {
                            friendlyName = (string)langKey.GetValue(string.Empty, friendlyName);
                            webName      = (string)langKey.GetValue(WEB_NAME_VALUE, webName);
                            webLanguage  = (string)langKey.GetValue(WEB_LANGUAGE_VALUE, webLanguage);
                            smartFormat  = Convert.ToBoolean(
                                (int)langKey.GetValue(SMART_FORMAT_VALUE, Convert.ToInt32(smartFormat)));
                            xmlDoc         = (string)langKey.GetValue(XML_DOC, xmlDoc);
                            xmlDocSurround = Convert.ToBoolean(
                                (int)langKey.GetValue(XML_DOC_SURROUND, Convert.ToInt32(xmlDocSurround)));
                            designerFiles  = (LanguageDesignerFiles)langKey.GetValue(DESIGNER_FILES, (int)designerFiles);
                            imports        = (LanguageImports)langKey.GetValue(IMPORTS, (int)imports);
                            ignoreCodeType = Convert.ToBoolean(
                                (int)langKey.GetValue(IGNORE_CODE_TYPE, Convert.ToInt32(ignoreCodeType)));
                            checkDuplicateNames = Convert.ToBoolean(
                                (int)langKey.GetValue(CHECK_DUPLICATE_NAMES, Convert.ToInt32(checkDuplicateNames)));
                            parentlessFullName = Convert.ToBoolean(
                                (int)langKey.GetValue(PARENTLESS_FULL_NAME, Convert.ToInt32(parentlessFullName)));
                            surroundWith = Convert.ToBoolean(
                                (int)langKey.GetValue(SURROUND_WITH_NAME, Convert.ToInt32(surroundWith)));
                        }
                    }
                    if (string.IsNullOrEmpty(friendlyName))
                    {
                        _log.LogMessage($"Skipped language {id} definition w/o a friendly name");
                        continue;
                    }
                    var webNames = !string.IsNullOrEmpty(webName) ? webName.Split(',') : new string[0];

                    var language = new LanguageSettings(id, friendlyName, xmlDoc)
                    {
                        WebNames            = webNames,
                        WebLanguage         = webLanguage,
                        SmartFormat         = smartFormat,
                        XmlDocSurround      = xmlDocSurround,
                        DesignerFiles       = designerFiles,
                        Imports             = imports,
                        IgnoreCodeType      = ignoreCodeType,
                        CheckDuplicateNames = checkDuplicateNames,
                        ParentlessFullName  = parentlessFullName,
                        SurroundWith        = surroundWith
                    };

                    var extKey = dpackKey.OpenSubKey(id + "\\" + EXTENSIONS_KEY);
                    if (extKey != null)
                    {
                        using (extKey)
                        {
                            var extensions = extKey.GetValueNames();
                            for (int extIndex = 0; extIndex < extensions.Length; extIndex++)
                            {
                                var ext = extensions[extIndex];

                                var enabled = Convert.ToBoolean((int)extKey.GetValue(ext, 1));
                                language.Extensions.Add(ext, enabled);
                            }
                        }
                    }

                    var commentKey = dpackKey.OpenSubKey(id + "\\" + COMMENTS_KEY);
                    if (commentKey != null)
                    {
                        using (commentKey)
                        {
                            var comments = commentKey.GetValueNames();
                            for (int commentIndex = 0; commentIndex < comments.Length; commentIndex++)
                            {
                                var comment = comments[commentIndex];

                                var enabled = Convert.ToBoolean((int)commentKey.GetValue(comment, 1));
                                language.Comments.Add(comment, enabled);
                            }
                        }
                    }

                    languages.Add(language);
                }         // for (index)
            }             // using

            return(languages);
        }