Пример #1
0
        /// <summary>
        /// Attempts to read program data from <see cref="ProgramDataPath"/> and sets file paths to base directory if the path specified is invalid
        /// </summary>
        private void InitializeProgramData()
        {
            // Create the file if it doesn't exist
            if (!File.Exists(ProgramDataPath))
            {
                ProjectTimeDataCollection.SaveProgramData(ProgramDataPath, new ProgramData());
            }

            ProgramData programData = ProjectTimeDataCollection.GetProgramData(ProgramDataPath);

            // Verify the read-in file's directory exists and that the file is an xml file, otherwise set path to default
            try
            {
                ProjectTimeDataPath = programData.ProjectTimeDataPath;
                FileInfo f = new FileInfo(ProjectTimeDataPath);
                if (!Directory.Exists(f.Directory.FullName))
                {
                    throw new Exception();
                }
                if (string.Compare(f.Extension, ".xml", true) != 0)
                {
                    throw new Exception();
                }
            }
            // Exception caught means read-in file's directory does not exist or that the file is not an xml file, so set to default
            catch (Exception ex)
            {
                ProjectTimeDataPath = DefaultProjectTimeDataPath;
            }

            // Verify the read-in directory exists, otherwise set path to default
            try
            {
                TimesheetsDir = programData.TimesheetsDir;
                if (!Directory.Exists(TimesheetsDir))
                {
                    throw new Exception();
                }
            }
            // Exception caught means read-in directory does not exist, so set to default
            catch (Exception ex)
            {
                TimesheetsDir = DefaultTimesheetsDir;
            }

            Name = programData.Name;
            ID   = programData.ID;
        }
Пример #2
0
 private void SaveProgramData()
 {
     ProjectTimeDataCollection.SaveProgramData(ProgramDataPath, new ProgramData(ProjectTimeDataPath, TimesheetsDir, Name, ID));
 }