berider /Rider/ViewModels/ViewModelController.cs

Language C# Lines 173
MD5 Hash e1585f56d2230d0112815cb32f97b8c8 Estimated Cost $3,326 (why?)
Repository https://bitbucket.org/lduparc/berider.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using GalaSoft.MvvmLight;
using Rider.Location;
using Rider.Tracking;
using System.Collections.ObjectModel;
using GalaSoft.MvvmLight.Messaging;
using System.ComponentModel;

namespace Rider.ViewModels
{
    public class ViewModelController
    {
        private static BackgroundWorker sessionBackgroundLoader;
        private static MainViewModel mainViewModel = null;
        private static SessionPageSelectionViewModel sessionViewModel = null;
        private static FluxViewModel fluxViewModel = null;
        private static MapViewModel mapViewModel = null;

        private static LocationService locationservice = null;
        private static TrackingService trackingService = null;
        private static ObservableCollection<SessionViewModel> sessions;

        public ViewModelController()
        {
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic", Justification = "This non-static member is needed for data binding purposes.")]

        public static MainViewModel MainViewModel
        {
            get
            {
                // Différer la création du modčle de vue autant que nécessaire
                if (mainViewModel == null)
                    mainViewModel = new MainViewModel();

                return mainViewModel;
            }
        }

        public static FluxViewModel FluxViewModel
        {
            get
            {
                // Différer la création du modčle de vue autant que nécessaire
                if (fluxViewModel == null)
                    fluxViewModel = new FluxViewModel();

                return fluxViewModel;
            }
        }

        public static MapViewModel MapViewModel
        {
            get
            {
                // Différer la création du modčle de vue autant que nécessaire
                if (mapViewModel == null)
                    mapViewModel = new MapViewModel();

                return mapViewModel;

            }
        }

        public static SessionPageSelectionViewModel SessionPageSelectionViewModel
        {
            get
            {
                // Différer la création du modčle de vue autant que nécessaire
                if (sessionViewModel == null)
                    sessionViewModel = new SessionPageSelectionViewModel();

                return sessionViewModel;
            }
        }

        #region LocationService

        public static LocationService LocationService
        {
            get
            {
                if (locationservice == null)
                    locationservice = Location.LocationService.Instance;

                return locationservice;
            }
        }

        public static void StartLocationService()
        {
            LocationService.StartLocationWatcher();
        }

        public static void StopLocationService()
        {
            LocationService.StopLocationWatcher();
        }

        #endregion

        #region TrackingService

        public static TrackingService TrackingService
        {
            get
            {
                if (trackingService == null)
                    trackingService = Tracking.TrackingService.Instance;

                return trackingService;
            }
        }

        public static void StartTrackingService()
        {
            if (!TrackingService.IsRunning)
                TrackingService.StartSession();
        }

        public static void StopTrackingService()
        {
            if (TrackingService.IsRunning)
                TrackingService.StopSession();
        }

        #endregion

        #region sessions

        public static ObservableCollection<SessionViewModel> Sessions
        {
            get
            {
                if (sessions == null)
                    sessions = new ObservableCollection<SessionViewModel>();

                return sessions;
            }
            private set
            {
                if (value != null)
                    sessions = value;
            }
        }

        public static void LoadSessionsSaved()
        {
            //Sessions.Clear();
            if (sessionBackgroundLoader == null)
            {
                sessionBackgroundLoader = new BackgroundWorker();
                sessionBackgroundLoader.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    ObservableCollection<SessionViewModel> list = new ObservableCollection<SessionViewModel>();
                    App.database.FindClosestSessions(list);
                    args.Result = list;
                };
                sessionBackgroundLoader.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                {
                    Sessions = args.Result as ObservableCollection<SessionViewModel>;
                    Messenger.Default.Send<bool>(true, SessionPageSelectionViewModel.sessionLoaded);
                };
            }

            sessionBackgroundLoader.RunWorkerAsync();
        }

        #endregion

    }
}
Back to Top