logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Runar  
#1 Posted : Thursday, January 19, 2017 8:33:09 AM(UTC)
Runar


Rank: Newbie

Joined: 9/7/2016(UTC)
Posts: 12
Norway

Thanks: 1 times
We have created a new extension to dynamically add new roles to ScreenConnect by using the following pseudo code:

Code:
var permissionProvider = new ScreenConnect.XmlPermissionProvider();
// get all roles
var allRoles = permissionProvider.GetAllRoles();
// add new role
allRoles.Add(new ScreenConnect.Role()) 
// save
permissionProvider.SaveRoles(allRoles);


This seems to work fine and the new role is stored in the ‘Role.xml’ file.
However we are unable to find the new role in the administration interface for ScreenConnect. It seems to be some caching issue and the new role will not show until we restart the service.
We have also tried to programmatically clear the cache after we call the ‘SaveRoles’ method without success. Example:

Code:
// clear cache
ScreenConnect.SecurityCacheManager.Invalidate();
                               
// clear everything in http cache
foreach (System.Collections.DictionaryEntry entry in HttpContext.Current.Cache){
    HttpContext.Current.Cache.Remove(entry.Key.ToString());
}

Is there any other way to clear the ScreenConnect cache from our extension so we could get this working smoothly?

Scott  
#2 Posted : Thursday, January 19, 2017 6:03:05 PM(UTC)
Scott


Rank: Administration

Medals: Level 4: Wise Old Owl! Received 100 Thanks!

Joined: 3/28/2014(UTC)
Posts: 2,441
United States

Thanks: 3 times
Was thanked: 300 time(s) in 258 post(s)
On what version of ScreenConnect are you seeing this behavior?

Also, is it on a Windows or Linux server?
ScreenConnect Team
Runar  
#3 Posted : Friday, January 20, 2017 10:54:39 AM(UTC)
Runar


Rank: Newbie

Joined: 9/7/2016(UTC)
Posts: 12
Norway

Thanks: 1 times
Originally Posted by: Scott Go to Quoted Post
On what version of ScreenConnect are you seeing this behavior?

Also, is it on a Windows or Linux server?

ScreenConnect_6.0.11622.6115_Release on Windows 2012 R2.
Scott  
#4 Posted : Friday, January 20, 2017 2:58:22 PM(UTC)
Scott


Rank: Administration

Medals: Level 4: Wise Old Owl! Received 100 Thanks!

Joined: 3/28/2014(UTC)
Posts: 2,441
United States

Thanks: 3 times
Was thanked: 300 time(s) in 258 post(s)
We made several changes around Role creation/population in 6.1. Using the following code within an Extension I was able to create a role with 0 permissions in 6.1:

Code:

public void AddRoleToProvider(string roleName)
{
	Permissions.Provider.SaveRoles(
		Permissions.Provider.GetAllRoles()
			.Where(_ => _.Name != roleName)
			.Append(new Role
			{
				Name = roleName,
				PermissionEntries = new PermissionEntry[]{}
			})
	);
}
ScreenConnect Team
Runar  
#5 Posted : Monday, January 23, 2017 7:13:09 AM(UTC)
Runar


Rank: Newbie

Joined: 9/7/2016(UTC)
Posts: 12
Norway

Thanks: 1 times
Originally Posted by: Scott Go to Quoted Post
We made several changes around Role creation/population in 6.1. Using the following code within an Extension I was able to create a role with 0 permissions in 6.1:

Code:

public void AddRoleToProvider(string roleName)
{
	Permissions.Provider.SaveRoles(
		Permissions.Provider.GetAllRoles()
			.Where(_ => _.Name != roleName)
			.Append(new Role
			{
				Name = roleName,
				PermissionEntries = new PermissionEntry[]{}
			})
	);
}

Thanks Scott, we'll try that.
Runar  
#6 Posted : Tuesday, April 4, 2017 1:43:42 PM(UTC)
Runar


Rank: Newbie

Joined: 9/7/2016(UTC)
Posts: 12
Norway

Thanks: 1 times
Hi.

We did not manage to solve the caching problem with the code you gave (we have to restart the web server to load it). We've kinda made a workaround (with restarting the web server every 3 hour), but we've faced another problem now. When we add a role though coding/api, it gets added to the XML file. But when we add another role before we restart the service, it writes over the other role we had created.

Do you have any suggestions to how we can fix this? (or better, fix the caching problem?)

We've tried both this
Code:
		permissionProvider.SaveRoles(
			permissionProvider.GetAllRoles()
				.Where(_ => _.Name != companyRole1.Name)
				.Append(companyRole1)
		);
		permissionProvider.SaveRoles(
			permissionProvider.GetAllRoles()
				.Where(_ => _.Name != companyRole2.Name)
				.Append(companyRole2)
		);

and this
Code:
		var allRoles = new List<ScreenConnect.Role>();
		allRoles.AddRange(permissionProvider.GetAllRoles());
		allRoles.Add(companyRole1);
		allRoles.Add(companyRole2);

		// save roles
		permissionProvider.SaveRoles(allRoles.ToArray());
		
		// clear cache
		ScreenConnect.SecurityCacheManager.Invalidate();
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.