Let me start off by apologizing for the very late response to your question. We strive towards replying a lot quicker than was the case with your question.
It is not the intention that the search framework should be used in this manner from a Smart Client MIP plugin; the Search workspace is the intended - centralized - place for a Smart Client user to navigate to when wanting to search for video.
The intention of exposing the SearchManager and related classes in the MIP SDK, is to allow a component integration to use the search framework in a similar manner as the Smart Client does, if the developer so desires. However, it is of course possible to do the same thing in a workspace plugin in the Smart Client which is what it seems you are trying to do.
With that said, you can still do what you are trying to do, and hopefully the code snippet below should point you in the right direction:
Item item = null; /* TODO: Get camera item(s) to perform the search on */
// Create a scope used as input to the search (typically tied to the UI and as such should be modifiable)
var to = DateTime.UtcNow;
var from = to.Subtract(TimeSpan.FromHours(2));
var scope = new CustomSearchScope(from, to, new[] { item });
// Create a search definition for the specific search agent
var definition = searchManager.CreateSearchDefinition(searchAgentPlugin.SearchFilterCategory, scope);
// Subscribe to events from the searchManager related to the search
searchManager.SearchResultReady += (sender, args) => { /* Handle search results as they arrive from the search agent(s) */ };
searchManager.ErrorOccurred += (sender, args) => { /* Deal with errors coming from the search agent(s) */ };
searchManager.SearchDone += (sender, args) => { /* Called when the searchManager finishes processing a search for a search agent */ };
// Start the search for the search definition created above
searchManager.StartSearch(definition, scope.From, scope.To, scope.Items);
private class CustomSearchScope : SearchScope
{
public override DateTime From { get; protected set; }
public override DateTime To { get; protected set; }
public override IEnumerable<Item> Items { get; protected set; }
public CustomSearchScope(DateTime from, DateTime to, IEnumerable<Item> items)
{
UpdateScope(from, to, items);
}
public void UpdateScope(DateTime from, DateTime to, IEnumerable<Item> items)
{
From = from;
To = to;
Items = items;
}
}
This is where the Smart Client has the built-logic to know how to deal with all the (common) filter value types by selecting a corresponding UI element (edit control) which can populate filter values of these types. For custom filter value types, a plugin will define its own UI element (SearchFilterEditControl) which can manipulate the associated filter value.
So for your scenario, where you are doing everything in code, you will need to handle that yourself.
You can find the available filters and create a value for it using something along the lines of the the snippet below. You will be provided with the base type, so you will need to type cast to the actual filter value type you need to work with, and set the desired values on it, and then call the AddFilterValue() on the SearchCriteria.
var filter = searchAgentPlugin.SearchFilterCategory.Filters.FirstOrDefault(f => f.Name == "e.g. IVA filter");
var filterValue = filter?.CreateValue() as IvaFilterValue;
if (filterValue != null)
{
filterValue.SomeProperty = "custom value";
definition.SearchCriteria.AddFilterValue(filter, filterValue);
}
But in your code snippet you cast to “IvaFilterValue” as an example.
Since I don’t have the Bosch source code to cast to this type I am unable to do this right?
Or should I add a reference to their dll and use the type that way?
Also, maybe in my use case it is possible to call the SearchFilterEditControl. How can I generate a pop-up to show this control? Should I cast this to control and add it to a form?
I used “IvaFilterValue” as an example of some filter value unknown to the Smart Client - in which case, yes, you will need to reference the DLL directly. In case it is a known value (e.g. StringFilterValue, BoolFilterValue, etc.) you can access them directly from the MIP SDK (VideoOS.Platform.dll).
The user control for editing a filter and the filter value itself are not directly related, there is a mapping - codewise - in between. It is the plugin that creates this mapping, and as such you should not directly instantiate edit controls yourself. To create an edit control, you can use the SearchUserControlResolver from the MIP SDK. This automatically loads all “filter value - to - edit control” mappings from the loaded plugins and exposes methods to instantiate them:
This method also expects a FilterConfiguration (first parameter) which is basically a type used to hold the values needed to “prepare” the edit control (e.g. max lengths, hint texts, default values, etc.). You can get this from the filter variable in the code snippet from my previous answer by calling filter.GetFilterConfiguration().
This of course assumes that you want the same edit control as the one used in the Search workspace. If not, you are pretty much on your own.
Once you have an edit control, it is a UserControl like any other, and you can place it anywhere you want; I would recommend that you place a ContentHolder control in your XAML where you want to host it, and then just assign the edit control to the Content property of it. Since you are creating a workspace plugin you should be able to add it directly in there, or pop up your own dialog containing it.
All in all, depending on how you do this, it might leave you with some pretty tight couplings to the Bosch DLL internals which is not something I would recommend.