/// <summary>
        /// Fires the BioPatML Repository Web service to grab our desire BioPatML pattern.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        public void GetWebPatternDetail(String id, String type)
        {
            #region Code for the blue "Loading" visual effect

            txtLoading.Visibility = System.Windows.Visibility.Visible;
            BlinkLoading.RepeatBehavior = RepeatBehavior.Forever;
            BlinkLoading.Begin();

            DefinitionInfo definition = new DefinitionInfo()
            {
                MainPatternId = id,
                MainPatternType = type
            };
            #endregion Code for the blue "Loading" visual effect

            #region Code for the background worker to invoke our BioPatML repository service
            bw.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                #region Initialize all the essential variables 

                DefinitionInfo target = (DefinitionInfo)args.Argument;
                bool done = false; 
                string result = string.Empty; 
                BioPatMLDataRepo.BioPatMLDataServiceClient repository = new BioPatMLDataServiceClient();
                
                #endregion

                repository.GetPatternDetailInfoCompleted += delegate
                    (object sender, GetPatternDetailInfoCompletedEventArgs e)
                {
                    //When finish retrieving data we assign the BioPatML String to the result variable
                    result = e.Result.ToString();
                    done = true;
                };

                //Fires the web service and pass in a definition which contains the pattern Id and its type
                repository.GetPatternDetailInfoAsync(target);

                while (!done) { System.Threading.Thread.Sleep(2000); };

                repository.CloseAsync(); //close the service
                repository = null; //clean up resources
                args.Result = result;
            };
            #endregion #region Code for the background worker to invoke our BioPatML repository service

            //When worker has finished its job
            //we want him to remake our repository treeview n end all visual effects
            bw.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                ReconstructTreeView(currBioPatMLStr = args.Result.ToString());
                #region End the blinking loading  effect
                txtLoading.Visibility = System.Windows.Visibility.Collapsed;
                BlinkLoading.Stop();
                #endregion
            };

            bw.RunWorkerAsync(definition);
        }
Esempio n. 2
0
        private void HandleMappingWithAllLooseProperties(
            DefinitionInfo mappingDefinition,
            DefinitionInfo keyDefinition,
            DefinitionInfo valueDefinition,
            MappingToken mapping)
        {
            var keys = new HashSet <String>(StringComparer.OrdinalIgnoreCase);

            while (m_unraveler.AllowScalar(mappingDefinition.Expand, out ScalarToken nextKeyScalar))
            {
                // Expression
                if (nextKeyScalar is ExpressionToken)
                {
                    if (nextKeyScalar is BasicExpressionToken)
                    {
                        mapping.Add(nextKeyScalar, Evaluate(valueDefinition));
                    }
                    else
                    {
                        var anyDefinition = new DefinitionInfo(mappingDefinition, TemplateConstants.Any);
                        mapping.Add(nextKeyScalar, Evaluate(anyDefinition));
                    }

                    continue;
                }

                // Not a string
                if (!(nextKeyScalar is StringToken nextKey))
                {
                    nextKey = new StringToken(nextKeyScalar.FileId, nextKeyScalar.Line, nextKeyScalar.Column, nextKeyScalar.ToString());
                }

                // Duplicate
                if (!keys.Add(nextKey.Value))
                {
                    m_context.Error(nextKey, TemplateStrings.ValueAlreadyDefined(nextKey.Value));
                    m_unraveler.SkipMappingValue();
                    continue;
                }

                // Validate
                Validate(nextKey, keyDefinition);

                // Add the pair
                var nextValue = Evaluate(valueDefinition);
                mapping.Add(nextKey, nextValue);
            }

            m_unraveler.ReadMappingEnd();
        }
        private void Validate(
            ref ScalarToken scalar,
            DefinitionInfo definition)
        {
            switch (scalar.Type)
            {
            case TokenType.Null:
            case TokenType.Boolean:
            case TokenType.Number:
            case TokenType.String:
                var literal = scalar as LiteralToken;

                // Legal
                if (definition.Get <ScalarDefinition>().Any(x => x.IsMatch(literal)))
                {
                    return;
                }

                // Not a string, convert
                if (literal.Type != TokenType.String)
                {
                    literal = new StringToken(literal.FileId, literal.Line, literal.Column, literal.ToString());

                    // Legal
                    if (definition.Get <StringDefinition>().Any(x => x.IsMatch(literal)))
                    {
                        scalar = literal;
                        return;
                    }
                }

                // Illegal
                m_context.Error(literal, TemplateStrings.UnexpectedValue(literal));
                break;

            case TokenType.BasicExpression:

                // Illegal
                if (definition.AllowedContext.Length == 0)
                {
                    m_context.Error(scalar, TemplateStrings.ExpressionNotAllowed());
                }

                break;

            default:
                m_context.Error(scalar, TemplateStrings.UnexpectedValue(scalar));
                break;
            }
        }
        public void Should_be_stored_a_created_definition_hash()
        {
            // Arrange
            var sampleInfo = new DefinitionInfo()
            {
                Id = "def01", Text = "def01_text"
            };
            var factory = new DefinitionDocumentFactory(localDataProvider);

            // Act
            var result = factory.CreateDefinitionDocumentFromInfo(localDataProvider.GetSession(), sampleInfo);

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(result.Hash));
        }
        static void GoToDefinition(DefinitionInfo definition)
        {
            if (!definition.HasFileName())
            {
                return;
            }

            var provider = FileService.OpenFile(definition.fileName) as ITextEditorProvider;

            if (provider != null)
            {
                Location location = provider.TextEditor.Document.OffsetToPosition(definition.minChar);
                FileService.JumpToFilePosition(definition.fileName, location.Line, location.Column);
            }
        }
