internal void watch()
        {
            var state = _connected;

            _connected = Ready();

            if (_connected == state)
            {
                return;
            }
            if (_connected)
            {
                Status =
                    Status == CalliopeStatus.Restarting
                        ? CalliopeStatus.Restarted
                        : CalliopeStatus.Connected;

                StatusChanged?.Invoke(Status);
                Connected?.Invoke();
            }
            else
            {
                if (Status == CalliopeStatus.AwaitingRestart)
                {
                    Status = CalliopeStatus.Restarting;
                }
                else
                {
                    Status = CalliopeStatus.Disconnected;
                }
                StatusChanged?.Invoke(Status);
                Disconnected?.Invoke();
            }
        }
 public CalliopeConnection(string drive, Action connected = null, Action disconnected = null, Action <CalliopeStatus> statusChanged = null)
 {
     Status         = CalliopeStatus.Disconnected;
     Drive          = drive;
     Connected     += connected;
     Disconnected  += disconnected;
     StatusChanged += statusChanged;
     Task.Factory.StartNew(() =>
     {
         while (_watch)
         {
             watch();
             Thread.Sleep(TimeSpan.FromSeconds(1));
         }
     });
 }
Пример #3
0
        public void ShowCalliopeStatus(CalliopeStatus status)
        {
            doInUi(() =>
            {
                switch (status)
                {
                case CalliopeStatus.Connected:
                    CalliopeVerbundenLabel_.Text     = TextFor.Connected;
                    calliopePicture.Image            = Properties.Resources.Calliope;
                    CalliopeVerbundenLabel.ForeColor = Color.Green;
                    break;

                case CalliopeStatus.AwaitingRestart:
                    CalliopeVerbundenLabel_.Text     = TextFor.AwaitingRestart;
                    calliopePicture.Image            = Properties.Resources.Calliope;
                    CalliopeVerbundenLabel.ForeColor = Color.DodgerBlue;
                    break;

                case CalliopeStatus.Restarting:
                    CalliopeVerbundenLabel_.Text     = TextFor.Restarting;
                    calliopePicture.Image            = Properties.Resources.Calliope;
                    CalliopeVerbundenLabel.ForeColor = Color.DodgerBlue;
                    break;

                case CalliopeStatus.Restarted:
                    CalliopeVerbundenLabel_.Text     = TextFor.Restarted;
                    calliopePicture.Image            = Properties.Resources.Calliope;
                    CalliopeVerbundenLabel.ForeColor = Color.Green;
                    break;

                case CalliopeStatus.Disconnected:
                default:
                    CalliopeVerbundenLabel_.Text     = TextFor.Disconnected;
                    calliopePicture.Image            = Properties.Resources.Calliope_sepia;
                    CalliopeVerbundenLabel.ForeColor = Color.DarkOrange;
                    break;
                }
            });
        }
        internal void CopyFrom(string file)
        {
            if (!Ready())
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                try
                {
                    Status = CalliopeStatus.AwaitingRestart;
                    StatusChanged?.Invoke(Status);
                    File.Copy(
                        file,
                        Path.Combine(Drive, Path.GetFileName(file)));
                }
                catch
                {
                    // ignored
                }
            });
        }
Пример #5
0
 private void statusChanged(CalliopeStatus status)
 {
     _view.ShowCalliopeStatus(status);
     Debug.WriteLine($"Status: {status}");
 }