Beispiel #1
0
        /// <summary>
        /// Loads the active system state object
        /// </summary>
        /// <param name="x">Active system state object</param>
        /// <returns>true is successful</returns>
        public SystemActiveState LoadActiveSystemStates()
        {
            SystemActiveState x = new SystemActiveState();
            string            activeStateFile = null;

            try
            {
                using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isolatedStorageFile.DirectoryExists("CarLocatorSystems"))
                    {
                        isolatedStorageFile.CreateDirectory("CarLocatorSystems");
                    }//end if

                    IsolatedStorageFileStream fileStream = null;

                    try
                    {
                        fileStream = isolatedStorageFile.OpenFile(@"CarLocatorSystems/ActiveSystemState.dat",
                                                                  FileMode.OpenOrCreate);

                        using (StreamReader streamReader =
                                   new StreamReader(fileStream))
                        {
                            fileStream      = null;
                            activeStateFile = streamReader.ReadToEnd();

                            if (activeStateFile.Length == 0)
                            {
                                return(x);
                            }
                        }
                    }//end using 2
                    finally
                    {
                        if (fileStream != null)
                        {
                            fileStream.Dispose();
                        }
                    }
                }//end using 1

                x = JsonConvert.DeserializeObject <SystemActiveState>(activeStateFile);

                x.loaded = true;

                return(x); //<= Loaded with Info
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButton.OK);
            }

            return(x);
        }
Beispiel #2
0
        /// <summary>
        /// Saves the current state of active systems
        /// ex.
        /// ParkingMeterNotifications.Active = true
        /// </summary>
        /// <param name="x">SystemActiveState object</param>
        /// <returns></returns>
        public bool SaveActiveSystemStates(SystemActiveState x)
        {
            try
            {
                string activeSystemStateJson = JsonConvert.SerializeObject(x, Formatting.Indented);

                using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isolatedStorageFile.DirectoryExists("CarLocatorSystems"))
                    {
                        isolatedStorageFile.CreateDirectory("CarLocatorSystems");
                    }//end if

                    IsolatedStorageFileStream fileStream = null;

                    try
                    {
                        fileStream = isolatedStorageFile.OpenFile(@"CarLocatorSystems/ActiveSystemState.dat"
                                                                  , FileMode.Create);

                        using (StreamWriter streamWriter = new StreamWriter(fileStream))
                        {
                            fileStream = null;
                            streamWriter.Write(activeSystemStateJson);
                        } //end using 3
                    }     //end using 2
                    finally
                    {
                        if (fileStream != null)
                        {
                            fileStream.Dispose();
                        }
                    }
                } //end using 1
                return(true);
            }     //end try
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error FileHandler.cs / SaveActiveSystemStates()", MessageBoxButton.OK);
            }

            return(false);
        }
Beispiel #3
0
 /// <summary>
 /// Saves the active system state
 /// </summary>
 /// <param name="x">StateFile Type</param>
 public void SaveActiveSystemStates(SystemActiveState x)
 {
     newHandler.SaveActiveSystemStates(x);
 }
Beispiel #4
0
 /// <summary>
 /// Loads ActiveSystemState Object
 /// </summary>
 /// <param name="x">SystemStateObject</param>
 public void LoadActiveSystemStates(out SystemActiveState x)
 {
     x = newHandler.LoadActiveSystemStates();
 }