コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcurrentRequestExecutor"/> class with the specified
        /// connection and memory pool.
        /// </summary>
        /// <param name="connection">The <see cref="S7Connection"/> that is used for this executor.</param>
        /// <param name="memoryPool">
        /// The <see cref="MemoryPool{T}" /> that is used for request and response memory allocations.
        /// </param>
        public ConcurrentRequestExecutor(S7Connection connection, MemoryPool <byte>?memoryPool = default)
        {
            if (connection.Parameters == null)
            {
                Sally7CommunicationSetupException.ThrowConnectionParametersNotSet();
            }

            Connection      = connection;
            socket          = connection.TcpClient.Client;
            bufferSize      = connection.Parameters.GetRequiredBufferSize();
            maxRequests     = connection.Parameters.MaximumNumberOfConcurrentRequests;
            this.memoryPool = memoryPool ?? MemoryPool <byte> .Shared;

            jobPool       = new JobPool(connection.Parameters.MaximumNumberOfConcurrentRequests);
            sendSignal    = new Signal();
            receiveSignal = new Signal();

            if (!sendSignal.TryInit())
            {
                Sally7Exception.ThrowFailedToInitSendingSignal();
            }
            if (!receiveSignal.TryInit())
            {
                Sally7Exception.ThrowFailedToInitReceivingSignal();
            }

            reader = new SocketTpktReader(socket);

#if !NETSTANDARD2_1_OR_GREATER && !NET5_0_OR_GREATER
            sendAwaitable = new SocketAwaitable(new SocketAsyncEventArgs());
#endif
        }
コード例 #2
0
        public Srv.Dto.S7.Model.S7Connection GetS7ConnectionModelById(IdObject idObject, CallContext context = default)
        {
            _logger.LogTrace("Query Behavior: " + GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod()?.Name);
            Srv.Dto.S7.S7Connection connection;

            if (idObject.Id.Equals(Guid.Empty))
            {
                connection = new S7Connection();
            }
            else
            {
                connection = _query.GetS7ConnectionById(idObject, context);
            }

            var automationTypeId = _queryKeyValue.AutomationTypeId(context);
            var connectionTypeId = _queryS7KeyValue.ConnectionTypeId(context);
            var cpuTypeId        = _queryS7KeyValue.CpuTypeId(context);

            return(new Srv.Dto.S7.Model.S7Connection(connection, automationTypeId.List, connectionTypeId.List, cpuTypeId.List));
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcurrentRequestExecutor"/> class with the specified
        /// connection and memory pool.
        /// </summary>
        /// <param name="connection">The <see cref="S7Connection"/> that is used for this executor.</param>
        /// <param name="memoryPool">
        /// The <see cref="MemoryPool{T}" /> that is used for request and response memory allocations.
        /// </param>
        public ConcurrentRequestExecutor(S7Connection connection, MemoryPool <byte> memoryPool)
        {
            if (connection.Parameters == null)
            {
                throw new ArgumentException(
                          "The connection must be initialized and it's Parameters property must have a value.");
            }

            Connection      = connection;
            socket          = connection.TcpClient.Client;
            bufferSize      = connection.Parameters.GetRequiredBufferSize();
            maxRequests     = connection.Parameters.MaximumNumberOfConcurrentRequests;
            this.memoryPool = memoryPool;

            var maxNumberOfConcurrentRequests = connection.Parameters.MaximumNumberOfConcurrentRequests;

            jobChannel     = Channel.CreateBounded <byte>(maxNumberOfConcurrentRequests);
            sendChannel    = Channel.CreateBounded <byte>(1);
            receiveChannel = Channel.CreateBounded <byte>(1);

            if (!Enumerable.Range(1, maxNumberOfConcurrentRequests).All(i => jobChannel.Writer.TryWrite((byte)i)))
            {
                throw new Exception($"Failed to initialize the job channel.");
            }

            if (!sendChannel.Writer.TryWrite(1))
            {
                throw new Exception("Failed to initialize the sending channel.");
            }
            if (!receiveChannel.Writer.TryWrite(1))
            {
                throw new Exception("Failed to initialize the receiving channel.");
            }

            requests = Enumerable.Range(0, maxNumberOfConcurrentRequests).Select(_ => new Request()).ToArray();

            reader        = new SocketTpktReader(socket);
            sendAwaitable = new SocketAwaitable(new SocketAsyncEventArgs());
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConcurrentRequestExecutor"/> class with the specified
 /// connection.
 /// </summary>
 /// <param name="connection">The <see cref="S7Connection"/> that is used for this executor.</param>
 public ConcurrentRequestExecutor(S7Connection connection) : this(connection, MemoryPool <byte> .Shared)
 {
 }