public void Apply(object objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: throw new NotSupportedException(Resources.TestOperationNotSupported); default: break; } }
internal void Apply(T objectToApplyTo, IObjectAdapter <T> adapter) { switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: throw new NotImplementedException("Test is currently not implemented."); default: break; } }
/// <summary> /// Apply this JsonPatchDocument /// </summary> /// <param name="objectToApplyTo">Object to apply the JsonPatchDocument to</param> /// <param name="adapter">IObjectAdapter instance to use when applying</param> /// <param name="logErrorAction">Action to log errors</param> public void ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter, Action <JsonPatchError> logErrorAction) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } foreach (var op in Operations) { try { op.Apply(objectToApplyTo, adapter); } catch (JsonPatchException jsonPatchException) { var errorReporter = logErrorAction ?? ErrorReporter.Default; errorReporter(new JsonPatchError(objectToApplyTo, op, jsonPatchException.Message)); // As per JSON Patch spec if an operation results in error, further operations should not be executed. break; } } }
public IEnumerable <PatchOperationResult> Apply(TModel objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException("objectToApplyTo"); } if (adapter == null) { throw new ArgumentNullException("adapter"); } switch (OperationType) { case OperationType.Add: return(adapter.Add(this, objectToApplyTo)); case OperationType.Remove: return(adapter.Remove(this, objectToApplyTo)); case OperationType.Replace: return(adapter.Replace(this, objectToApplyTo)); default: throw new InvalidOperationException(string.Format("Patch OperationType type '{0}' is invalid.", OperationType)); } }
public void Apply(object objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException("objectToApplyTo"); } if (adapter == null) { throw new ArgumentNullException("adapter"); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; } }
public bool TryGetObject(string objectId, out IObjectAdapter objectAdapter) { lock (_objects) { return(_objects.TryGetValue(objectId, out objectAdapter)); } }
public void Apply(TModel objectToApplyTo, IObjectAdapter <TModel> adapter) { switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: throw new NotSupportedException(Resources.TestOperationNotSupported); default: break; } }
/// <summary> /// Applies JSON patch operations on object and logs errors in <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary" />. /// </summary> /// <param name="patchDoc">The <see cref="T:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument`1" />.</param> /// <param name="objectToApplyTo">The entity on which <see cref="T:Microsoft.AspNetCore.JsonPatch.JsonPatchDocument`1" /> is applied.</param> /// <param name="objectAdapter">Object Adapter to use</param> /// <param name="modelState">The <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary" /> to add errors.</param> /// <param name="prefix">The prefix to use when looking up values in <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary" />.</param> public static void ApplyTo <T>( this JsonPatchDocument <T> patchDoc, T objectToApplyTo, IObjectAdapter objectAdapter, ModelStateDictionary modelState, string prefix) where T : class { if (patchDoc == null) { throw new ArgumentNullException(nameof(patchDoc)); } if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (modelState == null) { throw new ArgumentNullException(nameof(modelState)); } patchDoc.ApplyTo(objectToApplyTo, objectAdapter, jsonPatchError => { var affectedObjectName = jsonPatchError.AffectedObject.GetType().Name; var key = string.IsNullOrEmpty(prefix) ? affectedObjectName : prefix + "." + affectedObjectName; modelState.TryAddModelError(key, jsonPatchError.ErrorMessage); }); }
public void Apply(T objectToApplyTo, IObjectAdapter <T> adapter) { switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: adapter.Test(this, objectToApplyTo); break; default: break; } }
/// <summary> /// Apply this JsonPatchDocument /// </summary> /// <param name="objectToApplyTo">Object to apply the JsonPatchDocument to</param> /// <param name="adapter">IObjectAdapter instance to use when applying</param> public void ApplyTo([NotNull] TModel objectToApplyTo, [NotNull] IObjectAdapter adapter) { // apply each operation in order foreach (var op in Operations) { op.Apply(objectToApplyTo, adapter); } }
/// <summary> /// Apply the patch document, passing in a custom IObjectAdapter<typeparamref name=">"/>. /// This method will change the passed-in object. /// </summary> /// <param name="objectToApplyTo">The object to apply the JsonPatchDocument to</param> /// <param name="adapter">The IObjectAdapter instance to use</param> public void ApplyTo(T objectToApplyTo, IObjectAdapter <T> adapter) { // apply each operation in order foreach (var op in Operations) { op.Apply(objectToApplyTo, adapter); } }
/// <summary> /// Initializes a new instance of the <see cref="XmlSerializer" /> class. /// </summary> /// <param name="serializationManager">The serialization manager.</param> /// <param name="dataContractSerializerFactory">The data contract serializer factory.</param> /// <param name="xmlNamespaceManager">The XML namespace manager.</param> /// <param name="typeFactory">The type factory.</param> /// <param name="objectAdapter">The object adapter.</param> /// <exception cref="ArgumentNullException">The <paramref name="serializationManager" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="dataContractSerializerFactory" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespaceManager" /> is <c>null</c>.</exception> public XmlSerializer(ISerializationManager serializationManager, IDataContractSerializerFactory dataContractSerializerFactory, IXmlNamespaceManager xmlNamespaceManager, ITypeFactory typeFactory, IObjectAdapter objectAdapter) : base(serializationManager, typeFactory, objectAdapter) { Argument.IsNotNull("dataContractSerializerFactory", dataContractSerializerFactory); Argument.IsNotNull("xmlNamespaceManager", xmlNamespaceManager); _dataContractSerializerFactory = dataContractSerializerFactory; _xmlNamespaceManager = xmlNamespaceManager; }
public void Apply(TModel objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: if (adapter is IObjectAdapterWithTest adapterWithTest) { adapterWithTest.Test(this, objectToApplyTo); break; } else { throw new JsonPatchException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported)); } case OperationType.Invalid: throw new JsonPatchException( Resources.FormatInvalidJsonPatchOperation(op), innerException: null); default: break; } }
/// <summary> /// Initializes a new instance of the <see cref="SerializerBase{TSerializationContext}" /> class. /// </summary> /// <param name="serializationManager">The serialization manager.</param> /// <param name="typeFactory">The type factory.</param> /// <param name="objectAdapter">The object adapter.</param> /// <exception cref="ArgumentNullException">The <paramref name="serializationManager" /> is <c>null</c>.</exception> protected SerializerBase(ISerializationManager serializationManager, ITypeFactory typeFactory, IObjectAdapter objectAdapter) { Argument.IsNotNull("serializationManager", serializationManager); Argument.IsNotNull("typeFactory", typeFactory); Argument.IsNotNull("objectAdapter", objectAdapter); SerializationManager = serializationManager; TypeFactory = typeFactory; ObjectAdapter = objectAdapter; SerializationManager.CacheInvalidated += OnSerializationManagerCacheInvalidated; }
public IDisposable Add(string objectId, IObjectAdapter objectAdapter) { if (_disposed) { throw new ObjectDisposedException(nameof(ObjectsRepository)); } lock (_objects) { _objects.Add(objectId, objectAdapter); } return(new Disposable(() => Remove(objectId))); }
public void Apply(object objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: if (adapter is IObjectAdapterWithTest adapterWithTest) { adapterWithTest.Test(this, objectToApplyTo); break; } else { throw new NotSupportedException(Resources.TestOperationNotSupported); } default: break; } }
/// <summary> /// Applies the operation to the target object using the specified adapter. /// </summary> /// <param name="objectToApplyTo">The target object.</param> /// <param name="adapter">The <see cref="IObjectAdapter" />.</param> public void Apply(TModel objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo, typeof(TModel)); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo, typeof(TModel)); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo, typeof(TModel)); break; case OperationType.Move: adapter.Move(this, objectToApplyTo, typeof(TModel)); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo, typeof(TModel)); break; case OperationType.Test when adapter is IObjectAdapterWithTest adapterWithTest: adapterWithTest.Test(this, objectToApplyTo, typeof(TModel)); break; case OperationType.Test: throw new JsonPatchException(new JsonPatchError(objectToApplyTo, this, "The test operation is not supported.")); case OperationType.Invalid: throw new JsonPatchException($"Invalid JsonPatch operation '{Op}'."); } }
public void Apply(TModel objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: throw new NotImplementedException("Test is currently not implemented."); case OperationType.Invalid: throw new JsonPatchException( Resources.FormatInvalidJsonPatchOperation(op), innerException: null); default: break; } }
/// <summary> /// Apply this JsonPatchDocument /// </summary> /// <param name="objectToApplyTo">Object to apply the JsonPatchDocument to</param> /// <param name="adapter">IObjectAdapter instance to use when applying</param> public void ApplyTo(object objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } // apply each operation in order foreach (var op in Operations) { op.Apply(objectToApplyTo, adapter); } }
public void Apply(object objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: adapter.Test(this, objectToApplyTo); break; default: break; } }
public void Apply(TModel objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (adapter == null) { throw new ArgumentNullException(nameof(adapter)); } switch (OperationType) { case OperationType.Add: adapter.Add(this, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(this, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(this, objectToApplyTo); break; case OperationType.Move: adapter.Move(this, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(this, objectToApplyTo); break; case OperationType.Test: throw new JsonPatchException(new JsonPatchError(objectToApplyTo, this, Resources.TestOperationNotSupported)); default: break; } }
/// <summary> /// Apply this JsonPatchDocument /// </summary> /// <param name="objectToApplyTo">Object to apply the JsonPatchDocument to</param> /// <param name="adapter">IObjectAdapter instance to use when applying</param> public PatchResult ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new ArgumentNullException("objectToApplyTo"); } if (adapter == null) { throw new ArgumentNullException("adapter"); } var patchResult = new PatchResult(); foreach (var op in Operations) { patchResult.AddRange(op.Apply(objectToApplyTo, adapter)); } return(patchResult); }
internal static void Apply(this Operation operation, object objectToApplyTo, IObjectAdapter adapter) { if (objectToApplyTo == null) { throw new NullReferenceException("objectToApplyTo cannot be null"); } if (adapter == null) { throw new NullReferenceException("adapter cannot be null"); } switch (operation.OperationType) { case OperationType.Add: adapter.Add(operation, objectToApplyTo); break; case OperationType.Remove: adapter.Remove(operation, objectToApplyTo); break; case OperationType.Replace: adapter.Replace(operation, objectToApplyTo); break; case OperationType.Move: adapter.Move(operation, objectToApplyTo); break; case OperationType.Copy: adapter.Copy(operation, objectToApplyTo); break; case OperationType.Test: throw new NotImplementedException("Test is currently not implemented."); default: break; } }
/// <summary> /// Applies JSON patch operations on object and logs errors in <see cref="ModelStateDictionary"/>. /// </summary> /// <param name="patchDoc">The <see cref="JsonPatchDocument{T}"/>.</param> /// <param name="objectToApplyTo">The entity on which <see cref="JsonPatchDocument{T}"/> is applied.</param> /// <param name="objectAdapter">Object Adapter to use</param> /// <param name="modelState">The <see cref="ModelStateDictionary"/> to add errors.</param> public static void ApplyTo <T>( this JsonPatchDocument <T> patchDoc, T objectToApplyTo, IObjectAdapter objectAdapter, ModelStateDictionary modelState) where T : class { if (patchDoc == null) { throw new ArgumentNullException(nameof(patchDoc)); } if (objectToApplyTo == null) { throw new ArgumentNullException(nameof(objectToApplyTo)); } if (modelState == null) { throw new ArgumentNullException(nameof(modelState)); } patchDoc.ApplyTo(objectToApplyTo, objectAdapter, modelState, string.Empty); }
/// <summary> /// Initializes a new instance of the <see cref="ViewToViewModelMappingHelper"/> class. /// </summary> /// <param name="viewModelContainer">The view model container.</param> /// <param name="objectAdapter">The object adapter.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModelContainer"/> is <c>null</c>.</exception> public ViewToViewModelMappingHelper(IViewModelContainer viewModelContainer, IObjectAdapter objectAdapter) { Argument.IsNotNull("viewModelContainer", viewModelContainer); Argument.IsNotNull("objectAdapter", objectAdapter); Log.Debug("Initializing view model container to manage ViewToViewModel mappings"); ViewModelContainer = viewModelContainer; ObjectAdapter = objectAdapter; var viewModelContainerType = ViewModelContainerType; if (!_viewToViewModelMappingContainers.ContainsKey(viewModelContainerType)) { _viewToViewModelMappingContainers.Add(viewModelContainerType, new ViewToViewModelMappingContainer(viewModelContainerType)); } ViewModelContainer.ViewModelChanged += OnViewModelChanged; ViewModelContainer.PropertyChanged += OnViewModelContainerPropertyChanged; InitializeViewModel(ViewModelContainer.ViewModel); Log.Debug("Initialized view model container to manage ViewToViewModel mappings"); }
/// <summary> /// Initializes a new instance of the <see cref="JsonSerializer" /> class. /// </summary> /// <param name="serializationManager">The serialization manager.</param> /// <param name="typeFactory">The type factory.</param> /// <param name="objectAdapter">The object adapter.</param> /// <exception cref="ArgumentNullException">The <paramref name="serializationManager" /> is <c>null</c>.</exception> public JsonSerializer(ISerializationManager serializationManager, ITypeFactory typeFactory, IObjectAdapter objectAdapter) : base(serializationManager, typeFactory, objectAdapter) { PreserveReferences = true; WriteTypeInfo = true; }
/// <summary> /// Initializes the <see cref="ViewToViewModelMapping"/> for the specified <see cref="IViewModelContainer"/>. /// </summary> /// <param name="viewModelContainer">The view model container to initialize the mappings for.</param> /// <param name="objectAdapter">The object adapter.</param> /// <exception cref="ArgumentNullException">The <paramref name="viewModelContainer"/> is <c>null</c>.</exception> public static void InitializeViewToViewModelMappings(IViewModelContainer viewModelContainer, IObjectAdapter objectAdapter) { Argument.IsNotNull("viewModelContainer", viewModelContainer); if (_viewModelContainers.ContainsKey(viewModelContainer)) { return; } _viewModelContainers.Add(viewModelContainer, new ViewToViewModelMappingHelper(viewModelContainer, objectAdapter)); }
/// <summary> /// Initializes a new instance of the <see cref="BinarySerializer" /> class. /// </summary> /// <param name="serializationManager">The serialization manager.</param> /// <param name="typeFactory">The type factory.</param> /// <param name="objectAdapter">The object adapter.</param> /// <exception cref="ArgumentNullException">The <paramref name="serializationManager" /> is <c>null</c>.</exception> public BinarySerializer(ISerializationManager serializationManager, ITypeFactory typeFactory, IObjectAdapter objectAdapter) : base(serializationManager, typeFactory, objectAdapter) { if (DeserializationBinder is null) { DeserializationBinder = new RedirectDeserializationBinder(); } }
/// <summary> /// Initializes a new instance of the <see cref="AutoCompletionService"/> class. /// </summary> public AutoCompletionService(IObjectAdapter objectAdapter) { Argument.IsNotNull(nameof(objectAdapter), objectAdapter); _objectAdapter = objectAdapter; }
public PaymentRepository(IObjectAdapter<NewPayment, AddPaymentRequest> adapter) { _adapter = adapter; }