// ReSharper disable once FunctionComplexityOverflow protected EventSequence BaseOpenSequence(string fileName, IFileIOHandler ioHandler) { var contextNode = new XmlDocument(); contextNode.Load(fileName); var requiredNode = Xml.GetRequiredNode(contextNode, "Program"); var es = new EventSequence { FileName = fileName, FullChannels = new List <Channel>(), Channels = new List <Channel>(), PlugInData = new SetupData(), LoadableData = new LoadableData(), Extensions = new SequenceExtensions(), AudioDeviceVolume = int.Parse(Xml.GetNodeAlways(requiredNode, "AudioVolume", "100").InnerText), FileIOHandler = ioHandler }; var timeNode = requiredNode.SelectSingleNode("Time"); if (timeNode != null) { es.Time = Convert.ToInt32(timeNode.InnerText); } var eventPeriodNode = requiredNode.SelectSingleNode("EventPeriodInMilliseconds"); if (eventPeriodNode != null) { es.EventPeriod = Convert.ToInt32(eventPeriodNode.InnerText); } var minLevelNode = requiredNode.SelectSingleNode("MinimumLevel"); if (minLevelNode != null) { es.MinimumLevel = (byte)Convert.ToInt32(minLevelNode.InnerText); } var mnaxLevelNode = requiredNode.SelectSingleNode("MaximumLevel"); if (mnaxLevelNode != null) { es.MaximumLevel = (byte)Convert.ToInt32(mnaxLevelNode.InnerText); } var audioDeviceNode = requiredNode.SelectSingleNode("AudioDevice"); if (audioDeviceNode != null) { es.AudioDeviceIndex = int.Parse(audioDeviceNode.InnerText); } var profileNode = requiredNode.SelectSingleNode("Profile"); if (profileNode == null) { LoadEmbeddedData(requiredNode, es); } else { var path = Path.Combine(Paths.ProfilePath, profileNode.InnerText + Vendor.ProfileExtension); if (File.Exists(path)) { es.AttachToProfile(es.FileIOHandler.OpenProfile(path)); es.Groups = es.Profile.Groups; } else { LoadEmbeddedData(es.FileName, es); } } es.UpdateEventValueArray(); var audioFileNode = requiredNode.SelectSingleNode("Audio"); if (audioFileNode != null) { if (audioFileNode.Attributes != null) { es.Audio = new Audio(audioFileNode.InnerText, audioFileNode.Attributes["filename"].Value, Convert.ToInt32(audioFileNode.Attributes["duration"].Value)); } } var eventValueNode = requiredNode.SelectSingleNode("EventValues"); if (eventValueNode != null) { var buffer = Convert.FromBase64String(eventValueNode.InnerText); var index = 0; var count = es.FullChannels.Count; for (var row = 0; (row < count) && (index < buffer.Length); row++) { for (var column = 0; (column < es.TotalEventPeriods) && (index < buffer.Length); column++) { es.EventValues[row, column] = buffer[index++]; } } } var windowSizeNode = requiredNode.SelectSingleNode("WindowSize"); if (windowSizeNode != null) { var strArray = windowSizeNode.InnerText.Split(','); try { es.WindowWidth = Convert.ToInt32(strArray[0]); } catch { es.WindowWidth = 0; } try { es.WindowHeight = Convert.ToInt32(strArray[1]); } catch { es.WindowHeight = 0; } } windowSizeNode = requiredNode.SelectSingleNode("ChannelWidth"); if (windowSizeNode != null) { try { es.ChannelWidth = Convert.ToInt32(windowSizeNode.InnerText); } catch { es.ChannelWidth = 0; } } var engineTypeNode = requiredNode.SelectSingleNode("EngineType"); if (engineTypeNode != null) { try { es.EngineType = (EngineType)Enum.Parse(typeof(EngineType), engineTypeNode.InnerText); } // ReSharper disable EmptyGeneralCatchClause catch // ReSharper restore EmptyGeneralCatchClause {} } es.LoadableData.LoadFromXml(requiredNode); es.Extensions.LoadFromXml(requiredNode); es.ApplyGroup(); return(es); }