This example demonstrates how to subscribe to a published library.

This example uses the steps that are described in the Subscribe to a Content Library procedure.

...
using vmware.content;
using vmware.content.library;
 
...
 
// Create a StorageBacking instance to store
// the contents of the subscribed library on the local file system.
var libraryBacking = new StorageBacking();
libraryBacking.SetType(StorageBacking.Type.OTHER);
libraryBacking.SetStorageUri(new Uri("/mnt/nfs/cls-root"));
 
// Create a new SubscriptionInfo object to define the subscription
// behavior of the library.
var subscriptionInfo = new SubscriptionInfo();
subscriptionInfo.SetAuthenticationMethod(SubscriptionInfo.AuthenticationMethod.BASIC);
subscriptionInfo.SetUserName("libraryUser");
subscriptionInfo.SetPassword("password".ToCharArray());
subscriptionInfo.SetSubscriptionUrl(new Uri("https://www.acmecompary.com/library_inventory/lib.json"));
 
// Specify that the content of the subscribed library will be downloaded immediately
subscriptionInfo.SetAutomaticSyncEnabled(true);
 
// Set an SHA-1 hash of the SSL certificate of the remote endpoint.
subscriptionInfo.SetSslThumbprint("9B:00:3F:C4:4E:B1:F3:F9:0D:70:47:48:E7:0B:D1:A7:0E:DE:60:A5");
 
// Create a new LibraryModel object for the subscribed library.
var libraryModel = new LibraryModel();
libraryModel.SetType(vmware.content.LibraryModel.LibraryType.SUBSCRIBED);
libraryModel.SetName("SubscrLibrary");
 
// Attach the storage backing and the subscription info to the library model.
libraryModel.SetStorageBackings(new List<StorageBacking>() { libraryBacking });
libraryModel.SetSubscriptionInfo(subscriptionInfo);
 
// Create the new subscribed library.
SubscribedLibrary subscribedLibService = ServiceManager.VapiConnection.GetService<SubscribedLibrary>();
var clientToken = Guid.NewGuid().ToString();
var subscribedLibId = subscribedLibService.Create(clientToken, libraryModel);