Get camera name and logged user name - plugin development for smart client

I’m in the process of developing new plugin for Smart Client. I need to get information about the camera (camera name) after pushing the button (working on ActiveElementsOverlay plugin as a template).

I’ve noticed, that one of sample plugins displays camera name (in red font) but wasn’t able to figure out which plugin it was so I can check the sample code.

Also - can I get information about logged in user? (ID, user name)

Thanks!

The sample that cause the name of the camera to be shown as a red (pink) text overlay is Smart Client Overlay on Event..

https://doc.developer.milestonesys.com/html/index.html?base=samples/scoverlayonevent.html&tree=tree_1.html

Also -

The name of the user logged in is-

string VideoOS.Platform.Login.LoginSettings.UserName

https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_login_1_1_login_settings.html&tree=tree_search.html?search=loginsettings

I’m sorry, but I wasn’t able to find specific line of code - is there a simple solution, something like:

cameraid=GetCameraId();

or similar?

same with the user name:

userid/name=GetUser();

Thank you!

You must be in the right context so that you have the ImageViewerAddOn object but then it is a simple method.

abstract FQID VideoOS.Platform.Client.ImageViewerAddOn.CameraFQID

https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_client_1_1_image_viewer_add_on.html&tree=tree_search.html?search=addon

Username is always available no matter the context.

string VideoOS.Platform.Login.LoginSettings.UserName

https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_login_1_1_login_settings.html&tree=tree_search.html?search=username

Did you get it to work?

Unfortunately not, I’d need your help…

Remember when you helped me with code for custom buttons? I need a solution that:

  1. After clicking in button will display camera name, even using MessageBox.Show(). In general - I need camera name in string.
  2. Same with user login

The post I’m referring to is here:

https://developer.milestonesys.com/s/question/0D53X000063aFJbSAM/activeelementsoverlay-sample-code-new-buttons-interface

Thanks! I’ve tried multiple times, hope you can help, It’s important.

private void ButtonExtra_Click(object sender, RoutedEventArgs e)
{
	ImageViewerAddOn addOn = _buttonIVAddON[sender as Button];
	MessageBox.Show(addOn.CameraName);
	LoginSettings ls = LoginSettingsCache.GetLoginSettings(EnvironmentManager.Instance.MasterSite);
	MessageBox.Show(ls.FullyQualifiedUserName);
}

Thank you Bo, but unfortunately this code doesn’t work - it compiles fine in Visual Studion (no errors), but when I click on the button in Smart Client, it throws an error:

************** Exception Text **************

************** Outer Exception **************

Exception type:System.MissingMethodException

Exception message:Method not found: ‘System.String VideoOS.Platform.Login.LoginSettings.get_FullyQualifiedUserName()’.

Exception source:ActiveElementsOverlay

Exception Target Site: ButtonExtra_Click

at ActiveElementsOverlay.Background.ActiveElementsOverlayBackgroundPlugin.ButtonExtra_Click(Object sender, RoutedEventArgs e)

at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

at System.Windows.Controls.Primitives.ButtonBase.OnClick()

at System.Windows.Controls.Button.OnClick()

at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)

at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)

at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)

at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)

at System.Windows.Input.InputManager.ProcessStagingArea()

at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)

at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)

at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

************** System Info **************

Date and time: 12/20/2019 3:16:57 PM

Machine Name: DESKTOP-OILDD1G

Processors count: 8

OS version: Microsoft Windows NT 6.2.9200.0

64 bit OS: True

64 bit process: True

IP address: fe80::e4b0:af90:ab52:2450%10 (DESKTOP-OILDD1G)

Current user: DESKTOP-OILDD1G\KnowFalls

Product version 13.1.141.1

Execption log: [C:\ProgramData\Milestone\XProtect](file:C:/ProgramData/Milestone/XProtect) Smart Client\Exceptions\ExceptionLog_2019-12-20T03.16.57.1037.xml

I did test the code before showing it. I have a nagging suspicion that you might be testing with an older Smart Client. Let me know the version of the Smart Client and the MIP SDK you use.

I’m using Smart Client 2019 R1 and Milestone MIP SDK 2019 R2.

The error indicate that LoginSettings.FullyQualifiedUserName is not supported. This is true as it was introduced in 2019R2. Unfortunately this is not mentioned in the newer documentation as a newly added feature, and there is no mention when you lookup FullyQualifiedUserName in the documentation that it is supported from 2020R2.

When testing with 2019R1 I was able to make it work by using LoginSettings.UserName instead.

Thank you Bo, username works great!!!

But I still cannot get camera box name/id, have an error message as attached. Probably it is also related to different SDK/SC client.

Can you fix/modify the code related with displaying camera name/id like you did with username?

This you will have to debug, I guess the dictonaries is missing an entry in your implementation.

https://developer.milestonesys.com/s/article/debugging-techniques-for-Smart-Client-plugins

My code is based on template you provided a while ago. Please see this post, it includes code you created for us few months ago.

https://developer.milestonesys.com/s/question/0D53X000063aFJbSAM/activeelementsoverlay-sample-code-new-buttons-interface

I’d really appreciate answer to this question regarding camera name/id, it is super important for us.

It would be great if I can get just as simple solution as with username.

Thank you for your support.

My code works for me, you need to debug yours.

My code that works for me including the user name. http://download.milestonesys.com/MIPSDK/Samples/ActiveElementsOverlayBackgroundPluginUsername.zip

What did you find in your debugging?

Still need help on that - can you just provide same, working solution for displaying camera box name/id - same like for username (that worked just fine). Please take into consideration my version of SDK and Smart Client.

Tried to solve this problem using information from your previous posts, but unfortunately it didn’t work for me.

The latest file I supplied is including username and camera!

Bo, I was able to use your code and make it work. Thank you!

My next task is to use timers and trigger them after clicking one of the new buttons. The structure is the same as you provided. Please see this example.

While using this code within button, it does not compile correctly:

if (button.Content.Equals(“BUTONX”))

  {

    var timer1 = new Timer()

    {

      Interval = 1000

    };

    timer1.Enabled = true;

    timer1.Elapsed += OnTimedEvent;

    void OnTimedEvent(Object source, ElapsedEventArgs e)

    {

      //timeLeft--;

      //var timespan = TimeSpan.FromSeconds(timeLeft);

      //txtTimer.Text = timespan.ToString(@"mm\\:ss");

      MessageBox.Show("One Second");

    }

    MessageBox.Show("PRIVACY");

  }