/// <summary>
        /// Associate default portprofile with HNV LogicalNetwork.
        /// </summary>
        /// <param name="portProfileConfig">PortProfileConfig instance.</param>
        public void AssociatePortProfileWithHNV(PortProfileConfig portProfileConfig)
        {
            // Verify arguments.
            if (portProfileConfig == null) {
                return;
            }

            var vsemUplinkPortProfile = portProfileConfig.GetUplinkPortProfileById(VSEMODLConstants.UPLINK_PORT_PROFILE_ID);
            if (vsemUplinkPortProfile == null) {
                // If not exists default UplinkPortProfile, output ETW and return.
                ODLVSEMETW.EventWriteGetHNVUplinkPortProfileNotFound(MethodBase.GetCurrentMethod().Name,
                    string.Format("UplinkPortProfile Guid is {0}", VSEMODLConstants.UPLINK_PORT_PROFILE_ID.ToString()));
                return;
            }

            var tmpGuid = vsemUplinkPortProfile.LogicalNetworkDefinitionIds.FirstOrDefault(l => l.CompareTo(HNVODLConstants.LOGICAL_NETWORK_DEFINITION.ID) == 0);
            if (tmpGuid != Guid.Empty) {
                // If default PortProfile has been associated with HNV LogicalNetwork, return this function.
                return;
            }

            List<Guid> mergedGuidList = new List<Guid>();
            mergedGuidList.AddRange(vsemUplinkPortProfile.LogicalNetworkDefinitionIds);
            mergedGuidList.Add(HNVODLConstants.LOGICAL_NETWORK_DEFINITION.ID);
            vsemUplinkPortProfile.LogicalNetworkDefinitionIds = mergedGuidList.ToArray();

            List<KeyValuePair<string, string>> mergedTagList = new List<KeyValuePair<string, string>>();
            mergedTagList.AddRange(vsemUplinkPortProfile.Tags);
            mergedTagList.Add(new KeyValuePair<string, string>("Network", "HNV"));
            vsemUplinkPortProfile.Tags = mergedTagList.ToArray();

            vsemUplinkPortProfile.LastModifiedTimeStamp = System.DateTime.Now;
        }
        /// <summary>
        /// Update the VSEM repository.
        /// </summary>
        /// <param name="txnMng">Transaction manager.</param>
        public void UpdateConnection(TransactionManager txnMng)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();
            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder("\"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng));
            ODLVSEMETW.EventWriteStartLibrary(MethodBase.GetCurrentMethod().Name, json.ToString());
            if (txnMng == null) {
                throw new ArgumentException(
                    "txnMng' is null or invalid.");
            }

            string VtnHostName = this.ConnectionString;

            if (VtnHostName.StartsWith(@"https://", StringComparison.Ordinal)) {
                VtnHostName = VtnHostName.Substring(8);
            }

            VtnHostName = VtnHostName.Split('.', ':').First();
            var vseminformation = this.CreateVSEMInfo();

            // Make sure we can connect to the ODL
            if (!this.VerifyConnection(vseminformation.MinVTNCoVersion)) {
                ODLVSEMETW.EventWriteProcesOdlLibraryError(MethodBase.GetCurrentMethod().Name,
                    "WebAPI version is not supported.");
                throw new ArgumentException("WebAPI version is not supported.");
            }
            Controller odl_ctr = new Controller(this.ConnectionString, this.controllers, this.Credential);
            odl_ctr.Create_ctr(Constants.CTR_NAME);

            ODLVSEMETW.EventWriteCreateODLData(
                MethodBase.GetCurrentMethod().Name, "Creating VSEM repository.");

            VSEMConfig vsemConfig = new VSEMConfig();
            txnMng.SetConfigManager(vsemConfig, TransactionManager.OpenMode.WriteMode);

            // Update Configuration Data;
            vsemConfig.Info = vseminformation;
            vsemConfig.Controller = new VSEMController();
            vsemConfig.Controller.ControllerInfo = this.controllers;
            if (vsemConfig.NetworkServiceSystemInformation.Id.CompareTo(Guid.Empty) == 0) {
                vsemConfig.NetworkServiceSystemInformation = VSEMConnection.CreateSystemInfo();
            } else {
                VSEMODLConstants.SYSTEM_INFO_ID = vsemConfig.NetworkServiceSystemInformation.Id;
            }
            if (vsemConfig.SwitchExtensionInfo.Count == 0) {
                vsemConfig.SwitchExtensionInfo = VSEMConnection.CreateSwitchExtensionInfos();
            } else {
                VSEMODLConstants.SWITCH_EXTENSION_INFO_ID = vsemConfig.SwitchExtensionInfo[0].Id;
            }
            vsemConfig.SwitchExtensionInfo.ForEach((i) =>
                    VSEMConnection.AddSwitchFeatureToSwitchExtInfos(i, this.controllers));

            LogicalNetworkConfig logicalNetworkConfig = new LogicalNetworkConfig(VtnHostName);
            txnMng.SetConfigManager(logicalNetworkConfig, TransactionManager.OpenMode.WriteMode);
            if (logicalNetworkConfig.LogicalNetworks.Count == 0) {
                logicalNetworkConfig.LogicalNetworks =
                    this.CreateLogicalNetworks();
            }

            PortProfileConfig portProfileConfig = new PortProfileConfig();
            txnMng.SetConfigManager(portProfileConfig, TransactionManager.OpenMode.WriteMode);

            if (portProfileConfig.UplinkPortProfiles.Count == 0) {
                portProfileConfig.UplinkPortProfiles =
                    VSEMConnection.CreateUplinkPortProfiles();
            } else {
                VSEMODLConstants.UPLINK_PORT_PROFILE_ID = portProfileConfig.UplinkPortProfiles[0].Id;
            }

            if (portProfileConfig.VirtualPortProfiles.Count == 0) {
                portProfileConfig.VirtualPortProfiles =
                    VSEMConnection.CreateVirtualPortProfiles();
            }

            // Create HNV default resource.
            HNVLogicalNetworkManagement hnvMgmt = new HNVLogicalNetworkManagement(this.VtnHostName);
            hnvMgmt.CreateHNVLogicalNetwork(logicalNetworkConfig);
            hnvMgmt.AssociatePortProfileWithHNV(portProfileConfig);

            this.SaveVtncoInfo(txnMng, VtnHostName);

            ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty);
        }
        /// <summary>
        /// This method is responsible for extracting the VSEMVirtualPortProfile
        /// from the VSEM repository for the corresponding connection for the specified id.
        /// </summary>
        /// <param name="txnMng">Transaction manager.</param>
        /// <param name="id">Id of the VSEMVirtualPortProfile.</param>
        /// <returns>VSEMVirtualPortProfile instance attached with the connection.</returns>
        public VSEMVirtualPortProfile GetVSEMVirtualPortProfileById(
            TransactionManager txnMng,
            Guid id)
        {
            var JavaScriptSerializer = new JavaScriptSerializer();
            JavaScriptSerializer.MaxJsonLength = int.MaxValue;
            StringBuilder json = new StringBuilder("\"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng));
            json.Append(" \"id\":" + id.ToString("B"));
            ODLVSEMETW.EventWriteStartLibrary(
                    MethodBase.GetCurrentMethod().Name,
                    json.ToString());
            if (id == Guid.Empty) {
                ODLVSEMETW.EventWriteArgumentError(
                    MethodBase.GetCurrentMethod().DeclaringType.Name.ToString(),
                    MethodBase.GetCurrentMethod().Name,
                    "The parameter 'id' is null or invalid.");
                throw new ArgumentException(
                    "The parameter 'id' is null or invalid.");
            }

            ODLVSEMETW.EventWriteExtractVirtualPortProfile(
                "Extracting VirtualPortProfile Info.", string.Empty);
            var portProfileConfig = new PortProfileConfig();
            try {
                txnMng.SetConfigManager(portProfileConfig, TransactionManager.OpenMode.ReadMode);
                var ret = portProfileConfig.VirtualPortProfiles.FirstOrDefault(
                    port => port.Id == id);
                string output = "\"VSEMVirtualPortProfile\":" + JavaScriptSerializer.Serialize(ret);
                ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output);
                return ret;
            } catch (Exception ex) {
                ODLVSEMETW.EventWriteConfigManagerFileIOError(
                    MethodBase.GetCurrentMethod().Name,
                    string.Format(CultureInfo.CurrentCulture,
                    "PortProfile.config {0}\n{1}",
                    configFileIOErrorValidationMessage,
                    ex.Message));
                ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, string.Empty);
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture,
                    "PortProfile.config {0}",
                    configFileIOErrorValidationMessage));
            }
        }
 /// <summary>
 /// This method is responsible for extracting the list of VSEMVirtualPortProfile
 /// from the VSEM repository for the corresponding connection.
 /// </summary>
 /// <param name="txnMng">Transaction manager.</param>
 /// <returns>List of VSEMVirtualPortProfile instances
 /// attached with the connection.</returns>
 public List<VSEMVirtualPortProfile> GetVSEMVirtualPortProfile(
     TransactionManager txnMng)
 {
     var JavaScriptSerializer = new JavaScriptSerializer();
     JavaScriptSerializer.MaxJsonLength = int.MaxValue;
     StringBuilder json = new StringBuilder("\"TransactionManager\":" + JavaScriptSerializer.Serialize(txnMng));
     ODLVSEMETW.EventWriteStartLibrary(
             MethodBase.GetCurrentMethod().Name,
             json.ToString());
     ODLVSEMETW.EventWriteExtractVirtualPortProfilelist(
         "Extracting list of VirtualPortProfile Info.", string.Empty);
     var portProfileConfig = new PortProfileConfig();
     try {
         txnMng.SetConfigManager(portProfileConfig, TransactionManager.OpenMode.ReadMode);
     } catch (Exception ex) {
         ODLVSEMETW.EventWriteConfigManagerFileIOError(
             MethodBase.GetCurrentMethod().Name,
             string.Format(CultureInfo.CurrentCulture,
             "PortProfile.config {0}\n{1}",
             configFileIOErrorValidationMessage,
             ex.Message));
         throw new InvalidOperationException(
             string.Format(CultureInfo.CurrentCulture,
             "PortProfile.config {0}",
             configFileIOErrorValidationMessage));
     }
     string output = "\"VSEMVirtualPortProfile\":" + JavaScriptSerializer.Serialize(portProfileConfig.VirtualPortProfiles);
     ODLVSEMETW.EventWriteEndLibrary(MethodBase.GetCurrentMethod().Name, output);
     return portProfileConfig.VirtualPortProfiles;
 }