コード例 #1
0
ファイル: Global.asax.cs プロジェクト: kovavka/HSEvents
        protected void Application_Start(object sender, EventArgs e)
        {
            var container = new UnityContainer();

            RegisterUnityComponents(container);

            GlobalConfiguration.Configure(config =>
            {
                config.MapHttpAttributeRoutes();

                config.Routes.MapHttpRoute(
                    name: "AdminApi",
                    routeTemplate: "api/admin/{controller}/{action}"
                    );

                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "api/{controller}/{action}"
                    );

                config.Routes.MapHttpRoute(
                    name: "Index",
                    routeTemplate: "{controller}/{action}",
                    defaults: new { controller = "Home", action = "Index" }
                    );

                var jsonFormatter = config.Formatters.JsonFormatter;
                jsonFormatter.SerializerSettings.ContractResolver = new NHibernateContractResolver();
                jsonFormatter.UseDataContractJsonSerializer       = false;
            });

            NHibernateHelper.Configure(AppSettings.DefaultConnection);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            NHibernateHelper.Configure("Data Source=HALA\\SQLEXPRESS;Initial Catalog=HSEvents;Integrated Security=True;");

            using (var session = NHibernateHelper.OpenSession())
            {
                new AttendeesCreator().Run(session);
            }



            using (var repo = new NHGetAllRepository <EventExecution>())
            {
                repo.Delete(x => x.Event == null);
            }
        }
コード例 #3
0
        private void CheckConnectionMethod(object parameter)
        {
            var passwordBox = parameter as PasswordBox;

            if (passwordBox == null)
            {
                return;
            }

            var configureResults = NHibernateHelper.Configure(DbDataSource, DbInitialCatalog, DbUserId, passwordBox.Password, IntergatedSecurity);

            if (!configureResults)
            {
                ShowInfoMessage("Ошибка подключения к базе данных.\r\nПодробные сведения об ошибке:\r\n" + NHibernateHelper.LastError);
            }
            else
            {
                ShowInfoMessage("Успешное подключение к базе данных");
            }
        }
コード例 #4
0
        private void SaveMethod(object parameter)
        {
            var passwordBox = parameter as PasswordBox;

            if (passwordBox == null)
            {
                return;
            }

            ApplicationState.SetValue("DbDataSource", DbDataSource);
            ApplicationState.SetValue("DbInitialCatalog", DbInitialCatalog);
            if (IntergatedSecurity)
            {
                ApplicationState.SetValue("DbUserId", String.Empty);
                ApplicationState.SetValue("DbPassword", String.Empty);
            }
            else
            {
                ApplicationState.SetValue("DbUserId", DbUserId);

                var password = passwordBox.Password;
                ApplicationState.SetValue("DbPassword", password);
            }

            var configureResults = NHibernateHelper.Configure(DbDataSource, DbInitialCatalog, DbUserId, passwordBox.Password, IntergatedSecurity);

            if (!configureResults)
            {
                ShowInfoMessage("Ошибка подключения к базе данных.\r\nПодробные сведения об ошибке:\r\n" + NHibernateHelper.LastError);
            }
            else
            {
                ApplicationState.SaveConnectionSettings();
                CancelCommand.Execute(null);
            }
        }
コード例 #5
0
ファイル: LoginViewModel.cs プロジェクト: kyleabrock/Stock
        private void LoginMethod(object parameter)
        {
            InProgress = true;

            var dbDataSource       = ApplicationState.GetValue <string>("DbDataSource");
            var dbInitialCatalog   = ApplicationState.GetValue <string>("DbInitialCatalog");
            var dbUserId           = ApplicationState.GetValue <string>("DbUserId");
            var dbPassword         = ApplicationState.GetValue <string>("DbPassword");
            var integratedSecurity = ApplicationState.GetValue <bool>("IntegratedSecurity");

            NHibernateHelper.Configure(dbDataSource, dbInitialCatalog, dbUserId, dbPassword, integratedSecurity);

            var passwordBox = parameter as PasswordBox;

            if (passwordBox == null)
            {
                return;
            }

            if (!CheckConnection())
            {
                ErrorMessage = "Ошибка подключения к БД.";
                ShowError    = true;
                InProgress   = false;

                return;
            }

            var accountRepository = new AccountRepository();
            var account           = accountRepository.GetByLogin(LoginText);

            if (!account.IsNew)
            {
                byte[] hash    = GenerateSaltedHash(GetBytes(passwordBox.Password), GetBytes(account.Salt));
                string hashStr = Convert.ToBase64String(hash);

                if (string.Equals(hashStr, account.HashedPassword))
                {
                    var userAccRepository = new Repository <UserAcc>();
                    User = userAccRepository.GetById(account.Id);
                    ApplicationState.SetValue("User", User);
                    InProgress = false;

                    if (RememberCreditentials)
                    {
                        ApplicationState.SetValue("RememberCreditentials", RememberCreditentials);
                        ApplicationState.SetValue("LdapAuth", LdapAuth);
                        ApplicationState.SetValue("UserId", LoginText);
                        ApplicationState.SetValue("UserPassword", passwordBox.Password);
                    }
                    else
                    {
                        ApplicationState.SetValue("RememberCreditentials", false);
                        ApplicationState.SetValue("LdapAuth", false);
                        ApplicationState.SetValue("UserId", String.Empty);
                        ApplicationState.SetValue("UserPassword", String.Empty);
                    }
                    ApplicationState.SaveUserCreditentials();

                    return;
                }
            }

            ErrorMessage = "Ошибка. Неверный логин/пароль.";
            ShowError    = true;
            InProgress   = false;
        }