public static object GetNamedPropertyValue(NamedProperty property) { ThrowIf.Null(property, "property"); object propertyValue = null; // Special case GetValue calls (See Bug: 860194 for details)... FabricErrorCode errorCode = (FabricErrorCode)FabricClientState.HandleException(() => propertyValue = property.GetValue <object>()); if (errorCode != 0 && errorCode != FabricErrorCode.PropertyValueEmpty) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "GetProperty failed with an unexpected error code {0}", errorCode)); } return(propertyValue); }
internal async Task <NativeTypes.FABRIC_ERROR_CODE> HandleExceptionAsync(Func <Task> operation) { // TODO: this currently doesn't catch all exceptions // For example, if there is a null reference exception, it will return error code success // This should probably be changed to catch all NativeTypes.FABRIC_ERROR_CODE errorCode = 0; try { await operation(); } catch (CmdletInvocationException e) { if (!FabricClientState.TryGetErrorCode(e.InnerException, out errorCode)) { throw; } } catch (AggregateException e) { bool foundErrorCode = false; if (e.InnerExceptions != null) { foreach (Exception inner in e.Flatten().InnerExceptions) { if (FabricClientState.TryGetErrorCode(inner, out errorCode)) { foundErrorCode = true; break; } } } if (!foundErrorCode) { throw; } } return(errorCode); }