示例#1
0
 public static Rank GetRank(int userId, int routeId)
 {
     using (ISession iSession = NHSessionManager.GetSession())
     {
         return(GetRank(userId, routeId, iSession));
     }
 }
示例#2
0
    //--------------------------------------------------------------------------------
    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]);
        }
    }
示例#3
0
        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);
                }
            }
        }
示例#5
0
 //--------------------------------------------------------------------------------
 public static EventSubscriptor[] GetSubscriptors()
 {
     using (ISession iSession = NHSessionManager.GetSession())
     {
         var criteria = iSession.CreateCriteria <EventSubscriptor>();
         return(criteria.List <EventSubscriptor>().ToArray());
     }
 }
示例#6
0
 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>());
     }
 }
示例#7
0
 //--------------------------------------------------------------------------------
 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>());
     }
 }
示例#8
0
    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());
        }
    }
示例#9
0
    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>());
        }
    }
示例#10
0
    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);
        }
    }
示例#11
0
 public static void SaveAppointment(Appointment appointment)
 {
     using (ISession iSession = NHSessionManager.GetSession())
     {
         using (ITransaction transaction = iSession.BeginTransaction())
         {
             iSession.SaveOrUpdate(appointment);
             iSession.Flush();
             transaction.Commit();
         }
     }
 }
示例#12
0
 //--------------------------------------------------------------------------------
 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();
         }
     }
 }
示例#13
0
 //--------------------------------------------------------------------------------
 static DBHelper()
 {
     try
     {
         using (ISession iSession = NHSessionManager.GetSession())
         {
             LoadRoutes(iSession);
             LoadUsers(iSession);
         }
     }
     catch (Exception ex)
     {
         Log.Add(ex.ToString());
     }
 }
示例#14
0
        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);
        }
示例#15
0
 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();
         }
     }
 }
示例#16
0
 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();
         }
     }
 }
示例#17
0
    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);
        }
    }
示例#18
0
 //--------------------------------------------------------------------------------
 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();
 }
示例#19
0
 //--------------------------------------------------------------------------------
 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();
     }
 }
示例#20
0
    //--------------------------------------------------------------------------------
    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);
        }
    }
示例#21
0
 //--------------------------------------------------------------------------------
 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();
             }
         }
     }
 }
示例#22
0
 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" });
 }
示例#24
0
 /// <summary>
 /// Whether or not the DB we're using is MySql
 /// </summary>
 /// <returns></returns>
 public bool IsMySql()
 {
     return(NHSessionManager.IsMySqlDatabase());
 }
示例#25
0
 /// <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));
 }
示例#26
0
 public virtual void Terminate(bool isWeb = true)
 {
     NHSessionManager.CloseStorage(isWebSession: isWeb);
 }
示例#27
0
 public string GetConnectionString()
 {
     return(NHSessionManager.GetConnectionString());
 }
示例#28
0
 /// <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));
 }
示例#29
0
 public virtual void Init(bool isWeb = true)
 {
     //Sesson Factory
     NHSessionManager.Init(null, NHSessionManager.GetSessionKey(isWebSession: isWeb));
 }
示例#30
0
 public void CloseSession()
 {
     NHSessionManager.CloseStorage(_institutionCode);
 }