示例#1
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         LogManager.WriteLog("Unlock:Loading Unlock UI", LogManager.enumLogLevel.Debug);
         oApplicationLockObject = new ApplicationLockObject();
         ApplicationLock         oType     = oApplicationLockObject.GetLockTypes();
         List <ApplicationTypes> AppTypes  = oType.ApplicationType;
         List <LockTypes>        LockTypes = oType.LockType;
         AppTypes.Insert(0, new ApplicationTypes()
         {
             Lock_Application = "ALL"
         });
         LockTypes.Insert(0, new LockTypes()
         {
             Lock_Type = "ALL"
         });
         cmbLockApp.ItemsSource        = AppTypes;
         cmbLockApp.DisplayMemberPath  = "Lock_Application";
         cmbLockType.ItemsSource       = LockTypes;
         cmbLockType.DisplayMemberPath = "Lock_Type";
         cmbLockApp.SelectedIndex      = 0;
         cmbLockType.SelectedIndex     = 0;
         UnlockDetails();
     }
     catch (Exception Ex)
     {
         ExceptionManager.Publish(Ex);
     }
 }
        /// <summary>
        /// Initialize the application database.
        /// </summary>
        public static void InitializeDatabase()
        {
            using (var databaseUpdateLock = new ApplicationLock(LOCK_NAME, ApplicationSettings.ApplicationConnectionString))
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                // Try to obtain the lock on the database. If not obtained during the specified interval, retry.
                while (!databaseUpdateLock.TryGetLock(ApplicationSettings.DatabaseInitializationRetryInterval))
                {
                    // After the specified timeout, if the lock is still not obtained, throw an exception to stop the application starting
                    if (stopwatch.Elapsed.TotalMilliseconds >= ApplicationSettings.DatabaseInitializationTimeout)
                    {
                        throw new DatabaseUpdateException("Timeout trying to get the lock on the application database.");
                    }
                }

                stopwatch.Stop();

                // If the the lock is obtained, initialize the database
                try
                {
                    Database.SetInitializer(new MigrateDatabaseToLatestVersion <AWContext, Configuration>());

                    using (var context = new AWContext())
                    {
                        context.Database.Initialize(force: true);
                    }
                }
                finally
                {
                    databaseUpdateLock.ReleaseLock();
                }
            }
        }
示例#3
0
 /// <summary>
 /// 赋值应用程序锁数据操作
 /// </summary>
 /// <param name="factory"></param>
 /// <param name="reader"></param>
 /// <param name="prefix"></param>
 public static void SetApplicationLockStoreSelectFields(ApplicationLock alock, DbDataReader reader, string prefix)
 {
     alock.ID            = (Guid)reader[string.Format("{0}id", prefix)];
     alock.Name          = reader[string.Format("{0}name", prefix)].ToString();
     alock.Type          = reader[string.Format("{0}type", prefix)].ToString();
     alock.Configuration = reader[string.Format("{0}configuration", prefix)].ToString();
     alock.CreateTime    = (DateTime)reader[string.Format("{0}createtime", prefix)];
     alock.ModifyTime    = (DateTime)reader[string.Format("{0}modifytime", prefix)];
 }
        //=====================================================================================================================================================================
        private bool UseLogin()
        {
            ApplicationLock AppLock = new ApplicationLock();

            if (AppLock.UnLock())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        public ApplicationLock GetLockTypes()
        {
            ApplicationLock rsltApplicationLock = null;

            try
            {
                var result = _ApplicationLockDataAccess.GetLockTypes();
                var lstApplicationTypes = result.GetResult <ApplicationTypes>().ToList <ApplicationTypes>();
                var lstLockTypes        = result.GetResult <LockTypes>().ToList <LockTypes>();
                rsltApplicationLock = new ApplicationLock();
                rsltApplicationLock.ApplicationType = lstApplicationTypes;
                rsltApplicationLock.LockType        = lstLockTypes;
            }
            catch (Exception Ex)
            {
                ExceptionManager.Publish(Ex);
            }

            return(rsltApplicationLock);
        }
示例#6
0
        public ApplicationLock QueryByNameSync(string name)
        {
            ApplicationLock aLock = null;

            DBTransactionHelper.SqlTransactionWork(DBTypes.SqlServer, true, false, _distributeConnectionFactory.CreateReadForDistributeCoordinator(), (conn, transaction) =>
            {
                SqlTransaction sqlTran = null;
                if (transaction != null)
                {
                    sqlTran = (SqlTransaction)transaction;
                }

                using (SqlCommand command = new SqlCommand()
                {
                    Connection = (SqlConnection)conn,
                    CommandType = CommandType.Text,
                    CommandText = string.Format(@"SELECT {0} FROM [ApplicationLock] WHERE name=@name;", StoreHelper.GetApplicationLockStoreSelectFields(string.Empty)),
                    Transaction = sqlTran
                })
                {
                    var parameter = new SqlParameter("@name", SqlDbType.VarChar, 150)
                    {
                        Value = name
                    };
                    command.Parameters.Add(parameter);
                    command.Prepare();
                    SqlDataReader reader = null;

                    using (reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            aLock = new ApplicationLock();
                            StoreHelper.SetApplicationLockStoreSelectFields(aLock, reader, string.Empty);
                        }
                        reader.Close();
                    }
                }
            });
            return(aLock);
        }