public static void Run(string pathToXml, string connectionString, string databaseName) { try { var _opcClient = new OpcClientService(); if (pathToXml == null || pathToXml.Length == 0) { throw new ArgumentException(); } _connectionString = connectionString; _databaseName = databaseName; var _operations = XmlSerializer.GetOperations(pathToXml); _operationTriggers = new Dictionary <string, OpcOperation>(); _branchs = new List <string>() { "plc1", "hmi_recipe" }; _operationManager = new OperationManager(_logger); _applicationConfiguration = _applicationConfiguration ?? _opcClient.GetApplicationConfiguration(); _applicationInstance = _applicationInstance ?? _opcClient.GetApplicationInstance(_applicationConfiguration); _ifSertificate = _opcClient.CheckSertificate(_applicationInstance); _endpointConfiguration = _endpointConfiguration ?? _opcClient.GetEndpointConfiguration(_applicationConfiguration); try { _endpointDescription = _endpointDescription ?? _opcClient.GetEndpointDescription(); } catch (ServiceResultException ex) { throw ex; } _configuredEndPoint = _configuredEndPoint ?? _opcClient.GetConfiguredEndpoint(_endpointDescription, _endpointConfiguration); _session = _opcClient.GetSession(_applicationConfiguration, _configuredEndPoint); if (!_session.Connected) { Thread.Sleep(10000); return; } if (_session == null) { _session.KeepAliveInterval = 2000; _session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive); } SearchDataInTree(_session, ObjectIds.ObjectsFolder); foreach (var s in _branchs) { var _element = s; SearchDataInTree(_session, new NodeId((_references.FirstOrDefault(x => 0 == string.Compare(x.DisplayName.ToString(), _element, true)).NodeId.ToString()))); } _operationTriggers = _operationManager.GetOpcOperationCollection(_operations, _references); var _operationsListForSubscribe = _references.FindAll(x => true == _operationTriggers.Any(z => 0 == string.Compare(z.Value.key, x.DisplayName.ToString(), true))); var _subscription = new Subscription(_session.DefaultSubscription) { PublishingInterval = 1000 }; var _monitoredItems = Subscribe(_subscription, _operationsListForSubscribe); _monitoredItems.ForEach(i => i.Notification += OnNotification); Console.WriteLine("Step 1 - Add a list of items you wish to monitor to the subscription."); _subscription.AddItems(_monitoredItems); Console.WriteLine("Step 2 - Add the subscription to the session."); _session.AddSubscription(_subscription); _subscription.Create(); Console.WriteLine("===================//--//========================="); Console.ReadKey(true); } catch (Exception ex) { _logger.Error(ex, "Error SearchDataInTree method: {0}", ex.Message); } }