Provides access to a COM server.
Inheritance: ComObject
Ejemplo n.º 1
0
        /// <summary>
        /// Returns a localized client for the specified locale id.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <param name="localeId">The locales id.</param>
        /// <returns>A localized client.</returns>
        public ComClient GetLocalizedClient(IUserIdentity identity, int localeId)
        {
            // check if a logon is required.
            string userName = null;

            if (identity != null && identity.TokenType == UserTokenType.UserName)
            {
                userName = (identity.GetIdentityToken() as UserNameIdentityToken).UserName;
            }

            if (String.IsNullOrEmpty(userName) && localeId == ComUtils.LOCALE_SYSTEM_DEFAULT)
            {
                Utils.Trace("COM Client Selected: DEFAULT (no match for locale)");
                return(DefaultClient);
            }

            // create the key.
            StringBuilder buffer = new StringBuilder();

            buffer.Append(localeId);

            if (!String.IsNullOrEmpty(userName))
            {
                buffer.Append(':');
                buffer.Append(userName);
            }

            string key = buffer.ToString();

            if (m_localizedClients == null)
            {
                m_localizedClients = new Dictionary <string, ComClient>();
            }

            ComClient client = null;

            if (!m_localizedClients.TryGetValue(key, out client))
            {
                client              = CreateClient();
                client.Key          = key;
                client.LocaleId     = localeId;
                client.UserIdentity = identity;
                client.CreateInstance();
                m_localizedClients[key] = client;
            }

            // Utils.Trace("COM Client Seleted: {0}", key);
            return(client);
        }
        /// <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.");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns a localized client based on the preferred locales.
 /// </summary>
 /// <param name="identity">The identity to use.</param>
 /// <param name="preferredLocales">The locales to use.</param>
 /// <returns>A localized client.</returns>
 public ComClient GetLocalizedClient(IUserIdentity identity, IList <string> preferredLocales)
 {
     return(GetLocalizedClient(identity, ComClient.SelectLocaleId(AvailableLocaleIds, preferredLocales)));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscribeRequestManager"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="client">The COKM client wrapper.</param>
        /// <param name="propertySamplingInterval">The property sampling interval.</param>
        public SubscribeRequestManager(ServerSystemContext context, ComClient client, int propertySamplingInterval)
        {
            m_context = context;

            m_propertySamplingInterval = propertySamplingInterval;
            m_subscribedItems = new Dictionary<string, SubscribeItemRequest>();
            m_subscribedProperties = new Dictionary<string, SubscribePropertyRequest>();
            m_groups = new List<ComDaGroup>();
            m_monitoredItems = new Dictionary<uint, IMonitoredItem>();

            if (client == null)
            {
                LocaleId = ComUtils.LOCALE_SYSTEM_DEFAULT;
                UserIdentity = null;
                Key = String.Empty;
            }
            else
            {
                LocaleId = client.LocaleId;
                UserIdentity = client.UserIdentity;
                Key = client.Key;
            }
        }