public static async Task<string> GetSetInfo(string adminId, string set)
 {
     EntitySetType type;
     JavaScriptSerializer jser = new JavaScriptSerializer();
     dynamic sobj = jser.DeserializeObject(set) as dynamic;
     if (Enum.TryParse<EntitySetType>(sobj["set"], out type))
     {
         string filter = null;
         if (sobj.ContainsKey("setFilter"))
             filter = sobj["setFilter"];
         switch (type)
         {
             case EntitySetType.User:
                 {
                     var p = await GetMaxPriority(adminId);
                     UserServiceProxy svc = new UserServiceProxy();
                     var si = await svc.GetSetInfoAsync(Cntx, filter);
                     RoleServiceProxy rsvc = new RoleServiceProxy();
                     var roles = await rsvc.QueryDatabaseAsync(Cntx, new RoleSet(), null);
                     List<dynamic> rlist = new List<dynamic>();
                     foreach (var r in roles)
                     {
                         if (r.RolePriority <= p.Major)
                             rlist.Add(new { id = r.ID, name = r.RoleName, path = r.DistinctString, op = true });
                     }
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters, roles = rlist.ToArray() });
                     return json;
                 }
         }
     }
     return null;
 }
 public async Task<string> GetSetInfo(string sourceId, string set)
 {
     JavaScriptSerializer jser = new JavaScriptSerializer();
     dynamic sobj = jser.DeserializeObject(set) as dynamic;
     EntitySetType type;
     if (Enum.TryParse<EntitySetType>(sobj["set"], out type))
     {
         string filter = null;
         if (sobj.ContainsKey("setFilter"))
             filter = sobj["setFilter"];
         switch (type)
         {
             case EntitySetType.User:
                 {
                     UserServiceProxy svc = new UserServiceProxy();
                     var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                     return json;
                 }
             case EntitySetType.Role:
                 {
                     RoleServiceProxy svc = new RoleServiceProxy();
                     var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                     return json;
                 }
         }
     }
     return null;
 }
        public async Task <string> GetSetInfo(string sourceId, string set)
        {
            JavaScriptSerializer jser = new JavaScriptSerializer();
            dynamic       sobj        = jser.DeserializeObject(set) as dynamic;
            EntitySetType type;

            if (Enum.TryParse <EntitySetType>(sobj["set"], out type))
            {
                string filter = null;
                if (sobj.ContainsKey("setFilter"))
                {
                    filter = sobj["setFilter"];
                }
                switch (type)
                {
                case EntitySetType.User:
                {
                    UserServiceProxy svc = new UserServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }

                case EntitySetType.Role:
                {
                    RoleServiceProxy svc = new RoleServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }

                case EntitySetType.MemberNotification:
                {
                    MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }
                }
            }
            return(null);
        }
