Esempio n. 1
0
        public static void UpdateAQNMappings()
        {
            using (var scope = PuckCache.ServiceProvider.CreateScope())
            {
                var apiHelper = scope.ServiceProvider.GetService <I_Api_Helper>();
                foreach (var t in apiHelper.AllModels(true))
                {
                    if (PuckCache.ModelNameToAQN.ContainsKey(t.Name))
                    {
                        throw new Exception($"there is more than one ViewModel with the name:{t.Name}. ViewModel names must be unique!");
                    }
                    PuckCache.ModelNameToAQN[t.Name]  = t.AssemblyQualifiedName;
                    PuckCache.ModelNameToType[t.Name] = t;
                }

                var interfaces = ApiHelper.FindDerivedClasses(typeof(puck.core.Abstract.I_BaseModel)).Where(x => x.IsInterface).ToList();

                var interfaceNameToType = new Dictionary <string, Tuple <Type, List <FlattenedObject> > >();

                foreach (var _interface in interfaces)
                {
                    var implementingTypes = ApiHelper.FindDerivedClasses(_interface).ToList();
                    implementingTypes = implementingTypes.Where(x => typeof(BaseModel).IsAssignableFrom(x)).ToList();

                    if (implementingTypes.Count == 0)
                    {
                        continue;
                    }

                    var instance = ApiHelper.CreateInstance(implementingTypes.First());
                    try
                    {
                        ObjectDumper.SetPropertyValues(instance, setNullableFields: true);
                    }
                    catch (Exception ex)
                    {
                        PuckCache.PuckLog.Log(ex);
                        continue;
                    };

                    var dmp = ObjectDumper.Write(instance, int.MaxValue);

                    interfaceNameToType.Add(_interface.Name, new Tuple <Type, List <FlattenedObject> >(_interface, dmp));
                }

                PuckCache.InterfaceNameToType = interfaceNameToType;
            }
        }
Esempio n. 2
0
        public static void UpdateAnalyzerMappings()
        {
            using (var scope = PuckCache.ServiceProvider.CreateScope())
            {
                var apiHelper        = scope.ServiceProvider.GetService <I_Api_Helper>();
                var panalyzers       = new List <Analyzer>();
                var analyzerForModel = new Dictionary <Type, Analyzer>();
                foreach (var t in apiHelper.AllModels(true))
                {
                    var instance = ApiHelper.CreateInstance(t);
                    try
                    {
                        ObjectDumper.SetPropertyValues(instance, setNullableFields: true);
                    }
                    catch (Exception ex)
                    {
                        PuckCache.PuckLog.Log(ex);
                    };

                    var dmp       = ObjectDumper.Write(instance, int.MaxValue);
                    var analyzers = new Dictionary <string, Analyzer>();
                    PuckCache.TypeFields[t.AssemblyQualifiedName] = new Dictionary <string, Type>();
                    foreach (var p in dmp)
                    {
                        if (!PuckCache.TypeFields[t.AssemblyQualifiedName].ContainsKey(p.Key))
                        {
                            PuckCache.TypeFields[t.AssemblyQualifiedName].Add(p.Key, p.Type);
                        }
                        if (p.Analyzer == null)
                        {
                            continue;
                        }
                        if (!panalyzers.Any(x => x.GetType() == p.Analyzer.GetType()))
                        {
                            panalyzers.Add(p.Analyzer);
                        }
                        analyzers.Add(p.Key, panalyzers.Where(x => x.GetType() == p.Analyzer.GetType()).FirstOrDefault());
                    }
                    var pfAnalyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48), analyzers);
                    analyzerForModel.Add(t, pfAnalyzer);
                    PuckCache.AnalyzerDictionaryForModel[t] = analyzers;
                }
                PuckCache.Analyzers        = panalyzers;
                PuckCache.AnalyzerForModel = analyzerForModel;
            }
        }