コード例 #1
0
        public Guid RegisterClient(string name = null)
        {
            var id     = Guid.NewGuid();
            var status = new ClientStatus {
                ClientId = id, Name = name ?? id.ToString(), Online = false
            };

            Clients.Add(status);
            RaiseClientStatusChanged();
            return(id);
        }
コード例 #2
0
        public Maybe <DeviceController> GoOnline(Guid clientId)
        {
            log.Info($"Go online for client {clientId}");
            ClientStatus client = null;

            try
            {
                client = Clients.Single(p => p.Equals(clientId));
            }
            catch (InvalidOperationException e)
            {
                string message = $"Attempt to go online with unregistered client {clientId}";
                log.Error()
                .Exception(e)
                .Message("Attempt to go online with unregistered client {clientId}", clientId)
                .Write();
                return(Maybe <DeviceController> .Empty);
            }

            try
            {
                EnsureControllerInstanceCreatedAndOpen();
            }
            catch (TimeoutException tex)
            {
                log.Error()
                .Exception(tex)
                .Message("Not connected because state machine timed out waiting for Ready state")
                .Write();
                DestroyControllerInstance();
                return(Maybe <DeviceController> .Empty);
            }

            client.Online = true;
            RaiseClientStatusChanged();
            return(MaybeControllerInstance);
        }