I have added som cameras in my Management Client.
How can I find them in my plugin. Have tried the Configuration.Instance.GetItems().
But here i only find one item with the Kind.Camera kind.
Any tips on how I could get all the Camera Items as a list?
Earlier i have used the ItemPickerForm, then i can pick all the cameras I have added. But i cant find them all with other methods.
Hi,
You can try with this:
List<Item> items = Configuration.Instance.GetItemsByKind(Kind.Camera);
if (items.Any())
{
foreach (Item i in items)
{
EnvironmentManager.Instance.Log(false, "Log name and Id", i.Name + " : " + i.FQID.ObjectId.ToString());
}
}
This way you should get all enabled cameras.
The .GetItems() method returns a hierarchy. Here’s one way to enumerate through the hierarchy when all you want is a flat enumerable of unique (non-repeating) items. The HashSet is used to check whether we have already yield returned an Item with the same ObjectId. I use a Stack because I prefer to avoid recursive method calls when the depth of a hierarchy is unpredictable. In reality I doubt there are (m)any installations where the hierarchy could cause a stack overflow, but better safe than sorry. Plus I think the stack approach is far more readable.
private static IEnumerable<Item> EnumerateItemsByKind(Guid kind)
{
var hashSet = new HashSet<Guid>();
var stack = new Stack<Item>(Configuration.Instance.GetItemsByKind(kind));
while (stack.Count > 0)
{
var item = stack.Pop();
// If item is a folder of any kind, get the child items and add to stack
if (item.FQID.FolderType != FolderType.No)
{
item.GetChildren().ForEach(stack.Push);
continue;
}
// The same object could be listed in more than one place in a hierarchy.
// Using a hashset to quickly determine if a GUID has already been seen.
if (hashSet.Contains(item.FQID.ObjectId))
{
continue;
}
// Item is not a folder and the FQID.Kind should match the desired kind.
hashSet.Add(item.FQID.ObjectId);
yield return item;
}
}
This was exactly what i was looking for, it works perfectly. Thank you!