Esempio n. 6
0
        private Package CreatePackage(Request request, DefinitionInfo definitionInfo, DateTime?fakeDate = null)
        {
            var date        = fakeDate ?? DateTime.Now;
            var fakePackage = new Package()
            {
                Date                = date,
                Definitions         = new DefinitionInfo[] { definitionInfo },
                CollectRequests     = new Request[] { request },
                ScheduleInformation = new ScheduleInformation()
                {
                    ScheduleDate = date
                }
            };

            return(fakePackage);
        }
        public void Should_be_possible_to_create_a_definition_document_from_Dto()
        {
            // Arrange
            var sampleInfo = new DefinitionInfo();

            sampleInfo.Id   = "def01";
            sampleInfo.Text = "def01_text";
            var factory = new DefinitionDocumentFactory(localDataProvider);

            // Act
            var definitionDocument = factory.CreateDefinitionDocumentFromInfo(localDataProvider.GetSession(), sampleInfo);

            // Assert
            Assert.IsNotNull(definitionDocument);
            Assert.AreEqual(sampleInfo.Id, definitionDocument.OriginalId);
            Assert.AreEqual(sampleInfo.Text, definitionDocument.Text);
        }
            public DefinitionInfo(
                DefinitionInfo parent,
                String name)
            {
                m_schema = parent.m_schema;

                // Lookup the definition
                Definition = m_schema.GetDefinition(name);

                // Record allowed context
                if (Definition.ReaderContext.Length > 0)
                {
                    AllowedContext = new HashSet <String>(parent.AllowedContext.Concat(Definition.ReaderContext), StringComparer.OrdinalIgnoreCase).ToArray();
                }
                else
                {
                    AllowedContext = parent.AllowedContext;
                }
            }
Esempio n. 9
0
            public DefinitionInfo(
                DefinitionInfo parent,
                String name)
            {
                m_schema = parent.m_schema;

                // Lookup the definition
                Definition = m_schema.GetDefinition(name);

                // Determine whether to expand
                if (Definition.Context.Length > 0)
                {
                    AllowedContext = new HashSet <String>(parent.AllowedContext.Concat(Definition.Context)).ToArray();
                }
                else
                {
                    AllowedContext = parent.AllowedContext;
                }
            }
        public void Should_be_possible_to_load_a_created_definition()
        {
            IDocumentSession fakeSession = localDataProvider.GetSession();

            // Arrange
            var sampleInfo = new DefinitionInfo();

            sampleInfo.Id   = "def01";
            sampleInfo.Text = "def01_text";
            var factory = new DefinitionDocumentFactory(localDataProvider);

            // Act
            factory.CreateDefinitionDocumentFromInfo(fakeSession, sampleInfo);
            var definitionDocument = localDataProvider.GetSession().Query <DefinitionDocument>().Single(x => x.OriginalId == sampleInfo.Id);

            // Assert
            Assert.IsNotNull(definitionDocument);
            Assert.AreEqual(sampleInfo.Id, definitionDocument.OriginalId);
            Assert.AreEqual(sampleInfo.Text, definitionDocument.Text);
        }
        public TypeScriptLanguageItemWindow(TextEditor ed, Gdk.ModifierType modifierState, DefinitionInfo result)
        {
            string tooltip = GetTooltopString (result);
            if (string.IsNullOrEmpty (tooltip)|| tooltip == "?") {
                IsEmpty = true;
                return;
            }

            var label = new MonoDevelop.Components.FixedWidthWrapLabel () {
                Wrap = Pango.WrapMode.WordChar,
                Indent = -20,
                BreakOnCamelCasing = true,
                BreakOnPunctuation = true,
                Markup = tooltip,
            };
            this.BorderWidth = 3;
            Add (label);
            UpdateFont (label);

            EnableTransparencyControl = true;
        }
