private IEnumerable <IPsnInternalConfiguration> LoadPsnConfigurations(string psnConfigurationsPath) { var defaultsDirInfo = new DirectoryInfo(psnConfigurationsPath); var psnConfigFiles = defaultsDirInfo.GetFiles("psn.*.xml"); var psnConfiguratios = new List <IPsnInternalConfiguration>(); var assemblyKvStorageForPsnSignals = new KeyValueStringStorageXmlMemCache(Path.Combine(Support.GetAppDataDirectoryPathAndCreateItIfNeeded(), "PsnParameters.xml")); // TODO ??? foreach (var psnConfigFile in psnConfigFiles) { try { var configLaoder = new PsnProtocolConfigurationLoaderFromXml(psnConfigFile.FullName); var psnProtocolConfig = configLaoder.LoadConfiguration(); IPsnInternalConfigrationBuilder cfgBuilder = new PsnConfigurationBuilderFromLowLevel(psnProtocolConfig); IPsnInternalConfiguration psnConfig = cfgBuilder.BuildConfig(); psnConfiguratios.Add(psnConfig); } catch { continue; } } return(psnConfiguratios); }
private static void Main(string[] args) { try { _normalForeColor = Console.ForegroundColor; _normalBackColor = Console.BackgroundColor; var type = args.First(a => a.StartsWith(TypeStartArgs)).Substring(TypeStartArgs.Length); var file = args.First(a => a.StartsWith(FileStartArg)).Substring(FileStartArg.Length); var psnConfigs = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "defaults")).GetFiles(file); if (type == "addonly") { //var psnConfigs = (new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "defaults"))).GetFiles(file); foreach (var psnConfig in psnConfigs) { Console.WriteLine("Working with document: " + psnConfig.FullName); ApplyIds(psnConfig.FullName, false); } } else if (type == "replace") { //var psnConfigs = (new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, "defaults"))).GetFiles(file); foreach (var psnConfig in psnConfigs) { Console.WriteLine("Working with document: " + psnConfig.FullName); ApplyIds(psnConfig.FullName, true); } } else if (type == "getinfo") { var rpdIds = new List <Tuple <int, string, Guid> >(); foreach (var psnConfig in psnConfigs) { try { var loader = new PsnProtocolConfigurationLoaderFromXml(psnConfig.FullName); var config = loader.LoadConfiguration(); rpdIds.Add(new Tuple <int, string, Guid>(int.Parse(config.Information.RpdId), psnConfig.FullName, Guid.Parse(config.Id.IdentyString))); Console.WriteLine("RPD ID = " + config.Information.RpdId + " for config file: " + psnConfig.FullName); } catch (Exception ex) { Console.WriteLine(ex); } } Console.WriteLine(); Console.Write("Ordering configurations by RPD ID... "); var orderedIds = rpdIds.OrderBy(i => i).ToList(); Console.WriteLine("done, listing:----------------------------------------------------"); Console.WriteLine(); foreach (var orderedId in orderedIds) { Console.WriteLine("RPD ID = " + orderedId.Item1 + " for config file: " + orderedId.Item2); } Console.WriteLine(); Console.WriteLine("Grouping to display items with same RpdId attribute: =================================================="); Console.WriteLine(); var groupsByRpdId = orderedIds.GroupBy(item => item.Item1).OrderBy(g => g.Key); foreach (var g in groupsByRpdId) { var itemsCountInGroup = g.Count(); if (itemsCountInGroup > 1) { SetConsoleErrorColors(); Console.WriteLine(" RpdId = " + g.Key + " is taken by " + itemsCountInGroup + " configs : ----------------------------"); SetConsoleNormalColors(); var orderedGroup = g.OrderBy(t => t.Item2); // odering group items by psn config name foreach (var item in orderedGroup) { Console.WriteLine("RPD ID = " + item.Item1 + " for config file: " + item.Item2); } Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine("Grouping to display items with same Id attribute: ====================================================="); Console.WriteLine(); var groupsById = orderedIds.GroupBy(item => item.Item3).OrderBy(g => g.Key); foreach (var g in groupsById) { var itemsCountInGroup = g.Count(); if (itemsCountInGroup > 1) { SetConsoleErrorColors(); Console.WriteLine(" Id = " + g.Key + " is taken by " + itemsCountInGroup + " configs : -------------------------------"); SetConsoleNormalColors(); var orderedGroup = g.OrderBy(t => t.Item2); // odering group items by psn config name foreach (var item in orderedGroup) { Console.WriteLine("ID = " + item.Item3 + " for config file: " + item.Item2); } Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine("Summary:==============================================================================================="); Console.WriteLine(); int maxRpdId = rpdIds.Max(tuple => tuple.Item1); SetConsoleAccentedColors(); Console.WriteLine("Max RPD ID is: " + maxRpdId); SetConsoleNormalColors(); for (int i = 1; i < maxRpdId + 5; ++i) { if (rpdIds.All(tuple => tuple.Item1 != i)) { Console.WriteLine("Free RPD ID is: " + i); } } } } catch (Exception ex) { Console.WriteLine("Arguments: -type:<worktype> -file:<filemask>"); Console.WriteLine("<worktype> 'addonly' to add missed IDs"); Console.WriteLine("<worktype> 'replace' to rewrite all IDs"); Console.WriteLine("<filemask> is a masked filename, e.g. 'psn.*.xml'"); } }