Exemplo n.º 1
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (String.IsNullOrWhiteSpace(TrnKey))
        {
            SetErrorMessage("Invalid TrnKey");
            return;
        }

        if (String.IsNullOrWhiteSpace(ModuleName))
        {
            SetErrorMessage("Invalid ModuleName");
            return;
        }

        if (String.IsNullOrWhiteSpace(LanguagePair))
        {
            SetErrorMessage("Invalid LanguagePair");
            return;
        }

        using (var session = Hb8Factory.CreateSession())
        {
            var trn = (from n in session.Query <CD_Translation>()
                       where n.DateDeleted == null &&
                       n.TrnKey.ToLower() == TrnKey.ToLower() &&
                       n.LanguagePair.ToLower() == LanguagePair.ToLower() &&
                       n.ModuleName.ToLower() == ModuleName.ToLower()
                       select n).Single();

            tbDefaultText.Text    = trn.DefaultText;
            tbTranslatedText.Text = trn.TranslatedText;
        }
    }
Exemplo n.º 2
0
        public Guid?GetTokenOwnerID(Guid token)
        {
            var locker = GetLocker(token);

            lock (locker)
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var entity = (from n in session.Query <UM_LoginToken>()
                                      where n.DateDeleted == null &&
                                      n.LoginToken == token
                                      select n).FirstOrDefault();

                        var user = (Guid?)null;

                        if (!CheckExpiration(entity, session))
                        {
                            if (entity != null)
                            {
                                user = entity.UserID;
                            }
                        }

                        transaction.Commit();

                        return(user);
                    }
                }
            }
        }
Exemplo n.º 3
0
    protected void lnkDeleteLang_Click(object sender, EventArgs e)
    {
        var control = sender as LinkButton;

        if (control == null)
        {
            return;
        }

        Guid langID;

        if (!Guid.TryParse(control.CommandArgument, out langID))
        {
            return;
        }

        using (var session = Hb8Factory.CreateSession())
        {
            var language = (from n in session.Query <CD_Language>()
                            where n.ID == langID
                            select n).FirstOrDefault();

            if (language == null)
            {
                return;
            }

            language.DateDeleted = DateTime.Now;

            session.SubmitChanges(language);
        }
    }
Exemplo n.º 4
0
        public void ReleaseUserToken(Guid token)
        {
            var locker = GetLocker(token);

            lock (locker)
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var entity = (from n in session.Query <UM_LoginToken>()
                                      where n.DateDeleted == null &&
                                      n.LoginToken == token
                                      select n).FirstOrDefault();

                        if (entity != null)
                        {
                            entity.DateDeleted  = DateTime.Now;
                            entity.DeleteReason = 1;

                            session.Update(entity);

                            RemoveLocker(token);
                        }

                        transaction.Commit();
                    }
                }
            }
        }
Exemplo n.º 5
0
        public bool ValidateToken(Guid token)
        {
            var locker = GetLocker(token);

            lock (locker)
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var entity = (from n in session.Query <UM_LoginToken>()
                                      where n.DateDeleted == null &&
                                      n.LoginToken == token
                                      select n).FirstOrDefault();

                        var result = !CheckExpiration(entity, session);
                        if (result)
                        {
                            result = (entity != null);
                        }

                        transaction.Commit();

                        return(result);
                    }
                }
            }
        }
Exemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Guid trnID;
            if (Guid.TryParse(Request[trnIDKey], out trnID))
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    var trn = session.Query <CD_Translation>().First(n => n.ID == trnID);

                    TrnKey       = trn.TrnKey;
                    ModuleName   = trn.ModuleName;
                    LanguagePair = trn.LanguagePair;
                }
            }
            else
            {
                TrnKey       = Request[trnKeyKey];
                ModuleName   = Request[moduleNameKey];
                LanguagePair = Request[languagePairKey];
            }
        }

        tbKey.Text          = TrnKey;
        tbModuleName.Text   = ModuleName;
        tbLanguagePair.Text = LanguagePair;
    }
