Exemplo n.º 1
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;
                }

                string moduleName = GetDefaultModuleName(selected, solutionName) !;
                SafeConsole.WriteColor(ConsoleColor.Gray, $"Module name? ([Enter] for '{moduleName}'):");

                moduleName = Console.ReadLine().DefaultText(moduleName !);

                yield return(new Module(moduleName, selected.ToList()));

                types.SetRange(selected, a => a, a => true);
            }
        }
Exemplo n.º 2
0
            public RoleAllowedCache(Lite <RoleEntity> role, IMerger <Type, TypeAllowedAndConditions> merger, List <RoleAllowedCache> baseCaches, Dictionary <Type, TypeAllowedAndConditions>?newValues)
            {
                this.role = role;

                this.merger = merger;

                this.baseCaches = baseCaches;

                Func <Type, TypeAllowedAndConditions> defaultAllowed = merger.MergeDefault(role);

                Func <Type, TypeAllowedAndConditions> baseAllowed = k => merger.Merge(k, role, baseCaches.Select(b => KVP.Create(b.role, b.GetAllowed(k))));


                var keys = baseCaches
                           .Where(b => b.rules.OverrideDictionary != null)
                           .SelectMany(a => a.rules.OverrideDictionary !.Keys)
                           .ToHashSet();

                Dictionary <Type, TypeAllowedAndConditions>?tmpRules = keys.ToDictionary(k => k, baseAllowed);

                if (newValues != null)
                {
                    tmpRules.SetRange(newValues);
                }

                tmpRules = Simplify(tmpRules, defaultAllowed, baseAllowed);

                rules = new DefaultDictionary <Type, TypeAllowedAndConditions>(defaultAllowed, tmpRules);
            }
Exemplo n.º 3
0
    public IEnumerable <Module> ReactGetModules(Dictionary <Type, bool> types, string solutionName)
    {
        while (true)
        {
            var typesToShow = types.Keys.OrderBy(a => a.FullName).ToList();

            var selectedTypes = new ConsoleSwitch <int, Type>("Chose types for a new React module:")
                                .Load(typesToShow)
                                .Do(cs => cs.PrintOption = (key, vwd) =>
            {
                var used = types.GetOrThrow(vwd.Value);

                SafeConsole.WriteColor(used ? ConsoleColor.DarkGray :  ConsoleColor.White, " " + key);
                SafeConsole.WriteLineColor(used ? ConsoleColor.DarkGray: ConsoleColor.Gray, " - " + vwd.Description);
            })
                                .ChooseMultiple();

            if (selectedTypes.IsNullOrEmpty())
            {
                yield break;
            }

            var modules = selectedTypes.GroupBy(a => a.Namespace !.After(this.SolutionName + ".Entities").DefaultText(this.SolutionName))
                          .Select(gr => new Module(gr.Key.TryAfterLast(".") ?? gr.Key, gr.ToList())).ToList();

            foreach (var m in modules)
            {
                yield return(m);
            }

            types.SetRange(selectedTypes, a => a, a => true);
        }
    }
Exemplo n.º 4
0
        private Expression MapAndVisit(LambdaExpression lambda, params MetaProjectorExpression[] projs)
        {
            map.SetRange(lambda.Parameters, projs.Select(a => a.Projector));
            var result = Visit(lambda.Body);

            map.RemoveRange(lambda.Parameters);
            return(result);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public IEnumerable <Module> ReactGetModules(Dictionary <Type, bool> types, string solutionName)
        {
            while (true)
            {
                var typesToShow = types.Keys.OrderBy(a => types[a]).ThenBy(a => a.FullName).ToList();

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

                if (selectedTypes.IsNullOrEmpty())
                {
                    yield break;
                }

                var directories = Directory.GetDirectories(GetProjectFolder(), "App\\").Select(a => Path.GetFileName(a));

                string moduleName;
                if (directories.IsEmpty())
                {
                    moduleName = AskModuleName(solutionName, selectedTypes);
                }
                else
                {
                    var selectedName = directories.And("[New Module]").ChooseConsole(message: "Select a Module");

                    if (selectedName == "[New Module]")
                    {
                        moduleName = AskModuleName(solutionName, selectedTypes);
                    }
                    else
                    {
                        moduleName = selectedName;
                    }
                }

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

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

                types.SetRange(selectedTypes, a => a, a => true);
            }
        }
        protected override IDictionary <IVariable, IVariable> Flow(CFGNode node, IDictionary <IVariable, IVariable> output)
        {
            var input = new Dictionary <IVariable, IVariable>(output);
            var kill  = KILL[node.Id];
            var gen   = GEN[node.Id];

            foreach (var variable in kill)
            {
                this.RemoveCopiesWithVariable(input, variable);
            }

            input.SetRange(gen);
            return(input);
        }
Exemplo n.º 8
0
    public IEnumerable <QueryToken> GetExtensions(QueryToken parent)
    {
        var parentTypeClean = parent.Type.CleanType();

        var compatibleTypes = CompatibleTypes(parent.Type);

        var dic = compatibleTypes
                  .Select(t => RegisteredExtensions.TryGetValue(t))
                  .Aggregate((Dictionary <string, ExtensionInfo>?)null, (dic1, dic2) =>
        {
            if (dic1 == null)
            {
                return(dic2);
            }

            if (dic2 == null)
            {
                return(dic1);
            }

            var dic = new Dictionary <string, ExtensionInfo>();
            dic.SetRange(dic1);
            dic.DefaultRange(dic2);
            return(dic);
        });

        IEnumerable <QueryToken> extensionsTokens = dic == null?Enumerable.Empty <QueryToken>() :
                                                        dic.Values.Where(ei => ei.Inherit || compatibleTypes.Contains(ei.SourceType))
                                                        .Where(ei => ei.IsApplicable == null || ei.IsApplicable(parent))
                                                        .Select(v => v.CreateToken(parent));

        var pr = parentTypeClean.IsEntity() && !parentTypeClean.IsAbstract ? PropertyRoute.Root(parentTypeClean) :
                 parentTypeClean.IsEmbeddedEntity() ? parent.GetPropertyRoute() : null;

        var edi = pr == null ? null : RegisteredExtensionsDictionaries.TryGetC(pr);

        IEnumerable <QueryToken> dicExtensionsTokens = edi == null?Enumerable.Empty <QueryToken>() :
                                                           edi.GetAllTokens(parent);

        return(extensionsTokens.Concat(dicExtensionsTokens));
    }
Exemplo n.º 9
0
        public static Dictionary <K, V> InheritDictionary <K, V>(KeyValuePair <Type, Dictionary <K, V> > currentValue, KeyValuePair <Type, Dictionary <K, V> > baseValue, List <KeyValuePair <Type, Dictionary <K, V> > > newInterfacesValues)
        {
            if (currentValue.Value == null && baseValue.Value == null)
            {
                return(null);
            }

            Dictionary <K, V> newDictionary = new Dictionary <K, V>();

            if (baseValue.Value != null)
            {
                newDictionary.AddRange(baseValue.Value);
            }

            if (currentValue.Value != null)
            {
                newDictionary.SetRange(currentValue.Value);
            }

            return(newDictionary);
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
0
        public static Dictionary <K, V> InheritDictionaryInterfaces <K, V>(KeyValuePair <Type, Dictionary <K, V> > currentValue, KeyValuePair <Type, Dictionary <K, V> > baseValue, List <KeyValuePair <Type, Dictionary <K, V> > > newInterfacesValues)
        {
            if (currentValue.Value == null && baseValue.Value == null && newInterfacesValues.All(a => a.Value == null))
            {
                return(null);
            }

            Dictionary <K, V> newDictionary = new Dictionary <K, V>();

            if (baseValue.Value != null)
            {
                newDictionary.AddRange(baseValue.Value);
            }

            if (currentValue.Value != null)
            {
                newDictionary.SetRange(currentValue.Value);
            }

            var interfaces = newInterfacesValues.Where(a => a.Value != null);

            var keys = interfaces.SelectMany(inter => inter.Value.Keys).Distinct().Except(newDictionary.Keys);

            foreach (var item in keys)
            {
                var types = interfaces.Where(a => a.Value.ContainsKey(item)).Select(a => new { a.Key, Value = a.Value[item] }).ToList();

                var groups = types.GroupBy(t => t.Value);
                if (groups.Count() > 1)
                {
                    throw new InvalidOperationException("Ambiguity for key {0} in type {0} between interfaces {1}".FormatWith(item, currentValue.Key.Name, types.CommaAnd(t => t.Key.Name)));
                }

                newDictionary[item] = groups.Single().Key;
            }

            return(newDictionary);
        }
        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;
        }
Exemplo n.º 13
0
 public ReadOnlyDictionaryTests(DictT dict, params KeyValuePair <int, V>[] data)
 {
     _dict   = dict;
     _expect = new Dictionary <int, V>();
     _expect.SetRange(data);
 }
Exemplo n.º 14
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);
            }

        }