Hello.
I found a bug in the ConfigAddCameras of the MIP SDK sample that causes an exception, and solution for this exception.
I’d like to share it.
This bug may occur in regions that use full-width characters (East Asia).
Please note that it is unlikely to occur in Europe or America.
Prerequisites:
A camera group with full-width characters, “TestGroup123” (full-width characters), already exists in XProtect 2024 R2 server.
Reproduction steps:
In the ConfigAddCameras of the MIP SDK sample, specify the camera group “TestGroup123” (half-width characters) and add a camera to the group.
Result:
An exception occurs in [ServerTask task = folder.AddDeviceGroup(groupName, “group added by tool”);] and the exception message “name” is displayed.
Reason:
The following is my speculation.
1. [CameraGroup groupExist = ms.CameraGroupFolder.CameraGroups.Where(x => x.Name == groupName).FirstOrDefault();] distinguishes between full-width and half-width characters, so “TestGroup123” (full-width characters) and “TestGroup123” (half-width characters) will be determined to be different groups.
2. [ServerTask task = folder.AddDeviceGroup(groupName, “group added by tool”);] does not distinguish between full-width and half-width characters, so an exception occurs when attempting to register a “group name that is already registered” even though it should be rejected.
Solution for this exception:
It needs to replace [CameraGroup groupExist = ms.CameraGroupFolder.CameraGroups.Where(x => x.Name == groupName).FirstOrDefault();] with the following method.
private CameraGroup CheckGroupExist(CameraGroupFolder alreadyRegFolder, string groupName)
{
const string FULLWIDTH = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$%&’()*+,-./:;<=>?@[\]^_`{|}~";
const string HALFWIDTH = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
// Group name to be registered
string halfwidthGroupName = groupName;
for (int i = 0; i < FULLWIDTH.Length; i++)
{
// Change to half-width characters
halfwidthGroupName = halfwidthGroupName.Replace(FULLWIDTH[i], HALFWIDTH[i]);
}
// Check if it's already registered
foreach (CameraGroup alreadyRegGroup in alreadyRegFolder.CameraGroups)
{
// Group name already registered in XProtect 2024R2
string halfwidthAlreadyRegGroupName = alreadyRegGroup.Name;
for (int i = 0; i < FULLWIDTH.Length; i++)
{
// Change to half-width characters
halfwidthAlreadyRegGroupName = halfwidthAlreadyRegGroupName.Replace(FULLWIDTH[i], HALFWIDTH[i]);
}
if (halfwidthGroupName == halfwidthAlreadyRegGroupName)
{
// The group name entered by the user matches the name of a group already registered.
return alreadyRegGroup;
}
}
return null;
}
