Beispiel #1
0
        /// <summary>
        /// Loads Last State on start if it exists
        /// </summary>
        /// <returns> true if successful</returns>
        public bool LoadPreviousPZState(out object x)
        {
            ZoneStateFile zoneStateFile = new ZoneStateFile();



            string zoneStateFileJson = null;

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

                    IsolatedStorageFileStream fileStream = null;

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

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

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

                x = JsonConvert.DeserializeObject <ZoneStateFile>(zoneStateFileJson);

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

            x = zoneStateFile;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Save Current State on Exit
        /// </summary>
        /// <returns> true of successful</returns>
        public bool SaveCurrentPZState(object x)
        {
            ZoneStateFile zoneStateFile = (ZoneStateFile)x;

            try
            {
                string zoneStateFileJson = JsonConvert.SerializeObject(zoneStateFile, Formatting.Indented);

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

                    IsolatedStorageFileStream fileStream = null;

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

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

            return(false);
        }