/// <inheritdoc/> public bool RaiseEventReceivedEvent(EventGridEventModel model) { if (string.IsNullOrWhiteSpace(model.EventType) || string.IsNullOrWhiteSpace(model.Subject)) { return(false); } var eventGridViewerEventModel = _eventGridEventModelAdapter.Convert(model); EventReceived?.Invoke(this, new EventGridEventArgs(eventGridViewerEventModel)); return(true); }
/// <summary> /// Set the value of the property. /// </summary> public void SetValue(object input) { if (property == null) { return; } if (adaptor != null) { input = adaptor.Convert(input); } property.SetValue(propertyOwner, input, null); }
/// <summary> /// Set the value of the property. /// </summary> public void SetValue(object input) { if (!this.isHotfix) { if (property == null) { return; } if (adapter != null) { input = adapter.Convert(input, adapterOptions); } property.SetValue(propertyOwner, input, null); } else { if (adapter != null) { input = adapter.Convert(input, adapterOptions); } (this.propertyOwner as Framework.Hotfix.HotfixObject).Invoke("set_" + propertyName, input); } }
/// <summary> /// Set the value of the property. /// </summary> public void SetValue(object input) { if (property == null) { return; } if (adapter != null) { //Because C# uses the same syntax for unboxing & casting, We have to change the boxed type first just incase we are casting var adapterAttribute = TypeResolver.FindAdapterAttribute(adapter.GetType()); if (adapterAttribute != null) { try { input = Convert.ChangeType(input, adapterAttribute.InputType); } catch (Exception ex) { Debug.LogError(string.Format("Failed to convert value from {0} to {1}.", input.GetType(), adapterAttribute.InputType)); Debug.LogException(ex); } } input = adapter.Convert(input, adapterOptions); } //Fixing the boxed type again var propertyType = property.PropertyType; try { input = Convert.ChangeType(input, propertyType); } catch (Exception ex) { Debug.LogError(string.Format("Failed to convert value from {0} to {1}.", input.GetType(), propertyType)); Debug.LogException(ex); } property.SetValue(propertyOwner, input, null); }
/// <summary> /// Updates the UI widget when the value of the bound property has changed. /// </summary> private void UpdateUI(object widgetValue) { // Setting a UI property which is a value type to null can cause issues. if (widgetValue == null && boundUiProperty.PropertyInfo.PropertyType.IsValueType) { boundUiProperty.PropertyInfo.GetSetMethod() .Invoke(boundUiProperty.Object, new object[] { Activator.CreateInstance(boundUiProperty.PropertyInfo.PropertyType) }); } // Setting a UI property which is a string to null can also cause issues. else if (widgetValue == null && boundUiProperty.PropertyInfo.PropertyType == typeof(string)) { boundUiProperty.PropertyInfo.GetSetMethod() .Invoke(boundUiProperty.Object, new object[] { String.Empty }); } else { var value = adapter == null ? widgetValue : adapter.Convert(widgetValue); boundUiProperty.PropertyInfo.GetSetMethod() .Invoke(boundUiProperty.Object, new object[] { value }); } }
public async Task <IActionResult> Post() { IActionResult result = Ok(); try { // using StreamReader due to changes in .Net Core 3 serializer ie ValueKind using (var reader = new StreamReader(Request.Body, Encoding.UTF8)) { var json = await reader.ReadToEndAsync(); var eventGridEventModels = _eventGridSchemaAdapter.Convert(json); foreach (EventGridEventModel model in eventGridEventModels) { // EventGrid validation message if (model.EventType == EventTypes.EventGridSubscriptionValidationEvent) { var eventData = ((JObject)(model.EventData)).ToObject <SubscriptionValidationEventData>(); var responseData = new SubscriptionValidationResponse() { ValidationResponse = eventData.ValidationCode }; return(Ok(responseData)); } // handle all other events this.HandleEvent(model); return(result); } } } catch (Exception ex) { result = new StatusCodeResult(StatusCodes.Status500InternalServerError); } return(result); }