private DtoDelta<ITask> Dto(IDelta<ITask> task) { DtoLazyCollection<UserDto> systemUsers = new DtoLazyCollection<UserDto>(() => clsService.GetSystemUsers().Select(x => new UserDto(x))); DtoDelta<ITask> dtoResult = new DtoDelta<ITask>(task); if (task.CanReadWrite(x => x.Author)) { dtoResult.AddPropertyValues(x => x.Author, systemUsers); } if (task.CanReadWrite(x => x.Manager)) { dtoResult.AddPropertyValues(x => x.Manager, systemUsers); } if (task.CanReadWrite(x => x.ToEmployee)) { dtoResult.AddPropertyValues(x => x.ToEmployee, systemUsers); } if (task.CanReadWrite(x => x.Priority)) { dtoResult.AddPropertyValues(x => x.Priority, clsService.GetPriorities().Select(x => new PriorityDto(x))); } return dtoResult; }
public static IEnumerable<ScriptAccessor> GetScriptsInFolder(IDelta deltas, string folder) { var scripts = deltas .Scripts .Where(script => script.GetFullPath().Contains(folder)) .Select(script => script) .ToList(); return scripts; }
/// <inheritdoc/> public override bool TryGetPropertyReferencedValue(string name, out IDelta value) { return(_deltaNestedReferencedResources.TryGetValue(name, out value)); }
public Task <JsonResult> Patch(int pageDirectoryId, [FromBody] IDelta <UpdatePageDirectoryAccessRuleSetCommand> delta) { return(_apiResponseHelper.RunCommandAsync(pageDirectoryId, delta)); }
internal List <ODataProperty> AppendDynamicProperties(object source, IEdmStructuredTypeReference structuredType, ODataSerializerContext writeContext, List <ODataProperty> declaredProperties) { Contract.Assert(source != null); Contract.Assert(structuredType != null); Contract.Assert(writeContext != null); Contract.Assert(writeContext.Model != null); PropertyInfo dynamicPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary( structuredType.StructuredDefinition(), writeContext.Model); IEdmStructuredObject structuredObject = source as IEdmStructuredObject; object value; IDelta delta = source as IDelta; if (delta == null) { if (dynamicPropertyInfo == null || structuredObject == null || !structuredObject.TryGetPropertyValue(dynamicPropertyInfo.Name, out value) || value == null) { return(null); } } else { value = ((EdmStructuredObject)structuredObject).TryGetDynamicProperties(); } IDictionary <string, object> dynamicPropertyDictionary = (IDictionary <string, object>)value; // Build a HashSet to store the declared property names. // It is used to make sure the dynamic property name is different from all declared property names. HashSet <string> declaredPropertyNameSet = new HashSet <string>(declaredProperties.Select(p => p.Name)); List <ODataProperty> dynamicProperties = new List <ODataProperty>(); foreach (KeyValuePair <string, object> dynamicProperty in dynamicPropertyDictionary) { if (String.IsNullOrEmpty(dynamicProperty.Key) || dynamicProperty.Value == null) { continue; // skip the null object } if (declaredPropertyNameSet.Contains(dynamicProperty.Key)) { throw Error.InvalidOperation(SRResources.DynamicPropertyNameAlreadyUsedAsDeclaredPropertyName, dynamicProperty.Key, structuredType.FullName()); } IEdmTypeReference edmTypeReference = writeContext.GetEdmType(dynamicProperty.Value, dynamicProperty.Value.GetType()); if (edmTypeReference == null) { throw Error.NotSupported(SRResources.TypeOfDynamicPropertyNotSupported, dynamicProperty.Value.GetType().FullName, dynamicProperty.Key); } ODataEdmTypeSerializer propertySerializer = SerializerProvider.GetEdmTypeSerializer(edmTypeReference); if (propertySerializer == null) { throw Error.NotSupported(SRResources.DynamicPropertyCannotBeSerialized, dynamicProperty.Key, edmTypeReference.FullName()); } dynamicProperties.Add(propertySerializer.CreateProperty( dynamicProperty.Value, edmTypeReference, dynamicProperty.Key, writeContext)); } return(dynamicProperties); }
void OnDeltaDone() { m_currentDelta = null; }
public async Task <IActionResult> Patch(int pageId, [FromBody] IDelta <UpdatePageCommand> delta) { return(await _apiResponseHelper.RunCommandAsync(this, pageId, delta)); }
public void CanGetChangedPropertyNamesButOnlyUpdatable() { dynamic delta = new Delta <AddressEntity>(); IDelta idelta = delta as IDelta; // modify in the way we expect the formatter too. idelta.TrySetPropertyValue("City", "Sammamish"); Assert.Single(idelta.GetChangedPropertyNames()); Assert.Equal("City", idelta.GetChangedPropertyNames().Single()); Assert.Equal(4, idelta.GetUnchangedPropertyNames().Count()); // read the property back object city; Assert.True(idelta.TryGetPropertyValue("City", out city)); Assert.Equal("Sammamish", city); // limit updatable properties delta.UpdatableProperties.Clear(); delta.UpdatableProperties.Add("City"); delta.UpdatableProperties.Add("StreetAddress"); // modify the way people will through custom code delta.StreetAddress = "23213 NE 15th Ct"; string[] mods = idelta.GetChangedPropertyNames().ToArray(); Assert.Equal(2, mods.Length); Assert.Contains("StreetAddress", mods); Assert.Contains("City", mods); Assert.Equal("23213 NE 15th Ct", delta.StreetAddress); Assert.Empty(idelta.GetUnchangedPropertyNames()); // try to modify an un-updatable property idelta.TrySetPropertyValue("State", "IA"); mods = idelta.GetChangedPropertyNames().ToArray(); Assert.Equal(2, mods.Length); Assert.Contains("StreetAddress", mods); Assert.Contains("City", mods); Assert.Null(delta.State); Assert.Empty(idelta.GetUnchangedPropertyNames()); // limit a property that has been updated delta.UpdatableProperties.Remove("StreetAddress"); mods = idelta.GetChangedPropertyNames().ToArray(); Assert.Single(mods); Assert.Contains("City", mods); Assert.Null(delta.State); Assert.Empty(idelta.GetUnchangedPropertyNames()); // enable a property that has not been updated delta.UpdatableProperties.Add("State"); mods = idelta.GetChangedPropertyNames().ToArray(); Assert.Single(mods); Assert.Contains("City", mods); Assert.Null(delta.State); Assert.Single(idelta.GetUnchangedPropertyNames()); Assert.Equal("State", idelta.GetUnchangedPropertyNames().Single()); // enable a property that doesn't exist delta.UpdatableProperties.Add("Bogus"); mods = idelta.GetChangedPropertyNames().ToArray(); Assert.Single(mods); Assert.Contains("City", mods); Assert.Null(delta.State); Assert.Single(idelta.GetUnchangedPropertyNames()); Assert.Equal("State", idelta.GetUnchangedPropertyNames().Single()); // set a property that doesn't exist Assert.False(delta.TrySetPropertyValue("Bogus", "Bad")); mods = idelta.GetChangedPropertyNames().ToArray(); Assert.Single(mods); Assert.Contains("City", mods); Assert.Null(delta.State); Assert.Single(idelta.GetUnchangedPropertyNames()); Assert.Equal("State", idelta.GetUnchangedPropertyNames().Single()); }
public static IEnumerable<ScriptAccessor> GetDownScripts(IDelta delta) { return GetScriptsInFolder(delta, Down); }
/// <summary> /// Creates an <see cref="ODataComplexValue"/> for the object represented by <paramref name="graph"/>. /// </summary> /// <param name="graph">The value of the <see cref="ODataComplexValue"/> to be created.</param> /// <param name="complexType">The EDM complex type of the object.</param> /// <param name="writeContext">The serializer context.</param> /// <returns>The created <see cref="ODataComplexValue"/>.</returns> public virtual ODataComplexValue CreateODataComplexValue(object graph, IEdmComplexTypeReference complexType, ODataSerializerContext writeContext) { if (writeContext == null) { throw Error.ArgumentNull("writeContext"); } if (graph == null || graph is NullEdmComplexObject) { return(null); } IEdmComplexObject complexObject = graph as IEdmComplexObject ?? new TypedEdmComplexObject(graph, complexType, writeContext.Model); List <IEdmProperty> settableProperties = new List <IEdmProperty>(complexType.ComplexDefinition().Properties()); if (complexObject.IsDeltaResource()) { IDelta deltaProperty = graph as IDelta; Contract.Assert(deltaProperty != null); IEnumerable <string> changedProperties = deltaProperty.GetChangedPropertyNames(); settableProperties = settableProperties.Where(p => changedProperties.Contains(p.Name)).ToList(); } List <ODataProperty> propertyCollection = new List <ODataProperty>(); foreach (IEdmProperty property in settableProperties) { IEdmTypeReference propertyType = property.Type; ODataEdmTypeSerializer propertySerializer = SerializerProvider.GetEdmTypeSerializer(propertyType); if (propertySerializer == null) { throw Error.NotSupported(SRResources.TypeCannotBeSerialized, propertyType.FullName(), typeof(ODataMediaTypeFormatter).Name); } object propertyValue; if (complexObject.TryGetPropertyValue(property.Name, out propertyValue)) { if (propertyValue != null && propertyType != null && propertyType.IsComplex()) { IEdmTypeReference actualType = writeContext.GetEdmType(propertyValue, propertyValue.GetType()); if (actualType != null && propertyType != actualType) { propertyType = actualType; } } var odataProperty = propertySerializer.CreateProperty(propertyValue, propertyType, property.Name, writeContext); if (odataProperty != null) { propertyCollection.Add(odataProperty); } } } // Try to add the dynamic properties if the complex type is open. if (complexType.ComplexDefinition().IsOpen) { List <ODataProperty> dynamicProperties = AppendDynamicProperties(complexObject, complexType, writeContext, propertyCollection, new string[0]); if (dynamicProperties != null) { propertyCollection.AddRange(dynamicProperties); } } string typeName = complexType.FullName(); ODataComplexValue value = new ODataComplexValue() { Properties = propertyCollection, TypeName = typeName }; AddTypeNameAnnotationAsNeeded(value, writeContext.MetadataLevel); return(value); }
internal List <ODataProperty> AppendDynamicProperties(object source, IEdmStructuredTypeReference structuredType, ODataSerializerContext writeContext, List <ODataProperty> declaredProperties, string[] selectedDynamicProperties) { Contract.Assert(source != null); Contract.Assert(structuredType != null); Contract.Assert(writeContext != null); Contract.Assert(writeContext.Model != null); bool nullDynamicPropertyEnabled = false; if (source is EdmDeltaComplexObject || source is EdmDeltaEntityObject) { nullDynamicPropertyEnabled = true; } else if (writeContext.Request != null) { HttpConfiguration configuration = writeContext.Request.GetConfiguration(); if (configuration != null) { nullDynamicPropertyEnabled = configuration.HasEnabledNullDynamicProperty(); } } PropertyInfo dynamicPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary( structuredType.StructuredDefinition(), writeContext.Model); IEdmStructuredObject structuredObject = source as IEdmStructuredObject; object value; IDelta delta = source as IDelta; if (delta == null) { if (dynamicPropertyInfo == null || structuredObject == null || !structuredObject.TryGetPropertyValue(dynamicPropertyInfo.Name, out value) || value == null) { return(null); } } else { value = ((EdmStructuredObject)structuredObject).TryGetDynamicProperties(); } IDictionary <string, object> dynamicPropertyDictionary = (IDictionary <string, object>)value; // Build a HashSet to store the declared property names. // It is used to make sure the dynamic property name is different from all declared property names. HashSet <string> declaredPropertyNameSet = new HashSet <string>(declaredProperties.Select(p => p.Name)); List <ODataProperty> dynamicProperties = new List <ODataProperty>(); IEnumerable <KeyValuePair <string, object> > dynamicPropertiesToSelect = dynamicPropertyDictionary.Where( x => !selectedDynamicProperties.Any() || selectedDynamicProperties.Contains(x.Key)); foreach (KeyValuePair <string, object> dynamicProperty in dynamicPropertiesToSelect) { if (String.IsNullOrEmpty(dynamicProperty.Key)) { continue; } if (dynamicProperty.Value == null) { if (nullDynamicPropertyEnabled) { dynamicProperties.Add(new ODataProperty { Name = dynamicProperty.Key, Value = new ODataNullValue() }); } continue; } if (declaredPropertyNameSet.Contains(dynamicProperty.Key)) { throw Error.InvalidOperation(SRResources.DynamicPropertyNameAlreadyUsedAsDeclaredPropertyName, dynamicProperty.Key, structuredType.FullName()); } IEdmTypeReference edmTypeReference = writeContext.GetEdmType(dynamicProperty.Value, dynamicProperty.Value.GetType()); if (edmTypeReference == null) { throw Error.NotSupported(SRResources.TypeOfDynamicPropertyNotSupported, dynamicProperty.Value.GetType().FullName, dynamicProperty.Key); } ODataEdmTypeSerializer propertySerializer = SerializerProvider.GetEdmTypeSerializer(edmTypeReference); if (propertySerializer == null) { throw Error.NotSupported(SRResources.DynamicPropertyCannotBeSerialized, dynamicProperty.Key, edmTypeReference.FullName()); } dynamicProperties.Add(propertySerializer.CreateProperty( dynamicProperty.Value, edmTypeReference, dynamicProperty.Key, writeContext)); } return(dynamicProperties); }
/// <summary> /// Executes a command in a "Patch" style, allowing for a partial update of a resource. In /// order to support this method, there must be a query handler defined that implements /// IQueryHandler<GetQuery<TCommand>> so the full command object can be fecthed /// prior to patching. Once patched and executed, a formatted IHttpActionResult is returned, /// handling any validation errors and permission errors. /// </summary> /// <typeparam name="TCommand">Type of the command to execute</typeparam> /// <param name="controller">The Controller instance using the helper</param> /// <param name="delta">The delta of the command to patch and execute</param> public async Task <IActionResult> RunCommandAsync <TCommand>(Controller controller, IDelta <TCommand> delta) where TCommand : class, ICommand { var query = new GetUpdateCommandQuery <TCommand>(); var command = await _queryExecutor.ExecuteAsync(query); if (delta != null) { delta.Patch(command); } return(await RunCommandAsync(controller, command)); }
private TaskEntity CopyTaskTo(IDelta<ITask> task, TaskEntity taskEntity) { if(task.CanUpdate(x=>x.Id)) { taskEntity.Id = task.Instance.Id; } if (task.CanUpdate(x => x.CreatedDateTime)) { taskEntity.CreatedDateTime = task.Instance.CreatedDateTime; } if (task.CanUpdate(x => x.Author)) { taskEntity.AuthorId = task.Instance.Author.Id; } if (task.CanUpdate(x => x.Manager)) { taskEntity.ManagerId = task.Instance.Manager.Id; } if (task.CanUpdate(x => x.ToEmployee)) { taskEntity.EmployeeId = task.Instance.ToEmployee.Id; } if (task.CanUpdate(x => x.Name)) { taskEntity.Name = task.Instance.Name; } if (task.CanUpdate(x => x.Objective)) { taskEntity.Objective = task.Instance.Objective; } if (task.CanUpdate(x => x.Status)) { taskEntity.StatusId = task.Instance.Status.Id; } if (task.CanUpdate(x => x.Priority)) { taskEntity.PriorityId = task.Instance.Priority.Id; } if (task.CanUpdate(x => x.StartDateTime)) { taskEntity.StartDateTime = task.Instance.StartDateTime; } if (task.CanUpdate(x => x.EndDateTime)) { taskEntity.EndDateTime = task.Instance.EndDateTime; } if (task.CanUpdate(x => x.Result)) { taskEntity.Result = task.Instance.Result; } if (task.CanUpdate(x => x.Description)) { taskEntity.Description = task.Instance.Description; } return taskEntity; }
public ITask UpdateTask(IDelta<ITask> task) { TaskEntity taskEntity = Context.Set<TaskEntity>().FirstOrDefault(x => x.Id == task.Instance.Id); if (taskEntity != null) { CopyTaskTo(task, taskEntity); Context.SaveChanges(); } return GetTask(task.Instance.Id); }
public ITask InsertTask(IDelta<ITask> task) { CopyTaskTo(task, CreateNew<TaskEntity>()); Context.SaveChanges(); return GetTask(task.Instance.Id); }
public Task <JsonResult> Patch(int pageId, [FromBody] IDelta <UpdatePageCommand> delta) { return(_apiResponseHelper.RunCommandAsync(pageId, delta)); }
public async Task <IActionResult> PatchSeoSettings([FromBody] IDelta <UpdateSeoSettingsCommand> delta) { return(await _apiResponseHelper.RunCommandAsync(this, delta)); }
abstract public void SpawnNewDelta(IDelta delta);
private void SetDeltaPropertyValue(ODataSerializerContext writeContext, List <ODataProperty> properties, IDelta delta, string propertyName) { object propertyValue; if (delta.TryGetPropertyValue(propertyName, out propertyValue)) { Type propertyType; IEdmStructuredTypeReference expectedPropType = null; if (propertyValue == null) { // We need expected property type only if property value is null, else it will get from the value if (delta.TryGetPropertyType(propertyName, out propertyType)) { expectedPropType = writeContext.GetEdmType(propertyValue, propertyType) as IEdmStructuredTypeReference; } } SetPropertyValue(writeContext, properties, expectedPropType, propertyName, propertyValue); } }
abstract public void ListenDelta(IDelta delta);
public virtual void AppendDynamicProperties(ODataResource resource, SelectExpandNode selectExpandNode, ResourceContext resourceContext) { Contract.Assert(resource != null); Contract.Assert(selectExpandNode != null); Contract.Assert(resourceContext != null); if (!resourceContext.StructuredType.IsOpen || // non-open type (!selectExpandNode.SelectAllDynamicProperties && !selectExpandNode.SelectedDynamicProperties.Any())) { return; } bool nullDynamicPropertyEnabled = false; if (resourceContext.Request != null) { // TODO: /* * HttpConfiguration configuration = resourceContext.Request.GetConfiguration(); * if (configuration != null) * { * nullDynamicPropertyEnabled = configuration.HasEnabledNullDynamicProperty(); * }*/ } IEdmStructuredType structuredType = resourceContext.StructuredType; IEdmStructuredObject structuredObject = resourceContext.EdmObject; object value; IDelta delta = structuredObject as IDelta; if (delta == null) { PropertyInfo dynamicPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary(structuredType, resourceContext.EdmModel); if (dynamicPropertyInfo == null || structuredObject == null || !structuredObject.TryGetPropertyValue(dynamicPropertyInfo.Name, out value) || value == null) { return; } } else { value = ((EdmStructuredObject)structuredObject).TryGetDynamicProperties(); } IDictionary <string, object> dynamicPropertyDictionary = (IDictionary <string, object>)value; // Build a HashSet to store the declared property names. // It is used to make sure the dynamic property name is different from all declared property names. HashSet <string> declaredPropertyNameSet = new HashSet <string>(resource.Properties.Select(p => p.Name)); List <ODataProperty> dynamicProperties = new List <ODataProperty>(); IEnumerable <KeyValuePair <string, object> > dynamicPropertiesToSelect = dynamicPropertyDictionary.Where( x => !selectExpandNode.SelectedDynamicProperties.Any() || selectExpandNode.SelectedDynamicProperties.Contains(x.Key)); foreach (KeyValuePair <string, object> dynamicProperty in dynamicPropertiesToSelect) { if (String.IsNullOrEmpty(dynamicProperty.Key)) { continue; } if (dynamicProperty.Value == null) { if (nullDynamicPropertyEnabled) { dynamicProperties.Add(new ODataProperty { Name = dynamicProperty.Key, Value = new ODataNullValue() }); } continue; } if (declaredPropertyNameSet.Contains(dynamicProperty.Key)) { throw Error.InvalidOperation(SRResources.DynamicPropertyNameAlreadyUsedAsDeclaredPropertyName, dynamicProperty.Key, structuredType.FullTypeName()); } IEdmTypeReference edmTypeReference = resourceContext.SerializerContext.GetEdmType(dynamicProperty.Value, dynamicProperty.Value.GetType()); if (edmTypeReference == null) { throw Error.NotSupported(SRResources.TypeOfDynamicPropertyNotSupported, dynamicProperty.Value.GetType().FullName, dynamicProperty.Key); } if (edmTypeReference.IsStructured() || (edmTypeReference.IsCollection() && edmTypeReference.AsCollection().ElementType().IsStructured())) { if (resourceContext.DynamicComplexProperties == null) { resourceContext.DynamicComplexProperties = new ConcurrentDictionary <string, object>(); } resourceContext.DynamicComplexProperties.Add(dynamicProperty); } else { ODataEdmTypeSerializer propertySerializer = SerializerProvider.GetEdmTypeSerializer(resourceContext.Context, edmTypeReference); if (propertySerializer == null) { throw Error.NotSupported(SRResources.DynamicPropertyCannotBeSerialized, dynamicProperty.Key, edmTypeReference.FullName()); } dynamicProperties.Add(propertySerializer.CreateProperty( dynamicProperty.Value, edmTypeReference, dynamicProperty.Key, resourceContext.SerializerContext)); } } if (dynamicProperties.Any()) { resource.Properties = resource.Properties.Concat(dynamicProperties); } }
/// <inheritdoc/> public override bool TryGetPropertyReferencedValue(string name, out IDelta value) { throw new NotImplementedException(); }
public Property(IDelta owner ,PropertyInfo property) { ownerPtr = owner; propertyInfo = property; }
public void PushNewDelta(IDelta delta) { m_deltaFuture.Clear(); m_deltaHistory.Push(delta); }