Exemple #1
0
        /*
         * Persists the PersonFactory to given filePath, returns true if
         * data was persisted successfuly or false if not.
         */
        public bool Persist(BookingFactory bf, String filePath)
        {
            String dataDirName = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dataDirName))
            {
                Directory.CreateDirectory(dataDirName);
            }

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            try
            {
                System.IO.File.AppendAllText(filePath, bf.ToCSV());
            }
            catch
            {
                return(false);
            }

            return(true);
        }
        // METHODS:

        /*
         * Constructor.
         */
        public ModelFacade()

        {
            bFact    = BookingFactory.Instance;
            pFact    = PersonFactory.Instance;
            dpFacade = new DataPersistenceFacade();

            Dictionary <String, String> sysData;

            if (dpFacade.ReadSystemState(out sysData))
            {
                bFact.Restore(sysData);
                pFact.Restore(sysData);
            }
        }