Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
CoffeeConsumableManager.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Collections.ObjectModel;
3using System.Linq;
7
9{
17 {
18 private IEnumerable<IDevice> mConfiguredDevices;
19 private readonly ObservableCollection<IConsumablePool> mPools = new ObservableCollection<IConsumablePool>();
20 public ReadOnlyObservableCollection<IConsumablePool> Pools { get; }
21
27 {
28 return new CoffeeConsumableManager(this);
29 }
30
32 {
33 mKnownCoffeeMakers = new List<MockDevice>(copyFrom.mKnownCoffeeMakers);
34 mPerDeviceConsumables.AddRange(copyFrom.mPerDeviceConsumables.Select(item => item.Clone(this)));
36 }
37
38 // This is called by Chronos.
39 // ReSharper disable once MemberCanBePrivate.Global
41 {
42 Pools = new ReadOnlyObservableCollection<IConsumablePool>(mPools);
43 // looks like we are running in the designer?
44 if (Helpers.Debug == null)
45 {
46 ConfiguredDevices = new[] {new MockDevice(null) {Name = "Fake 1"}, new MockDevice(null) {Name = "Fake 2"}};
47 }
48 }
49
50 public IEnumerable<IDevice> ConfiguredDevices
51 {
52 set
53 {
54 mConfiguredDevices = value;
56 }
57 }
58
59 private readonly List<MockDevice> mKnownCoffeeMakers = new List<MockDevice>();
60 private readonly List<MockConsumablesForCoffeeMakerDevice> mPerDeviceConsumables = new List<MockConsumablesForCoffeeMakerDevice>();
61
63 {
64 var currentDevs = mConfiguredDevices.OfType<MockDevice>().ToList();
65 var removedDevs = mKnownCoffeeMakers.Except(currentDevs).ToList();
66 mPerDeviceConsumables.RemoveAll(item => removedDevs.Contains(item.ForDevice));
67 var newDevs = currentDevs.Except(mKnownCoffeeMakers).ToList();
68 mPerDeviceConsumables.AddRange(newDevs.Select(someDev => new MockConsumablesForCoffeeMakerDevice(someDev,this)));
69 mKnownCoffeeMakers.Clear();
70 mKnownCoffeeMakers.AddRange(currentDevs);
71 if (newDevs.Any() || removedDevs.Any())
72 {
74 }
75 }
76
77 private void PoolsChanged()
78 {
79 mPools.Clear();
80 foreach (var somePool in mPerDeviceConsumables.SelectMany(item => item.Pools))
81 {
82 mPools.Add(somePool);
83 }
84 }
85
86 public static string GetLocationIdentifier(MockDevice dev, string ingredientName)
87 {
88 return $"{dev.Name}:{ingredientName}";
89 }
90 }
91}
Classes and interfaces that are meant for plugins. The classes and interfaces below this namespace ar...
A fake device. This namespace contains the fake device driver and auxiliary classes for settings,...
Implement this interface if you need direct access to the list of configured devices.
Static instance for access to utility functions and resources.
Definition Helpers.cs:78
static IDebugHelper Debug
Utility functions for debugging.
Definition Helpers.cs:97
Keeps track of all consumables that are associated to our mock coffee machine.
CoffeeConsumableManager(CoffeeConsumableManager copyFrom)
readonly ObservableCollection< IConsumablePool > mPools
static string GetLocationIdentifier(MockDevice dev, string ingredientName)
IEnumerable< IDevice > ConfiguredDevices
List of IDevice for all configured devices in Chronos.
readonly List< MockConsumablesForCoffeeMakerDevice > mPerDeviceConsumables
IManageConsumables Clone()
Will be cloned for schedule validation.
ReadOnlyObservableCollection< IConsumablePool > Pools
List of all consumable pools you manage.
A chronos plugin implementation for a fake device. We pretend we are controlling a mixture of coffee ...
Definition MockDevice.cs:53