public MeasurementViewModel(Guid id, MeasurementSettings settings, IMeterReader reader) { MinorReadings = new ConcurrentQueue <Tuple <DateTime, ReadingData> >(); MajorReadings = new ConcurrentQueue <Tuple <DateTime, ReadingData> >(); OctaveValues = new ObservableCollection <OctaveBandGraphValue>(); MinorSpan = TimeSpan.FromTicks(settings.MinorInterval.Ticks * 15); MajorSpan = TimeSpan.FromTicks(settings.MajorInterval.Ticks * 15); readingHistory = new ReadingsStorage(MajorSpan); minorIntervalHistory = new ReadingsStorage(MinorSpan); majorIntervalHistory = new ReadingsStorage(majorSpan); minorGraphViewModel = new GraphViewModel("LAeq", readingHistory, minorIntervalHistory, MinorSpan); majorGraphViewModel = new GraphViewModel("LAeq", null, majorIntervalHistory, MajorSpan, false, true); lastMinorInterval = new DateTime(); lastMajorInterval = new DateTime(); started = DateTime.Now; popOutWindows = new LinkedList <MetroWindow>(); this.engine = new AudioViewEngine(settings.MinorInterval, settings.MajorInterval, reader); this.settings = settings; this.engine.ConnectionStatusEvent += connected => { if (ConnectionStatus == connected) { return; // No need } Task.Run(() => { ConnectionStatus = connected; DispatcherHelper.CheckBeginInvokeOnUI(() => { OnPropertyChanged(nameof(IsDisconnected)); }); }); }; if (settings.IsLocal) { // Registering the TCP Server for remote connections tcpServer = new TCPServerListener(settings); this.engine.RegisterListener(tcpServer); // Register the data storange unit dataStorage = new DataStorageMeterListener(id, DateTime.Now, settings); this.engine.RegisterListener(dataStorage); } this.engine.RegisterListener(new LocalStorageListener(AudioViewSettings.Instance.AutoSaveLocation, settings.ProjectName)); this.engine.RegisterListener(this); MinorClock = new AudioViewCountDownViewModel(false, settings.MinorInterval, settings.MinorDBLimit, settings.MinorClockMainItem, settings.MinorClockSecondaryItem); MajorClock = new AudioViewCountDownViewModel(true, settings.MajorInterval, settings.MajorDBLimit, settings.MajorClockMainItem, settings.MajorClockSecondaryItem); this.engine.RegisterListener(MinorClock); this.engine.RegisterListener(MajorClock); this.engine.Start(); Title = settings.ProjectName; }
public MainViewModel() { ShowControls = false; logger.Info("Audio View started at {0}", DateTime.Now); SettingsViewModel = SettingsViewModel.Instance; HistoryViewModel = new HistoryViewModel(); MeasurementsViewModel = new MeasurementsViewModel(this); service = new UserService(); User user = getAuthData(); if (user == null) { NeedLogIn = true; LogInFailed = false; LogInExpired = false; ShowControls = false; } else { // Verify expired try { //var audioViewEntities = new AudioViewEntities(); //audioViewEntities.Users.Where(x => x.username == "kasper").First(); var userResult = service.GetUserSync(user.UserName); if (userResult == null) { NeedLogIn = true; LogInFailed = true; LogInExpired = false; ShowControls = false; IsLoading = false; } else { if (user.Expires != null && userResult.Expires < DateTime.Now) { NeedLogIn = true; LogInFailed = false; LogInExpired = true; ShowControls = false; IsLoading = false; } else { NeedLogIn = false; LogInFailed = false; LogInExpired = false; ShowControls = true; IsLoading = false; } } } catch (Exception exp) { logger.Error(exp); if (user.Expires != null && user.Expires < DateTime.Now) { NeedLogIn = true; LogInFailed = true; LogInExpired = false; ShowControls = false; IsLoading = false; } else { // Allow user in NeedLogIn = false; LogInFailed = false; LogInExpired = false; ShowControls = true; IsLoading = false; } } } // Debug for me MeasurementsViewModel.NewViewModel = new NewMeasurementViewModel(MeasurementsViewModel); // Load offline files DataStorageMeterListener.UploadLocalFiles(); }