private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
private const string CAR_PHOTO_FILE_NAME = "CarPhoto.jpg" ; private const string CAR_KEY = "FuelTracker.Car" ; private static readonly IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings; public static void SaveCar(Action errorCallback) { try { appSettings[CAR_KEY] = Car; appSettings.Save(); SaveCarPhoto(CAR_PHOTO_FILE_NAME, Car.Picture, errorCallback); DeleteTempCarPhoto(); } catch (IsolatedStorageException) { errorCallback(); } } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- [System.Runtime.Serialization.IgnoreDataMemberAttribute]
- public BitmapImage Picture
- {
- get { return _picture; }
- set
- {
- _picture = value ;
- NotifyPropertyChanged ( "Picture" );
- }
- }
* This source code was highlighted with Source Code Highlighter .
- private const string CAR_PHOTO_DIR_NAME = "FuelTracker" ;
- private static void SaveCarPhoto ( string fileName, BitmapImage carPicture,
- Action errorCallback)
- {
- if (carPicture == null ) return ;
- try
- {
- using ( var store = IsolatedStorageFile.GetUserStoreForApplication ())
- {
- var bitmap = new WriteableBitmap (carPicture);
- var path = Path.Combine (CAR_PHOTO_DIR_NAME, fileName);
- if (! store.DirectoryExists (CAR_PHOTO_DIR_NAME))
- {
- store.CreateDirectory (CAR_PHOTO_DIR_NAME);
- }
- using ( var stream = store.OpenFile (path, FileMode .Create))
- {
- Extensions.SaveJpeg (bitmap, stream,
- bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
- }
- }
- }
- catch (IsolatedStorageException)
- {
- errorCallback ();
- }
- }
* This source code was highlighted with Source Code Highlighter .
- private static Car car;
- public static Car Car
- {
- get
- {
- if (car == null )
- {
- if (appSettings.Contains (CAR_KEY))
- {
- car = (Car) appSettings [CAR_KEY];
- car.Picture = GetCarPhoto (CAR_PHOTO_FILE_NAME);
- }
- else
- {
- car = new car ()
- {
- FillupHistory = new ObservableCollection <Fillup> ()
- };
- }
- }
- return car;
- }
- set {car = value ; }
- }
* This source code was highlighted with Source Code Highlighter .
- private static BitmapImage GetCarPhoto ( string fileName)
- {
- using (IsolatedStorageFile store =
- IsolatedStorageFile.GetUserStoreForApplication ())
- {
- string path = Path.Combine (CAR_PHOTO_DIR_NAME, fileName);
- if (! store.FileExists (path)) return null ;
- IsolatedStorageFileStream stream =
- store.OpenFile (path, FileMode .Open);
- try
- {
- var image = new BitmapImage ();
- image.SetSource (stream);
- return image;
- }
- finally
- {
- stream.Dispose ();
- }
- }
- }
* This source code was highlighted with Source Code Highlighter .
- public static void DeleteCar ()
- {
- Car = null ;
- appSettings.Remove (CAR_KEY);
- appSettings.Save ();
- DeleteCarPhoto ();
- DeleteTempCarPhoto ();
- }
Source: https://habr.com/ru/post/118455/
All Articles