Ejemplo n.º 1
0
 public void sendNotificationByUserId(int userId, string title = null)
 {
     try
     {
         if (string.IsNullOrEmpty(this.WebForm.RefId) || this.WebForm.TableRowId <= 0)
         {
             return;
         }
         List <Param> p = new List <Param> {
             { new Param {
                   Name = "id", Type = ((int)EbDbTypes.Int32).ToString(), Value = this.WebForm.TableRowId.ToString()
               } }
         };
         string pp = JsonConvert.SerializeObject(p).ToBase64();
         NotifyByUserIDResponse result = Service.Gateway.Send <NotifyByUserIDResponse>(new NotifyByUserIDRequest
         {
             Link    = $"/WebForm/Index?_r={this.WebForm.RefId}&_p={pp}&_m=1",
             Title   = title ?? this.WebForm.DisplayName + " notification",
             UsersID = userId
         });
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message + e.StackTrace);
     }
 }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
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++;
                }
            }
        }