Exemplo n.º 1
0
        private static ConfigFileSyncPermissionsSection parseSyncPermissionSection(XElement section)
        {
            ConfigFileSyncPermissionsSection returnMe = new ConfigFileSyncPermissionsSection();

            // Loop through each setting in this section
            foreach (XElement setting in section.Elements())
            {
                if (setting.Name == "AllowSync")
                {
                    returnMe.AllowSync = Parsers.ParseBool(setting.Value);
                }

                if (setting.Name == "AllowAdd")
                {
                    returnMe.AllowAdds = Parsers.ParseBool(setting.Value);
                }

                if (setting.Name == "AllowUpdate")
                {
                    returnMe.AllowUpdates = Parsers.ParseBool(setting.Value);
                }

                if (setting.Name == "AllowRemove")
                {
                    returnMe.AllowRemovals = Parsers.ParseBool(setting.Value);
                }

                if (setting.Name == "ForceUpdate")
                {
                    returnMe.ForceUpdate = Parsers.ParseBool(setting.Value);
                }
            }

            return(returnMe);
        }
Exemplo n.º 2
0
        public static ConfigFile LoadFromFile(string FileName)
        {
            if (!File.Exists(FileName))
            {
                throw new InvalidConfigFileException("Config file not found");
            }

            string connectionString_Internal = string.Empty;
            string connectionString_SL       = string.Empty;
            string schoolYearID = _defaultSchoolYearName;
            string logDirectory = _defaultLogDirectory;
            string logFilename  = _defaultLogFileName;
            ConfigFileSyncPermissionsSection _absenceReasonPermissions          = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _absenceStatusPermissions          = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _absencePermissions                = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _gradeLevelPermissions             = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _schoolPermissions                 = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _studentGradePlacementPermissions  = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _studentPermissions                = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _expectedAttendancePermissions     = new ConfigFileSyncPermissionsSection();
            ConfigFileSyncPermissionsSection _studentschoolenrolmentpermissions = new ConfigFileSyncPermissionsSection();

            // Load the file into XElement
            XElement configFile = XElement.Load(FileName);

            // Connection Strings
            List <XElement> databaseSections = configFile.Elements("Database").ToList();

            // Loop through all "Database" sections (hopefully only one)
            foreach (XElement section in databaseSections)
            {
                // Loop through each setting in this section
                foreach (XElement setting in section.Elements())
                {
                    if (setting.Name == "ConnectionStringInternal")
                    {
                        connectionString_Internal = setting.Value;
                    }

                    if (setting.Name == "ConnectionStringSchoolLogic")
                    {
                        connectionString_SL = setting.Value;
                    }
                }
            }

            // Sync Permissions

            // For each app permissions section
            foreach (XElement appPermissionSection in configFile.Elements("AppPermissions").ToList())
            {
                foreach (XElement section in appPermissionSection.Elements())
                {
                    if (section.Name == "Absences")
                    {
                        _absencePermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "AbsenceReasons")
                    {
                        _absenceReasonPermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "AbsenceStatuses")
                    {
                        _absenceStatusPermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "GradeLevels")
                    {
                        _gradeLevelPermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "Schools")
                    {
                        _schoolPermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "StudentGradePlacements")
                    {
                        _studentGradePlacementPermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "Students")
                    {
                        _studentPermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "ExpectedAttendance")
                    {
                        _expectedAttendancePermissions = parseSyncPermissionSection(section);
                    }
                    if (section.Name == "StudentSchoolEnrolments")
                    {
                        _studentschoolenrolmentpermissions = parseSyncPermissionSection(section);
                    }
                }
            }

            // Other settings
            List <XElement> otherSettingsSection = configFile.Elements("Other").ToList();

            // Loop through all "Other" sections (hopefully only one)
            foreach (XElement section in otherSettingsSection)
            {
                // Loop through each setting in this section
                foreach (XElement setting in section.Elements())
                {
                    if (setting.Name == "SchoolYearID")
                    {
                        schoolYearID = setting.Value;
                    }

                    if (setting.Name == "LogDirectory")
                    {
                        if (!string.IsNullOrEmpty(setting.Value))
                        {
                            logDirectory = setting.Value;
                            if (logDirectory.EndsWith("/"))
                            {
                                logDirectory = logDirectory.Substring(0, logDirectory.Length - 1);
                            }
                        }
                    }

                    if (setting.Name == "LogFileName")
                    {
                        if (!string.IsNullOrEmpty(setting.Value))
                        {
                            logFilename = setting.Value;
                        }
                    }
                }
            }

            return(new ConfigFile()
            {
                DatabaseConnectionString_Internal = connectionString_Internal,
                DatabaseConnectionString_SchoolLogic = connectionString_SL,
                SchoolYearName = schoolYearID,
                Loaded = true,
                AbsenceReasonPermissions = _absenceReasonPermissions,
                AbsenceStatusPermissions = _absenceStatusPermissions,
                AbsencePermissions = _absencePermissions,
                GradeLevelPermissions = _gradeLevelPermissions,
                SchoolPermissions = _schoolPermissions,
                StudentGradePlacementPermissions = _studentGradePlacementPermissions,
                StudentPermissions = _studentPermissions,
                ExpectedAttendancePermissions = _expectedAttendancePermissions,
                StudentSchoolEnrolmentPermissions = _studentschoolenrolmentpermissions,
                LogDirectory = logDirectory,
                LogFileName = logFilename
            });
        }