Exemplo n.º 7
0
        public IDictionary <Guid, Guid?> GetTokensOwners()
        {
            lock (lockersDict)
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var entities = (from n in session.Query <UM_LoginToken>()
                                        where n.DateDeleted == null
                                        select n).ToList();

                        var dict = new Dictionary <Guid, Guid?>(entities.Count);

                        foreach (var entity in entities)
                        {
                            if (!CheckExpiration(entity, session))
                            {
                                dict.Add(entity.ID, entity.UserID);
                            }
                        }

                        transaction.Commit();

                        return(dict);
                    }
                }
            }
        }
Exemplo n.º 8
0
 private static IList <CD_Language> LoadLanguages()
 {
     using (var session = Hb8Factory.CreateSession())
     {
         var languagesList = session.Query <CD_Language>().Where(n => n.DateDeleted == null).ToList();
         return(languagesList);
     }
 }
Exemplo n.º 9
0
    protected void btSave_Click(object sender, EventArgs e)
    {
        lblMessage.Text = String.Empty;

        if (String.IsNullOrWhiteSpace(tbDisplayName.Text))
        {
            lblMessage.Text = "Please enter display name";

            mpeAddEdit.Show();
            return;
        }

        if (String.IsNullOrWhiteSpace(tbPair.Text))
        {
            lblMessage.Text = "Please enter pair";

            mpeAddEdit.Show();
            return;
        }

        using (var session = Hb8Factory.CreateSession())
        {
            CD_Language language;

            if (LangID == null)
            {
                language             = new CD_Language();
                language.ID          = Guid.NewGuid();
                language.DateCreated = DateTime.Now;
            }
            else
            {
                language = (from n in session.Query <CD_Language>()
                            where n.ID == LangID
                            select n).FirstOrDefault();

                if (language == null)
                {
                    return;
                }
            }

            language.DisplayName = tbDisplayName.Text;
            language.EngName     = tbEngName.Text;
            language.NativeName  = tbNativeName.Text;
            language.Pair        = tbPair.Text;

            session.SubmitChanges(language);

            mpeAddEdit.Hide();
        }

        FillLanguagesGrid();
    }
Exemplo n.º 10
0
    protected void FillLanguagesGrid()
    {
        using (var session = Hb8Factory.CreateSession())
        {
            var languages = (from n in session.Query <CD_Language>()
                             where n.DateDeleted == null
                             select n).ToList();

            gvLanguages.DataSource = languages;
            gvLanguages.DataBind();
        }
    }
Exemplo n.º 11
0
    protected void btSave_Click(object sender, EventArgs e)
    {
        using (var session = Hb8Factory.CreateSession())
        {
            var dbTrn = (from n in session.Query <CD_Translation>()
                         where n.DateDeleted == null &&
                         n.TrnKey.ToLower() == TrnKey.ToLower() &&
                         n.LanguagePair.ToLower() == LanguagePair.ToLower() &&
                         n.ModuleName.ToLower() == ModuleName.ToLower()
                         select n).Single();

            dbTrn.DefaultText    = tbDefaultText.Text;
            dbTrn.TranslatedText = tbTranslatedText.Text;

            session.SubmitChanges(dbTrn);

            SetSuccessMessage("Save successfully");
        }
    }
Exemplo n.º 12
0
        protected void FillAttributesTree()
        {
            using (var session = Hb8Factory.CreateSession())
            {
                var attributesSchemas = (from n in session.Query<UM_AttributeSchema>()
                                         where n.DateDeleted == null
                                         select n).ToList();

                var converter = new AttributeSchemaEntityModelConverter(session);

                var model = new AttributeSchemasModel
                {
                    List = attributesSchemas.Select(n => converter.Convert(n)).ToList()
                };

                attributesSchemasControl.Model = model;
                attributesSchemasControl.DataBind();
            }
        }
Exemplo n.º 13
0
    protected void lnkEditLang_Click(object sender, EventArgs e)
    {
        lblMessage.Text = String.Empty;

        var control = sender as LinkButton;

        if (control == null)
        {
            return;
        }

        Guid langID;

        if (!Guid.TryParse(control.CommandArgument, out langID))
        {
            return;
        }

        using (var session = Hb8Factory.CreateSession())
        {
            var language = (from n in session.Query <CD_Language>()
                            where n.ID == langID
                            select n).FirstOrDefault();

            if (language == null)
            {
                return;
            }

            LangID = langID;

            tbDisplayName.Text = language.DisplayName;
            tbEngName.Text     = language.EngName;
            tbNativeName.Text  = language.NativeName;
            tbPair.Text        = language.Pair;

            ddlSystemLanguages.SelectedValue = language.Pair;

            mpeAddEdit.Show();
        }
    }
