private static Dictionary<string, string> AskForReplacementsWithMemory(HashSet<string> newNames, HashSet<string> oldNames, Dictionary<string, string> memory, string replacementKey)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();

            foreach (var kvp in memory)
            {
                if (oldNames.Contains(kvp.Key) && kvp.Value == null)
                {
                    oldNames.Remove(kvp.Key);
                }
                else if (oldNames.Contains(kvp.Key) && newNames.Contains(kvp.Value))
                {
                    oldNames.Remove(kvp.Key);
                    newNames.Remove(kvp.Value);
                    result.Add(kvp.Key, kvp.Value);
                }
            }

            Replacements rep = new Replacements();

            rep.AskForReplacements(oldNames, newNames, replacementKey);

            var answers = rep.TryGetC(replacementKey);
            if (answers != null)
            {
                result.AddRange(answers);
                memory.SetRange(answers);
            }

            var toDelete = oldNames.Except(newNames);
            if(answers != null)
                toDelete = toDelete.Except(answers.Keys);

            memory.SetRange(toDelete.Select(n => KVP.Create(n, (string)null)));

            return result;
        }
Example #2
0
        public static IEnumerable<Module> GetModules(Dictionary<Type, bool> types, string solutionName)
        {
            while (true)
            {
                var typesToShow = types.Keys.OrderBy(a => types[a]).ThenBy(a => a.FullName).ToList();

                var selected = new ConsoleSwitch<int, Type>("Chose types for a new Logic module:")
                    .Load(typesToShow, t => (types[t] ? "-" : " ") + t.FullName)
                    .ChooseMultiple();

                if (selected.IsNullOrEmpty())
                    yield break;

                SafeConsole.WriteColor(ConsoleColor.Gray, "Module name? (Nothing to exit):");

                string moduleName = GetDefaultModuleName(selected, solutionName);
                if (moduleName.HasText())
                    SendKeys.SendWait(moduleName);

                moduleName = Console.ReadLine();

                if (!moduleName.HasText())
                    yield break;

                yield return new Module
                {
                    ModuleName = moduleName,
                    Types = selected.ToList()
                };

                types.SetRange(selected, a => a, a => true);
            }

        }