Exemple #1
0
        //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);
        }
Exemple #2
0
        //send notifications and email etc
        public static void PostProcessGlobals(EbWebForm _this, FG_Root _globals, Service services)
        {
            if (_globals.system == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(_this.RefId) || _this.TableRowId <= 0)
            {
                return;
            }

            if (_globals.system.Notifications.Count > 0)
            {
                EbFnGateway.SendSystemNotifications(_this, _globals, services);
            }

            if (_globals.system.EmailNotifications.Count > 0)
            {
                if (_this.Notifications == null)
                {
                    _this.Notifications = new List <EbFormNotification>();
                }

                foreach (FG_EmailNotification notification in _globals.system.EmailNotifications)
                {
                    _this.Notifications.Add(new EbFnEmail()
                    {
                        RefId = notification.RefId
                    });
                }
            }

            if (_globals.system.PushNotifications.Count > 0)
            {
                if (_this.Notifications == null)
                {
                    _this.Notifications = new List <EbFormNotification>();
                }

                foreach (FG_Notification notification in _globals.system.PushNotifications)
                {
                    _this.Notifications.Add(new EbFnMobile()
                    {
                        IsDirectNotification = true,
                        NotifyUserId         = notification.UserId,
                        ProcessedMsgTitle    = notification.Title ?? _this.DisplayName,
                        ProcessedMessage     = notification.Message ?? string.Empty
                    });
                }
            }
        }
Exemple #3
0
        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);
                }
            }
        }
Exemple #4
0
 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++;
     }
 }
Exemple #5
0
 public virtual void SendNotification(EbWebForm _this, EbConnectionFactory ConnFactory, Service service, FG_Root globals, ref int resp)
 {
 }
Exemple #6
0
        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++;
            }
        }
Exemple #7
0
        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++;
                }
            }
        }