Exemplo n.º 14
0
        public static bool Login(String loginName, String password)
        {
            if (String.IsNullOrWhiteSpace(password) || String.IsNullOrWhiteSpace(loginName))
            {
                return(false);
            }

            loginName = loginName.Trim().ToLower();


            using (var session = Hb8Factory.CreateSession())
            {
                CurrentUser = session.Query <UM_User>().FirstOrDefault(n => n.LoginName == loginName &&
                                                                       n.Password == password &&
                                                                       n.IsActive &&
                                                                       n.IsSuperAdmin &&
                                                                       n.DateDeleted == null);

                return(CurrentUser != null);
            }
        }
Exemplo n.º 15
0
        private static IDictionary <String, String> LoadTranslations()
        {
            using (var session = Hb8Factory.CreateSession())
            {
                var translationsList = session.Query <CD_Translation>().ToList();

                var trnList = (from n in translationsList
                               select new
                {
                    n.TrnKey,
                    n.ModuleName,
                    n.LanguagePair,
                    n.TranslatedText,
                    n.DateDeleted,
                }).ToList();

                var keyedTranList = (from n in trnList.AsParallel()
                                     let key = GenCacheItemKey(n.ModuleName, n.LanguagePair, n.TrnKey)
                                               select new
                {
                    Key = key,
                    n.TrnKey,
                    n.ModuleName,
                    n.LanguagePair,
                    n.TranslatedText,
                    n.DateDeleted,
                }).ToList();

                var translationsLp = keyedTranList.ToLookup(n => n.Key);

                var translationsDict = (from grp in translationsLp
                                        let trn = grp.First(m => m.DateDeleted == null)
                                                  let pair = new KeyValuePair <String, String>(grp.Key, trn.TranslatedText)
                                                             select pair).ToDictionary();

                return(translationsDict);
            }
        }
Exemplo n.º 16
0
        public Guid CreateUserToken(Guid userID)
        {
            lock (lockersDict)
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var entity = (from n in session.Query <UM_LoginToken>()
                                      where n.UserID == userID &&
                                      n.DateDeleted == null
                                      orderby n.DateCreated descending
                                      select n).FirstOrDefault();

                        if (entity == null || CheckExpiration(entity, session))
                        {
                            entity = new UM_LoginToken
                            {
                                ID          = Guid.NewGuid(),
                                DateCreated = DateTime.Now,
                                UserID      = userID,
                                LoginToken  = Guid.NewGuid(),
                            };

                            session.Save(entity);

                            SetExpiration(entity, session);
                            GetLocker(entity.LoginToken);
                        }

                        transaction.Commit();

                        return(entity.LoginToken);
                    }
                }
            }
        }
Exemplo n.º 17
0
        private static void AddOrUpdateInDb(String moduleName, String languagePair, String trnKey, String defaultText, String translatedText)
        {
            try
            {
                using (var session = Hb8Factory.CreateSession())
                {
                    var dbTrn = (from n in session.Query <CD_Translation>()
                                 where n.ModuleName == moduleName &&
                                 n.TrnKey == trnKey &&
                                 n.LanguagePair == languagePair       //&&
                                                                      //n.Hashcode == db.GenTrnHashCode(moduleName, trnKey, languagePair)
                                 select n).FirstOrDefault();

                    if (dbTrn == null)
                    {
                        dbTrn = new CD_Translation
                        {
                            ID          = Guid.NewGuid(),
                            DateCreated = DateTime.Now
                        };
                    }

                    dbTrn.ModuleName     = moduleName;
                    dbTrn.TrnKey         = trnKey;
                    dbTrn.LanguagePair   = languagePair;
                    dbTrn.DefaultText    = defaultText;
                    dbTrn.TranslatedText = translatedText;

                    session.SubmitChanges(dbTrn);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }