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?
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.
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);
}