.NET Library Initialization

NuGet package for standalone application development, MilestoneSystems.VideoOS.Platform.SDK, is available from https://www.nuget.org/profiles/milestonesys. Applications developed using those libraries should be compiled as Any CPU or x64 and can be run in 64-bit architecture.

A standalone application using the .NET Library must initialize the components of the library that will be used by the application.

The .NET Library currently has six areas to initialize:

Each of the DLLs has different dependencies to other DLLs. When you use MilestoneSystems.VideoOS.Platform.SDK NuGet package, all needed DLLs are being copied to the output folder when building the project. These DLLs should be copied with the final solution to the end-user machines via the install process.

Note: The VideoOS.Platform.SDK.UI.dll, VideoOS.Platform.SDK.Export.dll and VideoOS.Platform.Media.dll are using C++ dlls. To run in 64-bit environments, they will require your application EXE file being compiled for target x64.

Initialization can be done in the Program.cs file like this:


VideoOS.Platform.SDK.Environment.Initialize();
VideoOS.Platform.SDK.UI.Environment.Initialize();
VideoOS.Platform.SDK.Export.Environment.Initialize();
VideoOS.Platform.SDK.Media.Environment.Initialize();
VideoOS.Platform.SDK.Log.Environment.Initialize();

The first statement is always required, the others are only required if your application is using features supported by those areas.

Login Process

After the environment initialization is complete, the application must log in. The following code shows how to log in using different types of credentials. For instance, the CameraStreamResolution sample shows how to log in with different credential types.


Uri uri = new Uri("http://myserver");
bool secureOnly = true; // If true, only authentication over https is accepted. If false, authentication over both http and https is accepted.

// This will reuse the Windows credentials you are logged in with
NetworkCredential nc = System.Net.CredentialCache.DefaultNetworkCredentials;

// This will use specific Windows credentials
// NetworkCredential nc = new NetworkCredential("username", "password");

// You need this to apply "basic" credentials.
// Below, do AddServer(uri, cc) instead of AddServer(uri, nc)
// CredentialCache cc = VideoOS.Platform.Login.Util.BuildCredentialCache(uri, "username", "password", "Basic");
        
// Alternatively, the BuildCredentialCache can also build credential for Windows login
// CredentialCache cc = VideoOS.Platform.Login.Util.BuildCredentialCache(uri, "domain-or-machine-name\username", "password", "Negotiate");
       
VideoOS.Platform.SDK.Environment.AddServer(secureOnly, uri, nc);

try
{
    VideoOS.Platform.SDK.Environment.Login(uri);
}
catch (ServerNotFoundMIPException snfe)
{
    // Report "Server not found: "
}
catch (InvalidCredentialsMIPException ice)
{
    // Report  "Invalid credentials"
}
catch (Exception)
{
    // Report  "Other error connecting to: " + uri.DnsSafeHost;
}

// No exception thrown means success.
// Loading the configuration Items may take time. If you wish, you may force a load now.
// If you don't load the Items explicitly, they will be loaded automatically when needed.
if (IfeelLikeLoadingNow)
{
    VideoOS.Platform.SDK.Environment.LoadConfiguration(uri)
}

Using the DialogLoginForm

Another way to initialize the .NET Library is to use the DialogLoginForm to log in and initialize the server connection. This form will show a login dialog, and connect to the server with the credential provided. Only upon successful completion, or cancellation, will the dialog return. Please observe that the DialogLoginForm limits you to log in to one server at a time.


private static readonly Guid IntegrationId = new Guid("cb77dfe2-339e-4e6e-9c48-2f1ea09f057f");
private const string IntegrationName = "My Integration Name";
private const string Version = "1.0";
private const string ManufacturerName = "Sample Manufacturer";

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    VideoOS.Platform.SDK.Environment.Initialize();
    // Initialize all the other areas needed in the application.
    DialogLoginForm loginForm = new DialogLoginForm(SetLoginResult, IntegrationId, IntegrationName, Version, ManufacturerName);
    Application.Run(loginForm);
    if (Connected)
    {
      Application.Run(new MainForm());
    }
}

private static bool Connected = false;
private static void SetLoginResult(bool connected)
{
    Connected = connected;
}