public Task <HRESULT[]> Start(IList <OpcDaItem> items, ICollection <object> values,
                                      CancellationToken token)
        {
            try
            {
                var serverHandles = ArrayHelpers.GetServerHandles(items);

                HRESULT[] ppErrors;
                int       cancelId = _asyncIO2.Write(serverHandles, values.ToArray(), TransactionId, out ppErrors);

                if (ppErrors.All(e => e.Failed)) // if all errors no callback will take place
                {
                    _requestManager.CompleteRequest(TransactionId);
                    _tcs.SetResult(ppErrors);
                }
                else
                {
                    CancellationId = cancelId;
                    RequestHelpers.SetCancellationHandler(token, Cancel);
                }
                return(Task);
            }
            catch (Exception ex)
            {
                _requestManager.CompleteRequest(TransactionId);
                _tcs.SetException(ex);
                return(Task);
            }
        }
        public Task <OpcDaItemValue[]> Start(IList <OpcDaItem> items, IList <TimeSpan> maxAge, CancellationToken token)
        {
            try
            {
                var       serverHandles = ArrayHelpers.GetServerHandles(items);
                HRESULT[] ppErrors;
                int       cancelId = _asyncIO3.ReadMaxAge(serverHandles, maxAge, TransactionId, out ppErrors);
                if (ppErrors.All(e => e.Failed)) // if all errors no callback will take place
                {
                    _requestManager.CompleteRequest(TransactionId);
                    var result = new OpcDaItemValue[ppErrors.Length];
                    for (var i = 0; i < result.Length; i++)
                    {
                        result[i] = new OpcDaItemValue {
                            Error = ppErrors[i], Item = items[i]
                        };
                    }
                    _tcs.SetResult(result);
                }
                else
                {
                    CancellationId = cancelId;
                    RequestHelpers.SetCancellationHandler(token, Cancel);
                }

                return(Task);
            }
            catch (Exception ex)
            {
                _requestManager.CompleteRequest(TransactionId);
                _tcs.SetException(ex);
                return(Task);
            }
        }
Пример #3
0
        public Task <OpcDaItemValue[]> Start(TimeSpan maxAge, CancellationToken token)
        {
            try
            {
                int cancelId = _asyncIO3.RefreshMaxAge(maxAge, TransactionId);
                CancellationId = cancelId;
                RequestHelpers.SetCancellationHandler(token, Cancel);

                return(Task);
            }
            catch (Exception ex)
            {
                _requestManager.CompleteRequest(TransactionId);
                _tcs.SetException(ex);
                return(Task);
            }
        }
        public Task <OpcDaItemValue[]> Start(OpcDaDataSource dataSource, CancellationToken token)
        {
            try
            {
                int cancelId = _asyncIO2.Refresh2((OPCDATASOURCE)dataSource, TransactionId);
                CancellationId = cancelId;
                RequestHelpers.SetCancellationHandler(token, Cancel);

                return(Task);
            }
            catch (Exception ex)
            {
                _requestManager.CompleteRequest(TransactionId);
                _tcs.SetException(ex);
                return(Task);
            }
        }