/// <summary>
 /// Adds the argument to the collection of arguments on this instance.
 /// </summary>
 /// <param name="child">The child.</param>
 public override void AddChild(IDocumentPart child)
 {
     if (child is QueryInputArgument qa)
     {
         this.AddArgument(qa);
     }
     else
     {
         base.AddChild(child);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Adds the argument to the collection of arguments on this instance.
 /// </summary>
 /// <param name="child">The child.</param>
 public override void AddChild(IDocumentPart child)
 {
     if (child is QueryInputValue qiv)
     {
         this.ListItems.Add(qiv);
         qiv.AssignParent(this.OwnerArgument);
         qiv.OwnerValue = this;
     }
     else
     {
         base.AddChild(child);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Adds the new context item to the current instance. If an item of the given type already exists on
        /// this context, it is replaced with this new item. When a null vaue is supplied for either the key
        /// or the item it is automatically skipped.
        /// </summary>
        /// <param name="item">The item in question.</param>
        /// <param name="keyAsType">The specific type to use as the key type for the item.</param>
        protected void AddOrUpdateContextItem(IDocumentPart item, Type keyAsType)
        {
            if (item == null || keyAsType == null)
            {
                return;
            }

            if (_itemType == keyAsType)
            {
                throw new ArgumentException($"The active '{keyAsType.FriendlyName()}' cannot be changed.");
            }

            if (this.ContextItems.ContainsKey(keyAsType))
            {
                this.ContextItems.Remove(keyAsType);
            }

            this.ContextItems.Add(keyAsType, item);
        }
Esempio n. 4
0
        private ILocalizationUnit Parse(IDocumentPart part)
        {
            var headers = part as HeaderCollection;
            var unit    = part as Unit;

            if (headers != null)
            {
                var metadata = new LocalizationMetadata();
                foreach (var header in headers)
                {
                    metadata.Add(header.Name, header.Value);
                }
                return(metadata);
            }
            else if (unit != null)
            {
                return(ParsePoMessageUnit(unit));
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Adds the argument to the collection of arguments on this instance.
 /// </summary>
 /// <param name="child">The child.</param>
 public virtual void AddChild(IDocumentPart child)
 {
     throw new InvalidOperationException($"{this.GetType().FriendlyName()} cannot contain children of type '{child?.GetType()}'");
 }
Esempio n. 6
0
 /// <summary>
 /// Adds the new context item to the current instance. If an item of the given type already exists on
 /// this context, it is replaced with this new item. When a null vaue is supplied it is automatically
 /// skipped.
 /// </summary>
 /// <param name="item">The item in question.</param>
 protected void AddOrUpdateContextItem(IDocumentPart item)
 {
     this.AddOrUpdateContextItem(item, item?.GetType());
 }
 public void Add(IDocumentPart documentPart)
 {
     _documentParts.Add(documentPart);
     Console.WriteLine("Added part " + documentPart.GetPartType());
 }
Esempio n. 8
0
 /// <summary>
 /// Adds the argument to the collection of arguments on this instance.
 /// </summary>
 /// <param name="child">The child.</param>
 public override void AddChild(IDocumentPart child)
 {
     throw new InvalidOperationException($"{nameof(QueryEnumInputValue)} cannot contain children of type '{child?.GetType()}'");
 }
Esempio n. 9
0
        private ILocalizationUnit Parse(IDocumentPart part)
        {
            var headers = part as HeaderCollection;
            var unit = part as Unit;

            if (headers != null) {
                var metadata = new LocalizationMetadata ();
                foreach (var header in headers) {
                    metadata.Add (header.Name, header.Value);
                }
                return metadata;
            } else if (unit != null) {
                return ParsePoMessageUnit (unit);
            } else {
                return null;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds a new document part to this context, inserting where appropriate and updating the
        /// doc scope as necessary.
        /// </summary>
        /// <param name="docPart">The document part to add to this context.</param>
        public void AddDocumentPart(IDocumentPart docPart)
        {
            switch (docPart)
            {
            case QueryOperation qo:
                this.AddOrUpdateContextItem(qo);
                this.BeginNewOperation(qo);
                _activePart = qo;
                break;

            case QueryVariable qv:
                this.AddOrUpdateContextItem(qv);
                var variables = _operation?.CreateVariableCollection();
                variables?.AddVariable(qv);
                _activePart = qv;
                break;

            case QueryFragment qf:
                this.AddOrUpdateContextItem(qf);
                this.BeginNewDocumentScope();
                break;

            case FieldSelection fs:
                this.AddOrUpdateContextItem(fs);
                _selectionSet.AddFieldSelection(fs);
                this.DocumentScope = new DocumentScope(this.DocumentScope, fs);
                _activePart        = fs;
                break;

            case QueryDirective qd:
                // directives never alter the current scope, they just work within it
                this.AddOrUpdateContextItem(qd);
                this.DocumentScope.InsertDirective(qd);
                _activePart = qd;
                break;

            case QueryInputArgument qa:
                if (_activePart is IQueryArgumentContainerDocumentPart argContainer)
                {
                    argContainer.AddArgument(qa);
                }

                // query arguments never retain parent scopes; they are considered independent
                this.AddOrUpdateContextItem(qa);
                this.DocumentScope = new DocumentScope(part: qa);
                _activePart        = qa;
                break;

            case QueryInputValue qiv:
                if (_activePart is IInputValueDocumentPart qia)
                {
                    qia.AssignValue(qiv);
                }
                else if (_activePart is QueryInputValue partQiv)
                {
                    partQiv.AddChild(qiv);
                }

                this.AddOrUpdateContextItem(qiv, typeof(QueryInputValue));
                _activePart = qiv;
                break;

            default:
                this.Messages.Critical(
                    $"Unrecognized document element or position. The document element at the current position " +
                    "could not be processed and the query was terminated. Double check your document and try again.",
                    Constants.ErrorCodes.INVALID_DOCUMENT,
                    this.ActiveNode.Location.AsOrigin());
                break;
            }
        }
Esempio n. 11
0
 public void Add(IDocumentPart documentPart)
 {
     _parts.Add(documentPart);
 }