Esempio n. 1
0
        public static DbResult DropAndRecreate()
        {
            DbResult apiResult = new DbResult();

            try
            {
                SetConnectionStringInDatabaseHandler();
                IConfigurationSource source = System.Configuration.ConfigurationManager.GetSection(SectionName) as IConfigurationSource;
                ActiveRecordStarter.Initialize(source, TypesToKeepTrackOf.ToArray());
                ActiveRecordStarter.DropSchema();
                ActiveRecordStarter.UpdateSchema();
                apiResult.SetSuccessAsStatusInResponseFields();
            }
            catch (Exception ex)
            {
                if (ex.Message.ToUpper().Contains("MORE THAN ONCE"))
                {
                    apiResult.StatusCode = DbGlobals.SUCCESS_STATUS_CODE;
                    apiResult.StatusDesc = "SUSPECTED DOUBLE INITIALIZE: " + ex.Message;
                }
                else
                {
                    apiResult.SetFailuresAsStatusInResponseFields(ExceptionLeadString + ex.Message);
                }
            }

            return(apiResult);
        }
Esempio n. 2
0
        private static void InitDatabase()
        {
            var config          = ActiveRecordSectionHandler.Instance;
            var assemblyLibrary = Assembly.Load("FileProccesor");

            ActiveRecordStarter.Initialize(assemblyLibrary, config);

            switch (ConfigurationManager.AppSettings["Enviroment"])
            {
            case "Development":
                ActiveRecordStarter.DropSchema();
                ActiveRecordStarter.CreateSchema();
                break;

            case "Testing":
                ActiveRecordStarter.UpdateSchema();
                break;

            default:
                break;
            }


            var callbackContext = new CallbackContext("Conectado a la Base de Datos", ActiveRecordStarter.ConfigurationSource.ToString());

            var notification = new Notification(_application.Name, _notificationType.Name, DateTime.Now.Ticks.ToString(), "InitDatabase", "OK");

            _growl.Notify(notification, callbackContext);
        }
Esempio n. 3
0
        public ActionResult Login(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (WebSecurity.UserExists(model.Email) &&
                    WebSecurity.GetPasswordFailuresSinceLastSuccess(model.Email) > 4 &&
                    WebSecurity.GetLastPasswordFailureDate(model.Email).AddSeconds(60) > DateTime.UtcNow)
                {
                    return(RedirectToAction("AccountLockedOut"));
                }

                // Attempt to login to the Security object using provided creds
                if (WebSecurity.Login(model.Email, model.Password, model.RememberMe))
                {
                    try
                    {
                        //ensure the Account record
                        var defaultAccount = Account.FindBy(WebSecurity.GetUserId(model.Email));
                        if (defaultAccount == null)
                        {
                            defaultAccount        = new Account();
                            defaultAccount.UserId = WebSecurity.GetUserId(model.Email);
                            defaultAccount.Save();
                        }
                    }
                    catch
                    {
                        ActiveRecordStarter.UpdateSchema();

                        //ensure the Account record
                        var defaultAccount = Account.FindBy(WebSecurity.GetUserId(model.Email));
                        if (defaultAccount == null)
                        {
                            defaultAccount        = new Account();
                            defaultAccount.UserId = WebSecurity.GetUserId(model.Email);
                            defaultAccount.Save();
                        }
                    }


                    if (returnUrl.IsEmpty())
                    {
                        return(RedirectToAction("Index", "Work"));
                    }
                    else
                    {
                        return(Redirect(returnUrl));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 4
0
        //Creates the Db if it doesnt exist, updates the db schema and initializes the db connection
        public static DbResult CreateDbIfNotExistsAndUpdateSchema(string DbConnectionString = null)
        {
            DbResult apiResult = new DbResult();

            try
            {
                AutoFindTypesToKeepTrackOf();

                //create the db
                apiResult = ExecuteCreateDatabaseSQLIfNotExists(DbConnectionString);

                //we failed to create the db
                if (apiResult.StatusCode != DbGlobals.SUCCESS_STATUS_CODE)
                {
                    return(apiResult);
                }

                //try to create stored procedures for fetching
                //parameters for any other stored proc
                //this makes calls to any AutoParams method much faster
                //if its successfull otherwise we default to executing raw sql
                CreateStoredProcedures();

                IConfigurationSource source = GetConfigurationSource(DbConnectionString);

                //initialize active record
                ActiveRecordStarter.Initialize(source, TypesToKeepTrackOf.ToArray());
                ActiveRecordStarter.UpdateSchema();

                //we are all good
                _is_init_successfull = true;
                apiResult.SetSuccessAsStatusInResponseFields();
            }
            catch (Exception ex)
            {
                if (ex.Message.ToUpper().Contains("MORE THAN ONCE"))
                {
                    _is_init_successfull = true;
                    apiResult.StatusCode = DbGlobals.SUCCESS_STATUS_CODE;
                    apiResult.StatusDesc = "SUSPECTED DOUBLE INITIALIZE: " + ex.Message;
                }
                else
                {
                    apiResult.SetFailuresAsStatusInResponseFields(EXCEPTION_LEAD_STRING + ex.Message);
                }
            }

            return(apiResult);
        }
Esempio n. 5
0
        private static void InitDatabase()
        {
            var config          = ActiveRecordSectionHandler.Instance;
            var assemblyLibrary = Assembly.Load("FileProccesor");

            ActiveRecordStarter.Initialize(assemblyLibrary, config);

            switch (ConfigurationManager.AppSettings["Enviroment"])
            {
            case "Development":
                ActiveRecordStarter.DropSchema();
                ActiveRecordStarter.CreateSchema();
                break;

            case "Testing":
                ActiveRecordStarter.UpdateSchema();
                break;

            default:
                break;
            }
        }
Esempio n. 6
0
        internal ApiResult DropAndRecreate()
        {
            ApiResult apiResult = new ApiResult();

            try
            {
                IConfigurationSource source             = System.Configuration.ConfigurationManager.GetSection("activerecord") as IConfigurationSource;
                List <Type>          typesToKeepTrackOf = GetTypesToKeepTrackOf();
                ActiveRecordStarter.Initialize(source, typesToKeepTrackOf.ToArray());
                ActiveRecordStarter.DropSchema();
                ActiveRecordStarter.UpdateSchema();
                Seed();
                apiResult.SetSuccessAsStatusInResponseFields();
            }
            catch (Exception ex)
            {
                HandleError("OnInitialize", "EXCEPTION", ex.Message);
                apiResult.SetFailuresAsStatusInResponseFields("FAILED TO INTIALIZE API");
            }

            return(apiResult);
        }
Esempio n. 7
0
 public static void Update()
 {
     ActiveRecordStarter.UpdateSchema();
 }