public object ExecuteEmailRetriever(EbApi Api, Service Service, EbStaticFileClient FileClient, bool isMq) { try { EbConnectionFactory EbConnectionFactory = new EbConnectionFactory(Api.SolutionId, Api.Redis); if (EbConnectionFactory.EmailRetrieveConnection[this.MailConnection] != null) { RetrieverResponse retrieverResponse = EbConnectionFactory.EmailRetrieveConnection[this.MailConnection].Retrieve(Service, this.DefaultSyncDate, FileClient, Api.SolutionId, isMq, SubmitAttachmentAsMultipleForm); EbWebForm _form = Api.Redis.Get <EbWebForm>(this.Reference); SchemaHelper.GetWebFormSchema(_form); if (!(_form is null)) { WebformData data = _form.GetEmptyModel(); foreach (RetrieverMessage _m in retrieverResponse?.RetrieverMessages) { InsertFormData(_form, data, _m, this.Reference, Api.SolutionId, Api.UserObject, Api.Redis, Service, EbConnectionFactory); } } else { throw new ApiException("[ExecuteEmailRetriever], form objects is not in redis."); } } else { throw new ApiException("[ExecuteEmailRetriever], mail connection doesn't exist."); } }
public void AfterRedisGetBasicInfoByService(Service service, IRedisClient Redis) { this.FormLinks = new List <FormLink>(); foreach (DVBaseColumn col in this.Columns) { if (col.Check4FormLink()) { try { this.WebForm = Redis.Get <EbWebForm>(col.LinkRefId); if (this.WebForm == null) { var result = service.Gateway.Send <EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest { RefId = col.LinkRefId }); this.WebForm = EbSerializers.Json_Deserialize(result.Data[0].Json); Redis.Set <EbWebForm>(col.LinkRefId, this.WebForm); } this.FormLinks.Add(new FormLink { DisplayName = this.WebForm.DisplayName, Refid = col.LinkRefId, Params = col.FormParameters }); } catch (Exception e) { Console.WriteLine("AfterRedisGetBasicInfo " + e.Message); } } } }
//Process => Notifications property + Notifications from nextStage script of review ctrl public static int SendNotifications(EbWebForm _this, EbConnectionFactory ConnFactory, Service service) { if (_this.Notifications?.Count == 0) { return(0); } int resp = 0; try { FG_Root globals = GlobalsGenerator.GetCSharpFormGlobals_NEW(_this, _this.FormData, _this.FormDataBackup, ConnFactory.DataDB, null, false); foreach (EbFormNotification ebFn in _this.Notifications) { if (!string.IsNullOrEmpty(ebFn.SendOnlyIf?.Code)) { object soi = _this.ExecuteCSharpScriptNew(ebFn.SendOnlyIf.Code, globals); if (!(soi is bool && Convert.ToBoolean(soi))) { Console.WriteLine($"SendNotifications [SendOnlyIf is not TRUE]: {ebFn.GetType().Name}({ebFn.Name}) skipped."); continue; } } ebFn.SendNotification(_this, ConnFactory, service, globals, ref resp); } } catch (FormException ex) { Console.WriteLine($"Exception: {ex.Message}\nCode: {ex.ExceptionCode}\nMessageInternal: {ex.MessageInternal}\nStackTraceInteranl: {ex.StackTraceInternal}"); } catch (Exception ex) { Console.WriteLine($"Exception: {ex.Message}\nStackTrace: {ex.StackTrace}"); } return(resp); }
public override void SendNotification(EbWebForm _this, EbConnectionFactory ConnFactory, Service service, FG_Root globals, ref int resp) { if (!string.IsNullOrWhiteSpace(this.RefId)) { try { service.Gateway.Send <EmailAttachmenResponse>(new SMSInitialRequest { RefId = this.RefId, Params = new List <Param> { { new Param { Name = "id", Type = ((int)EbDbTypes.Int32).ToString(), Value = _this.TableRowId.ToString() } } }, SolnId = _this.SolutionObj.SolutionID, UserAuthId = _this.UserObj.AuthId, UserId = _this.UserObj.UserId }); } catch (Exception ex) { string temp = $"Exception when tried to send EbFnSms\n Message: ${ex.Message} \nRefId: ${this.RefId} \nStackTrace: ${ex.StackTrace}"; throw new FormException($"Unable to process notification.", (int)HttpStatusCode.InternalServerError, ex.Message, temp); } resp++; } }
public void UpdateWebForm(EbWebForm webForm) { List <EbControl> flatControls = webForm.Controls.FlattenEbControls().ToList(); Dictionary <string, int> counter = new Dictionary <string, int>(); foreach (EbMobileControl ctrl in this.ChildControls) { if (ctrl is EbMobileTableLayout tableLayout) { foreach (EbMobileTableCell cell in tableLayout.CellCollection) { foreach (EbMobileControl tableCtrl in cell.ControlCollection) { this.CreateOrUpdateControl(webForm, flatControls, tableCtrl, counter); } } } else if (ctrl is EbMobileDataGrid) { continue; } else { this.CreateOrUpdateControl(webForm, flatControls, ctrl, counter); } } }
public static void SendSystemNotifications(EbWebForm _this, FG_Root _globals, Service services) { List <Param> p = new List <Param> { { new Param { Name = "id", Type = ((int)EbDbTypes.Int32).ToString(), Value = _this.TableRowId.ToString() } } }; string _params = JsonConvert.SerializeObject(p).ToBase64(); string link = $"/WebForm/Index?_r={_this.RefId}&_p={_params}&_m=1"; foreach (FG_Notification notification in _globals.system.Notifications) { try { string title = notification.Title ?? _this.DisplayName + " notification"; if (notification.NotifyBy == FG_NotifyBy.UserId) { Console.WriteLine($"PostProcessGlobals -> NotifyByUserIDRequest. Tilte: {title}, UserId: {notification.UserId}"); NotifyByUserIDResponse result = services.Gateway.Send <NotifyByUserIDResponse>(new NotifyByUserIDRequest { Link = link, Title = title, UsersID = notification.UserId }); } else if (notification.NotifyBy == FG_NotifyBy.RoleIds) { Console.WriteLine($"PostProcessGlobals -> NotifyByUserRoleRequest. Tilte: {title}, RoleIds: {notification.RoleIds}"); NotifyByUserRoleResponse result = services.Gateway.Send <NotifyByUserRoleResponse>(new NotifyByUserRoleRequest { Link = link, Title = title, RoleID = notification.RoleIds }); } else if (notification.NotifyBy == FG_NotifyBy.UserGroupIds) { Console.WriteLine($"PostProcessGlobals -> NotifyByUserGroupRequest. Tilte: {title}, UserGroupId: {notification.UserGroupIds}"); NotifyByUserGroupResponse result = services.Gateway.Send <NotifyByUserGroupResponse>(new NotifyByUserGroupRequest { Link = link, Title = title, GroupId = notification.UserGroupIds }); } } catch (Exception e) { Console.WriteLine("Exception in PostProcessGlobals: SystemNotification\nMessage: " + e.Message + "\nStackTrace: " + e.StackTrace); } } }
public EbWebForm GenerateWebForm(string displayName) { string guid = Guid.NewGuid().ToString("N"); EbWebForm webForm = new EbWebForm { EbSid = guid, Name = guid, DisplayName = displayName + " (Web)", TableName = this.TableName, Padding = new UISides { Top = 20, Right = 20, Bottom = 20, Left = 20 } }; Dictionary <string, int> counter = new Dictionary <string, int>(); foreach (EbMobileControl ctrl in this.ChildControls) { if (ctrl is EbMobileTableLayout tableLayout) { foreach (EbMobileTableCell cell in tableLayout.CellCollection) { foreach (EbMobileControl tableCtrl in cell.ControlCollection) { int count = this.GetControlCount(tableCtrl, counter); EbControl ebControl = tableCtrl.GetWebFormControl(count); webForm.Controls.Add(ebControl); } } } else if (ctrl is EbMobileDataGrid) { continue; } else { int count = this.GetControlCount(ctrl, counter); EbControl ebControl = ctrl.GetWebFormControl(count); webForm.Controls.Add(ebControl); } } return(webForm); }
//for system/mobile notification public DbParameter[] GetParameters(EbWebForm _this, IDatabase DataDB, Dictionary <string, string> QryParams) { List <DbParameter> _p = new List <DbParameter>(); int _idx = 0; foreach (KeyValuePair <string, string> p in QryParams) { SingleTable Table = null; if (_this.FormData.MultipleTables.ContainsKey(p.Value)) { Table = _this.FormData.MultipleTables[p.Value]; } else if (_this.FormDataBackup?.MultipleTables.ContainsKey(p.Value) == true) { Table = _this.FormDataBackup.MultipleTables[p.Value]; } else { throw new FormException("Bad Request", (int)HttpStatusCode.BadRequest, $"SendNotifications: Notify by UserId parameter {p.Key} is not idetified", $"{p.Value} not found in MultipleTables"); } TableSchema _table = _this.FormSchema.Tables.Find(e => e.TableName == p.Value); if (_table.TableType != WebFormTableTypes.Normal) { throw new FormException("Bad Request", (int)HttpStatusCode.BadRequest, $"SendNotifications: Notify by UserId parameter {p.Key} is not idetified", $"{p.Value} found in MultipleTables but it is not a normal table"); } if (Table.Count != 1) { throw new FormException("Bad Request", (int)HttpStatusCode.BadRequest, $"SendNotifications: Notify by UserId parameter {p.Key} is not idetified", $"{p.Value} found in MultipleTables but table is empty"); } SingleColumn Column = Table[0].Columns.Find(e => e.Control?.Name == p.Key); if (Column?.Control == null) { throw new FormException("Bad Request", (int)HttpStatusCode.BadRequest, $"SendNotifications: Notify by UserId parameter {p.Key} is not idetified", $"{p.Value} found in MultipleTables but data not available"); } ParameterizeCtrl_Params args = new ParameterizeCtrl_Params(DataDB, _p, Column, _idx, _this.UserObj); Column.Control.ParameterizeControl(args, _this.CrudContext); _idx = args.i; _p[_idx - 1].ParameterName = p.Key; } return(_p.ToArray()); }
private void CreateOrUpdateControl(EbWebForm webForm, List <EbControl> flatControls, EbMobileControl ctrl, Dictionary <string, int> counter) { EbControl control = flatControls.Find(c => c.Name == ctrl.Name); if (control != null) { string cType = control.GetType().Name; if (!counter.ContainsKey(cType)) { counter[cType] = 0; } try { MatchCollection cmatch = CounterRegex.Matches(control.EbSid); if (cmatch.Count > 0) { int c = Convert.ToInt32(cmatch.LastOrDefault().Value); counter[cType] = counter[cType] < c ? c : counter[cType]; } } catch (Exception ex) { counter[cType]++; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } ctrl.UpdateWebFormControl(control); } else { string name = ctrl.EbControlType; counter[name] = counter.ContainsKey(name) ? ++counter[name] : 0; webForm.Controls.Add(ctrl.GetWebFormControl(counter[name])); } }
//Send my actions push notifications public static async Task <EbNFResponse> SendMobileNotification(EbWebForm _this, EbConnectionFactory ConnFactory, Service service) { EbNFResponse resp = new EbNFResponse("0"); try { if (_this.MyActNotification?.SendPushNotification == true && ConnFactory.MobileAppConnection != null) { List <int> userIds = new List <int>(); if (_this.MyActNotification.ApproverEntity == ApproverEntityTypes.Users) { userIds = _this.MyActNotification.UserIds; } else if (_this.MyActNotification.ApproverEntity == ApproverEntityTypes.Role || _this.MyActNotification.ApproverEntity == ApproverEntityTypes.DynamicRole || _this.MyActNotification.ApproverEntity == ApproverEntityTypes.UserGroup) { string Qry; if (_this.MyActNotification.ApproverEntity == ApproverEntityTypes.UserGroup) { Qry = $"SELECT userid FROM eb_user2usergroup WHERE groupid = {_this.MyActNotification.UserGroupId} AND COALESCE(eb_del, 'F') = 'F'; "; } else// static/dynamic role { Qry = $"SELECT user_id FROM eb_role2user WHERE role_id = ANY(STRING_TO_ARRAY('{_this.MyActNotification.RoleIds.Join(",")}'::TEXT, ',')::INT[]) AND COALESCE(eb_del, 'F') = 'F'; "; } EbDataTable dt = ConnFactory.DataDB.DoQuery(Qry); foreach (EbDataRow dr in dt.Rows) { int.TryParse(dr[0].ToString(), out int temp); if (!userIds.Contains(temp)) { userIds.Add(temp); } } } else { throw new Exception("Invalid approver entity: " + _this.MyActNotification.ApproverEntity); } if (userIds.Count == 0) { throw new Exception("User Id collection is empty"); } List <string> userAuthIds = new List <string>(); EbNFData Data = new EbNFData() { Title = _this.MyActNotification.Title, Message = _this.MyActNotification.Description, Link = new EbNFLink() { LinkType = EbNFLinkTypes.Action, ActionId = _this.MyActNotification.MyActionId } }; EbAzureNFClient client = EbAzureNFClient.Create(ConnFactory.MobileAppConnection); foreach (int uid in userIds) { string authId = _this.SolutionObj.SolutionID + CharConstants.COLON + uid + CharConstants.COLON + TokenConstants.MC; User user = service.Redis.Get <User>(authId); if (user != null) { if (user.LocationIds.Contains(-1) || user.LocationIds.Contains(_this.LocationId)) { userAuthIds.Add(client.ConvertToAuthTag(authId)); } } } if (userAuthIds.Count > 0) { EbNFRequest req = new EbNFRequest() { Platform = PNSPlatforms.GCM, Tags = userAuthIds }; req.SetPayload(new EbNFDataTemplateAndroid() { Data = Data }); resp = await client.Send(req); } } } catch (Exception ex) { resp.Message = ex.Message; Console.WriteLine("Exception in SendMobileNotification: " + ex.Message); } Console.WriteLine("SendMobileNotification response: " + resp.Message); return(resp); }
public virtual void SendNotification(EbWebForm _this, EbConnectionFactory ConnFactory, Service service, FG_Root globals, ref int resp) { }
public override void SendNotification(EbWebForm _this, EbConnectionFactory ConnFactory, Service service, FG_Root globals, ref int resp) { if (ConnFactory.MobileAppConnection == null) { return; } List <int> uids = new List <int>(); if (this.IsDirectNotification) { uids.Add(this.NotifyUserId); } else { string Qry = null; DbParameter[] _p = null; if (this.NotifyBy == EbFnSys_NotifyBy.Roles) { Qry = $"SELECT user_id FROM eb_role2user WHERE role_id = ANY(STRING_TO_ARRAY('{this.Roles.Join(",")}'::TEXT, ',')::INT[]) AND COALESCE(eb_del, 'F') = 'F'; "; } else if (this.NotifyBy == EbFnSys_NotifyBy.UserGroup) { Qry = $"SELECT userid FROM eb_user2usergroup WHERE groupid = {this.UserGroup} AND COALESCE(eb_del, 'F') = 'F'; "; } else if (this.NotifyBy == EbFnSys_NotifyBy.Users) { Qry = this.Users.Code; _p = this.GetParameters(_this, ConnFactory.DataDB, this.QryParams); } if (!string.IsNullOrWhiteSpace(Qry)) { EbDataTable dt; if (_p == null) { dt = ConnFactory.DataDB.DoQuery(Qry); } else { dt = ConnFactory.DataDB.DoQuery(Qry, _p); } foreach (EbDataRow dr in dt.Rows) { int.TryParse(dr[0].ToString(), out int temp); if (!uids.Contains(temp)) { uids.Add(temp); } } if (uids.Count == 0) { return; } this.ProcessedMsgTitle = _this.DisplayName; if (!string.IsNullOrEmpty(this.MessageTitle?.Code)) { object msg = _this.ExecuteCSharpScriptNew(this.MessageTitle.Code, globals); this.ProcessedMsgTitle = msg.ToString(); } this.ProcessedMessage = string.Empty; if (!string.IsNullOrEmpty(this.Message?.Code)) { object msg = _this.ExecuteCSharpScriptNew(this.Message.Code, globals); this.ProcessedMessage = msg.ToString(); } } } if (uids.Count > 0) { List <string> userAuthIds = new List <string>(); EbNFData Data = new EbNFData() { Title = this.ProcessedMsgTitle, Message = this.ProcessedMessage }; EbAzureNFClient client = EbAzureNFClient.Create(ConnFactory.MobileAppConnection); foreach (int uid in uids) { userAuthIds.Add(client.ConvertToAuthTag(_this.SolutionObj.SolutionID + CharConstants.COLON + uid + CharConstants.COLON + TokenConstants.MC)); } EbNFRequest req = new EbNFRequest() { Platform = PNSPlatforms.GCM, Tags = userAuthIds }; req.SetPayload(new EbNFDataTemplateAndroid() { Data = Data }); try { client.Send(req); } catch (Exception ex) { string temp = $"Exception when tried to send EbFnMobile\n Message: ${ex.Message} \nStackTrace: ${ex.StackTrace}"; throw new FormException($"Unable to process notification.", (int)HttpStatusCode.InternalServerError, ex.Message, temp); } resp++; } }
public override void SendNotification(EbWebForm _this, EbConnectionFactory ConnFactory, Service service, FG_Root globals, ref int resp) { IDatabase DataDB = ConnFactory.DataDB; string message = "Notification from " + _this.DisplayName; if (!string.IsNullOrEmpty(this.Message?.Code)) { object msg = _this.ExecuteCSharpScriptNew(this.Message.Code, globals); message = msg.ToString(); } List <Param> plist = new List <Param> { { new Param { Name = "id", Type = ((int)EbDbTypes.Int32).ToString(), Value = _this.TableRowId.ToString() } } }; string _params = JsonConvert.SerializeObject(plist).ToBase64(); string link = $"/WebForm/Index?_r={_this.RefId}&_p={_params}&_m=1"; if (this.NotifyBy == EbFnSys_NotifyBy.Roles) { try { NotifyByUserRoleResponse result = service.Gateway.Send <NotifyByUserRoleResponse>(new NotifyByUserRoleRequest { Link = link, Title = message, RoleID = this.Roles }); } catch (Exception ex) { string temp = $"Exception when tried to send EbFnSys_NotifyBy.Roles\n Message: ${ex.Message} \nLink: ${link} \nTitle: ${message} \nRolesId: ${(this?.Roles == null ? "null" : string.Join(",", this.Roles))} \nStackTrace: ${ex.StackTrace}"; //Console.WriteLine(temp); throw new FormException($"Unable to process notification.", (int)HttpStatusCode.InternalServerError, ex.Message, temp); } resp++; } else if (this.NotifyBy == EbFnSys_NotifyBy.UserGroup) { try { NotifyByUserGroupResponse result = service.Gateway.Send <NotifyByUserGroupResponse>(new NotifyByUserGroupRequest { Link = link, Title = message, GroupId = new List <int> { this.UserGroup } }); } catch (Exception ex) { string temp = $"Exception when tried to send EbFnSys_NotifyBy.UserGroup\n Message: ${ex.Message} \nLink: ${link} \nTitle: ${message} \nGroupId: ${this.UserGroup} \nStackTrace: ${ex.StackTrace}"; //Console.WriteLine(temp); throw new FormException($"Unable to process notification.", (int)HttpStatusCode.InternalServerError, ex.Message, temp); } resp++; } else if (this.NotifyBy == EbFnSys_NotifyBy.Users) { DbParameter[] _p = this.GetParameters(_this, ConnFactory.DataDB, this.QryParams); List <int> uids = new List <int>(); EbDataTable dt = DataDB.DoQuery(this.Users.Code, _p); foreach (EbDataRow dr in dt.Rows) { int.TryParse(dr[0].ToString(), out int temp); if (!uids.Contains(temp)) { uids.Add(temp); } } foreach (int uid in uids) { try { NotifyByUserIDResponse result = service.Gateway.Send <NotifyByUserIDResponse>(new NotifyByUserIDRequest { Link = link, Title = message, UsersID = uid, User_AuthId = _this.UserObj.AuthId }); } catch (Exception ex) { string temp = $"Exception when tried to send EbFnSys_NotifyBy.Users\n Message: ${ex.Message} \nLink: ${link} \nTitle: ${message} \nUserId: ${uid} \nStackTrace: ${ex.StackTrace}"; Console.WriteLine("NotifyByUserIDRequest Inner Exception 1" + ex.InnerException?.Message + ex.InnerException?.StackTrace); Console.WriteLine("NotifyByUserIDRequest Inner Exception 2 " + ex.InnerException?.InnerException?.Message + ex.InnerException?.InnerException?.StackTrace); throw new FormException($"Unable to process notification.", (int)HttpStatusCode.InternalServerError, ex.Message, temp); } } if (uids.Count > 0) { resp++; } } }
public void AfterRedisGetBasicInfo(IServiceClient client, IRedisClient Redis) { this.FormLinks = new List <FormLink>(); foreach (DVBaseColumn col in this.Columns) { if (col.Check4FormLink()) { try { this.WebForm = Redis.Get <EbWebForm>(col.LinkRefId); if (this.WebForm == null) { var result = client.Get <EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest { RefId = col.LinkRefId }); this.WebForm = EbSerializers.Json_Deserialize(result.Data[0].Json); Redis.Set <EbWebForm>(col.LinkRefId, this.WebForm); } this.FormLinks.Add(new FormLink { DisplayName = this.WebForm.DisplayName, Refid = col.LinkRefId, Params = col.FormParameters }); } catch (Exception e) { Console.WriteLine("AfterRedisGetBasicInfo " + e.Message); } } } this.FormLinks = this.FormLinks.GroupBy(x => x.Refid).Select(x => x.First()).ToList(); DVBaseColumn Col = this.Columns.Get("eb_action"); if (Col != null) { foreach (DVColumnCollection _colcoll in this.ColumnsCollection) { DVBaseColumn __col = _colcoll.Pop(Col.Name, EbDbTypes.String, false); } if (Col is DVStringColumn && this.AutoGen) { DVBaseColumn actcol = new DVActionColumn { Data = Col.Data, Name = Col.Name, sTitle = Col.sTitle, Type = EbDbTypes.String, bVisible = true, sWidth = "100px", ClassName = Col.ClassName, LinkRefId = Col.LinkRefId, LinkType = Col.LinkType, FormMode = Col.FormMode, FormId = Col.FormId, Align = Align.Center, IsCustomColumn = true }; this.Columns.Remove(Col); this.Columns.Add(actcol); } } if (this.Columns.Get("eb_created_by") != null) { this.Columns.Get("eb_created_by").RenderType = EbDbTypes.String; } if (this.Columns.Get("eb_lastmodified_by") != null) { this.Columns.Get("eb_lastmodified_by").RenderType = EbDbTypes.String; } if (this.Columns.Get("eb_loc_id") != null) { this.Columns.Get("eb_loc_id").RenderType = EbDbTypes.String; } }