示例#1
0
        protected void AddContext(PipelineContext context)
        {
            context.CreateOperations();
            var defaultPipeline = context.GetDefaultPipeline();
            var operationList   = new IUpdateOperation[0];

            defaultPipeline.GetRunSystems(ref operationList);
            var fixedUpdateOperations = operationList.Where(q => q is IFixedUpdateOperation).ToArray();

            if (fixedUpdateOperations.Length > 0)
            {
                _fixedUpdatePipelines.Add(new CustomPipeline(context, context.CreateOperations("FixedUpdate", fixedUpdateOperations)));
            }

            var lateUpdateOperations = operationList.Where(q => q is ILateUpdateOperation).ToArray();

            if (lateUpdateOperations.Length > 0)
            {
                _lateUpdatePipelines.Add(new CustomPipeline(context, context.CreateOperations("LateUpdate", lateUpdateOperations)));
            }

            defaultPipeline.RemoveRunSystems(fixedUpdateOperations.Concat(lateUpdateOperations).ToArray());
            _defaultPipelines.Add(new CustomPipeline(context, defaultPipeline));

            _contexts.Add(context);
        }
 private IQueryable <TEntity> ApplyOperation(IUpdateOperation <TEntity> update)
 {
     return(_appDbContext
            .Set <TEntity>()
            .Where(update.Criteria)
            .OrderBys(update.SortingInstructions)
            .AsTracking());
 }
示例#3
0
 public IUpdateResponse UpdateDocuments(IUpdateOperation operation)
 {
     if (Authorize(operation, false))
     {
         return(_nodeContext.TopologyImpl.UpdateDocuments(operation));
     }
     return(null);
 }
示例#4
0
        public IUpdateResponse UpdateDocuments(IUpdateOperation operation)
        {
            DatabaseExists(operation.Database);

            IStore database = _databases[operation.Database];

            return(database.UpdateDocuments(operation));
        }
示例#5
0
 /// <summary>
 /// Gets all run systems.
 /// </summary>
 /// <param name="list">List to put results in it. If null - will be created.</param>
 /// <returns>Amount of systems in list.</returns>
 public int GetRunSystems(ref IUpdateOperation[] list)
 {
     if (list == null || list.Length < _runSystemsCount)
     {
         list = new IUpdateOperation[_runSystemsCount];
     }
     Array.Copy(_runSystems, 0, list, 0, _runSystemsCount);
     return(_runSystemsCount);
 }
        public async Task UpdateOneAsync(IUpdateOperation <TEntity> update)
        {
            var entity = await ApplyOperation(update).FirstOrDefaultAsync();

            update.Mutation(entity);

            await _appDbContext.SaveChangesAsync();

            update.UpdatedIds = new[] { entity.Id };
        }
        public async Task UpdateManyAsync(IUpdateOperation <TEntity> update)
        {
            var entities = await ApplyOperation(update).ToListAsync();

            foreach (var entity in entities)
            {
                update.Mutation(entity);
            }

            await _appDbContext.SaveChangesAsync();

            update.UpdatedIds = entities.Select(x => x.Id);
        }
示例#8
0
        /// <summary>
        /// Parses the values of <see cref="InnerXml"/>, <see cref="Value"/> and <see cref="Attribute"/> into <see cref="IUpdateOperation"/>s.
        /// </summary>
        protected IUpdateOperation[] GetOperations()
        {
            if (!IsNullOrEmpty(InnerXml))
            {
                var ops = new IUpdateOperation[InnerXml.Length];
                for (int n = 0; n < InnerXml.Length; n++)
                {
                    ops[n] = new SetInnerXmlOperation(InnerXml[n], UseEmptyTag);
                }
                return(ops);
            }
            else if (!IsNullOrEmpty(Value))
            {
                var ops = new IUpdateOperation[Value.Length];
                if (!IsNullOrEmpty(Attribute))
                {
                    if (Attribute.Length > 1 && Attribute.Length != Value.Length)
                    {
                        throw new ArgumentException("Attribute must have only 1 item or be in 1:1 correspondance with Value");
                    }

                    var namespaceUri = !IsNullOrEmpty(AttributeNamespace) ? AttributeNamespace : new[] { "" };
                    if (namespaceUri.Length > 1 && namespaceUri.Length != Attribute.Length)
                    {
                        throw new ArgumentException("AttributeNamespace must have only 1 item or be in 1:1 correspondance with Attribute");
                    }

                    for (int n = 0; n < Value.Length; n++)
                    {
                        ops[n] = new SetAttributeOperation(Value[n], Attribute.Length == 1 ? Attribute[0] : Attribute[n], namespaceUri.Length == 1 ? namespaceUri[0] : namespaceUri[n]);
                    }
                }
                else
                {
                    for (int n = 0; n < Value.Length; n++)
                    {
                        ops[n] = new SetValueOperation(Value[n], UseEmptyTag);
                    }
                }
                return(ops);
            }
            else
            {
                return(new[] { new SetValueOperation(string.Empty, UseEmptyTag) });
            }
        }
