Пример #1
0
        private static void GetTagsDictionary()
        {
            var path = Settings.Default.SavePath + Settings.Default.KnownTagsFileName + ".txt";

            if (!File.Exists(path))
            {
                return;
            }

            var lines = File.ReadAllLines(path);

            foreach (var line in lines)
            {
                var x = line.Split(";");

                if (x.Length < 2)
                {
                    continue;
                }

                var key = x[0].Normalize(NormalizationForm.FormKC).ToUpper();

                if (KnownTags.ContainsKey(key))
                {
                    continue;
                }

                KnownTags.Add(key, x[1]);
            }
        }
Пример #2
0
        public void RegisterMetadata(string key, Value value, Item context)
        {
            if (CheckingStyle == JournalCheckingStyleEnum.CHECK_WARNING || CheckingStyle == JournalCheckingStyleEnum.CHECK_ERROR)
            {
                if (!KnownTags.Contains(key))
                {
                    if (context == null)
                    {
                        if (ForceChecking)
                        {
                            FixedMetadata = true;
                        }
                        KnownTags.Add(key);
                    }
                    else if (!FixedMetadata && context != null && context.State != ItemStateEnum.Uncleared)
                    {
                        KnownTags.Add(key);
                    }
                    else if (CheckingStyle == JournalCheckingStyleEnum.CHECK_WARNING)
                    {
                        CurrentContext.Warning(String.Format("Unknown metadata tag '{0}'", key));
                    }
                    else if (CheckingStyle == JournalCheckingStyleEnum.CHECK_ERROR)
                    {
                        throw new ParseError(String.Format("Unknown metadata tag '{0}'", key));
                    }
                }
            }

            if (!Value.IsNullOrEmpty(value))
            {
                foreach (CheckExprPair pair in TagCheckExprsMap.GetValues(key))
                {
                    BindScope  boundScope = new BindScope(CurrentContext.Scope, context);
                    ValueScope valScope   = new ValueScope(boundScope, value);

                    if (!pair.Expr.Calc(valScope).AsBoolean)
                    {
                        if (pair.CheckExprKind == CheckExprKindEnum.EXPR_ASSERTION)
                        {
                            throw new ParseError(String.Format(ParseError.ParseError_MetadataAssertionFailedFor, key, value, pair.Expr));
                        }
                        else
                        {
                            CurrentContext.Warning(String.Format(ParseError.ParseError_MetadataCheckFailedFor, key, value, pair.Expr));
                        }
                    }
                }
            }
        }