Example #1
0
        public UserPolicy GetUserPolicy(User user)
        {
            var path = GetPolicyFilePath(user);

            if (!File.Exists(path))
            {
                return(GetDefaultPolicy(user));
            }

            try
            {
                lock (_policySyncLock)
                {
                    return((UserPolicy)_xmlSerializer.DeserializeFromFile(typeof(UserPolicy), path));
                }
            }
            catch (IOException)
            {
                return(GetDefaultPolicy(user));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error reading policy file: {path}", path);

                return(GetDefaultPolicy(user));
            }
        }
Example #2
0
        public UserPolicy GetUserPolicy(User user)
        {
            var path = GetPolifyFilePath(user);

            try
            {
                lock (_policySyncLock)
                {
                    return((UserPolicy)_xmlSerializer.DeserializeFromFile(typeof(UserPolicy), path));
                }
            }
            catch (DirectoryNotFoundException)
            {
                return(GetDefaultPolicy(user));
            }
            catch (FileNotFoundException)
            {
                return(GetDefaultPolicy(user));
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error reading policy file: {0}", ex, path);

                return(GetDefaultPolicy(user));
            }
        }
Example #3
0
        private DeviceProfile ParseProfileFile(string path, DeviceProfileType type)
        {
            lock (_profiles)
            {
                if (_profiles.TryGetValue(path, out Tuple <InternalProfileInfo, DeviceProfile> profileTuple))
                {
                    return(profileTuple.Item2);
                }

                try
                {
                    DeviceProfile profile;

                    var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);

                    profile = ReserializeProfile(tempProfile);

                    profile.Id = path.ToLowerInvariant().GetMD5().ToString("N", CultureInfo.InvariantCulture);

                    _profiles[path] = new Tuple <InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);

                    return(profile);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Error parsing profile file: {Path}", path);

                    return(null);
                }
            }
        }
Example #4
0
        private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type)
        {
            lock (_profiles)
            {
                Tuple <InternalProfileInfo, DeviceProfile> profileTuple;
                if (_profiles.TryGetValue(path, out profileTuple))
                {
                    return(profileTuple.Item2);
                }

                try
                {
                    var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);

                    profile.Id          = path.ToLower().GetMD5().ToString("N");
                    profile.ProfileType = type;

                    _profiles[path] = new Tuple <InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);

                    return(profile);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error parsing profile xml: {0}", ex, path);

                    return(null);
                }
            }
        }
Example #5
0
        private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type)
        {
            lock (_profiles)
            {
                DeviceProfile profile;
                if (_profiles.TryGetValue(path, out profile))
                {
                    return(profile);
                }

                try
                {
                    profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);

                    profile.Id          = path.ToLower().GetMD5().ToString("N");
                    profile.ProfileType = type;

                    _profiles[path] = profile;

                    return(profile);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error parsing profile xml: {0}", ex, path);

                    return(null);
                }
            }
        }
Example #6
0
        public void GetFileCopy <T>(ref T obj, string filename)
        {
            var path = DataPath + @"\" + filename;

            if (File.Exists(path))
            {
                obj = (T)_xmlSerializer.DeserializeFromFile(typeof(T), path);
            }
            else
            {
                obj = (T)Activator.CreateInstance <T>();
            }
        }
        private static List <SeriesTimer> GetSeriesTimerData(string dataPath, IXmlSerializer xmlSerializer)
        {
            List <SeriesTimer> dummy = new List <SeriesTimer>();
            var timerPath            = Path.Combine(dataPath, "seriesTimers.xml");

            try
            {
                return((List <SeriesTimer>)xmlSerializer.DeserializeFromFile(dummy.GetType(), timerPath));
            }
            catch (FileNotFoundException)
            {
                return(dummy);
            }
        }
Example #8
0
        private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type)
        {
            try
            {
                var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);

                profile.Id          = path.ToLower().GetMD5().ToString("N");
                profile.ProfileType = type;

                return(profile);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error parsing profile xml: {0}", ex, path);

                return(null);
            }
        }
Example #9
0
        private DeviceProfile ParseProfileFile(string path, DeviceProfileType type)
        {
            lock (_profiles)
            {
                Tuple <InternalProfileInfo, DeviceProfile> profileTuple;
                if (_profiles.TryGetValue(path, out profileTuple))
                {
                    return(profileTuple.Item2);
                }

                try
                {
                    DeviceProfile profile;

                    if (string.Equals(Path.GetExtension(path), ".xml", StringComparison.OrdinalIgnoreCase))
                    {
                        var tempProfile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);

                        profile = ReserializeProfile(tempProfile);
                    }
                    else
                    {
                        profile = (DeviceProfile)_jsonSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
                    }

                    profile.Id          = path.ToLower().GetMD5().ToString("N");
                    profile.ProfileType = type;

                    _profiles[path] = new Tuple <InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile);

                    return(profile);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error parsing profile file: {0}", ex, path);

                    return(null);
                }
            }
        }