Esempio n. 12
0
        static void GoToDefinition(DefinitionInfo definition)
        {
            if (!definition.HasFileName())
            {
                return;
            }

            IViewContent view = FileService.OpenFile(definition.fileName);

            if (view == null)
            {
                return;
            }

            ITextEditor textEditor = view.GetService <ITextEditor>();

            if (textEditor != null)
            {
                TextLocation location = textEditor.Document.GetLocation(definition.minChar);
                FileService.JumpToFilePosition(definition.fileName, location.Line, location.Column);
            }
        }
            public DefinitionInfo(
                DefinitionInfo parent,
                String name)
            {
                m_schema           = parent.m_schema;
                m_availableContext = parent.m_availableContext;

                // Lookup the definition
                Definition = m_schema.GetDefinition(name);

                // Determine whether to expand
                if (Definition.Context.Length > 0)
                {
                    m_allowedContext = new HashSet <String>(parent.m_allowedContext.Concat(Definition.Context)).ToArray();
                    Expand           = m_availableContext.IsSupersetOf(m_allowedContext);
                }
                else
                {
                    m_allowedContext = parent.m_allowedContext;
                    Expand           = parent.Expand;
                }
            }
        private void HandleMappingWithWellKnownProperties(
            DefinitionInfo definition,
            List <MappingDefinition> mappingDefinitions,
            MappingToken mapping)
        {
            // Check if loose properties are allowed
            String         looseKeyType         = null;
            String         looseValueType       = null;
            DefinitionInfo?looseKeyDefinition   = null;
            DefinitionInfo?looseValueDefinition = null;

            if (!String.IsNullOrEmpty(mappingDefinitions[0].LooseKeyType))
            {
                looseKeyType   = mappingDefinitions[0].LooseKeyType;
                looseValueType = mappingDefinitions[0].LooseValueType;
            }

            var keys = new HashSet <String>(StringComparer.OrdinalIgnoreCase);

            while (m_unraveler.AllowScalar(definition.Expand, out ScalarToken nextKeyScalar))
            {
                // Expression
                if (nextKeyScalar is ExpressionToken)
                {
                    var anyDefinition = new DefinitionInfo(definition, TemplateConstants.Any);
                    mapping.Add(nextKeyScalar, Evaluate(anyDefinition));
                    continue;
                }

                // Not a string, convert
                if (!(nextKeyScalar is StringToken nextKey))
                {
                    nextKey = new StringToken(nextKeyScalar.FileId, nextKeyScalar.Line, nextKeyScalar.Column, nextKeyScalar.ToString());
                }

                // Duplicate
                if (!keys.Add(nextKey.Value))
                {
                    m_context.Error(nextKey, TemplateStrings.ValueAlreadyDefined(nextKey.Value));
                    m_unraveler.SkipMappingValue();
                    continue;
                }

                // Well known
                if (m_schema.TryMatchKey(mappingDefinitions, nextKey.Value, out String nextValueType))
                {
                    var nextValueDefinition = new DefinitionInfo(definition, nextValueType);
                    var nextValue           = Evaluate(nextValueDefinition);
                    mapping.Add(nextKey, nextValue);
                    continue;
                }

                // Loose
                if (looseKeyType != null)
                {
                    if (looseKeyDefinition == null)
                    {
                        looseKeyDefinition   = new DefinitionInfo(definition, looseKeyType);
                        looseValueDefinition = new DefinitionInfo(definition, looseValueType);
                    }

                    Validate(nextKey, looseKeyDefinition.Value);
                    var nextValue = Evaluate(looseValueDefinition.Value);
                    mapping.Add(nextKey, nextValue);
                    continue;
                }

                // Error
                m_context.Error(nextKey, TemplateStrings.UnexpectedValue(nextKey.Value));
                m_unraveler.SkipMappingValue();
            }

            // Only one
            if (mappingDefinitions.Count > 1)
            {
                var hitCount = new Dictionary <String, Int32>();
                foreach (MappingDefinition mapdef in mappingDefinitions)
                {
                    foreach (String key in mapdef.Properties.Keys)
                    {
                        if (!hitCount.TryGetValue(key, out Int32 value))
                        {
                            hitCount.Add(key, 1);
                        }
                        else
                        {
                            hitCount[key] = value + 1;
                        }
                    }
                }

                List <String> nonDuplicates = new List <String>();
                foreach (String key in hitCount.Keys)
                {
                    if (hitCount[key] == 1)
                    {
                        nonDuplicates.Add(key);
                    }
                }
                nonDuplicates.Sort();

                String listToDeDuplicate = String.Join(", ", nonDuplicates);
                m_context.Error(mapping, TemplateStrings.UnableToDetermineOneOf(listToDeDuplicate));
            }

            m_unraveler.ReadMappingEnd();
        }
        internal static TemplateToken Evaluate(
            TemplateContext context,
            String type,
            TemplateToken template,
            Int32 removeBytes,
            Int32?fileId,
            Boolean omitHeader = false)
        {
            TemplateToken result;

            if (!omitHeader)
            {
                if (fileId != null)
                {
                    context.TraceWriter.Info("{0}", $"Begin evaluating template '{context.GetFileName(fileId.Value)}'");
                }
                else
                {
                    context.TraceWriter.Info("{0}", "Begin evaluating template");
                }
            }

            var evaluator = new TemplateEvaluator(context, template, removeBytes);

            try
            {
                var availableContext = new HashSet <String>(StringComparer.OrdinalIgnoreCase);
                foreach (var key in context.ExpressionValues.Keys)
                {
                    availableContext.Add(key);
                }
                foreach (var function in context.ExpressionFunctions)
                {
                    availableContext.Add($"{function.Name}()");
                }

                var definitionInfo = new DefinitionInfo(context.Schema, type, availableContext);
                result = evaluator.Evaluate(definitionInfo);

                if (result != null)
                {
                    evaluator.m_unraveler.ReadEnd();
                }
            }
            catch (Exception ex)
            {
                context.Error(fileId, null, null, ex);
                result = null;
            }

            if (!omitHeader)
            {
                if (fileId != null)
                {
                    context.TraceWriter.Info("{0}", $"Finished evaluating template '{context.GetFileName(fileId.Value)}'");
                }
                else
                {
                    context.TraceWriter.Info("{0}", "Finished evaluating template");
                }
            }

            return(result);
        }
