The user permission management program under development is adding users to roles through the following SDK via Component Integration.
(Role:VideoOS.Platform.ConfigurationItems.Role)
Role.UserFolder.AddRoleMember(userSid)
The site already has over 50 roles.
When the program repeatedly calls the above function to add the user as a member of all roles, severe system delays occur after around 20 calls.
Symptoms:
-Unable to login through the smart client
-Live video freezes
The symptoms disappear once the last execution is complete in the slowed-down state with increased function execution time.
Testing:
Even adding a 1000ms delay between each AddRoleMember call causes the symptoms to occur.
Request:
Please provide any guidelines or points to check regarding the use of this function.
Attached:
The following function repeatedly calls AddRoleMember.
thanks.
//roles : current milestone system roles
//userSid : sid to add
//thirdpartyRoleKey : target role id (use role desc field)
//ex : exception message
public static int AddUserToRole(List roles, string userSid, string thirdpartyRoleKey, out string ex)
{
ex = string.Empty;
try
{
var role = roles.Find(it => it.Desc == thirdpartyRoleKey);
if (role == null)
{
return -1; //not found
}
if (role.Role == null)
{
ex = "ConfigurationItem is null";
return -1;
}
if (role.Role.UserFolder == null)
{
ex = "role.Role.UserFolder is null";
return -1;
}
bool exist = false;
foreach (var user in role.Role.UserFolder.Users)
{
if (user.Sid == userSid)
{ exist = true; break; }
}
if (exist == true)
{ //already user exist
return 0;
}
var task = role.Role.UserFolder.AddRoleMember(userSid);
if ((task != null) &&
(task.State == VideoOS.Platform.ConfigurationItems.StateEnum.Success))
{
return 1;
}
}
catch (Exception e)
{ ex = e.ToString(); }
return -1;
}
public class MIPRole
{
public MIPRole(VideoOS.Platform.ConfigurationItems.Role role, string name, string thirdpartyRoleKey)
{
Role = role;
Name = name;
Desc = desc;
}
public VideoOS.Platform.ConfigurationItems.Role Role { get; set; } = null;
public string Name { get; set; } = string.Empty;
public string Desc { get; set; } = string.Empty;
public override string ToString()
{
return $"{Name}({Desc})";
}
}