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); } } }
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); } } }
private IEnumerable <DeviceProfile> GetProfiles(string path, DeviceProfileType type) { try { var allFiles = _fileSystem.GetFiles(path) .ToList(); var xmlFies = allFiles .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .ToList(); var parseFiles = new List <FileSystemMetadata>(); parseFiles.AddRange(xmlFies); return(parseFiles .Select(i => ParseProfileFile(i.FullName, type)) .Where(i => i != null) .ToList()); } catch (IOException) { return(new List <DeviceProfile>()); } }
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); } } }
private IEnumerable <InternalProfileInfo> GetProfileInfos(string path, DeviceProfileType type) { try { return(new DirectoryInfo(path) .EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => new InternalProfileInfo { Path = i.FullName, Info = new DeviceProfileInfo { Id = i.FullName.ToLower().GetMD5().ToString("N"), Name = _fileSystem.GetFileNameWithoutExtension(i), Type = type } }) .ToList()); } catch (DirectoryNotFoundException) { return(new List <InternalProfileInfo>()); } }
private void SaveProfile(DeviceProfile profile, string path, DeviceProfileType type) { lock (_profiles) { _profiles[path] = new Tuple <InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile); } SerializeToXml(profile, path); }
private InternalProfileInfo GetInternalProfileInfo(FileSystemMetadata file, DeviceProfileType type) { return(new InternalProfileInfo( new DeviceProfileInfo { Id = file.FullName.ToLowerInvariant().GetMD5().ToString("N", CultureInfo.InvariantCulture), Name = _fileSystem.GetFileNameWithoutExtension(file), Type = type }, file.FullName)); }
private InternalProfileInfo GetInternalProfileInfo(FileSystemMetadata file, DeviceProfileType type) { return(new InternalProfileInfo { Path = file.FullName, Info = new DeviceProfileInfo { Id = file.FullName.ToLower().GetMD5().ToString("N"), Name = _fileSystem.GetFileNameWithoutExtension(file), Type = type } }); }
private IEnumerable <InternalProfileInfo> GetProfileInfos(string path, DeviceProfileType type) { try { return(_fileSystem.GetFiles(path) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => GetInternalProfileInfo(i, type)) .ToList()); } catch (DirectoryNotFoundException) { return(new List <InternalProfileInfo>()); } }
private IEnumerable <DeviceProfile> GetProfiles(string path, DeviceProfileType type) { try { return(_fileSystem.GetFiles(path) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => ParseProfileXmlFile(i.FullName, type)) .Where(i => i != null) .ToList()); } catch (DirectoryNotFoundException) { return(new List <DeviceProfile>()); } }
private IEnumerable <DeviceProfile> GetProfiles(string path, DeviceProfileType type) { try { return(_fileSystem.GetFilePaths(path) .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => ParseProfileFile(i, type)) .Where(i => i != null) .ToList() !); // We just filtered out all the nulls } catch (IOException) { return(Array.Empty <DeviceProfile>()); } }
public static DeviceProfile GetSystemProfile(DeviceProfileType id) { switch (id) { case DeviceProfileType.Auto: return(ParseTopology("Unknown")); case DeviceProfileType.Atem1ME: return(ParseTopology("Atem1MEProductionSwitcher")); case DeviceProfileType.AtemTelevisionStudioHD: return(ParseTopology("AtemTelevisionStudioHD")); case DeviceProfileType.Atem2ME4K: default: return(ParseTopology("Atem2MEProductionStudio4K")); } }
private IEnumerable <DeviceProfile> GetProfiles(string path, DeviceProfileType type) { try { var xmlFies = _fileSystem.GetFilePaths(path) .Where(i => string.Equals(Path.GetExtension(i), ".xml", StringComparison.OrdinalIgnoreCase)) .ToList(); return(xmlFies .Select(i => ParseProfileFile(i, type)) .Where(i => i != null) .ToList()); } catch (IOException) { return(new List <DeviceProfile>()); } }
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); } }
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); } } }
private IEnumerable<DeviceProfile> GetProfiles(string path, DeviceProfileType type) { try { return _fileSystem.GetFiles(path) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => ParseProfileXmlFile(i.FullName, type)) .Where(i => i != null) .ToList(); } catch (DirectoryNotFoundException) { return new List<DeviceProfile>(); } }
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; } } }
private IEnumerable<InternalProfileInfo> GetProfileInfos(string path, DeviceProfileType type) { try { return _fileSystem.GetFiles(path) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => GetInternalProfileInfo(i, type)) .ToList(); } catch (DirectoryNotFoundException) { return new List<InternalProfileInfo>(); } }
private InternalProfileInfo GetInternalProfileInfo(FileSystemMetadata file, DeviceProfileType type) { return new InternalProfileInfo { Path = file.FullName, Info = new DeviceProfileInfo { Id = file.FullName.ToLower().GetMD5().ToString("N"), Name = _fileSystem.GetFileNameWithoutExtension(file), Type = type } }; }
private void SaveProfile(DeviceProfile profile, string path, DeviceProfileType type) { lock (_profiles) { _profiles[path] = new Tuple<InternalProfileInfo, DeviceProfile>(GetInternalProfileInfo(_fileSystem.GetFileInfo(path), type), profile); } _xmlSerializer.SerializeToFile(profile, path); }
private IEnumerable<InternalProfileInfo> GetProfileInfos(string path, DeviceProfileType type) { try { return _fileSystem.GetFiles(path) .Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase)) .Select(i => new InternalProfileInfo { Path = i.FullName, Info = new DeviceProfileInfo { Id = i.FullName.ToLower().GetMD5().ToString("N"), Name = _fileSystem.GetFileNameWithoutExtension(i), Type = type } }) .ToList(); } catch (DirectoryNotFoundException) { return new List<InternalProfileInfo>(); } }
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; } }
/// <summary> /// Initializes a new instance of the <see cref="DeviceProfileInfo"/> class. /// </summary> /// <param name="id">The Id of the profile.</param> /// <param name="name">The name of the profile.</param> /// <param name="type">The type of the profile.</param> public DeviceProfileInfo(string id, string name, DeviceProfileType type) { Id = id; Name = name; Type = type; }