Пример #1
0
 internal TaskThread(string institutionCode)
 {
     _tasks          = new Dictionary <string, string>();
     Seconds         = ConfigurationHelper.AppSettingsItem("TaskThreadIntervalInSeconds", 600);
     InstitutionCode = institutionCode;
     logger          = Utilities.Logger;
     logger.SetNLogLogger("TaskThread-" + institutionCode);
 }
Пример #2
0
 public void Apply(IPropertyInstance instance)
 {
     if (!ConfigurationHelper.AppSettingsItem <bool>("SingleTenant"))
     {
         Entities.BaseEntity e;
         if (instance.Name == nameof(e.InstitutionCode) && instance.Property.PropertyType == typeof(string))
         {
             instance.Index("ind_InstitutionCode");
         }
     }
 }
Пример #3
0
 public AppFilterDefinition()
 {
     if (!ConfigurationHelper.AppSettingsItem <bool>("SingleTenant"))
     {
         //Where IsDeleted != true AND InstitutionCode = :instCode
         WithName(Utilities.InstitutionFilterName)
         .WithCondition($"{Utilities.SoftDeletePropertyName} != :{Utilities.SoftDeleteParamName} AND {Utilities.InstitutionCodePropertyName} = :{Utilities.InstitutionCodeQueryParamName}")
         .AddParameter(Utilities.InstitutionCodeQueryParamName, NHibernateUtil.String)
         .AddParameter(Utilities.SoftDeleteParamName, NHibernateUtil.Boolean);
     }
 }
Пример #4
0
        public void Apply(IClassInstance instance)
        {
            //Table name rule
            var tableName = instance.EntityType.Name.ToPlural();

            if (ConfigurationHelper.AppSettingsItem <bool>("UseLowercaseTableNames"))
            {
                tableName = tableName.ToLowerInvariant();
            }
            instance.Table(tableName);
            //To filter queries based on what I've defined in the Tenant filter definition
            instance.ApplyFilter <AppFilterDefinition>();
        }
Пример #5
0
        /// <summary>
        /// Audit Trail at every login or logout attempt. Do not set the second parameter
        /// if it was possible at all to retrieve the user. In that case, just bundle the user in session.
        /// We'll pick it up from there.
        /// </summary>
        /// <param name="action">The action.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="remarks">Remarks.</param>
        public virtual void AuditLogin(EventType action, string userName = null, string remarks = null, string institutionCode = null)
        {
            //NOTE: A' + B' = (AB)' in boolean algebra
            if (!(ConfigurationHelper.AppSettingsItem <bool>("EnableAuditTrail") && ConfigurationHelper.AppSettingsItem <bool>("TrailLogins")))
            {
                return;
            }
            if (action != EventType.Login && action != EventType.Logout && action != EventType.FailedLogin)
            {
                return;
            }

            AuditLog auditTrail = new AuditLog
            {
                EventType       = action,
                EventDate       = DateTime.Now.GetLocalTime(),
                Remark          = remarks,
                InstitutionCode = institutionCode,
            };

            try
            {
                if (HttpContext.Current != null)
                {
                    var webHelper = new WebHelper();
                    if (!string.IsNullOrWhiteSpace(userName)) // usuall when the user fails to type in the right username (action == AuditAction.FAILEDLOGIN)
                    {
                        auditTrail.UserName = userName;
                    }
                    else
                    {
                        var user = webHelper.GetCurrentlyLoggedInUser();
                        if (user != null)
                        {
                            auditTrail.UserName = user.UserName;
                            auditTrail.UserId   = user.Id;
                        }
                    }
                    auditTrail.ClientIpAddress = webHelper.GetCurrentIpAddress();
                    auditTrail.ClientName      = HttpContext.Current.Request.UserHostName;
                }
            }
            catch
            {
                auditTrail.ClientName = "[Could not resolve Client Name]";
            }
        }
Пример #6
0
 public AutomappingConfiguration()
 {
     isSingleTenant  = ConfigurationHelper.AppSettingsItem <bool>("SingleTenant");
     searchableTypes = null;
 }
Пример #7
0
        /// <summary>
        /// NB: If your tables were created on the fly, then you'll have to pass in the entity name to get the right table.
        /// And, If you must pass in 'autoPersistenceModel', you should only pass in a dynamically created mapping file.
        /// <para>NB: The returned session only Flushes when you commit. You can always change to .FlushMode to your taste.</para>
        /// </summary>
        /// <param name="institutionCode"></param>
        /// <param name="dbConnection"></param>
        /// <param name="doFreshSession"></param>
        /// <returns></returns>
        public static ISession GetSession(string institutionCode = "", DbConnection dbConnection = null, bool doFreshSession = false)
        {
            bool            isWebSession = IsWeb();
            string          sessionKey   = GetSessionKey(institutionCode, isWebSession);
            ISessionStorage storage      = null;

            if (!doFreshSession)
            {
                SessionStorages.TryGetValue(sessionKey, out storage);
            }
            if (storage == null)
            {
                if (isWebSession)
                {
                    storage = new WebSessionStorage {
                        InstitutionCode = institutionCode
                    };
                }
                else
                {
                    storage = new NonWebSessionStorage();
                }
            }

            //Get the current session from the storage object
            ISession session = doFreshSession ? null : storage.Session;

            //Start a new session if no current session exists
            if (session == null || !session.IsOpen)
            {
                ISessionFactory fac;
                string          instCode = sessionKey.Split('_')[0]; // will be 'Utilities.INST_DEFAULT_CODE' if 'institutionCode' is null or empty
                if (SessionFactories.TryGetValue(instCode, out fac) && fac != null)
                {
                    //Do what now? Nothing.
                }
                else
                {
                    fac = BuildFactory(instCode, sessionKey);
                }

                //Apply the interceptor if any was registered and open the session
                if (dbConnection == null)
                {
                    session = fac.OpenSession();
                }
                else
                {
                    //session = fac.OpenSession(dbConnection);
                    session = fac.WithOptions().Connection(dbConnection).OpenSession();
                }
            }

            if (session != null)
            {
                if (!ConfigurationHelper.AppSettingsItem <bool>("SingleTenant"))
                {
                    session.EnableFilter(Utilities.InstitutionFilterName)
                    .SetParameter(Utilities.InstitutionCodeQueryParamName, institutionCode)
                    .SetParameter(Utilities.SoftDeleteParamName, true);
                }
                session.FlushMode = FlushMode.Commit;
                //Begin a transaction
                if (!session.IsConnected || session.Transaction == null || !session.Transaction.IsActive || session.Transaction.WasCommitted || session.Transaction.WasRolledBack) //if (storage is WebSessionStorage)
                {
                    int retryCount = 3;
                    while (retryCount > 0)
                    {
                        try
                        {
                            session.BeginTransaction();
                        }
                        catch (Exception)
                        {
                            if (retryCount > 0)
                            {
                                Thread.Sleep(1000);
                                retryCount--;
                                continue;
                            }
                            else
                            {
                                throw;
                            }
                        }

                        break;
                    }
                }
            }
            if (!doFreshSession)
            {
                //Update the storage with the new session
                storage.Session             = session;
                SessionStorages[sessionKey] = storage;
            }
            //if (isWebSession)
            //{
            //    SessionStorages[sessionKey] = (WebSessionStorage)storage;
            //}

            return(session);
        }