public IActionResult GenericPost([FromBody] GenericRequest request) { Log.Debug("BEGUN: Start Post Method"); IEFTPlugin plugin; var response = new GenericResponse() { Payload = request.PayLoad, Info = request.Info, Result = new Result() { ErrorCode = "", OperationType = request.OperationType, } }; //var operation = DictionaryExtensions.DictionaryToObject<Operation>(request.PayLoad.AdditionalInfo); //operation.CashierID = request.PayLoad.CashierID; //operation.CurrencyCode = request.PayLoad.CurrencyCode; //operation.SessionId = request.PayLoad.SessionId; //operation.OperationType = request.OperationType; try { _plugins = PluginLoadContext.ReadExtensions(Config); plugin = _plugins; var infoPlugin = plugin.GetInfo(); response.Info.PluginInfo = infoPlugin; if (!infoPlugin.Capabilities.Any(x => x.ToLower() == request.OperationType.ToLower())) { response.Result.Status = "Error"; response.Result.ResponseCode = "Operation not supported"; Log.Fatal("END: Operation not supported by plugin"); return(BadRequest(JsonConvert.SerializeObject(response))); } else { if (synch) { Log.Debug("END: Post Method"); return(Post(request, response, plugin)); } else { Log.Debug("END: Post Method"); return(PostAsync(request, response, plugin)); } } } catch (Exception e) { Log.Fatal("END: Error ", e); return(BadRequest(JsonConvert.SerializeObject(response))); } }
public IActionResult Post(GenericRequest request, GenericResponse response, IEFTPlugin plugin) { MethodInfo theMethod = plugin.GetType().GetMethod(request.OperationType); response = (GenericResponse)theMethod.Invoke(plugin, new object[] { request, response }); // response = plugin.Request(request, response); return(Ok(JsonConvert.SerializeObject(response))); }
public static IEFTPlugin GetTypeFromAssembly(string typeName, IOptions <ConfigInfo> Config) { var assemblyQName = GetAssemblyName(typeName); IEFTPlugin printerObject = null; if (!string.IsNullOrEmpty(assemblyQName)) { var type = Type.GetType(assemblyQName); printerObject = Activator.CreateInstance(type, Config) as IEFTPlugin; } return(printerObject); }
public void GetInfo_ShouldReturnPluginInfoIfExist() { ConfigureWithoutBindMethod(); try { _plugins = PluginLoadContext.ReadExtensions(Config); } catch (Exception e) { } ConfigureWithoutBindMethod(); var infoPlugin = _plugins.GetInfo(); Assert.IsNotNull(infoPlugin); }
public void InitMethod_ReturnError() { ConfigureWithoutBindMethod(); try { _plugins = PluginLoadContext.ReadExtensions(Config); } catch (Exception e) { } request.OperationType = "init"; var init = _plugins.Init(request, response); Assert.AreEqual(init.Result.Status, "Success"); //Mock<IEFTPlugin> mock1 = new Mock<IEFTPlugin>(); //var tes=mock1.Setup(x => x.Init(request, response)).Returns(response); //var t = tes; }
public IActionResult PostAsync(GenericRequest request, GenericResponse response, IEFTPlugin plugin) { response.Result.Status = "processing"; new Task(() => { MethodInfo theMethod = plugin.GetType().GetMethod(request.OperationType); response = (GenericResponse)theMethod.Invoke(plugin, new object[] { request, response }); MongoDatabase.Update(response.Result); }).Start(); Save(response.Result); return(Ok(JsonConvert.SerializeObject(response))); }