private void App_OnStartup(object sender, StartupEventArgs e) { var colorsForGraphics = new List <Color> { Colors.LawnGreen, Colors.Red, Colors.Cyan, Colors.Yellow, Colors.Coral, Colors.LightGreen, Colors.HotPink, Colors.DeepSkyBlue, Colors.Gold, Colors.Orange, Colors.Violet, Colors.White, Colors.Fuchsia, Colors.LightSkyBlue, Colors.LightGray, Colors.Khaki, Colors.SpringGreen, Colors.Tomato, Colors.LightCyan, Colors.Goldenrod, Colors.SlateBlue, Colors.Cornsilk, Colors.MediumPurple, Colors.RoyalBlue, Colors.MediumVioletRed, Colors.MediumTurquoise }; _debugLogger = new RelayMultiLoggerWithStackTraceSimple( new RelayLoggerWithStackTrace( new RelayActionLogger(s => { }), new StackTraceFormatterWithNullSuport(" > ", "[NO STACK INFO]")), new RelayLoggerWithStackTrace( new RelayLogger( new ColoredConsoleLogger(ConsoleColor.Red, ConsoleColor.Black), new ChainedFormatter(new List <ITextFormatter> { new ThreadFormatter(" > ", true, false, false), new DateTimeFormatter(" > ") })), new StackTraceFormatterWithNullSuport(" > ", "[NO STACK INFO]")), new RelayLoggerWithStackTrace( new RelayLogger( new ColoredConsoleLogger(ConsoleColor.Yellow, ConsoleColor.Black), new ChainedFormatter(new List <ITextFormatter> { new ThreadFormatter(" > ", true, false, false), new DateTimeFormatter(" > ") })), new StackTraceFormatterWithNullSuport(" > ", "[NO STACK INFO]")), new RelayLoggerWithStackTrace( new RelayLogger( new ColoredConsoleLogger(ConsoleColor.DarkCyan, ConsoleColor.Black), new ChainedFormatter(new List <ITextFormatter> { new ThreadFormatter(" > ", true, false, false), new DateTimeFormatter(" > ") })), new StackTraceFormatterNothing()), new RelayLoggerWithStackTrace( new RelayLogger( new ColoredConsoleLogger(ConsoleColor.Cyan, ConsoleColor.Black), new ChainedFormatter(new List <ITextFormatter> { new ThreadFormatter(" > ", true, false, false), new DateTimeFormatter(" > ") })), new StackTraceFormatterNothing()), new RelayLoggerWithStackTrace( new RelayLogger( new ColoredConsoleLogger(ConsoleColor.Green, ConsoleColor.Black), new ChainedFormatter(new List <ITextFormatter> { new ThreadFormatter(" > ", false, true, false), new DateTimeFormatter(" > ") })), new StackTraceFormatterWithNullSuport(" > ", string.Empty)), new RelayLoggerWithStackTrace( new RelayLogger( new ColoredConsoleLogger(ConsoleColor.White, ConsoleColor.Black), new ChainedFormatter(new List <ITextFormatter> { new ThreadFormatter(" > ", true, false, false), new DateTimeFormatter(" > ") })), new StackTraceFormatterNothing())); var loggerAndRegPoint = new LoggerRegistrationPointThreadSafe(); _commonLogger = loggerAndRegPoint; _loggerRegPoint = loggerAndRegPoint; var paramLoggerAndRegPoint = new ParamLoggerRegistrationPointThreadSafe(); _commonParamLogger = paramLoggerAndRegPoint; _paramLoggerRegPoint = paramLoggerAndRegPoint; var cmdSenderHost = new CommandSenderHostThreadSafe(); _cmdSenderHostSettable = cmdSenderHost; _cmdSenderHost = cmdSenderHost; var targetAddressHost = new TargetAddressHostThreadSafe(1); _targetAddressHostSettable = targetAddressHost; _targetAddressHost = targetAddressHost; var notifySendingEnabled = new NotifySendingEnabledThreadSafe(false); _notifySendingEnabledRaisable = notifySendingEnabled; _notifySendingEnabled = notifySendingEnabled; var ainsCounter = new AinsCounterThreadSafe(1); _ainsCounterRaisable = ainsCounter; _ainsCounter = ainsCounter; _cycleThreadHolder = new CycleThreadHolderThreadSafe(); var ainSettingsStorage = new AinSettingsStorageThreadSafe(_ainsCounter, _notifySendingEnabled); _ainSettingsStorage = ainSettingsStorage; _ainSettingsStorageSettable = ainSettingsStorage; _ainSettingsStorageUpdatedNotify = ainSettingsStorage; var ainSettingsReader = new AinSettingsReader(_cmdSenderHost, _targetAddressHost, _commonLogger, _ainSettingsStorageSettable, _debugLogger); _ainSettingsReader = ainSettingsReader; _ainSettingsReadNotify = ainSettingsReader; _ainSettingsReadNotifyRaisable = ainSettingsReader; _ainSettingsWriter = new AinSettingsWriter(_cmdSenderHost, _targetAddressHost, _ainsCounterRaisable, _ainSettingsReader); _autoTimeSetter = new AutoTimeSetter(_cmdSenderHost, _notifySendingEnabled, _targetAddressHost, _commonLogger); var engineSettingsStorage = new EngineSettingsStorageThreadSafe(); _engineSettingsStorage = engineSettingsStorage; _engineSettingsStorageSettable = engineSettingsStorage; _engineSettingsStorageUpdatedNotify = engineSettingsStorage; var engineSettingsReader = new EngineSettingsReader(_cmdSenderHost, _targetAddressHost, _commonLogger, _engineSettingsStorageSettable, _debugLogger); _engineSettingsReader = engineSettingsReader; _engineSettingsReadNotify = engineSettingsReader; _engineSettingsReadNotifyRaisable = engineSettingsReader; _engineSettingsWriter = new EngineSettingsWriter(_cmdSenderHost, _targetAddressHost, _engineSettingsReader); _autoSettingsReader = new AutoSettingsReader( _notifySendingEnabled, _ainsCounterRaisable, _ainSettingsReader, _ainSettingsStorageSettable, _commonLogger, _engineSettingsReader, _engineSettingsStorageSettable); _bsEthernetLogsReadCycleModel = new ReadCycleModel(_cmdSenderHost, targetAddressHost, notifySendingEnabled); var uiRoot = new SimpleUiRoot(new WpfUiNotifierAsync(Dispatcher.CurrentDispatcher)); var ainCommandAndCommonTelemetryVm = new AinCommandAndCommonTelemetryViewModel( new AinCommandAndMinimalCommonTelemetryViewModel( _cmdSenderHost, _targetAddressHost, uiRoot, _commonLogger, _notifySendingEnabled, 0, _ainSettingsStorage, _ainSettingsStorageUpdatedNotify), new TelemetryCommonViewModel(), _cmdSenderHost, _targetAddressHost, uiRoot, _notifySendingEnabled); // TODO: Register something but not VM? _cycleThreadHolder.RegisterAsCyclePart(ainCommandAndCommonTelemetryVm); new CommandWindow { DataContext = new CommandWindowViewModel(ainCommandAndCommonTelemetryVm) }.Show(); new BsEthernetLogsWindow { DataContext = new WindowViewModel(uiRoot, _bsEthernetLogsReadCycleModel) }.Show(); var mainViewModel = new MainViewModel( new SimpleUiRoot(new WpfUiNotifierAsync(Dispatcher.CurrentDispatcher)), new WpfWindowSystem(), colorsForGraphics, _cmdSenderHostSettable, _targetAddressHost, _debugLogger, _loggerRegPoint, _notifySendingEnabledRaisable, _commonParamLogger, _ainsCounterRaisable, _cycleThreadHolder, _ainSettingsReader, _ainSettingsReadNotify, _ainSettingsReadNotifyRaisable, _ainSettingsWriter, _ainSettingsStorage, _ainSettingsStorageSettable, _ainSettingsStorageUpdatedNotify, _bsEthernetLogsReadCycleModel, _engineSettingsReader, _engineSettingsWriter, _engineSettingsReadNotify, _engineSettingsReadNotifyRaisable, _engineSettingsStorage, _engineSettingsStorageSettable, _engineSettingsStorageUpdatedNotify); new MainWindow { DataContext = mainViewModel }.Show(); }
public MainViewModel(IUserInterfaceRoot uiRoot, IWindowSystem windowSystem, List <Color> colors, ICommandSenderHostSettable commandSenderHostSettable, ITargetAddressHost targetAddressHost, IMultiLoggerWithStackTrace <int> debugLogger, ILoggerRegistrationPoint loggerRegistrationPoint, INotifySendingEnabledRaisable notifySendingEnabled, IParameterLogger paramLogger, IAinsCounterRaisable ainsCounterRaisable, ICycleThreadHolder cycleThreadHolder, IAinSettingsReader ainSettingsReader, IAinSettingsReadNotify ainSettingsReadNotify, IAinSettingsReadNotifyRaisable ainSettingsReadNotifyRaisable, IAinSettingsWriter ainSettingsWriter, IAinSettingsStorage ainSettingsStorage, IAinSettingsStorageSettable ainSettingsStorageSettable, IAinSettingsStorageUpdatedNotify storageUpdatedNotify, ReadCycleModel bsEthernetReadCycleModel, IEngineSettingsReader engineSettingsReader, IEngineSettingsWriter engineSettingsWriter, IEngineSettingsReadNotify engineSettingsReadNotify, IEngineSettingsReadNotifyRaisable engineSettingsReadNotifyRaisable, IEngineSettingsStorage engineSettingsStorage, IEngineSettingsStorageSettable engineSettingsStorageSettable, IEngineSettingsStorageUpdatedNotify engineSettingsStorageUpdatedNotify) { _uiRoot = uiRoot; _colors = colors; _commandSenderHostSettable = commandSenderHostSettable; _commandSenderHost = commandSenderHostSettable; _targetAddressHost = targetAddressHost; _isPortOpened = false; // Лог программы: _debugLogger = debugLogger; _loggerRegistrationPoint = loggerRegistrationPoint; // разрешение к отправке (COM-порт открыт/закрыт) _notifySendingEnabled = notifySendingEnabled; ProgramLogVm = new ProgramLogViewModel(_uiRoot, _debugLogger, new DateTimeFormatter(" > ")); _logger = new RelayLogger(ProgramLogVm); _loggerRegistrationPoint.RegisterLoggegr(_logger); GetPortsAvailable(); OpenPortCommand = new RelayCommand(OpenPort, () => !_isPortOpened); ClosePortCommand = new RelayCommand(ClosePort, () => _isPortOpened); GetPortsAvailableCommand = new RelayCommand(GetPortsAvailable); _paramLogger = paramLogger; _ainsCounterRaisable = ainsCounterRaisable; _cycleThreadHolder = cycleThreadHolder; _ainSettingsReader = ainSettingsReader; _ainSettingsReadNotify = ainSettingsReadNotify; _ainSettingsWriter = ainSettingsWriter; // Блоки АИН в системе: AinsCountInSystem = new List <int> { 1, 2, 3 }; SelectedAinsCount = AinsCountInSystem.First(); var ainSettingsReadedWriter = new AinSettingsReaderWriter(_ainSettingsReader, _ainSettingsWriter); _engineSettingsReader = engineSettingsReader; _engineSettingsWriter = engineSettingsWriter; _engineSettingsReadNotify = engineSettingsReadNotify; _engineSettingsReadNotifyRaisable = engineSettingsReadNotifyRaisable; _engineSettingsStorage = engineSettingsStorage; _engineSettingsStorageSettable = engineSettingsStorageSettable; _engineSettingsStorageUpdatedNotify = engineSettingsStorageUpdatedNotify; AinCommandAndCommonTelemetryVm = new AinCommandAndCommonTelemetryViewModel( new AinCommandAndMinimalCommonTelemetryViewModel(_commandSenderHost, _targetAddressHost, _uiRoot, _logger, _notifySendingEnabled, 0, ainSettingsStorage, storageUpdatedNotify), new TelemetryCommonViewModel(), _commandSenderHost, _targetAddressHost, _uiRoot, _notifySendingEnabled); _cycleThreadHolder.RegisterAsCyclePart(AinCommandAndCommonTelemetryVm); TelemtryVm = new TelemetryViewModel(_uiRoot, _commandSenderHost, _targetAddressHost, _logger, _cycleThreadHolder, _ainsCounterRaisable, _paramLogger, _notifySendingEnabled); SettingsVm = new SettingsViewModel(_uiRoot, _logger, ainSettingsReadedWriter, _ainSettingsReadNotify, ainSettingsReadNotifyRaisable, ainSettingsStorage, ainSettingsStorageSettable, storageUpdatedNotify, _ainsCounterRaisable, _commandSenderHost, _targetAddressHost, _notifySendingEnabled, _engineSettingsReader, _engineSettingsWriter, _engineSettingsReadNotify, _engineSettingsReadNotifyRaisable, _engineSettingsStorage, _engineSettingsStorageSettable, _engineSettingsStorageUpdatedNotify, _debugLogger); // TODO: can be moved to app.xaml.cs if needed ArchiveVm = new ArchivesViewModel( new ArchiveViewModel(_commandSenderHost, _targetAddressHost, _uiRoot, _logger, _notifySendingEnabled, 0), new ArchiveViewModel(_commandSenderHost, _targetAddressHost, _uiRoot, _logger, _notifySendingEnabled, 1)); MnemonicChemeVm = new MnemonicChemeViewModel(Path.Combine(Environment.CurrentDirectory, "mnemoniccheme.png")); OldLookVm = new OldLookViewModel(_uiRoot, windowSystem, _commandSenderHost, _targetAddressHost, _notifySendingEnabled, this, _logger, _debugLogger, _cycleThreadHolder, _ainsCounterRaisable, _paramLogger, ainSettingsStorage, storageUpdatedNotify); _ain1StateColor = Colors.Gray; _ain2StateColor = Colors.Gray; _ain3StateColor = Colors.Gray; _ain1IsUsed = true; _ain2IsUsed = false; _ain3IsUsed = false; _ainsCounterRaisable.AinsCountInSystemHasBeenChanged += ainsCount => { switch (ainsCount) { case 1: Ain1IsUsed = true; Ain2IsUsed = false; Ain3IsUsed = false; break; case 2: Ain1IsUsed = true; Ain2IsUsed = true; Ain3IsUsed = false; break; case 3: Ain1IsUsed = true; Ain2IsUsed = true; Ain3IsUsed = true; break; default: throw new Exception("Такое число АИН в системе не поддерживается"); } }; AinCommandAndCommonTelemetryVm.AinsLinkInformationHasBeenUpdated += (ain1Error, ain2Error, ain3Error) => { Ain1StateColor = ain1Error.HasValue ? ain1Error.Value ? Colors.Red : Colors.YellowGreen : Colors.Gray; Ain2StateColor = ain2Error.HasValue ? ain2Error.Value ? Colors.Red : Colors.YellowGreen : Colors.Gray; Ain3StateColor = ain3Error.HasValue ? ain3Error.Value ? Colors.Red : Colors.YellowGreen : Colors.Gray; }; _notifySendingEnabled.SendingEnabledChanged += isEnabled => { // TODO: execution in ui thread Ain1StateColor = Colors.Gray; Ain2StateColor = Colors.Gray; Ain3StateColor = Colors.Gray; }; EngineAutoSetupVm = new EngineAutoSetupViewModel( new TableViewModel("Начальные значения:", _logger), new TableViewModel("После тестирования:", _logger), _notifySendingEnabled, _ainSettingsReader, _ainSettingsReadNotify, _ainSettingsWriter, _uiRoot, _logger, _commandSenderHost, _targetAddressHost, bsEthernetReadCycleModel); _logger.Log("Программа загружена"); }
public OldLookViewModel(IUserInterfaceRoot userInterfaceRoot, IWindowSystem windowSystem, ICommandSenderHost commanSenderHost, ITargetAddressHost targetAddressHost, INotifySendingEnabled notifySendingEnabled, ILinkContol linkContol, ILogger logger, IMultiLoggerWithStackTrace <int> debugLogger, ICycleThreadHolder cycleThreadHolder, IAinsCounter ainsCounter, IParameterLogger parameterLogger, IAinSettingsStorage ainSettingsStorage, IAinSettingsStorageUpdatedNotify storageUpdatedNotify) { _ainSettingsStorage = ainSettingsStorage; _storageUpdatedNotify = storageUpdatedNotify; var commonTelemetryVm = new TelemetryCommonViewModel(); BsEthernetSettingsVm = new BsEthernetSettingsViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled); BsEthernetNominalsVm = new BsEthernetNominalsViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled); SystemControlVm = new SystemControlViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled, linkContol, commonTelemetryVm); var ain1TelemetryVm = new AinTelemetryViewModel(commonTelemetryVm, 0, commanSenderHost, logger, userInterfaceRoot); var ain2TelemetryVm = new AinTelemetryViewModel(commonTelemetryVm, 1, commanSenderHost, logger, userInterfaceRoot); var ain3TelemetryVm = new AinTelemetryViewModel(commonTelemetryVm, 2, commanSenderHost, logger, userInterfaceRoot); AinTelemetriesVm = new AinTelemetriesViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, SystemControlVm, commonTelemetryVm, ain1TelemetryVm, ain2TelemetryVm, ain3TelemetryVm); // TODO: sending enabled control? cycleThreadHolder.RegisterAsCyclePart(ain1TelemetryVm); cycleThreadHolder.RegisterAsCyclePart(ain2TelemetryVm); cycleThreadHolder.RegisterAsCyclePart(ain3TelemetryVm); cycleThreadHolder.RegisterAsCyclePart(AinTelemetriesVm); var ain1CommandOnlyVm = new AinCommandAndMinimalCommonTelemetryViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, notifySendingEnabled, 0, _ainSettingsStorage, _storageUpdatedNotify); var ain2CommandOnlyVm = new AinCommandAndMinimalCommonTelemetryViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, notifySendingEnabled, 1, _ainSettingsStorage, _storageUpdatedNotify); var ain3CommandOnlyVm = new AinCommandAndMinimalCommonTelemetryViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, notifySendingEnabled, 2, _ainSettingsStorage, _storageUpdatedNotify); Ain1CommandVm = new AinCommandViewModel(ain1CommandOnlyVm, commonTelemetryVm, ain1TelemetryVm, AinTelemetriesVm); Ain2CommandVm = new AinCommandViewModel(ain2CommandOnlyVm, commonTelemetryVm, ain2TelemetryVm, AinTelemetriesVm); Ain3CommandVm = new AinCommandViewModel(ain3CommandOnlyVm, commonTelemetryVm, ain3TelemetryVm, AinTelemetriesVm); Ain1SettingsVm = new AinSettingsViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled, 0); Ain2SettingsVm = new AinSettingsViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled, 1); Ain3SettingsVm = new AinSettingsViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled, 2); RectifierTelemetriesVm = new RectifierTelemetriesViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem); // TODO: sending enabled control? cycleThreadHolder.RegisterAsCyclePart(RectifierTelemetriesVm); CoolerTelemetriesVm = new CoolerTelemetriesViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, debugLogger, windowSystem); // TODO: sending enabled control? EngineSettingsVm = new EngineSettingsViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, windowSystem, notifySendingEnabled); }
public TelemetryViewModel(IUserInterfaceRoot userInterfaceRoot, ICommandSenderHost commanSenderHost, ITargetAddressHost targetAddressHost, ILogger logger, ICycleThreadHolder cycleThreadHolder, IAinsCounter ainsCounter, IParameterLogger parameterLogger, INotifySendingEnabled notifySendingEnabled) { Group01ParametersVm = new Group01ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, ainsCounter, parameterLogger); cycleThreadHolder.RegisterAsCyclePart(Group01ParametersVm); Group02ParametersVm = new Group02ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, parameterLogger); cycleThreadHolder.RegisterAsCyclePart(Group02ParametersVm); Group03ParametersVm = new Group03ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, parameterLogger); cycleThreadHolder.RegisterAsCyclePart(Group03ParametersVm); Group04ParametersVm = new Group04ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, notifySendingEnabled); Group07ParametersVm = new Group07ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, parameterLogger); cycleThreadHolder.RegisterAsCyclePart(Group07ParametersVm); Group08ParametersVm = new Group08ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, parameterLogger); cycleThreadHolder.RegisterAsCyclePart(Group08ParametersVm); Group09ParametersVm = new Group09ParametersViewModel(commanSenderHost, targetAddressHost, userInterfaceRoot, logger, ainsCounter, parameterLogger); cycleThreadHolder.RegisterAsCyclePart(Group09ParametersVm); }