Are there any samples showing specifically how to implement the CustomProperties class for Cameras? I tried searching through them and couldn’t find any.
I’m adding new cameras to the recording server via code in the background plugin and need to add some custom properties to the cameras at the same time, which need to be able to be accessed in the management and smart clients (specifically in a client plugin we’re developing). Seems obvious that the CustomProperties class is made for that, but I’m having issues actually setting the key/value. I’ve tried using the SetProperty method unsuccessfully so far. I’ve also tried to implement a similar method to how I set devicedriversettings using the Configuration API but have proven unsuccessful there as well.
Thanks for the info, but I’m still having some issues. I’ve tried to implement the AssociatedProperties class but I can’t get it to work with an instance of the camera. I think this may be because I’m trying to do all of this in Background only. All I want to do is add 2 basic string Key/Value pairs to an instance of a camera basically flagging it as one of our cameras.
If you look at the AddCameras sample, I’m trying to do this after I’ve added the hardware to the recording server using the addHardwareServerTask, but before saving the camera (see 2nd code snippet) since I have access to our api data I need to save at this point. All of this is within the background plugin only. In trying to use AssociatedProperties as in the AdminTabSample, I can’t use the camera instance because it’s not an ‘Item’ type, so I tried to get the Item using this:
var cameraItem = Configuration.Instance.GetItem(Guid.Parse(camera.Id), Kind.Camera);
but that always returns null; This is why I thought the CustomProperties class would be what I needed but I can’t find those used in any samples and all attempts I’ve made in using them have thus far failed. I appreciate your help with this.
Hardware hardware = new Hardware(EnvironmentManager.Instance.MasterSite.ServerId, path);
hardware.Name = hwname;
hardware.Enabled = true;
hardware.Save();
Camera camera = hardware.CameraFolder.Cameras.First();
camera.Name = camName;
camera.Enabled = true;
// logic to add custom camera properties here
// i.e. camera.OurCustomId = "OurCustomID"
camera.Save();
When using the AssociatedProperties class, you access properties via the ‘Properties’ dictionary - dont use SetProperty.
Then call .Save() when the 2 properties are updated.
The camera Item is part of the construction.
This support was released first time with 2017 R3.
Running from background plugin should be fine, as long as you ensure the app is logged in before doing anything (e.g. dont start your work in the Init method of the background plugin).
Consider to make an AdminTab plugin, as mentioned in previous post, and return false to the ‘IsVisible()’ method.
I don’t really want to go so far to make an admin plugin because it seems unnecessary. These properties will only be set when the cameras are being created in the background, and at no time would they ever be updated or even shown in the UI (only accessed by our code). Also, all of this is happening automatically so all a user does is login to our API through the admin plugin and the background plugin adds/updates all the cameras without the user having to do anything at all.
I seem to be getting closer to making this work but it looks like the camera being a ‘ConfigurationItem’ and not an ‘Item’ at the time of creation is the problem, since creating a new instance of AssociatedProperties requires an ‘Item’. Trying to get that camera item with:
var cameraItem = Configuration.Instance.GetItem(camGuid, Kind.Camera);
doesn’t work because even though the cameras were just created and saved, they’re not yet available for the Configuration class to find. I tested this by running:
List<Item> cameraItems = Configuration.Instance.GetItemsByKind(Kind.Camera);
and none of the newly created cameras are found. If I run that same line of code again on a subsequent login/camera update, then these previously created cameras show up (with the correct Guid that I was using in the first line of code). I should be able to do all of this with only one trip to the background plugin. The only workaround I can see right now is creating the cameras, temporarily setting some standard properties, letting all the code run its course, maybe setting a timeout, getting back to the admin plugin (which is actually a separate plugin the way we set it up) and then calling the background plugin a 2nd time just to set the AssociatedProperties and change the temp settings back to what they should be.
Thanks again for the help and sorry if some of this is basic stuff, I’ll admit that C#/.NET isn’t my primary skillset (or what we use here) and something I’ve been having to learn along the way as I work with the MIP SDK.
OK, So I assumed you were running the background plugin in the Management Client. Background plugin can run in Management Clinet, Event Server and Smart Client.
And yes, newly added cameras are available on the server, but in Smart Client it does not get updated automatically (there is a refresh method, but it realoads everything!), the Event Server reloads configuration after a few minutes or so. The Management Client needs a refresh also.
The CustomProperties ConfigurationItem contains a set of XML strings, one for each AssociatedProperties that might exists for the device (e.g. Camera). You navigate from a camera ConfigurationItem to its CustomProperties via the folder, and access one CustomProperties ConfigurationItem with multiple properties, the key to this class’s property dictionary is your plugin GUID and the value is an XML string that contains the Associated properties.
You will be able to work entirely with ConfigurationItem’s to perform this process withut involving ‘Item’.
Try run the AdminTabPlugin to get some data for a camera, and use the ConfigAPIClient to navigate as I wrote above - and I think you can figure this out 