public bool ExecuteEmail(EbApi Api, RabbitMqProducer MessageProducer3) { bool status; try { EbEmailTemplate emailTemplate = Api.GetEbObject <EbEmailTemplate>(this.Reference, Api.Redis, Api.ObjectsDB); List <Param> InputParams = EbApiHelper.GetEmailParams(emailTemplate, Api.Redis, Api.ObjectsDB); Api.FillParams(InputParams); MessageProducer3.Publish(new EmailAttachmentRequest() { ObjId = Convert.ToInt32(this.Reference.Split(CharConstants.DASH)[3]), Params = InputParams, UserId = Api.UserObject.UserId, UserAuthId = Api.UserObject.AuthId, SolnId = Api.SolutionId, RefId = this.Reference }); status = true; string msg = $"The mail has been sent successfully to {emailTemplate.To} with subject {emailTemplate.Subject} and cc {emailTemplate.Cc}"; Api.ApiResponse.Message.Description = msg; } catch (Exception ex) { throw new ApiException("[ExecuteEmail], " + ex.Message); } return(status); }
public T GetEbObject <T>(string refId, IRedisClient Redis, IDatabase ObjectsDB) { T ebObject = EbApiHelper.GetEbObject <T>(refId, Redis, ObjectsDB); if (ebObject == null) { string message = $"{typeof(T).Name} not found"; this.ApiResponse.Message.Description = message; throw new ApiException(message); } return(ebObject); }
public object ExecuteConnectApi(EbApi Api, Service Service) { ApiResponse resp = null; try { EbApi apiObject = Api.GetEbObject <EbApi>(this.Reference, Api.Redis, Api.ObjectsDB); if (apiObject.Name.Equals(Api.Name)) { Api.ApiResponse.Message.ErrorCode = ApiErrorCode.ResourceCircularRef; Api.ApiResponse.Message.Description = "Calling Api from the same not allowed, terminated due to circular reference"; throw new ApiException("[ExecuteConnectApi], Circular refernce"); } else { List <Param> InputParam = EbApiHelper.GetReqJsonParameters(apiObject.Resources, Api.Redis, Api.ObjectsDB); Api.FillParams(InputParam); Dictionary <string, object> d = InputParam.Select(p => new { prop = p.Name, val = p.Value }).ToDictionary(x => x.prop, x => x.val as object); string version = this.Version.Replace(".w", ""); resp = Service.Gateway.Send(new ApiMqRequest { Name = this.RefName, Version = version, Data = d, SolnId = Api.SolutionId, UserAuthId = Api.UserObject.AuthId, UserId = Api.UserObject.UserId }); if (resp.Message.ErrorCode == ApiErrorCode.NotFound) { Api.ApiResponse.Message.ErrorCode = ApiErrorCode.ResourceNotFound; Api.ApiResponse.Message.Description = resp.Message.Description; throw new ApiException("[ExecuteConnectApi], resource api not found"); } } } catch (Exception ex) { throw new ApiException("[ExecuteConnectApi], " + ex.Message); } return(resp); }
private object GetResult(ApiResources resource) { try { return(EbApiHelper.GetResult(resource, this.Api, MessageProducer3, this, this.FileClient)); } catch (Exception ex) { if (ex is ExplicitExitException) { this.Api.ApiResponse.Message.Status = "Success"; this.Api.ApiResponse.Message.Description = ex.Message; this.Api.ApiResponse.Message.ErrorCode = ApiErrorCode.ExplicitExit; } else { this.Api.ApiResponse.Message.Status = "Error"; this.Api.ApiResponse.Message.Description = $"Failed to execute Resource '{resource.Name}' " + ex.Message; } throw new ApiException("[GetResult] ," + ex.Message); } }
public void GetApiObject(ApiMqRequest request) { int UserId; string SolutionId; string UserAuthId; Dictionary <string, object> ApiData; if (request.HasRefId()) { SolutionId = request.JobArgs.SolnId; UserAuthId = request.JobArgs.UserAuthId; ApiData = request.JobArgs.ApiData; UserId = request.JobArgs.UserId; try { this.Api = new EbApi(); this.EbConnectionFactory = new EbConnectionFactory(SolutionId, Redis); this.Api = Api.GetApi(request.JobArgs?.RefId, this.Redis, this.EbConnectionFactory.DataDB, this.EbConnectionFactory.ObjectsDB); this.Api.ApiResponse = new ApiResponse(); } catch (Exception ex) { Console.WriteLine($"Failed resolve api object from refid '{request.JobArgs?.RefId}'"); Console.WriteLine(ex.Message); } } else { SolutionId = request.SolnId; UserAuthId = request.UserAuthId; ApiData = request.Data; UserId = request.UserId; try { this.EbConnectionFactory = new EbConnectionFactory(SolutionId, Redis); this.Api = EbApiHelper.GetApiByName(request.Name, request.Version, this.EbConnectionFactory.ObjectsDB); if (!(this.Api is null)) { Api.Redis = this.Redis; Api.ObjectsDB = this.EbConnectionFactory.ObjectsDB; Api.DataDB = this.EbConnectionFactory.DataDB; this.Api.ApiResponse = new ApiResponse(); } } catch (Exception ex) { Console.WriteLine($"Failed resolve api object from refid '{this.Api?.RefId}'"); Console.WriteLine(ex.Message); } } if (this.Api is null) { this.Api = new EbApi { ApiResponse = new ApiResponse() }; this.Api.ApiResponse.Message.ErrorCode = ApiErrorCode.ApiNotFound; this.Api.ApiResponse.Message.Status = "Api does not exist"; this.Api.ApiResponse.Message.Description = $"Api does not exist!,"; throw new Exception(this.Api.ApiResponse.Message.Description); } this.Api.SolutionId = SolutionId; this.Api.UserObject = GetUserObject(UserAuthId); this.Api.GlobalParams = ProcessGlobalDictionary(ApiData); this.Api.GlobalParams["eb_currentuser_id"] = UserId; if (!this.Api.GlobalParams.ContainsKey("eb_loc_id")) { this.Api.GlobalParams["eb_loc_id"] = this.Api.UserObject.Preference.DefaultLocation; } }
public object ExecuteScript(EbApi Api, RabbitMqProducer mqp, Service service, EbStaticFileClient Fileclient) { ApiGlobalParent global; if (this.EvaluatorVersion == EvaluatorVersion.Version_1) { global = new ApiGlobals(Api.GlobalParams); } else { global = new ApiGlobalsCoreBase(Api.GlobalParams); } global.ResourceValueByIndexHandler += (index) => { object resourceValue = Api.Resources[index].Result; if (resourceValue != null && resourceValue is string converted) { if (converted.StartsWith("{") && converted.EndsWith("}") || converted.StartsWith("[") && converted.EndsWith("]")) { string formated = converted.Replace(@"\", string.Empty); return(JObject.Parse(formated)); } } return(resourceValue); }; global.ResourceValueByNameHandler += (name) => { int index = Api.Resources.GetIndex(name); object resourceValue = Api.Resources[index].Result; if (resourceValue != null && resourceValue is string converted) { if (converted.StartsWith("{") && converted.EndsWith("}") || converted.StartsWith("[") && converted.EndsWith("]")) { string formated = converted.Replace(@"\", string.Empty); return(JObject.Parse(formated)); } } return(resourceValue); }; global.GoToByIndexHandler += (index) => { Api.Step = index; Api.Resources[index].Result = EbApiHelper.GetResult(Api.Resources[index], Api, mqp, service, Fileclient); }; global.GoToByNameHandler += (name) => { int index = Api.Resources.GetIndex(name); Api.Step = index; Api.Resources[index].Result = EbApiHelper.GetResult(Api.Resources[index], Api, mqp, service, Fileclient); }; global.ExitResultHandler += (obj) => { ApiScript script = new ApiScript { Data = JsonConvert.SerializeObject(obj), }; Api.ApiResponse.Result = script; Api.Step = Api.Resources.Count - 1; }; ApiResources lastResource = Api.Step == 0 ? null : Api.Resources[Api.Step - 1]; if (this.EvaluatorVersion == EvaluatorVersion.Version_1 && lastResource?.Result is EbDataSet dataSet) { (global as ApiGlobals).Tables = dataSet.Tables; } ApiScript result; try { result = this.Execute(global); } catch (Exception ex) { throw ex; } return(result); }