示例#9
0
        public int RemoveRunSystems(IUpdateOperation[] list)
        {
            var tempRunSystem = new IUpdateOperation[16];
            var tempRunCount  = 0;

            for (var i = 0; i < _runSystemsCount; i++)
            {
                bool foundOperation = false;
                for (var j = 0; j < list.Length; j++)
                {
                    if (_runSystems[i].GetType() == list[j].GetType())
                    {
                        foundOperation = true;
                        break;
                    }
                }
                if (!foundOperation)
                {
                    if (tempRunCount == tempRunSystem.Length)
                    {
                        Array.Resize(ref tempRunSystem, tempRunCount << 1);
                    }
                    tempRunSystem[tempRunCount++] = _runSystems[i];
                }
            }
            for (var i = _runSystemsCount - 1; i >= 0; i--)
            {
                _runSystems[i] = null;
            }
            _runSystemsCount = 0;

            for (var i = 0; i < tempRunCount; i++)
            {
                Add(tempRunSystem[i]);
            }

            return(_runSystemsCount);
        }
示例#10
0
        /// <summary>
        /// Creates, updates and inserts a node.
        /// </summary>
        private void InsertNode(XmlNode anchor, IUpdateOperation updateOperation)
        {
            // create node according to type
            XmlNode newXmlNode;

            switch (GetNodeType())
            {
            case XmlNodeType.Attribute:
                newXmlNode = XmlDocument.CreateAttribute(Name, Namespace ?? string.Empty);
                break;

            case XmlNodeType.Element:
                newXmlNode = XmlDocument.CreateElement(Name, Namespace ?? string.Empty);
                break;

            case XmlNodeType.CData:
                newXmlNode = XmlDocument.CreateCDataSection(string.Empty);
                break;

            case XmlNodeType.Comment:
                newXmlNode = XmlDocument.CreateComment(string.Empty);
                break;

            case XmlNodeType.SignificantWhitespace:
                newXmlNode = XmlDocument.CreateSignificantWhitespace(string.Empty);
                break;

            case XmlNodeType.Text:
                newXmlNode = XmlDocument.CreateTextNode(string.Empty);
                break;

            case XmlNodeType.Whitespace:
                newXmlNode = XmlDocument.CreateWhitespace(string.Empty);
                break;

            default:
                // should not happen
                throw new ArgumentOutOfRangeException();
            }

            // update node with input
            updateOperation.Update(newXmlNode);

            // insert node relative to anchor
            if (newXmlNode is XmlAttribute)
            {
                var newXmlAttribute = (XmlAttribute)newXmlNode;
                switch (GetNodePosition())
                {
                case XmlNodePosition.Append:
                case XmlNodePosition.After:
                    if (anchor is XmlAttribute)
                    {
                        var xmlAttribute = (XmlAttribute)anchor;
                        if (xmlAttribute.OwnerElement != null)
                        {
                            xmlAttribute.OwnerElement.Attributes.InsertAfter(newXmlAttribute, xmlAttribute);
                        }
                    }
                    else if (anchor.Attributes != null)
                    {
                        anchor.Attributes.Append(newXmlAttribute);
                    }
                    break;

                case XmlNodePosition.Prepend:
                case XmlNodePosition.Before:
                    if (anchor is XmlAttribute)
                    {
                        var xmlAttribute = (XmlAttribute)anchor;
                        if (xmlAttribute.OwnerElement != null)
                        {
                            xmlAttribute.OwnerElement.Attributes.InsertBefore(newXmlAttribute, xmlAttribute);
                        }
                    }
                    else if (anchor.Attributes != null)
                    {
                        anchor.Attributes.Prepend(newXmlAttribute);
                    }
                    break;

                default:
                    // should not happen
                    throw new ArgumentOutOfRangeException();
                }
            }
            else
            {
                switch (GetNodePosition())
                {
                case XmlNodePosition.Append:
                    anchor.AppendChild(newXmlNode);
                    break;

                case XmlNodePosition.Prepend:
                    anchor.PrependChild(newXmlNode);
                    break;

                case XmlNodePosition.After:
                    if (anchor.ParentNode != null)
                    {
                        anchor.ParentNode.InsertAfter(newXmlNode, anchor);
                    }
                    break;

                case XmlNodePosition.Before:
                    if (anchor.ParentNode != null)
                    {
                        anchor.ParentNode.InsertBefore(newXmlNode, anchor);
                    }
                    break;

                default:
                    // should not happen
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
示例#11
0
文件: XmlInsert.cs 项目: nhannd/Xian
		/// <summary>
		/// Creates, updates and inserts a node.
		/// </summary>
		private void InsertNode(XmlNode anchor, IUpdateOperation updateOperation)
		{
			// create node according to type
			XmlNode newXmlNode;
			switch (GetNodeType())
			{
				case XmlNodeType.Attribute:
					newXmlNode = XmlDocument.CreateAttribute(Name, Namespace ?? string.Empty);
					break;
				case XmlNodeType.Element:
					newXmlNode = XmlDocument.CreateElement(Name, Namespace ?? string.Empty);
					break;
				case XmlNodeType.CData:
					newXmlNode = XmlDocument.CreateCDataSection(string.Empty);
					break;
				case XmlNodeType.Comment:
					newXmlNode = XmlDocument.CreateComment(string.Empty);
					break;
				case XmlNodeType.SignificantWhitespace:
					newXmlNode = XmlDocument.CreateSignificantWhitespace(string.Empty);
					break;
				case XmlNodeType.Text:
					newXmlNode = XmlDocument.CreateTextNode(string.Empty);
					break;
				case XmlNodeType.Whitespace:
					newXmlNode = XmlDocument.CreateWhitespace(string.Empty);
					break;
				default:
					// should not happen
					throw new ArgumentOutOfRangeException();
			}

			// update node with input
			updateOperation.Update(newXmlNode);

			// insert node relative to anchor
			if (newXmlNode is XmlAttribute)
			{
				var newXmlAttribute = (XmlAttribute) newXmlNode;
				switch (GetNodePosition())
				{
					case XmlNodePosition.Append:
					case XmlNodePosition.After:
						if (anchor is XmlAttribute)
						{
							var xmlAttribute = (XmlAttribute) anchor;
							if (xmlAttribute.OwnerElement != null)
								xmlAttribute.OwnerElement.Attributes.InsertAfter(newXmlAttribute, xmlAttribute);
						}
						else if (anchor.Attributes != null)
						{
							anchor.Attributes.Append(newXmlAttribute);
						}
						break;
					case XmlNodePosition.Prepend:
					case XmlNodePosition.Before:
						if (anchor is XmlAttribute)
						{
							var xmlAttribute = (XmlAttribute) anchor;
							if (xmlAttribute.OwnerElement != null)
								xmlAttribute.OwnerElement.Attributes.InsertBefore(newXmlAttribute, xmlAttribute);
						}
						else if (anchor.Attributes != null)
						{
							anchor.Attributes.Prepend(newXmlAttribute);
						}
						break;
					default:
						// should not happen
						throw new ArgumentOutOfRangeException();
				}
			}
			else
			{
				switch (GetNodePosition())
				{
					case XmlNodePosition.Append:
						anchor.AppendChild(newXmlNode);
						break;
					case XmlNodePosition.Prepend:
						anchor.PrependChild(newXmlNode);
						break;
					case XmlNodePosition.After:
						if (anchor.ParentNode != null)
							anchor.ParentNode.InsertAfter(newXmlNode, anchor);
						break;
					case XmlNodePosition.Before:
						if (anchor.ParentNode != null)
							anchor.ParentNode.InsertBefore(newXmlNode, anchor);
						break;
					default:
						// should not happen
						throw new ArgumentOutOfRangeException();
				}
			}
		}
示例#12
0
 public UpdateResult(IUpdateOperation operation, IAsyncResult asyncResult)
     : base(operation, asyncResult)
 {
 }
示例#13
0
 private static UpdateDefinition <TEntity> CreateUpdateDefinition(IUpdateOperation <TEntity> update)
 => update.Mutation.Invoke(new UpdateDefinitionBuilder <TEntity>());
示例#14
0
 public async Task UpdateOneAsync(IUpdateOperation <TEntity> update)
 => await _mongoCollection.UpdateOneAsync(update.Criteria, CreateUpdateDefinition(update));