コード例 #1
0
        /// <summary>
        /// Convert to service model
        /// </summary>
        /// <param name="diagnostics"></param>
        /// <param name="config"></param>
        /// <param name="codec"></param>
        /// <returns></returns>
        public static ServiceResultModel Encode(this IVariantEncoder codec,
                                                List <OperationResultModel> diagnostics, DiagnosticsModel config)
        {
            if ((diagnostics?.Count ?? 0) == 0)
            {
                return(null); // All well
            }
            var result     = diagnostics.LastOrDefault(d => !d.TraceOnly);
            var statusCode = result?.StatusCode;

            return(new ServiceResultModel {
                // The last operation result is the one that caused the service to fail.
                StatusCode = statusCode?.Code,
                ErrorMessage = result?.DiagnosticsInfo?.AdditionalInfo ?? (statusCode == null ?
                                                                           null : StatusCode.LookupSymbolicId(statusCode.Value.CodeBits)),
                Diagnostics = codec.Write(diagnostics, config)
            });
        }
コード例 #2
0
 /// <summary>
 /// Convert to service model
 /// </summary>
 /// <param name="statusCode"></param>
 /// <param name="diagnosticsInfo"></param>
 /// <param name="config"></param>
 /// <param name="codec"></param>
 /// <returns></returns>
 public static ServiceResultModel Encode(this IVariantEncoder codec,
                                         StatusCode?statusCode, DiagnosticInfo diagnosticsInfo = null,
                                         DiagnosticsModel config = null)
 {
     if ((statusCode?.Code ?? StatusCodes.Good) == StatusCodes.Good)
     {
         return(null); // All well
     }
     return(new ServiceResultModel {
         // The last operation result is the one that caused the service to fail.
         StatusCode = statusCode?.Code,
         ErrorMessage = diagnosticsInfo?.AdditionalInfo ?? (statusCode == null ?
                                                            null : StatusCode.LookupSymbolicId(statusCode.Value.CodeBits)),
         Diagnostics = config == null ? null : codec.Write(
             new List <OperationResultModel> {
             new OperationResultModel {
                 DiagnosticsInfo = diagnosticsInfo,
                 StatusCode = statusCode.Value
             }
         }, config)
     });
 }