Esempio n. 16
0
 public void SetRootDefinitions(DefinitionInfo[] definitions)
 {
     this.m_RootDefinitions = definitions;
 }
 string GetTooltopString(DefinitionInfo info)
 {
     return string.Format ("{0} {1} (in {2} {3})",
                           info.Kind,
                           info.Name,
                           info.ContainerKind,
                           info.ContainerName);
 }
Esempio n. 18
0
        private TemplateToken ReadValue(DefinitionInfo definition)
        {
            m_memory.IncrementEvents();

            // Scalar
            if (m_objectReader.AllowLiteral(out LiteralToken literal))
            {
                var scalar = ParseScalar(literal, definition.AllowedContext);
                Validate(ref scalar, definition);
                m_memory.AddBytes(scalar);
                return(scalar);
            }

            // Sequence
            if (m_objectReader.AllowSequenceStart(out SequenceToken sequence))
            {
                m_memory.IncrementDepth();
                m_memory.AddBytes(sequence);

                var sequenceDefinition = definition.Get <SequenceDefinition>().FirstOrDefault();

                // Legal
                if (sequenceDefinition != null)
                {
                    var itemDefinition = new DefinitionInfo(definition, sequenceDefinition.ItemType);

                    // Add each item
                    while (!m_objectReader.AllowSequenceEnd())
                    {
                        var item = ReadValue(itemDefinition);
                        sequence.Add(item);
                    }
                }
                // Illegal
                else
                {
                    // Error
                    m_context.Error(sequence, TemplateStrings.UnexpectedSequenceStart());

                    // Skip each item
                    while (!m_objectReader.AllowSequenceEnd())
                    {
                        SkipValue();
                    }
                }

                m_memory.DecrementDepth();
                return(sequence);
            }

            // Mapping
            if (m_objectReader.AllowMappingStart(out MappingToken mapping))
            {
                m_memory.IncrementDepth();
                m_memory.AddBytes(mapping);

                var mappingDefinitions = definition.Get <MappingDefinition>().ToList();

                // Legal
                if (mappingDefinitions.Count > 0)
                {
                    if (mappingDefinitions.Count > 1 ||
                        m_schema.HasProperties(mappingDefinitions[0]) ||
                        String.IsNullOrEmpty(mappingDefinitions[0].LooseKeyType))
                    {
                        HandleMappingWithWellKnownProperties(definition, mappingDefinitions, mapping);
                    }
                    else
                    {
                        var keyDefinition   = new DefinitionInfo(definition, mappingDefinitions[0].LooseKeyType);
                        var valueDefinition = new DefinitionInfo(definition, mappingDefinitions[0].LooseValueType);
                        HandleMappingWithAllLooseProperties(definition, keyDefinition, valueDefinition, mapping);
                    }
                }
                // Illegal
                else
                {
                    m_context.Error(mapping, TemplateStrings.UnexpectedMappingStart());

                    while (!m_objectReader.AllowMappingEnd())
                    {
                        SkipValue();
                        SkipValue();
                    }
                }

                m_memory.DecrementDepth();
                return(mapping);
            }

            throw new InvalidOperationException(TemplateStrings.ExpectedScalarSequenceOrMapping());
        }
 public String GetPatternDetailInfo(DefinitionInfo def)
 {
     return RepositoryManager.GetPatternXML(def);
 }
