private TreeNodeModel GetCommandNode(List<Command> commands, List<RoleCommandView> myCommands)
        {
            //if the logined user has all commands for all application or one application
            //either way, we should show all the commands.
            bool hasAllCommand = myCommands.FirstOrDefault(rc => rc.Command_Id == BuiltIns.AllCommand.Id) != null;

            TreeNodeModel allCommandsNode = new TreeNodeModel { name = Text.AllCommand,items = new List<TreeNodeModel>()};

            if (hasAllCommand)
            {
                commands.ForEach(cmd =>
                {
                    if (cmd.CommandType == BuiltIns.BackendCommandType
                        && cmd.Application_Id == BuiltIns.AllApplication.Id
                        && !string.IsNullOrEmpty(cmd.ActionName)
                        && !BuiltIns.ExcludeCommandIds.Contains(cmd.Id))
                    {
                        allCommandsNode.items.Add(new TreeNodeModel
                        {
                            id = cmd.Id,
                            name = cmd.Name,
                            url = cmd.ActionName
                        });
                    }
                });
            }
            else
            {
                myCommands.ForEach(rc =>
                {
                    var cmd = commands.FirstOrDefault(cc => cc.Id == rc.Command_Id);
                    if (rc.CommandType == BuiltIns.BackendCommandType
                        && rc.Application_Id == BuiltIns.AllApplication.Id
                        && !string.IsNullOrEmpty(rc.ActionName)
                        && !BuiltIns.ExcludeCommandIds.Contains(rc.Command_Id))
                    {
                        allCommandsNode.items.Add(new TreeNodeModel
                        {
                            id=cmd.Id,
                            name = rc.Command_Name,
                            url = rc.ActionName
                        });

                    }
                });
            }
            return allCommandsNode;
        }
 private void OnlineUserCountChangedEventHandler(List<RoomViewModel> changedRooms)
 {
     List<TreeNodeModel> roomGroupsUserCount = new List<TreeNodeModel>();
     ApplicationVM.LocalCache.AllRoomGroupVMs.ForEach(g =>
         {
             var c = g.GetOnlineUserCount();
             if (g.OnlineUserCount != c)
             {
                 g.OnlineUserCount = c;
                 var node = new TreeNodeModel { id = g.Id, count = c, rootid = g.RootRoomGroupVM.Id, name = g.Name };
                 roomGroupsUserCount.Add(node);
             }
         });
     List<NodeModel> roomsUserCount = new List<NodeModel>();
     changedRooms.ForEach(r =>
         {
             var node = new NodeModel { id = r.Id, count = r.OnlineUserCount, rootid = r.RootRoomGroupVM.Id, name = r.Name };
             roomsUserCount.Add(node);
         });
     JavaScriptSerializer js = new JavaScriptSerializer();
     CallJavaScript("UpdateOnlineUserCountAsync", js.Serialize(roomGroupsUserCount), js.Serialize(roomsUserCount));
 }
Пример #3
0
 public override object ToJson()
 {
     
     TreeNodeModel root = new TreeNodeModel() { id = Id, name = Name, value = Id.ToString(), url = Location, count = OnlineUserCount };
    
     if (ImageVM != null && ImageVM.Id > 0 && (!string.IsNullOrEmpty(ImageVM.StaticImageFile)))
     {
         root.icon = ImageVM.StaticImageFile;
     }
     if (RoomVMs != null && RoomVMs.Count > 0)
     {
         root.nodes = new List<NodeModel>();
         foreach (var r in RoomVMs)
         {
             if (!string.IsNullOrEmpty(r.ServiceIp) && r.Enabled == true)
             {
                 root.nodes.Add(r.ToJson() as NodeModel);
             }
         }
     }
     if (SubRoomGroupVMs != null && SubRoomGroupVMs.Count > 0)
     {
         root.items = new List<TreeNodeModel>();
         foreach (var srg in SubRoomGroupVMs)
         {
             if(srg.Enabled == true)
                 root.items.Add(srg.ToJson() as TreeNodeModel);
         }
     }
     
     return root;
 }
        private TreeNodeModel GetApplicationNode(List<Application> applications, List<Command> commands, List<RoleCommandView> myCommands)
        {
            bool hasAllApplication = myCommands.FirstOrDefault(rc => rc.Application_Id == BuiltIns.AllApplication.Id) != null;

            TreeNodeModel allApplicationsNode = new TreeNodeModel { name = Text.AllApplication, items = new List<TreeNodeModel>() };

            if (hasAllApplication)
            {
                applications.ForEach(a => allApplicationsNode.items.Add(new TreeNodeModel { name = a.Name, id = a.Id }));
            }
            else
            {
                myCommands.ForEach(rc =>
                {
                    if (rc.CommandType == BuiltIns.BackendCommandType)
                    {
                        var appNode = allApplicationsNode.items.FirstOrDefault(a => a.id== rc.Application_Id);
                        if (appNode == null)
                        {
                            var app = applications.FirstOrDefault(a => a.Id == rc.Application_Id);
                            if (app != null)
                            {
                                allApplicationsNode.items.Add(new TreeNodeModel { id = app.Id, name = app.Name });
                            }
                        }
                    }
                });
            }

            bool hasAllCommandForAllApplication = myCommands.FirstOrDefault(rc => rc.Application_Id == BuiltIns.AllApplication.Id && rc.Command_Id == BuiltIns.AllCommand.Id) != null;

            allApplicationsNode.items.ForEach(r =>
                {
                    r.items = new List<TreeNodeModel>();

                    bool hasAllCommandForCurrentApplication = myCommands.FirstOrDefault(rc => rc.Application_Id == r.id && rc.Command_Id == BuiltIns.AllCommand.Id) != null;
                    
                    if (hasAllCommandForAllApplication || hasAllCommandForCurrentApplication)
                    {
                        commands.ForEach(c =>
                            {
                                if (c.CommandType == BuiltIns.BackendCommandType
                                    && c.Application_Id == r.id
                                    && !string.IsNullOrEmpty(c.ActionName)
                                    && !BuiltIns.ExcludeCommandIds.Contains(c.Id))
                                {
                                    r.items.Add(new TreeNodeModel { id = c.Id, name = c.Name, url = c.ActionName });
                                }
                            });
                    }
                    else
                    {
                        myCommands.ForEach(rc =>
                            {
                                var cmd = commands.FirstOrDefault(c => c.Id == rc.Command_Id);
                                if (rc.Application_Id == r.id
                                    && cmd.CommandType == BuiltIns.BackendCommandType
                                    && cmd.Application_Id == r.id
                                    && !string.IsNullOrEmpty(cmd.ActionName)
                                    && !BuiltIns.ExcludeCommandIds.Contains(cmd.Id))
                                {
                                    r.items.Add(new TreeNodeModel { id = cmd.Id, name = cmd.Name, url = cmd.ActionName });
                                }
                            });
                    }
                    
                });

            return allApplicationsNode;
        }
 private TreeNodeModel GetPersonalNode()
 {
     TreeNodeModel personalNode = new TreeNodeModel { name = Text.PersonalManagement, items = new List<TreeNodeModel>() };
     personalNode.items.Add(new TreeNodeModel { id = BuiltIns.PersonalInfoCommand.Id, name = BuiltIns.PersonalInfoCommand.Name, url = BuiltIns.PersonalInfoCommand.ActionName });
     personalNode.items.Add(new TreeNodeModel { id = BuiltIns.PasswordCommand.Id, name = BuiltIns.PasswordCommand.Name, url = BuiltIns.PasswordCommand.ActionName });
     return personalNode;
 }