Пример #1
0
        private T GetFromCompositeValue<T>(ApplicationDataCompositeValue value)
        {
            if (value == null)
            {
                return default(T);
            }

            Type concreteType = null;
            object serializedType;
            if (value.TryGetValue(TypeKey, out serializedType))
            {
                concreteType = Type.GetType(serializedType.ToString());
            }

            object serializedData;
            if (value.TryGetValue(ValueKey, out serializedData))
            {
                // We need this if we're trying to deserialize an interface. When being serialized, we saved
                // the concrete type. So we deserialize to that, then cast to the requested interface.
                if (concreteType != null)
                {
                    return (T)JsonConvert.DeserializeObject(serializedData.ToString(), concreteType);
                }
                else
                {
                    return JsonConvert.DeserializeObject<T>(serializedData.ToString());
                }
            }
            else
            {
                return default(T);
            }
        } 
Пример #2
0
            public static LayoutPreferences FromCompositeValue(ApplicationDataCompositeValue compositeValue)
            {
                var pref = new LayoutPreferences
                {
                    LayoutMode                 = (FolderLayoutModes)(int)compositeValue[nameof(LayoutMode)],
                    GridViewSize               = (int)compositeValue[nameof(GridViewSize)],
                    DirectorySortOption        = (SortOption)(int)compositeValue[nameof(DirectorySortOption)],
                    DirectorySortDirection     = (SortDirection)(int)compositeValue[nameof(DirectorySortDirection)],
                    IsAdaptiveLayoutOverridden = compositeValue[nameof(IsAdaptiveLayoutOverridden)] is bool val ? val : false,
                };

                if (compositeValue.TryGetValue(nameof(DirectoryGroupOption), out var gpOption))
                {
                    pref.DirectoryGroupOption = (GroupOption)(int)gpOption;
                }

                try
                {
                    pref.ColumnsViewModel = JsonConvert.DeserializeObject <ColumnsViewModel>(compositeValue[nameof(ColumnsViewModel)] as string, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });
                }
                catch (Exception)
                {
                }

                return(pref);
            }
Пример #3
0
        public static int GetInt32(this ApplicationDataCompositeValue container, string key, int defaultValue)
        {
            if (container.TryGetValue(key, out object value) && value is int result)
            {
                return(result);
            }

            return(defaultValue);
        }
Пример #4
0
        public static bool GetBoolean(this ApplicationDataCompositeValue container, string key, bool defaultValue)
        {
            if (container.TryGetValue(key, out object value) && value is bool result)
            {
                return(result);
            }

            return(defaultValue);
        }
Пример #5
0
        private async void Page_LoadedAsync(object sender, RoutedEventArgs e)
        {
            PageBusy("Loading events from dataset " + _viewModel.Dataset.Name + " ...");
            await _viewModel.LoadDataAsync();

            PopulateSensors();
            DrawSensors();
            PopulateAnnotateFlyout();
            // Check Application Settings for last saved states. If the state exists and is valid, load the state
            ApplicationDataCompositeValue datasetLastSavedStates =
                AppSettingsService.RetrieveFromSettings <ApplicationDataCompositeValue>(
                    "DatasetLastSavedStates", new ApplicationDataCompositeValue()
                    );

            if (datasetLastSavedStates.TryGetValue(_viewModel.Dataset.Name, out object jsonDatasetSavedState))
            {
                DatasetViewSavedState datasetState = JsonConvert.DeserializeObject <DatasetViewSavedState>((string)jsonDatasetSavedState);
                if (datasetState.Day <= _viewModel.LastEventDate && datasetState.Day >= _viewModel.FirstEventDate)
                {
                    await _viewModel.LoadEventsAsync(datasetState.Day);
                }
                _viewModel.EventViewFilter = datasetState.Filter;
                _viewModel.RefreshEventsInView();
                if (datasetState.EventTimeTag != null)
                {
                    int i = 0;
                    for (i = 0; i < _viewModel.EventsInView.Count; i++)
                    {
                        SensorEventViewModel sensorEvent = (SensorEventViewModel)_viewModel.EventsInView[i];
                        if (sensorEvent.TimeTag >= datasetState.EventTimeTag)
                        {
                            _viewModel.SelectedSensorEvent = sensorEvent;
                            break;
                        }
                    }
                    if (i == _viewModel.EventsInView.Count && i != 0)
                    {
                        _viewModel.SelectedSensorEvent = (SensorEventViewModel)_viewModel.EventsInView.Last();
                    }
                }
                else
                {
                    if (datasetState.EventInView >= 0 && datasetState.EventInView < _viewModel.EventsInView.Count)
                    {
                        _viewModel.SelectedSensorEvent = (SensorEventViewModel)dataListView.Items[datasetState.EventInView];
                    }
                }
                if (_viewModel.SelectedSensorEvent != null)
                {
                    dataListView.ScrollIntoView(_viewModel.SelectedSensorEvent);
                }
            }
            PageReady();
        }