12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- namespace Cbdx
- {
- internal class DataExchangeDispatcher : IDataExchangeDispatcher
- {
- private readonly Dictionary<string, Dictionary<string, ServiceActionBind>> _serviceDictionary;
- public DataExchangeDispatcher(Dictionary<string, Dictionary<string, ServiceActionBind>> serviceDictionary)
- {
- _serviceDictionary = serviceDictionary;
- }
- public string InvokeService(string service, string action, string input)
- {
- DataExchangeResultBase result;
- try
- {
- if (false == _serviceDictionary.TryGetValue(service, out var controller)) throw new EntryPointNotFoundException($"Service [{service}] not found");
- if (false == controller.TryGetValue(action, out var actionBind)) throw new EntryPointNotFoundException($"Action [{action}] on [{service}] not found");
- var ret = actionBind.Invoke(input);
- result = new DataExchangeDataResult<object> { Success = true, Data = ret };
- }
- catch (Exception ex)
- {
- result = new DataExchangeErrorResult(ex.Message, ex.StackTrace);
- }
- return JsonConvert.SerializeObject(result);
- }
- }
- }
|