Best method to obtain camera credentials in Smart Client?

I need to make API requests from a Smart Client plugin that requires the camera username/password. I understand camera credentials cannot be retrieved in the Smart Client as they can be in the Management Client. What are my options? Is there a recommended approach to this?

Thanks.

Following two samples might be helpful for you.

This sample, ConfigAPI Client sample demonstrates how to get camera information.

https://doc.developer.milestonesys.com/html/index.html?base=samples/componentsamples/configapiclient/readme.html&tree=tree_2.html

Recording server → (Recording server name) → Hardware → Hardware name

You will see username and click Read Hardware Password.

Also, there is another configuration API sample that runs in the Smart Client environment. This sample might be helpful.

https://doc.developer.milestonesys.com/html/index.html?base=samples/pluginsamples/adduserwithconfigapi/readme.html&tree=tree_1.html

Thanks but still having trouble with this.

I can get the camera password when running the the ConfigAPI Client Sample, however when I put this functionality in a smart client plugin I get an error.

Specifically, after I successfully retrieve the hardware objects it throws a null error when I attempt to call ReadPasswordHardware();

Is this a permissions issue? I am the only user and admin. Any ideas?

My guess is that you execute the ReadPasswordHardware() but do not correctly read the result embedded in the ServerTask. Maybe this snippet of code will fix it, if it does not please share your code for me to see.

ServerTask servertask = hardware.ReadPasswordHardware();
ICollection<string> keys= servertask.GetPropertyKeys();
foreach (var key in keys) 
{
	string prop = servertask.GetProperty(key);
	label1.Text += key + " " + prop + Environment.NewLine;
}

This did not fix it, and is essentially what I had before. It fails at:

ServerTask servertask = hardware.ReadPasswordHardware();

Giving the following error:

I can loop through and see the properties (username, Address, etc.) for each device but as soon I call ReadPasswordHardware() it throws the error in the attached image. I am trying to do this from Activate() in a Toolbar Plugin, i.e. when the toolbar item is clicked. Here is the full code:

try
            {
 
                var ms = new ManagementServer(EnvironmentManager.Instance.MasterSite);
                var hardwares = ms.RecordingServerFolder.RecordingServers.SelectMany(rs => rs.HardwareFolder.Hardwares);
 
                foreach (var h in hardwares)
                {
 
                    // This works
                    string keyStr = "";
                    foreach (var key in h.GetPropertyKeys())
                    {
                        string prop = h.GetProperty(key);
                        keyStr += key + " " + prop + Environment.NewLine;
                    }
 
                    MessageBox.Show("key list...\n" + keyStr);
 
                    // Fails here
                    ServerTask addHardwareServerTask = h.ReadPasswordHardware();
 
                    while (addHardwareServerTask.State != StateEnum.Error && addHardwareServerTask.State != StateEnum.Success)
                    {
                        System.Threading.Thread.Sleep(1000);
                        addHardwareServerTask.UpdateState();
                    }
 
                    MessageBox.Show("Hardware add task: " + addHardwareServerTask.State);
                    if (addHardwareServerTask.State == StateEnum.Error)
                    {
                        MessageBox.Show("Hardware add error: " + addHardwareServerTask.ErrorText);
                    }
                    else if (addHardwareServerTask.State == StateEnum.Success)
                    {
                        //string path = addHardwareServerTask.Path;       // For the added hardware
                        foreach (var p in addHardwareServerTask.GetPropertyKeys())
                        {
                            MessageBox.Show(p + "=" + addHardwareServerTask.GetProperty(p));
                        }
                        // alter other camera properties(?)
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("ex: " + ex);
            }

I put your snippet of code in the SCToolbarplugin ShowCameraNameViewItemToolbarPluginInstance Activate method and it worked perfectly.

Could please try again? Perhaps with the file I modified..

Thanks for your help Bo. I had to do a fresh install of the Smart Client but it’s working now.