Refresh EnvironnementManager

I’m trying to get the list of all the analytics events configured on a Milestone server. To this end, I’m using ManagementServer.AnalyticsEventFolder.AnalyticsEvents, as suggested in a previous post (https://developer.milestonesys.com/s/question/0D53X0000BnqyI0SQI/is-it-possible-to-get-the-list-of-all-analytics-events).

This works pretty well, however, there is a scenario where it ends up wrong. Scenario’s the following:

  • Trying to connect to a machine that is not a Milestone server (eg by having a typo in the server address)
  • Correcting the address and reconnecting to the Milestone server

In this situation, when executing the following line

ManagementServer ^server = gcnew ManagementServer(EnvironmentManager::Instance->MasterSite->ServerId);

The following exception is raised : “VideoOS.Platform.ArgumentMIPException: ‘Server with serverId not found’”

I’m assuming this has to do with the EnvironnementManager not being refreshed after the reconnection to the Milestone server? If so, is there any way to refresh this manually? So far, the only way to make it work is to close and execute my software again.

The login method should handle the update of the EnvironmentManager.Instance.MasterSite. How does the code you use for logging in look like?

Thanks for your answer,

Our system is starting to get a bit complex, so I will try to summarize a bit in here, let me know if you think that something is missing:

void MilestoneSdk::Connect(String ^url, Net::NetworkCredential ^credential)
{
	Net::CredentialCache ^cache = gcnew Net::CredentialCache();
	cache->Add(m_serverUri, authType, credential);
 
	VideoOS::Platform::SDK::Environment::Initialize();
	VideoOS::Platform::SDK::Media::Environment::Initialize();
	VideoOS::Platform::SDK::Environment::AddServer(s_isOnlyUsingSecureConnection, m_serverUri, cache, s_masterOnly);
	VideoOS::Platform::SDK::Environment::Login(m_serverUri, s_masterOnly);
}

Once again, this is more of a pseudo-code that summarizes the main process, since the real code is starting to get a bit complex, but I think you have the main steps here. Please let me know if we are missing something.

I was not able to reproduce the issue with the latest version of MilestoneSystems.VideoOS.Platform.SDK NuGet package. I have attached the test application (in C#) I implemented for testing the scenario.

I would suggest that you take a look at your code and check how you handle the unsuccessful login:

  • Are you removing the incorrect server using VideoOS.Platform.SDK.RemoveServer()?
  • Are you updating the credential cache with the correct serverUri?
  • Is the consecutive login to the correct server succesful?

I am also attaching the executable for the test app in case you want to run it without compiling.

The application is a console application and expects the following command line arguments:

username password authenticationType incorrectServerAddress correctServerAddress

For example:

user1234 password1234 Basic https://incorrectAddress https://CorrectAddress

Your sample works perfectly fine, it seems the execution was not exactly as I thought, and I was missing the RemoveServer() call.

This now works just as intended, thank you very much for your time!