public static Rank GetRank(int userId, int routeId) { using (ISession iSession = NHSessionManager.GetSession()) { return(GetRank(userId, routeId, iSession)); } }
//-------------------------------------------------------------------------------- public static void CountVisitor(HttpRequest request, HttpSessionState session) { string host = request["REMOTE_HOST"]; long visitorSessionCount; using (ISession iSession = NHSessionManager.GetSession()) { using (ITransaction transaction = iSession.BeginTransaction()) { Visitor visitor = iSession.Get <Visitor>(host); if (visitor == null) { visitor = new Visitor(host); } visitor.Visits++; iSession.SaveOrUpdate(visitor); iSession.Flush(); visitorSessionCount = visitor.Visits; transaction.Commit(); session[VisitorSessionCount] = visitorSessionCount; } Expression <Func <Visitor, object> > expr = v => v.Visits; var criteria = iSession.CreateCriteria <Visitor>() .SetProjection(Projections.Sum(expr), Projections.Count(expr)); object[] result = criteria.UniqueResult <object[]>(); session[SessionCount] = Convert.ToInt64(result[0]); session[HostCount] = Convert.ToInt64(result[1]); } }
protected void Application_Start() { var container = new Container(); // Simple Injector for MVC container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterMvcIntegratedFilterProvider(); // Simple Injector - other services var baseContainer = new BaseContainer(container: container); var resolver = new SimpleInjectorDependencyResolver(baseContainer.Container); DependencyResolver.SetResolver(resolver); // Very Important MyServiceLocator.SetIoCContainer(baseContainer.Container); MyMvcServiceLocator.SetIoCContainer(resolver); // Initialize MVC settings AppStartInitializer.Initialize(); NHSessionManager.AddEntityAssemblies(new[] { "MultiTenancyFramework.Mvc" }); }
public void OnResultExecuted(ResultExecutedContext filterContext) { var x = filterContext.HttpContext; // exclude static resources // The key is that from an MVC point of view, if the Physical Path has an extension, then it's a physical resource if (string.IsNullOrWhiteSpace(x.Request.PhysicalPath)) { return; } var ext = System.IO.Path.GetExtension(x.Request.PhysicalPath); if (!string.IsNullOrWhiteSpace(ext)) { return; } if (x.Items.Contains(WebSessionStorage.CurrentSessionKey)) { var storageSet = new Dictionary <string, ISessionStorage>(NHSessionManager.SessionStorages); if (storageSet != null && storageSet.Count > 0) { foreach (var storage in storageSet.Values) { //Closes the session if there's any open session if (storage != null && storage.Session != null) { NHSessionManager.CloseStorage(((WebSessionStorage)storage)?.InstitutionCode); } } storageSet.Clear(); x.Items.Remove(WebSessionStorage.CurrentSessionKey); } } }
//-------------------------------------------------------------------------------- public static EventSubscriptor[] GetSubscriptors() { using (ISession iSession = NHSessionManager.GetSession()) { var criteria = iSession.CreateCriteria <EventSubscriptor>(); return(criteria.List <EventSubscriptor>().ToArray()); } }
public static Appointment GetAppointment(int id) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Appointment, object> > expr = rt => rt.Id; var criteria = iSession.CreateCriteria <Appointment>(); criteria.Add(Restrictions.Eq("id", id)); return(criteria.UniqueResult <Appointment>()); } }
//-------------------------------------------------------------------------------- public static EventSubscriptor LoadSubscriptor(string email) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <EventSubscriptor, object> > expr = rt => rt.EMail; var criteria = iSession.CreateCriteria <EventSubscriptor>(); criteria.Add(Restrictions.Eq(Projections.Property(expr), email)); return(criteria.UniqueResult <EventSubscriptor>()); } }
public static EventSubscriptor[] GetSubscriptors(int eventId) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <EventSubscriptor, object> > expr = rt => rt.EventId; var criteria = iSession.CreateCriteria <EventSubscriptor>(); criteria.Add(Restrictions.Eq(Projections.Property(expr), eventId)); return(criteria.List <EventSubscriptor>().ToArray()); } }
public static IList <Rank> GetRanks(int routeId) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Rank, object> > expr = rt => rt.RouteId; var criteria = iSession.CreateCriteria <Rank>(); criteria.Add(Restrictions.Eq(Projections.Property(expr), routeId)); return(criteria.List <Rank>()); } }
public static IList <Appointment> GetAppointments() { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Appointment, object> > expr = rt => rt.AppointmentDate; var criteria = iSession.CreateCriteria <Appointment>(); criteria.AddOrder(Order.Asc(Projections.Property(expr))); IList <Appointment> apps = criteria.List <Appointment>(); return(apps); } }
public static void SaveAppointment(Appointment appointment) { using (ISession iSession = NHSessionManager.GetSession()) { using (ITransaction transaction = iSession.BeginTransaction()) { iSession.SaveOrUpdate(appointment); iSession.Flush(); transaction.Commit(); } } }
//-------------------------------------------------------------------------------- public static void SaveSubscriptor(EventSubscriptor subscriptor) { using (ISession iSession = NHSessionManager.GetSession()) { //aggiungo l'utente al database, oppure lo aggiorno using (ITransaction transaction = iSession.BeginTransaction()) { iSession.SaveOrUpdate(subscriptor); iSession.Flush(); transaction.Commit(); } } }
//-------------------------------------------------------------------------------- static DBHelper() { try { using (ISession iSession = NHSessionManager.GetSession()) { LoadRoutes(iSession); LoadUsers(iSession); } } catch (Exception ex) { Log.Add(ex.ToString()); } }
static void Init() { var baseContainer = new BaseContainer(); MyServiceLocator.SetIoCContainer(baseContainer.Container); // Initialize MVC settings //AppStartInitializer.Initialize(); NHSessionManager.AddEntityAssemblies(new[] { "ConsoleTests" }); var fileRules = new Dictionary <string, Tuple <string, LoggingLevel> > { { "NHibernate.SQL", new Tuple <string, LoggingLevel>("${shortdate}_nh.log", LoggingLevel.Debug) } }; LoggerConfigurationManager.ConfigureNLog(true, fileRules); }
public static void DeleteAppointment(int appointmentId) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Appointment, object> > expr = rt => rt.Id; var criteria = iSession.CreateCriteria <Appointment>(); criteria.Add(Restrictions.Eq("id", appointmentId)); Appointment app = criteria.UniqueResult <Appointment>(); using (ITransaction transaction = iSession.BeginTransaction()) { iSession.Delete(app); iSession.Flush(); transaction.Commit(); } } }
public static void DeleteOldAppointments() { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Appointment, object> > expr = rt => rt.AppointmentDate; var criteria = iSession.CreateCriteria <Appointment>(); criteria.Add(Restrictions.Lt(Projections.Property(expr), DateTime.Now - TimeSpan.FromDays(3))); //aggiungo l'utente al database, oppure lo aggiorno using (ITransaction transaction = iSession.BeginTransaction()) { foreach (Appointment app in criteria.List <Appointment>()) { iSession.Delete(app); } iSession.Flush(); transaction.Commit(); } } }
public static double GetMediumRank(Route r, out int voteNumber) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Rank, object> > expr = rt => rt.RouteId; var criteria = iSession.CreateCriteria <Rank>(); criteria.Add(Restrictions.Eq(Projections.Property(expr), r.Id)); expr = rt => rt.RankNumber; criteria.SetProjection(Projections.Sum(expr), Projections.Count(expr)); object[] result = criteria.UniqueResult <object[]>(); voteNumber = (int)result[1]; return(voteNumber == 0 ? 0.0 : Convert.ToDouble(result[0]) / (double)voteNumber); } }
//-------------------------------------------------------------------------------- public static void DeleteRoute(Route route) { using (ISession iSession = NHSessionManager.GetSession()) { //aggiungo l'utente al database, oppure lo aggiorno using (ITransaction transaction = iSession.BeginTransaction()) { iSession.Delete(route); iSession.Flush(); transaction.Commit(); } } new Thread(() => { using (ISession ss = NHSessionManager.GetSession()) { DBHelper.LoadRoutes(ss); } }).Start(); }
//-------------------------------------------------------------------------------- public static void SaveUser(MTBUser user) { using (ISession iSession = NHSessionManager.GetSession()) { //aggiungo l'utente al database, oppure lo aggiorno using (ITransaction transaction = iSession.BeginTransaction()) { iSession.SaveOrUpdate(user); iSession.Flush(); transaction.Commit(); } new Thread(() => { using (ISession ss = NHSessionManager.GetSession()) { DBHelper.LoadUsers(ss); } }).Start(); } }
//-------------------------------------------------------------------------------- public static IList ExecQuery(string queryString) { using (ISession iSession = NHSessionManager.GetSession()) { ISQLQuery query = iSession.CreateSQLQuery(queryString); IList genericList = query.List(); if (genericList.Count == 0) { return(new ArrayList()); } Type t = CreateType(genericList[0] as object[]); if (t == null) { return(new ArrayList()); } for (int i = 0; i < genericList.Count; i++) { genericList[i] = CreateTypeInstance(t, genericList[i] as object[]); } return(genericList); } }
//-------------------------------------------------------------------------------- public static void SaveRank(int userId, int routeId, byte rank) { using (ISession iSession = NHSessionManager.GetSession()) { Rank r = GetRank(userId, routeId, iSession); if (r == null) { r = new Rank(); r.RouteId = routeId; r.UserId = userId; } if (r.RankNumber != rank) { r.RankNumber = rank; using (ITransaction transaction = iSession.BeginTransaction()) { iSession.SaveOrUpdate(r); iSession.Flush(); transaction.Commit(); } } } }
public static void DeletePost(int appointmentId, int postId) { using (ISession iSession = NHSessionManager.GetSession()) { Expression <Func <Appointment, object> > expr = rt => rt.Id; var criteria = iSession.CreateCriteria <Appointment>(); criteria.Add(Restrictions.Eq("id", appointmentId)); Appointment app = criteria.UniqueResult <Appointment>(); foreach (Post p in app.AppointmentPosts) { if (p.Id == postId) { app.AppointmentPosts.Remove(p); break; } } using (ITransaction transaction = iSession.BeginTransaction()) { iSession.SaveOrUpdate(app); iSession.Flush(); transaction.Commit(); } } }
public void Init(HttpApplication context) { NHSessionManager.AddEntityAssemblies(new[] { "MultiTenancyFramework.Mvc" }); NHSessionManager.AddMappingAssemblies(new[] { "MultiTenancyFramework.Mvc.NHibernate" }); }
/// <summary> /// Whether or not the DB we're using is MySql /// </summary> /// <returns></returns> public bool IsMySql() { return(NHSessionManager.IsMySqlDatabase()); }
/// <summary> /// WARNING: /// <para>DO NOT use this session directly for anything other than retrieves (like constructing QueryOver or CreateCriteria). /// For every other case, use what is provided in the base class</para> /// <para>NB: The returned session only Flushes when you commit. You can always change to .FlushMode to your taste.</para> /// </summary> /// <returns></returns> public virtual ISession BuildSession() { return(NHSessionManager.GetSession(_institutionCode)); }
public virtual void Terminate(bool isWeb = true) { NHSessionManager.CloseStorage(isWebSession: isWeb); }
public string GetConnectionString() { return(NHSessionManager.GetConnectionString()); }
/// <summary> /// When more than one entity can be mapped to a table, this will scan and select the correct one, based mostly on the inheritance structure. /// </summary> public void SetEntityName <T>() { EntityName = NHSessionManager.GetEntityNameToUseInNHSession(typeof(T)); }
public virtual void Init(bool isWeb = true) { //Sesson Factory NHSessionManager.Init(null, NHSessionManager.GetSessionKey(isWebSession: isWeb)); }
public void CloseSession() { NHSessionManager.CloseStorage(_institutionCode); }