コード例 #1
0
        /// <summary>
        /// Apply the delta set
        /// </summary>
        private void ApplyDelta(string delta, ClassRepository classRepository)
        {
            // Load the Delta Set
            try
            {
                DeltaSet ds = DeltaSet.Load(delta);
                if (ds.MetaData == null)
                {
                    throw new InvalidOperationException("Delta set is missing data...");
                }

                DeltaEngine de = new DeltaEngine(ds);
                de.Apply(classRepository);
            }
            catch (Exception e)
            {
                Trace.WriteLine(String.Format("Delta: Won't apply '{0}', reason: {1}", delta, e.Message), "error");
                Exception ie = e.InnerException;
                while (ie != null)
                {
                    Trace.WriteLine(String.Format("Caused by: {0}", ie.Message), "error");
                    ie = ie.InnerException;
                }
            }
        }
コード例 #2
0
        public void PatchOnDeltaSet_ThrowsArgumentNull_OriginalSet()
        {
            // Arrange
            DeltaSet <DeltaSetOfTTests> set = new DeltaSet <DeltaSetOfTTests>();

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => set.Patch(null), "originalSet");
        }
コード例 #3
0
        public void DeltaSet_Returns_ExpectedClrType()
        {
            // Arrange
            DeltaSet <DeltaSetOfTTests> set = new DeltaSet <DeltaSetOfTTests>();

            // Act & Assert
            Assert.Equal(typeof(DeltaSetOfTTests), set.ExpectedClrType);
        }
コード例 #4
0
        public void DeltaSet_Returns_StructuredType()
        {
            // Arrange
            DeltaSet <DeltaSetOfTTests> set = new DeltaSet <DeltaSetOfTTests>();

            // Act & Assert
            Assert.Equal(typeof(DeltaSetOfTTests), set.StructuredType);
        }
コード例 #5
0
        // public IActionResult Patch(EdmChangedObjectCollection changes)
        public IActionResult Patch(DeltaSet <Organization> changes)
        {
            /*
             * {
             * "@odata.context":"http://localhost/$metadata#Organizations/$delta",
             * "value":[
             * {
             * "@odata.id":"Organizations(42)",
             * "Name":"Micrsoft"
             * },
             * {
             * "@odata.context":"http://localhost/$metadata#Organizations/$deletedLink",
             * "source":"Organizations(32)",
             * "relationship":"Departs",
             * "target":"Departs(12)"
             * },
             * {
             * "@odata.context":"http://localhost/$metadata#Organizations/$link",
             * "source":"Organizations(22)",
             * "relationship":"Departs",
             * "target":"Departs(2)"
             * },
             * {
             * "@odata.context":"http://localhost/$metadata#Organizations/$deletedEntity",
             * "id":"Organizations(12)",
             * "reason":"deleted"
             * }
             * ]
             * }
             */

            //changes.ApplyDeleteLink = (l) => { };

            //IList<Organization> originalSet = new List<Organization>();

            // changes.Patch(originalSet);

            return(Ok());
        }
コード例 #6
0
        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                return(null);
            }

            if (edmType == null)
            {
                throw Error.ArgumentNull(nameof(edmType));
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull(nameof(readContext));
            }

            if (!edmType.IsCollection() || !edmType.AsCollection().ElementType().IsStructured())
            {
                throw Error.Argument(nameof(edmType), SRResources.TypeMustBeResourceSet, edmType.ToTraceString());
            }

            ODataDeltaResourceSetWrapper resourceSet = item as ODataDeltaResourceSetWrapper;

            if (resourceSet == null)
            {
                throw Error.Argument(nameof(item), SRResources.ArgumentMustBeOfType, typeof(ODataDeltaResourceSetWrapper).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            IEdmStructuredTypeReference elementType = edmType.AsCollection().ElementType().AsStructured();

            IEnumerable result = ReadDeltaResourceSet(resourceSet, elementType, readContext);

            if (result != null)
            {
                if (readContext.IsNoClrType)
                {
                    EdmChangedObjectCollection changedObjCollection = new EdmChangedObjectCollection(elementType.Definition as IEdmEntityType);
                    foreach (IEdmChangedObject changedObject in result)
                    {
                        changedObjCollection.Add(changedObject);
                    }

                    return(changedObjCollection);
                }
                else
                {
                    Type elementClrType     = readContext.Model.GetClrType(elementType);
                    Type changedObjCollType = typeof(DeltaSet <>).MakeGenericType(elementClrType);

                    DeltaSet deltaSet = Activator.CreateInstance(changedObjCollType) as DeltaSet;
                    foreach (var delta in result)
                    {
                        IDeltaItem deltaItem = delta as IDeltaItem;
                        if (deltaItem != null)
                        {
                            deltaSet.Add(deltaItem);
                        }
                    }

                    return(deltaSet);
                }
            }
            else
            {
                return(result);
            }
        }
コード例 #7
0
 /// <summary>
 /// Creates a new delta engine with the specified
 /// delta set
 /// </summary>
 public DeltaEngine(DeltaSet deltaSet)
 {
     this.m_deltaSet = deltaSet;
     ValidateDeltaSet();
 }