Esempio n. 20
0
        public DefinitionDocument CreateDefinitionDocumentFromInfo(IDocumentSession session, DefinitionInfo definitionInfo)
        {
            var definition = new DefinitionDocument();

            // Save properties
            definition.OriginalId = definitionInfo.Id;
            definition.Text       = definitionInfo.Text;

            // Generate document hash
            definition.Hash = Convert.ToBase64String(new System.Security.Cryptography.SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(definition.Text)));

            session.Store(definition);
            session.SaveChanges();

            return(definition);
        }
        private TemplateToken Evaluate(DefinitionInfo definition)
        {
            // Scalar
            if (m_unraveler.AllowScalar(definition.Expand, out ScalarToken scalar))
            {
                if (scalar is LiteralToken literal)
                {
                    Validate(ref literal, definition);
                    return(literal);
                }
                else
                {
                    return(scalar);
                }
            }

            // Sequence start
            if (m_unraveler.AllowSequenceStart(definition.Expand, out SequenceToken sequence))
            {
                var sequenceDefinition = definition.Get <SequenceDefinition>().FirstOrDefault();

                // Legal
                if (sequenceDefinition != null)
                {
                    var itemDefinition = new DefinitionInfo(definition, sequenceDefinition.ItemType);

                    // Add each item
                    while (!m_unraveler.AllowSequenceEnd(definition.Expand))
                    {
                        var item = Evaluate(itemDefinition);
                        sequence.Add(item);
                    }
                }
                // Illegal
                else
                {
                    // Error
                    m_context.Error(sequence, TemplateStrings.UnexpectedSequenceStart());

                    // Skip each item
                    while (!m_unraveler.AllowSequenceEnd(expand: false))
                    {
                        m_unraveler.SkipSequenceItem();
                    }
                }

                return(sequence);
            }

            // Mapping
            if (m_unraveler.AllowMappingStart(definition.Expand, out MappingToken mapping))
            {
                var mappingDefinitions = definition.Get <MappingDefinition>().ToList();

                // Legal
                if (mappingDefinitions.Count > 0)
                {
                    if (mappingDefinitions.Count > 1 ||
                        m_schema.HasProperties(mappingDefinitions[0]) ||
                        String.IsNullOrEmpty(mappingDefinitions[0].LooseKeyType))
                    {
                        HandleMappingWithWellKnownProperties(definition, mappingDefinitions, mapping);
                    }
                    else
                    {
                        var keyDefinition   = new DefinitionInfo(definition, mappingDefinitions[0].LooseKeyType);
                        var valueDefinition = new DefinitionInfo(definition, mappingDefinitions[0].LooseValueType);
                        HandleMappingWithAllLooseProperties(definition, keyDefinition, valueDefinition, mapping);
                    }
                }
                // Illegal
                else
                {
                    m_context.Error(mapping, TemplateStrings.UnexpectedMappingStart());

                    while (!m_unraveler.AllowMappingEnd(expand: false))
                    {
                        m_unraveler.SkipMappingKey();
                        m_unraveler.SkipMappingValue();
                    }
                }

                return(mapping);
            }

            throw new ArgumentException(TemplateStrings.ExpectedScalarSequenceOrMapping());
        }
