コード例 #1
0
        /// <summary>
        /// Convert from service result to diagnostics info
        /// </summary>
        /// <param name="result"></param>
        /// <param name="config"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static List <OperationResultModel> ToOperationResults(this ServiceResultModel result,
                                                                     DiagnosticsModel config, ServiceMessageContext context)
        {
            if (result?.Diagnostics == null)
            {
                return(null);
            }
            var root = kDiagnosticsProperty;

            switch (config?.Level ?? Twin.Models.DiagnosticsLevel.Status)
            {
            case Twin.Models.DiagnosticsLevel.Diagnostics:
            case Twin.Models.DiagnosticsLevel.Verbose:
                using (var decoder = new JsonDecoderEx(result.Diagnostics.CreateReader(), context)) {
                    var results = decoder.ReadEncodeableArray <OperationResultModel>(root).ToList();
                    if (results.Count == 0)
                    {
                        return(null);
                    }
                    return(results);
                }

            case Twin.Models.DiagnosticsLevel.Status:
                // TODO
                break;

            case Twin.Models.DiagnosticsLevel.Operations:
                // TODO
                break;

            default:
                break;
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Convert from service result to diagnostics info
        /// </summary>
        /// <param name="result"></param>
        /// <param name="config"></param>
        /// <param name="codec"></param>
        /// <returns></returns>
        public static List <OperationResultModel> Decode(
            this IVariantEncoder codec, ServiceResultModel result, DiagnosticsModel config)
        {
            if (result?.Diagnostics == null)
            {
                return(null);
            }
            var root = kDiagnosticsProperty;

            switch (config?.Level ?? Core.Models.DiagnosticsLevel.Status)
            {
            case Core.Models.DiagnosticsLevel.Diagnostics:
            case Core.Models.DiagnosticsLevel.Verbose:
                using (var text = new StringReader(result.Diagnostics.ToString()))
                    using (var reader = new Newtonsoft.Json.JsonTextReader(text))
                        using (var decoder = new JsonDecoderEx(reader, codec.Context)) {
                            var results = decoder.ReadEncodeableArray <OperationResultModel>(root).ToList();
                            if (results.Count == 0)
                            {
                                return(null);
                            }
                            return(results);
                        }

            case Core.Models.DiagnosticsLevel.Status:
                // TODO
                break;

            case Core.Models.DiagnosticsLevel.Operations:
                // TODO
                break;

            default:
                break;
            }
            return(null);
        }