Example #4
0
        public static async Task <string> GetSetInfo(string adminId, string set)
        {
            EntitySetType        type;
            JavaScriptSerializer jser = new JavaScriptSerializer();
            dynamic sobj = jser.DeserializeObject(set) as dynamic;

            if (Enum.TryParse <EntitySetType>(sobj["set"], out type))
            {
                string filter = null;
                if (sobj.ContainsKey("setFilter"))
                {
                    filter = sobj["setFilter"];
                }
                switch (type)
                {
                case EntitySetType.User:
                {
                    var p = await GetMaxPriority(adminId);

                    UserServiceProxy svc = new UserServiceProxy();
                    var si = await svc.GetSetInfoAsync(Cntx, filter);

                    RoleServiceProxy rsvc = new RoleServiceProxy();
                    var roles             = await rsvc.QueryDatabaseAsync(Cntx, new RoleSet(), null);

                    List <dynamic> rlist = new List <dynamic>();
                    foreach (var r in roles)
                    {
                        if (r.RolePriority <= p.Major)
                        {
                            rlist.Add(new { id = r.ID, name = r.RoleName, path = r.DistinctString, op = true });
                        }
                    }
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters, roles = rlist.ToArray() });
                    return(json);
                }
                }
            }
            return(null);
        }
 public async Task<string> GetSetInfo(string sourceId, string set)
 {
     JavaScriptSerializer jser = new JavaScriptSerializer();
     dynamic sobj = jser.DeserializeObject(set) as dynamic;
     EntitySetType type;
     if (Enum.TryParse<EntitySetType>(sobj["set"], out type))
     {
         string filter = null;
         if (sobj.ContainsKey("setFilter"))
             filter = sobj["setFilter"];
         switch (type)
         {
             case EntitySetType.User:
                 {
                     UserServiceProxy svc = new UserServiceProxy();
                     var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                     return json;
                 }
             case EntitySetType.Role:
                 {
                     RoleServiceProxy svc = new RoleServiceProxy();
                     var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                     return json;
                 }
             case EntitySetType.MemberNotification:
                 {
                     MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy();
                     var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                     return json;
                 }
             case EntitySetType.ShortMessage:
                 {
                     if (filter == null)
                         throw new Exception("The page is not properly parameterized!");
                     else
                     {
                         Func<string, string, int> count = (s, p) =>
                         {
                             int _cnt = 0;
                             int i = 0;
                             while ((i = s.IndexOf(p, i)) != -1)
                             {
                                 _cnt++;
                                 i += p.Length;
                             }
                             return _cnt;
                         };
                         if (filter.Contains("ToID is null") && filter.Contains("___usergroups___") && count(filter, "||") == 0)
                         {
                             string[] mbgrpIds = await GroupChatViewContext.UserGroupChatMembers(System.Web.HttpContext.Current.User.Identity.GetUserId());
                             if (mbgrpIds == null || mbgrpIds.Length == 0)
                                 throw new Exception(ResourceUtils.GetString("234038e6185f013e25d0213c06f5a0e9", "You are not a member of any chat group."));
                             string groupexpr = "";
                             foreach (var gid in mbgrpIds)
                                 groupexpr += (groupexpr != "" ? " || " : "") + "GroupID == \"" + gid + "\"";
                             filter = filter.Replace("___usergroups___", groupexpr);
                         }
                         else if (filter.EndsWith("&& ToID is not null && GroupID is null && ( ToID == \"{0}\" || FromID == \"{0}\" )") && count(filter, "||") == 1)
                         {
                             filter = string.Format(filter, System.Web.HttpContext.Current.User.Identity.GetUserId());
                         }
                         else
                             throw new Exception("The page is not properly parameterized!");
                     }
                     ShortMessageServiceProxy svc = new ShortMessageServiceProxy();
                     var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);
                     JavaScriptSerializer ser = new JavaScriptSerializer();
                     string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                     return json;
                 }
         }
     }
     return null;
 }
        public async Task <string> GetSetInfo(string sourceId, string set)
        {
            JavaScriptSerializer jser = new JavaScriptSerializer();
            dynamic       sobj        = jser.DeserializeObject(set) as dynamic;
            EntitySetType type;

            if (Enum.TryParse <EntitySetType>(sobj["set"], out type))
            {
                string filter = null;
                if (sobj.ContainsKey("setFilter"))
                {
                    filter = sobj["setFilter"];
                }
                switch (type)
                {
                case EntitySetType.User:
                {
                    UserServiceProxy svc = new UserServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }

                case EntitySetType.Role:
                {
                    RoleServiceProxy svc = new RoleServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }

                case EntitySetType.MemberNotification:
                {
                    MemberNotificationServiceProxy svc = new MemberNotificationServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }

                case EntitySetType.ShortMessage:
                {
                    if (filter == null)
                    {
                        throw new Exception("The page is not properly parameterized!");
                    }
                    else
                    {
                        Func <string, string, int> count = (s, p) =>
                        {
                            int _cnt = 0;
                            int i    = 0;
                            while ((i = s.IndexOf(p, i)) != -1)
                            {
                                _cnt++;
                                i += p.Length;
                            }
                            return(_cnt);
                        };
                        if (filter.Contains("ToID is null") && filter.Contains("___usergroups___") && count(filter, "||") == 0)
                        {
                            string[] mbgrpIds = await GroupChatViewContext.UserGroupChatMembers(System.Web.HttpContext.Current.User.Identity.GetUserId());

                            if (mbgrpIds == null || mbgrpIds.Length == 0)
                            {
                                throw new Exception(ResourceUtils.GetString("234038e6185f013e25d0213c06f5a0e9", "You are not a member of any chat group."));
                            }
                            string groupexpr = "";
                            foreach (var gid in mbgrpIds)
                            {
                                groupexpr += (groupexpr != "" ? " || " : "") + "GroupID == \"" + gid + "\"";
                            }
                            filter = filter.Replace("___usergroups___", groupexpr);
                        }
                        else if (filter.EndsWith("&& ToID is not null && GroupID is null && ( ToID == \"{0}\" || FromID == \"{0}\" )") && count(filter, "||") == 1)
                        {
                            filter = string.Format(filter, System.Web.HttpContext.Current.User.Identity.GetUserId());
                        }
                        else
                        {
                            throw new Exception("The page is not properly parameterized!");
                        }
                    }
                    ShortMessageServiceProxy svc = new ShortMessageServiceProxy();
                    var si = await svc.GetSetInfoAsync(ApplicationContext.ClientContext, filter);

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    string json = ser.Serialize(new { EntityCount = si.EntityCount, Sorters = si.Sorters });
                    return(json);
                }
                }
            }
            return(null);
        }