public static COMException CreateException(this TraceType traceType, NativeTypes.FABRIC_ERROR_CODE error, string format, params object[] args) { string message = string.Format(CultureInfo.InvariantCulture, format, args); var exception = new COMException(message, (int)error); traceSource.WriteExceptionAsWarningWithId(traceType.Name, traceType.Id, exception, string.Empty); return(exception); }
public static COMException CreateException(string traceType, NativeTypes.FABRIC_ERROR_CODE error, string format, params object[] args) { string message = string.Format(CultureInfo.InvariantCulture, format, args); var exception = new COMException(message, (int)error); TestabilityTrace.TraceSource.WriteWarning(traceType, exception.ToString()); return(exception); }
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); }
public static bool TryGetErrorCode(Exception exception, out NativeTypes.FABRIC_ERROR_CODE errorCode) { ReleaseAssert.AssertIf(exception == null, "Exception cannot be null in TryGetErrorCode"); errorCode = NativeTypes.FABRIC_ERROR_CODE.E_FAIL; COMException comException = exception.InnerException as COMException; if (comException == null) { TestabilityTrace.TraceSource.WriteWarning( TraceSource, "Client operation failed with exception which does not have inner com exception to extract error code for handling: {0}", exception); return(false); } errorCode = (NativeTypes.FABRIC_ERROR_CODE)comException.ErrorCode; ReleaseAssert.AssertIf(errorCode == 0, "HRESULT cannot be 0 for exception: {0}", exception); return(true); }
internal static OperationResult <TResult[]> GetOperationResultArray(NativeTypes.FABRIC_ERROR_CODE errorCode, IEnumerable <TResult> resultList) { TResult[] resultArray = resultList == null ? null : resultList.ToArray(); return(FabricClientState.CreateOperationResultFromNativeErrorCode <TResult[]>(errorCode, resultArray)); }
public static OperationResult CreateOperationResultFromNativeErrorCode(NativeTypes.FABRIC_ERROR_CODE errorCode) { return(new OperationResult((uint)errorCode)); }
public static OperationResult <T> CreateOperationResultFromNativeErrorCode <T>(NativeTypes.FABRIC_ERROR_CODE errorCode) { return(new OperationResult <T>((uint)errorCode, default(T))); }
public static OperationResult <WinFabricRepairTask[]> ConvertToWinFabricRepairTaskList(IList <RepairTask> repairTaskList, NativeTypes.FABRIC_ERROR_CODE errorCode) { OperationResult <WinFabricRepairTask[]> actualResult = FabricClientState.CreateOperationResultFromNativeErrorCode <WinFabricRepairTask[]>(errorCode); if (repairTaskList != null) { IList <WinFabricRepairTask> winFabricRepairTasks = new List <WinFabricRepairTask>(repairTaskList.Count); foreach (RepairTask repairTask in repairTaskList) { WinFabricRepairTask winFabricRepairTask = Convert(repairTask); winFabricRepairTasks.Add(winFabricRepairTask); } actualResult = FabricClientState.CreateOperationResultFromNativeErrorCode <WinFabricRepairTask[]>(winFabricRepairTasks.ToArray()); } return(actualResult); }
public OperationResult <TestServicePartitionInfo[]> ConvertToServicePartitionResult(NativeTypes.FABRIC_ERROR_CODE errorCode, ResolvedServicePartition resolvedPartition) { OperationResult <TestServicePartitionInfo[]> result = FabricClientState.CreateOperationResultFromNativeErrorCode <TestServicePartitionInfo[]>(errorCode); if (resolvedPartition != null) { // Store ResolvedServicePartition object when the users need to call apis on this object int id = this.PartitionHolder.StoreObject(resolvedPartition); result = FabricClientState.Convert(resolvedPartition, id); } return(result); }
public async Task <uint> ExecuteAndConvertExceptionToUintAsync(Func <Task> operation) { NativeTypes.FABRIC_ERROR_CODE errorCode = await HandleExceptionAsync(operation); return((uint)errorCode); }