Ejemplo n.º 1
0
        public Persister(PersisterSettings settings)
        {
            Settings = settings;
            ValidateSettings();

            _undoRedoHandler = new UndoRedoHandler <T>(Settings.MaxHistorySteps);
            _undoRedoHandler.CanRedoChanged += UndoRedoHandler_CanRedoChanged;
            _undoRedoHandler.CanUndoChanged += UndoRedoHandler_CanUndoChanged;

            _serializer = new ObjectToFileSerializer();
            InitializeAutoSave();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads data from provided path into a new persister class with loaded object from given path
        /// </summary>
        /// <param name="settings">Persister settings</param>
        /// <param name="pathToFile">Path to file to be used to load data</param>
        /// <returns>New Persister class with loaded object</returns>
        /// <exception cref="PersisterException">Throws on incorrect parameters</exception>
        public static Persister <T> Load(PersisterSettings settings, string pathToFile)
        {
            if (settings == null)
            {
                throw new PersisterException("settings parameter cannot be null!");
            }
            if (string.IsNullOrEmpty(pathToFile))
            {
                throw new PersisterException("path to file parameter cannot be null or empty!");
            }

            return(new Persister <T>(settings, pathToFile, typeof(T)));
        }
Ejemplo n.º 3
0
 private Persister(PersisterSettings settings, string pathToFile, Type objectType) : this(settings)
 {
     TrackedObject = (T)_serializer.Deserialize(pathToFile, objectType);
 }