using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Microsoft.AspNet.Builder; using Microsoft.Extensions.Logging; namespace Yavsc { using Microsoft.Data.Entity; using Models; using Yavsc.Billing; public partial class Startup { /// /// Lists Available user profile classes, /// populated at startup, using reflexion. /// public static List ProfileTypes = new List(); public static List UserSettings = new List(); public static Dictionary> Billing = new Dictionary> (); /// /// Lists available command forms. /// This is hard coded. /// public static readonly string[] Forms = new string[] { "Profiles", "HairCut" }; private void ConfigureWorkflow(IApplicationBuilder app, SiteSettings settings, ILogger logger) { System.AppDomain.CurrentDomain.ResourceResolve += OnYavscResourceResolve; foreach (var a in System.AppDomain.CurrentDomain.GetAssemblies()) { foreach (var c in a.GetTypes()) { if (c.IsClass && !c.IsAbstract && c.GetInterface("ISpecializationSettings") != null) { ProfileTypes.Add(c); } } } foreach (var propinfo in typeof(ApplicationDbContext).GetProperties()) { foreach (var attr in propinfo.CustomAttributes) { // something like a DbSet? if (attr.AttributeType == typeof(Yavsc.Attributes.ActivitySettingsAttribute)) { // TODO swith () case {} if (typeof(IQueryable).IsAssignableFrom(propinfo.PropertyType)) {// double-bingo logger.LogVerbose($"Pro: {propinfo.Name}"); UserSettings.Add(propinfo); } else // Design time error { var msg = $@"La propriété {propinfo.Name} du contexte de la base de donnée porte l'attribut [ActivitySetting], mais n'implemente pas l'interface IQueryable ({propinfo.MemberType.GetType()})"; logger.LogCritical(msg); } } } } Billing.Add("Brush", new Func ( ( db, id) => { var query = db.HairCutQueries.Include(q=>q.Prestation).Single(q=>q.Id == id) ; query.SelectedProfile = db.BrusherProfile.Single(b=>b.UserId == query.PerformerId); return query; })) ; Billing.Add("MBrush",new Func ( (db, id) => db.HairMultiCutQueries.Single(q=>q.Id == id))); Billing.Add("Rdv", new Func ( (db, id) => db.RdvQueries.Single(q=>q.Id == id))); } public static System.Reflection.Assembly OnYavscResourceResolve(object sender, ResolveEventArgs ev) { return AppDomain.CurrentDomain.GetAssemblies()[0]; } } }