public CabinetInfo(Cabinet Cabinet) { InitializeComponent(); this.Cabinet = Cabinet; }
/// <summary> /// Configures the system based on the data loaded from ini files. /// </summary> /// <param name="LedControlConfigList">The list of loaded led control config data.</param> /// <param name="Table">The table object to be configured.</param> /// <param name="Cabinet">The cabinet object to be configured.</param> /// <param name="RomName">Name of the rom to be used for the setup.</param> public void Setup(LedControlConfigList LedControlConfigList, DirectOutput.Table.Table Table, Cabinet Cabinet, string RomName) { Dictionary<int, TableConfig> TableConfigDict = LedControlConfigList.GetTableConfigDictonary(RomName); Dictionary<int, Dictionary<int, IToy>> ToyAssignments = SetupCabinet(TableConfigDict, Cabinet); SetupTable(Table, TableConfigDict, ToyAssignments); }
/// <summary> /// Initializes a new instance of the <see cref="CabinetOutputList"/> class. /// </summary> /// <param name="Cabinet">The cabinet to which the list belongs.</param> public CabinetOutputList(Cabinet Cabinet) { _Cabinet = Cabinet; }
/// <summary> /// Configures and initializes/starts and configures the Pinball object /// </summary> /// <param name="GlobalConfigFilename">The global config filename.</param> /// <param name="TableFilename">The table filename.</param> /// <param name="RomName">Name of the rom.</param> public void Init(string GlobalConfigFilename = "", string TableFilename = "", string RomName = "") { bool GlobalConfigLoaded = true; //Load the global config try { if (!GlobalConfigFilename.IsNullOrWhiteSpace()) { FileInfo GlobalConfigFile = new FileInfo(GlobalConfigFilename); GlobalConfig = GlobalConfig.GetGlobalConfigFromConfigXmlFile(GlobalConfigFile.FullName); if (GlobalConfig == null) { GlobalConfigLoaded = false; //set new global config object if it config could not be loaded from the file. GlobalConfig = new GlobalConfig(); } GlobalConfig.GlobalConfigFilename = GlobalConfigFile.FullName; } else { GlobalConfig = new GlobalConfig(); GlobalConfig.GlobalConfigFilename = GlobalConfigFilename; } } catch (Exception E) { throw new Exception("DirectOutput framework could initialize global config.\n Inner exception: {0}".Build(E.Message), E); } if (GlobalConfig.EnableLogging) { try { Log.Filename = GlobalConfig.GetLogFilename((!TableFilename.IsNullOrWhiteSpace() ? new FileInfo(TableFilename).FullName : ""), RomName); Log.Init(); } catch (Exception E) { throw new Exception("DirectOutput framework could initialize the log file.\n Inner exception: {0}".Build(E.Message), E); } } try { if (GlobalConfigLoaded) { Log.Write("Global config loaded from: {0}".Build(GlobalConfigFilename)); } else { if (!GlobalConfigFilename.IsNullOrWhiteSpace()) { Log.Write("Could not find or load theGlobalConfig file {0}".Build(GlobalConfigFilename)); } else { Log.Write("No GlobalConfig file loaded. Using newly instanciated GlobalConfig object instead."); } } Log.Write("Loading Pinball parts"); //Load global script files Log.Write("Loading script files"); Scripts.LoadAndAddScripts(GlobalConfig.GetGlobalScriptFiles()); //Load table script files if (!TableFilename.IsNullOrWhiteSpace()) { Scripts.LoadAndAddScripts(GlobalConfig.GetTableScriptFiles(new FileInfo(TableFilename).FullName)); } Log.Write("Script files loaded"); Log.Write("Loading cabinet"); //Load cabinet config Cabinet = null; FileInfo CCF = GlobalConfig.GetCabinetConfigFile(); if (CCF != null) { Log.Write("Will load cabinet config file: {0}".Build(CCF.FullName)); try { Cabinet = Cabinet.GetCabinetFromConfigXmlFile(CCF); Cabinet.CabinetConfigurationFilename = CCF.FullName; if (Cabinet.AutoConfigEnabled) { Log.Write("Cabinet config file has AutoConfig feature enable. Calling AutoConfig."); Cabinet.AutoConfig(); } Log.Write("Cabinet config loaded successfully from {0}".Build(CCF.FullName)); } catch (Exception E) { Log.Exception("A exception occured when load cabinet config file: {0}".Build(CCF.FullName), E); } } if (Cabinet == null) { Log.Write("No cabinet config file loaded. Will use AutoConfig."); //default to a new cabinet object if the config cant be loaded Cabinet = new Cabinet(); Cabinet.AutoConfig(); } Log.Write("Cabinet loaded"); Log.Write("Loading table config"); //Load table config Table = new DirectOutput.Table.Table(); Table.AddLedControlConfig = true; if (!TableFilename.IsNullOrWhiteSpace()) { FileInfo TableFile = new FileInfo(TableFilename); FileInfo TCF = GlobalConfig.GetTableConfigFile(TableFile.FullName); if (TCF != null) { Log.Write("Will load table config from {0}".Build(TCF.FullName)); try { Table = DirectOutput.Table.Table.GetTableFromConfigXmlFile(GlobalConfig.GetTableConfigFile(TableFile.FullName)); Table.TableConfigurationFilename = GlobalConfig.GetTableConfigFile(TableFile.FullName).FullName; Log.Write("Table config loaded successfully from {0}".Build(TCF.FullName)); } catch (Exception E) { Log.Exception("A exception occured when loading table config: {0}".Build(TCF.FullName), E); } if (Table.AddLedControlConfig) { Log.Write("Table config allows mix with ledcontrol configs."); } } else { Log.Warning("No table config file found. Will try to load config from LedControl file(s)."); } } else { Log.Write("No TableFilename specified, will use empty tableconfig"); } if (Table.AddLedControlConfig) { if (!RomName.IsNullOrWhiteSpace()) { Log.Write("Will try to load configs from DirectOutput.ini or LedControl.ini file(s) for RomName {0}".Build(RomName)); //Load ledcontrol LedControlConfigList L = new LedControlConfigList(); if (GlobalConfig.LedControlIniFiles.Count > 0) { Log.Write("Will try to load table config from LedControl file(s) specified in global config."); L.LoadLedControlFiles(GlobalConfig.LedControlIniFiles, false); } else { bool FoundIt = false; List<string> LookupPaths = new List<string>(); if (!TableFilename.IsNullOrWhiteSpace()) { if (new FileInfo(TableFilename).Directory.Exists) { LookupPaths.Add(new FileInfo(TableFilename).Directory.FullName); } } LookupPaths.AddRange(new string[] { GlobalConfig.GetGlobalConfigDirectory().FullName, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) }); LedControlIniFileList LedControlIniFiles = new LedControlIniFileList(); string[] LedControlFilenames = { "directoutputconfig", "ledcontrol" }; foreach (string LedControlFilename in LedControlFilenames) { foreach (string P in LookupPaths) { DirectoryInfo DI = new DirectoryInfo(P); List<FileInfo> Files = new List<FileInfo>(); foreach (FileInfo FI in DI.EnumerateFiles()) { if (FI.Name.ToLower().StartsWith(LedControlFilename.ToLower()) && FI.Name.ToLower().EndsWith(".ini")) { Files.Add(FI); } } foreach (FileInfo FI in Files) { if (string.Equals(FI.Name, "{0}.ini".Build(LedControlFilename), StringComparison.OrdinalIgnoreCase)) { LedControlIniFiles.Add(FI.FullName, 1); FoundIt = true; } else { string F = FI.Name.Substring(LedControlFilename.Length, FI.Name.Length - LedControlFilename.Length - 4); if (F.IsInteger()) { int LedWizNr = -1; if (int.TryParse(F, out LedWizNr)) { if (!LedControlIniFiles.Contains(LedWizNr)) { LedControlIniFiles.Add(FI.FullName, LedWizNr); FoundIt = true; } } } } }; if (FoundIt) break; } if (FoundIt) break; } if (FoundIt) { L.LoadLedControlFiles(LedControlIniFiles, false); Log.Write("{0} directoutput.ini or ledcontrol.ini files loaded.".Build(LedControlIniFiles.Count)); } else { Log.Write("No directoutput.ini or ledcontrol.ini files found. No directoutput.ini or ledcontrol.ini configs will be loaded."); } } if (!L.ContainsConfig(RomName)) { Log.Write("No config for table found in LedControl data for RomName {0}.".Build(RomName)); } else { Log.Write("Config for RomName {0} exists in LedControl data. Updating cabinet and config.".Build(RomName)); DirectOutput.LedControl.Setup.Configurator C = new DirectOutput.LedControl.Setup.Configurator(); C.EffectMinDurationMs = GlobalConfig.LedControlMinimumEffectDurationMs; C.EffectRGBMinDurationMs = GlobalConfig.LedControlMinimumRGBEffectDurationMs; C.Setup(L, Table, Cabinet, RomName); C = null; // L.UpdateTableConfig(Table, RomName, Cabinet); } L = null; } else { Log.Write("Cant load config from directoutput.ini or ledcontrol.ini file(s) since no RomName was supplied. No ledcontrol config will be loaded."); } } if (Table.TableName.IsNullOrWhiteSpace()) { if (!TableFilename.IsNullOrWhiteSpace()) { Table.TableName = Path.GetFileNameWithoutExtension(new FileInfo(TableFilename).FullName); } else if (!RomName.IsNullOrWhiteSpace()) { Table.TableName = RomName; } } if (!TableFilename.IsNullOrWhiteSpace()) { Table.TableFilename = new FileInfo(TableFilename).FullName; } if (!RomName.IsNullOrWhiteSpace()) { Table.RomName = RomName; } Log.Write("Table config loading finished"); Log.Write("Pinball parts loaded"); Log.Write("Starting processes"); InitStatistics(); Cabinet.Init(this); Table.Init(this); Alarms.Init(this); Table.TriggerStaticEffects(); Cabinet.Update(); //Add the thread initializing the framework to the threadinfo list ThreadInfo TI = new ThreadInfo(Thread.CurrentThread); TI.HeartBeatTimeOutMs = 10000; TI.HostName = "External caller"; TI.HeartBeat(); ThreadInfoList.Add(TI); InitMainThread(); Log.Write("Framework initialized."); Log.Write("Have fun! :)"); } catch (Exception E) { Log.Exception("A eception occured during initialization", E); throw new Exception("DirectOutput framework has encountered a exception during initialization.\n Inner exception: {0}".Build(E.Message), E); } }
private Dictionary<int, Dictionary<int, IToy>> SetupCabinet(Dictionary<int, TableConfig> TableConfigDict, Cabinet Cabinet) { Dictionary<int, Dictionary<int, IToy>> ToyAssignments = new Dictionary<int, Dictionary<int, IToy>>(); Dictionary<int, LedWizEquivalent> LedWizEquivalentDict = new Dictionary<int, LedWizEquivalent>(); foreach (IToy T in Cabinet.Toys.Where(Toy => Toy is LedWizEquivalent).ToList()) { LedWizEquivalentDict.Add(((LedWizEquivalent)T).LedWizNumber, (LedWizEquivalent)T); } foreach (KeyValuePair<int, TableConfig> KV in TableConfigDict) { int LedWizNr = KV.Key; ToyAssignments.Add(LedWizNr, new Dictionary<int, IToy>()); TableConfig TC = KV.Value; if (LedWizEquivalentDict.ContainsKey(LedWizNr)) { LedWizEquivalent LWE = LedWizEquivalentDict[LedWizNr]; foreach (TableConfigColumn TCC in TC.Columns) { IToy TargetToy = null; switch (TCC.RequiredOutputCount) { case 3: //RGB Led if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1) && LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2)) { //Try to get the toy try { //Toy does already exist TargetToy = (IToy)Cabinet.Toys.First(Toy => Toy is IRGBAToy && ((IRGBAToy)Toy).OutputNameRed == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName && ((IRGBAToy)Toy).OutputNameGreen == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName && ((IRGBAToy)Toy).OutputNameBlue == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName); } catch { //Toy does not exist. Create toyname and toy string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number); if (Cabinet.Toys.Contains(ToyName)) { int Cnt = 1; while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt))) { Cnt++; } ToyName = "{0} {1}".Build(ToyName, Cnt); } TargetToy = (IToy)new RGBAToy() { Name = ToyName, OutputNameRed = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName, OutputNameGreen = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 1).OutputName, OutputNameBlue = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber + 2).OutputName }; Cabinet.Toys.Add(TargetToy); } ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy); } break; case 1: //Single output //Analog output if (LWE.Outputs.Any(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber)) { try { TargetToy = Cabinet.Toys.First(Toy => Toy is IAnalogAlphaToy && ((IAnalogAlphaToy)Toy).OutputName == LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName); } catch { //Toy does not exist. Create toyname and toy string ToyName = "LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.Number); if (Cabinet.Toys.Contains(ToyName)) { int Cnt = 1; while (Cabinet.Toys.Contains("{0} {1}".Build(ToyName, Cnt))) { Cnt++; } ToyName = "{0} {1}".Build(ToyName, Cnt); } TargetToy = (IToy)new AnalogAlphaToy() { Name = ToyName, OutputName = LWE.Outputs.First(Output => Output.LedWizEquivalentOutputNumber == TCC.FirstOutputNumber).OutputName }; Cabinet.Toys.Add(TargetToy); } ToyAssignments[LedWizNr].Add(TCC.Number, TargetToy); } break; default: //Unknow value Log.Warning("A illegal number ({0}) of required outputs has been found in a table config colum {0} for ledcontrol nr. {2}. Cant configure toy.".Build(TCC.RequiredOutputCount, TCC.Number, LedWizNr)); break; } } } } return ToyAssignments; }