public TrainControl(Z21Client.Z21Client _controller, Vehicle _vehicle, Database _db)
        {
            try
            {
                if (_controller is null || _vehicle is null || _db is null)
                {
                    throw new NullReferenceException($"Parameter {nameof(_controller)} ist null!");
                }

                db         = _db;
                controller = _controller;

                DataContext = this;
                InitializeComponent();
                Activate();

                Vehicle = db.Vehicles.Include(e => e.Functions).ToList().FirstOrDefault(e => e.Id == _vehicle.Id) !;

                if (Vehicle is null)
                {
                    throw new NullReferenceException($"Vehilce with adress {_vehicle.Address} not found!");
                }

                Adresse = new(Vehicle.Address);
                Title   = $"{Vehicle.Address} - {(string.IsNullOrWhiteSpace(Vehicle.Name) ? Vehicle.FullName : Vehicle.Name)}";

                SlowestVehicleInTractionList = Vehicle;

                controller.LogOn();
                controller.OnGetLocoInfo     += Controller_OnGetLocoInfo;
                controller.TrackPowerChanged += Controller_TrackPowerChanged;
                controller.OnStatusChanged   += Controller_OnStatusChanged;
                controller.GetLocoInfo(new LokAdresse(Vehicle.Address));
                controller.GetStatus();

                DrawAllFunctions();
                DrawAllVehicles(db.Vehicles.ToList().Where(m => m.Id != Vehicle.Id));

                MultiTractionList.Add(new MultiTractionItem(Vehicle));
            }
            catch (Exception ex)
            {
                Close();
                Logger.Log("Fehler beim öffnen des Controllers.", ex);
                MessageBox.Show($"Beim öffnen des Controllers ist ein Fehler aufgetreten: {(string.IsNullOrWhiteSpace(ex?.Message) ? "" : ex.Message)}", "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
 public Einmessen(Database db, Z21Client.Z21Client controller)
 {
     this.DataContext = this;
     if (db is null)
     {
         throw new ApplicationException($"Paramter '{nameof(db)}' darf nicht null sein!");
     }
     if (controller is null)
     {
         throw new ApplicationException($"Paramter '{nameof(controller)}' darf nicht null sein!");
     }
     this.Db         = db;
     this.Controller = controller;
     InitializeComponent();
     SetupManagementEventWatcher();
     Controller.OnGetLocoInfo += OnGetLocoInfoEventArgs;
 }