/// <summary> /// Updates the metadata cached for the server. /// </summary> private void DoMetadataUpdate(object state) { try { if (!Server.IsRunning) { return; } ComClientManager system = (ComClientManager)SystemContext.SystemHandle; ComClient client = (ComClient)system.SelectClient(SystemContext, true); int[] availableLocales = client.QueryAvailableLocales(); if (availableLocales != null) { lock (Server.DiagnosticsLock) { // check if the server is running. if (!Server.IsRunning) { return; } // get the LocaleIdArray property. BaseVariableState localeArray = Server.DiagnosticsNodeManager.Find(Opc.Ua.VariableIds.Server_ServerCapabilities_LocaleIdArray) as BaseVariableState; List <string> locales = new List <string>(); // preserve any existing locales. string[] existingLocales = localeArray.Value as string[]; if (existingLocales != null) { locales.AddRange(existingLocales); } for (int ii = 0; ii < availableLocales.Length; ii++) { if (availableLocales[ii] == 0 || availableLocales[ii] == ComUtils.LOCALE_SYSTEM_DEFAULT || availableLocales[ii] == ComUtils.LOCALE_USER_DEFAULT) { continue; } try { System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.GetCultureInfo(availableLocales[ii]); if (!locales.Contains(culture.Name)) { locales.Add(culture.Name); } } catch (Exception e) { Utils.Trace(e, "Can't process an invalid locale id: {0:X4}.", availableLocales[ii]); } } localeArray.Value = locales.ToArray(); } } // invoke callback. if (m_metadataUpdateCallback != null) { m_metadataUpdateCallback(state); } } catch (Exception e) { Utils.Trace(e, "Unexpected error updating HDA server metadata."); } }