Setting Camera Roles

Please, is there a way to programmatically assign a specific Role to a Camera?

Many Thanks,

Frediano

Yes. There are some ways (I do not mention them all but the ones I guess are the most likely to be what you need.)..

Using the Configuration API strongly typed classes:

ChangeSecurityPermissions
ServerTask VideoOS.Platform.ConfigurationItems.Camera.ChangeSecurityPermissions(String userPath)

Edit permissions.
Parameters
userPath User path. User path format: /User[SID]. ‘SID’ can contain role ID.

-

Using Rest API:

Change storage for device ChangeSecurityPermissions

I also found this older topic that might be interesting.

Sorry Bo, but it is non clear for me.

2 Questions:

  • how to address specific camera to set permission
  • how to set specific Role and not User

Many Thanks,

Frediano

The specific Camera object is what you can get from the Configuration API VideoOS.Platform.ConfigurationItems;
Snippet of code showing two ways to get the Camera object for a specific camera:

using VideoOS.Platform.ConfigurationItems;

private Camera CameraPicker()
{
Item cam = new Item();
FQID cameraFQID = new FQID();
ItemPickerForm form = new ItemPickerForm();
form.KindFilter = Kind.Camera;
form.AutoAccept = true;
form.Init(Configuration.Instance.GetItems());
if (form.ShowDialog() == DialogResult.OK)
{
cameraFQID = form.SelectedItem.FQID;
return new Camera(cameraFQID);
}
else return null;
}

private Camera CameraFind()
{
ManagementServer mgt = new ManagementServer(EnvironmentManager.Instance.MasterSite.ServerId);
var cam = mgt.RecordingServerFolder.RecordingServers.FirstOrDefault().HardwareFolder.Hardwares.First(x => x.Name.Contains(“Test”)).CameraFolder.Cameras.FirstOrDefault(x => x.Name.Contains(“Test”));
return cam;
}

And a snippet of code how to read and change security permissions, note how it uses a role, not a user:

private void CameraPermission(Camera camera)
{
	ManagementServer mgt = new ManagementServer(EnvironmentManager.Instance.MasterSite.ServerId);
	var role = mgt.RoleFolder.Roles.First(x => x.Name.Equals("Operator"));
	ServerTask servertask = camera.ChangeSecurityPermissions(role.Path);
	if (servertask.ItemType == "InvokeInfo")
	{
		ICollection<string> keys = servertask.GetPropertyKeys();
		foreach (var key in keys)
		{
			string property = servertask.GetProperty(key);
			label1.Text += $"{key} {property}" + Environment.NewLine;
			if (key == "GENERIC_READ")
			{
				string newProperty = (property == "False") ? "True" : "False";

				servertask.SetProperty(key, newProperty);
				label1.Text += $"Property change - {key} set to {newProperty}" + Environment.NewLine;
			}
		}
	}
	servertask.ExecuteDefault();
}

The code is first draft, please use only for inspiration.

Many Thanks Bo, it works perfectly

Frediano