Beispiel #1
0
 private void EnsureCorrectState(CnxState allowedStates, [CallerMemberName] string methodName = "<unknown>")
 {
     if ((state & allowedStates) == 0)
     {
         var message = $"Connection (${this}) is not in the correct state for the requested operation (${methodName}). Current state: ${state} Allowed states: ${allowedStates}";
         throw new InvalidOperationException(message);
     }
 }
        private void Start()
        {
            if (!IsPaired)
            {
                var message = $"{ToString()} - Connection cannot be started without pairing first.";
                throw new InvalidOperationException(message);
            }

            lock (stateLock)
            {
                EnsureCorrectState(CnxState.Created);
                var batchProcessor = new BatchProcessor(this, serviceHost, transport, logger);
                Task.Run(() => batchProcessor.ProcessAsync(cancelTokenSource.Token));
                state = CnxState.Connected;
            }
        }