Is there a better way to get Generic Events for use as sources in AlarmDefinitions?

Part 3 of my alarm editor implementation journey…

I have a working alarm definition editor, with one significant caveat remaining which is kind of stumping me, and I wonder if anybody has any idea how to do this in a less brittle way.

Basically, it seems that generic events with paths that look like “GenericEvent[]” are not valid options for alarm sources. However, in the Management Client, when you set sources for an Alarm and, eg, set the Event Type as “External Events” you find the Generic Events under the User Defined Events.

I was able to get my editor to load generic event metadata (ie, the display names to show the user) using these “UserDefinedEvent[<GUID’>]” Paths that are in the SourceList (where GUID’ != GUID) after retrieving an alarm which has a Generic Event set as a source already by constructing a GenericEvent with the VideoOS.Platform.ConfigurationItems.GenericEvent(ServerId, Path) constructor. But I still needed to get a list of valid Paths to use to fill the dropdown menus so that the user could set a Generic Event as a source as in the Management Client.

I eventually found out that I could just use Platform.Configuration.GetItems() and check for Properties[“EventType”] == “Generic”, and try to build a GenericEvent with the GenericEvent(FQID) constructor. It strangely gives a PathNotFoundMIPException, and the Message in the Exception shows the path as “InputEvent[<GUID’>]”, the same mystery GUID that the Generic Event has when I pull it from an existing alarm. So I parse the Exception Message for the path, replace InputEvent with UserDefinedEvent, and build the GenericEvent with THAT path, and it works… I can validate and save the alarm with this path in the SourceList.

But I really shouldn’t have to be parsing Exception Messages to mimic the functionality of the Management Client. Is there a better way to get these Paths/GUIDs?

Cheers,

Derek

Please do this to get all GenericEvents in system:

            var folder = new GenericEventFolder(EnvironmentManager.Instance.MasterSite.ServerId, "/" + ItemTypes.GenericEventFolder);
            ICollection<GenericEvent> allGenericEvents = folder.GenericEvents;
            foreach (var ge in allGenericEvents)
            {
                Console.WriteLine("GE: " + ge.Path + ", name=" + ge.DisplayName);
            }

We would like to know why GenericEvent(FQID) fails, can you please share your FQID?

Thanks for the response Rie,

As you mention that does give me all the GenericEvents, but the Paths therein are not accepted as sources for the Alarm Definition.

Here is an example of an FQID that fails constructing a GenericEvent:

Server:XPCO:milestonetest.siroonian.local Id:6ed4be22-37f7-4ca3-83d8-a26b3c9513f6, ObjectId:a69733ba-9957-45ee-ab03-d0c936a333b4, Type:5fc737a9-bbf6-4473-a421-7e8075d45d9c

I actually see that ObjectId is the same GUID that I need to build the paths that the AlarmDefinition will accept, so that saves me from needing to parse the Exception message, but you see the Kind GUID (listed here as Type) corresponds to InputEvent instead of UserDefinedEvent or GenericEvent, which is probably the reason it is failing, and means I still need to take the extra step of converting the Kind before constructing.

Is it a design decision to have the GenericEvent paths in the context of the AlarmDefinition source in this weird form as UserDefinedEvent[GUID’] instead of the canonical GenericEvent[GUID] (note the GUID is not even the same) or is it a secondary effect?

Milestone Development will start an investigation. Let me get back to you when I get news from them.

I am sorry for delayed response. I got a news from Milestone Development so please see following comment.

-----

Please try use this method to convert from a MIP Item of Kind=TriggerEvent to a path.

        /// <summary>
        /// Uses a FQID from a UserDefined Event with a property of "EventType=Generic"
        /// And returns the path for a GenericEvent to be used for Configuration API handling
        /// </summary>
        /// <param name="fqid"></param>
        /// <returns></returns>
        private static string FindGenericEventPathFromFQID(FQID fqid)
        {
            var genericEVentKind = new Guid("d4d19c01-03f2-4ac6-9d2b-5356b5de62f1");
 
            var geKind = new MIPKind(EnvironmentManager.Instance.MasterSite.ServerId, genericEVentKind);
            geKind.FillChildren(new string[] { "GenericEvent" });
            foreach (MIPItem item in geKind.MIPItemFolder.MIPItems)
            {
                if (fqid.ObjectId == new Guid(item.GetProperty("ShadowId")))
                    return string.Format("GenericEvent[{0}]", item.Id);
            }
            return null;
        }