Esempio n. 22
0
        private void HandleMappingWithWellKnownProperties(
            DefinitionInfo definition,
            List <MappingDefinition> mappingDefinitions,
            MappingToken mapping)
        {
            // Check if loose properties are allowed
            String         looseKeyType         = null;
            String         looseValueType       = null;
            DefinitionInfo?looseKeyDefinition   = null;
            DefinitionInfo?looseValueDefinition = null;

            if (!String.IsNullOrEmpty(mappingDefinitions[0].LooseKeyType))
            {
                looseKeyType   = mappingDefinitions[0].LooseKeyType;
                looseValueType = mappingDefinitions[0].LooseValueType;
            }

            var keys             = new HashSet <String>(StringComparer.OrdinalIgnoreCase);
            var hasExpressionKey = false;

            while (m_objectReader.AllowLiteral(out LiteralToken rawLiteral))
            {
                var nextKeyScalar = ParseScalar(rawLiteral, definition.AllowedContext);
                // Expression
                if (nextKeyScalar is ExpressionToken)
                {
                    hasExpressionKey = true;
                    // Legal
                    if (definition.AllowedContext.Length > 0)
                    {
                        m_memory.AddBytes(nextKeyScalar);
                        var anyDefinition = new DefinitionInfo(definition, TemplateConstants.Any);
                        mapping.Add(nextKeyScalar, ReadValue(anyDefinition));
                    }
                    // Illegal
                    else
                    {
                        m_context.Error(nextKeyScalar, TemplateStrings.ExpressionNotAllowed());
                        SkipValue();
                    }

                    continue;
                }

                // Not a string, convert
                if (!(nextKeyScalar is StringToken nextKey))
                {
                    nextKey = new StringToken(nextKeyScalar.FileId, nextKeyScalar.Line, nextKeyScalar.Column, nextKeyScalar.ToString());
                }

                // Duplicate
                if (!keys.Add(nextKey.Value))
                {
                    m_context.Error(nextKey, TemplateStrings.ValueAlreadyDefined(nextKey.Value));
                    SkipValue();
                    continue;
                }

                // Well known
                if (m_schema.TryMatchKey(mappingDefinitions, nextKey.Value, out String nextValueType))
                {
                    m_memory.AddBytes(nextKey);
                    var nextValueDefinition = new DefinitionInfo(definition, nextValueType);
                    var nextValue           = ReadValue(nextValueDefinition);
                    mapping.Add(nextKey, nextValue);
                    continue;
                }

                // Loose
                if (looseKeyType != null)
                {
                    if (looseKeyDefinition == null)
                    {
                        looseKeyDefinition   = new DefinitionInfo(definition, looseKeyType);
                        looseValueDefinition = new DefinitionInfo(definition, looseValueType);
                    }

                    Validate(nextKey, looseKeyDefinition.Value);
                    m_memory.AddBytes(nextKey);
                    var nextValue = ReadValue(looseValueDefinition.Value);
                    mapping.Add(nextKey, nextValue);
                    continue;
                }

                // Error
                m_context.Error(nextKey, TemplateStrings.UnexpectedValue(nextKey.Value));
                SkipValue();
            }

            // Only one
            if (mappingDefinitions.Count > 1)
            {
                var hitCount = new Dictionary <String, Int32>();
                foreach (MappingDefinition mapdef in mappingDefinitions)
                {
                    foreach (String key in mapdef.Properties.Keys)
                    {
                        if (!hitCount.TryGetValue(key, out Int32 value))
                        {
                            hitCount.Add(key, 1);
                        }
                        else
                        {
                            hitCount[key] = value + 1;
                        }
                    }
                }

                List <String> nonDuplicates = new List <String>();
                foreach (String key in hitCount.Keys)
                {
                    if (hitCount[key] == 1)
                    {
                        nonDuplicates.Add(key);
                    }
                }
                nonDuplicates.Sort();

                String listToDeDuplicate = String.Join(", ", nonDuplicates);
                m_context.Error(mapping, TemplateStrings.UnableToDetermineOneOf(listToDeDuplicate));
            }
            else if (mappingDefinitions.Count == 1 && !hasExpressionKey)
            {
                foreach (var property in mappingDefinitions[0].Properties)
                {
                    if (property.Value.Required)
                    {
                        if (!keys.Contains(property.Key))
                        {
                            m_context.Error(mapping, $"Required property is missing: {property.Key}");
                        }
                    }
                }
            }
            ExpectMappingEnd();
        }