示例#1
0
 public Lock(System.Threading.ReaderWriterLock rwl, LockType lt)
 {
     rwlock = rwl;
     if (type == LockType.ForReading)
         rwl.AcquireReaderLock(-1);
     else if (type == LockType.ForWriting)
         rwl.AcquireWriterLock(-1);
 }
        public Calculator(LockType lockType, int lower, int upper, int modulus, int threads, ProgramMode programMode, string hash)
        {
            this.lower = lower; this.upper = upper;
            this.modulus = modulus; this.threads = threads;
            this.hash = hash;

            LockObject locker = CreateLocker(lockType);
            loop = CreateLoop(locker, programMode);
        }
        public bool GetLock(Guid entityId, LockType lockType)
        {
            LockType value;
            if (locks.TryGetValue(entityId, out value) && lockType == value)
                return true;

            var sessionManager = SessionManager.Manager;
            var session = sessionManager.GetSession(sessionManager.Current);
            using (var transaction = session.DbInfo.Connection.BeginTransaction(IsolationLevel.Serializable))
            {
                try
                {
                    var reader = ExecuteReader(entityId, session, (SqlTransaction)transaction);
                    var query = CREATE_QUERY;
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var sessionId = reader.GetGuid(0);
                            var type = reader.GetInt16(1);

                            if (!Enum.TryParse<LockType>(type.ToString(), out value))
                            {
                                reader.Close();
                                throw new Exception("Wrong LockType fetched. " + type);
                            }

                            if ((lockType == LockType.Write || value == LockType.Write) && session.Id.CompareTo(sessionId) != 0)
                            {
                                reader.Close();
                                throw new Exception(string.Format("Can't get {0} lock for {1}, session {2} has {3} lock.", lockType.ToString(), SessionManager.Manager.GetSession(session.Id).Name, SessionManager.Manager.GetSession(sessionId).Name, value.ToString()));
                            }

                            if (session.Id.CompareTo(sessionId) == 0)
                                query = UPDATE_QUERY;
                        }
                    }
                    reader.Close();
                    ExecuteNonQuery(query, entityId, session, lockType, transaction);
                    transaction.Commit();
                    Console.WriteLine(string.Format("Session {0} adquired {1} lock for VersionId: {2}", session.Name, lockType.ToString(), entityId));
                    if (locks.ContainsKey(entityId))
                        locks[entityId] = lockType;
                    else
                        locks.Add(entityId, lockType);
                }
                catch (Exception ex)
                {

                    transaction.Rollback();
                    Console.WriteLine(ex.Message);
                    return false;
                }
            }
            return true;
        }
示例#4
0
        public void GetLock(Guid entityId, LockType lockType)
        {
            LockType value;
            if (locks.TryGetValue(entityId, out value) && lockType == value)
                return;

            var connection = new SqlConnection(SQL_CONNECTION);
            connection.Open();
            using (var transaction = connection.BeginTransaction(IsolationLevel.Serializable))
            {
                try
                {
                    var reader = ExecuteReader(entityId, connection, transaction);
                    var query = CREATE_QUERY;
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var currentOwnerId = reader.GetGuid(0);
                            var type = reader.GetInt16(1);

                            if (!Enum.TryParse<LockType>(type.ToString(), out value))
                            {
                                reader.Close();
                                throw new Exception("Wrong LockType fetched. " + type);
                            }

                            if ((lockType == LockType.Write || value == LockType.Write) && Session.Id.CompareTo(currentOwnerId) != 0)
                            {
                                reader.Close();
                                throw new Exception(string.Format("Can't get {0} lock for {1}, session ID '{2}' has {3} lock.", lockType.ToString(), Session.Name, currentOwnerId.ToString(), value.ToString()));
                            }

                            if (Session.Id.CompareTo(currentOwnerId) == 0)
                                query = UPDATE_QUERY;
                        }
                    }
                    reader.Close();
                    ExecuteNonQuery(query, entityId, lockType, connection, transaction);
                    transaction.Commit();
                    if (locks.ContainsKey(entityId))
                        locks[entityId] = lockType;
                    else
                        locks.Add(entityId, lockType);
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
示例#5
0
        public void UpgradeToWriterLock()
        {
            System.Diagnostics.Debug.Assert(type == LockType.ForReading);

            if (type == LockType.ForReading)
            {
                rwlock.UpgradeToWriterLock(-1);
                type = LockType.ForWriting;
            }
        }
示例#6
0
 public void DowngradeToReaderLock()
 {
     System.Diagnostics.Debug.Assert(type == LockType.ForWriting);
     if (type == LockType.ForWriting)
     {
         System.Threading.LockCookie c = cookie.Value;
         rwlock.DowngradeFromWriterLock(ref c);
         cookie = null;
         type = LockType.ForReading;
     }
 }
 LockObject CreateLocker(LockType lockType)
 {
     switch (lockType)
     {
         case LockType.TaS:
             return new TTaSLock();
         case LockType.Lock:
             return new StatementLock();
         default:
             throw new NotImplementedException();
     }
 }
示例#8
0
        public Lock(System.Threading.ReaderWriterLock rwl, LockType lt)
        {
            rwlock = rwl;
            if (type == LockType.ForReading)
                rwl.AcquireReaderLock(-1);
            else if (type == LockType.ForWriting)
                rwl.AcquireWriterLock(-1);

            #if DEBUG
            callingfunction = new System.Diagnostics.StackTrace();
            #endif
        }
示例#9
0
文件: Lock.cs 项目: wli3/Its.Log
 public static ILockHelper Prepare(this ReaderWriterLockSlim lok, LockType type)
 {
     switch (type)
     {
         case LockType.Read:
             return new ReadLockHelper(lok);
         case LockType.UpgradeableRead:
             return new UpgradeableReadLockHelper(lok);
         case LockType.Write:
         default:
             return new WriteLockHelper(lok);
     }
 }
示例#10
0
        public static ILock Create(LockType lockType)
        {
            switch (lockType)
            {
                case LockType.NoLock:
                    return new NoLock();

                case LockType.SpinLock:
                    return new SpinLock();

                case LockType.ClrLock:
                    return new ClrLock();

                default:
                    return null;
            }
        }
        public void ProcessAsync(Func<Task> func, LockType lockType)
        {
            if (_isStopped)
                throw new TaskCanceledException("Fiber was stopped");

            switch (lockType)
            {
                case LockType.None:
                    func();
                    break;
                case LockType.Read:
                    _readLockedQueue.Post(func);
                    break;
                case LockType.Write:
                    _writeLockedQueue.Post(func);
                    break;
            }
        }
 public void AdcquireLock(Guid lockable, Guid owner, LockType type)
 {
     var lockInfo = GetLockInfo(lockable, owner);
     if(!lockInfo.HasLock(type))
     {
         if(CanClaimLock(lockable, owner, type))
         {
             var db = ApplicationManager.INSTANCE.GetDbProvider();
             var connection = db.CreateConnection();
             connection.Open();
             try
             {
                 var transaction = connection.BeginTransaction(IsolationLevel.Serializable);
                 try
                 {
                     using (var command = connection.CreateCommand())
                     {
                         command.CommandType = CommandType.Text;
                         command.Transaction = transaction;
                         if (lockInfo.LockType == LockType.None)
                             command.CommandText = string.Format(INSERT_SQL, lockable, owner, (byte)type);
                         else
                             command.CommandText = string.Format(UPDATE_SQL, (byte)type, lockable, owner);
                         command.ExecuteNonQuery();
                         transaction.Commit();
                     }
                 }
                 catch(DbException e)
                 {
                     transaction.Rollback();
                     throw new ConcurrencyException("Unable to lock: " + lockable);
                 }
             }
             finally
             {
                 connection.Close();
             }
         }
         else
         {
             throw new ConcurrencyException("Unable to lock: " + lockable);
         }
     }
 }
示例#13
0
文件: LockState.cs 项目: vebin/BD2
 internal LockState(LockManager LockManager, LockType LockType, IEnumerable<LockableBase> BaseDataObjectStateTrackers, Action<LockState> StateChanged, Action<LockState> ReportStale, TimeSpan Timeout)
 {
     if (LockManager == null)
         throw new ArgumentNullException ("LockManager");
     if (BaseDataObjectStateTrackers == null)
         throw new ArgumentNullException ("BaseDataObjects");
     if (StateChanged == null)
         throw new ArgumentNullException ("StateChanged");
     if (ReportStale == null)
         throw new ArgumentNullException ("ReportStale");
     lockManager = LockManager;
     lock_status = new object ();
     reportStale = ReportStale;
     lockType = LockType;
     lockables = new SortedSet<LockableBase> (BaseDataObjectStateTrackers);
     stateChanged = StateChanged;
     defaultTimeout = Timeout;
     if (Timeout == TimeSpan.Zero) {
         Timeout = TimeSpan.MaxValue;
     }
 }
		public Recordset _OpenRecordset(RecordsetType type, RecordsetOption options, LockType lockedits)
		{
			return new Recordset(qd._OpenRecordset(type, options, lockedits));
		}
示例#15
0
		public static bool TryToLockType (Int16 value, out LockType rval)
		{
			return ToLockType (value, out rval) == 0;
		}
示例#16
0
		public static Int16 FromLockType (LockType value)
		{
			Int16 rval;
			if (FromLockType (value, out rval) == -1)
				ThrowArgumentException (value);
			return rval;
		}
示例#17
0
 public void Put(int id, [FromBody] LockType value)
 {
     value.LockTypeID = id;
     lockTypeRepository.Edit(value);
 }
示例#18
0
 private static ReaderWriterLockService Get(ReaderWriterLockSlim rwlock, LockType lockType, bool noEscalate)
 {
     return(Get(rwlock, lockType, false, noEscalate));
 }
        public override void ShowGUI()
        {
            if (IsSingleLockMovement ())
            {
                doUpLock = (LockType) EditorGUILayout.EnumPopup ("Movement:", doUpLock);
            }
            else
            {
                doUpLock = (LockType) EditorGUILayout.EnumPopup ("Up movement:", doUpLock);
                doDownLock = (LockType) EditorGUILayout.EnumPopup ("Down movement:", doDownLock);
                doLeftLock = (LockType) EditorGUILayout.EnumPopup ("Left movement:", doLeftLock);
                doRightLock = (LockType) EditorGUILayout.EnumPopup ("Right movement:", doRightLock);
            }

            if (IsInFirstPerson ())
            {
                freeAimLock = (LockType) EditorGUILayout.EnumPopup ("Free-aiming:", freeAimLock);
            }

            if (!IsUltimateFPS ())
            {
                doRunLock = (PlayerMoveLock) EditorGUILayout.EnumPopup ("Walk / run:", doRunLock);
                doGravityLock = (LockType) EditorGUILayout.EnumPopup ("Affected by gravity?", doGravityLock);
                movePath = (Paths) EditorGUILayout.ObjectField ("Move path:", movePath, typeof (Paths), true);
            }

            if (AllowHeadTurning ())
            {
                doHotspotHeadTurnLock = (LockType) EditorGUILayout.EnumPopup ("Hotspot head-turning?", doHotspotHeadTurnLock);
            }

            AfterRunningOption ();
        }
示例#20
0
 public SetSkillLock( int skill, LockType type )
     : base(0x3A)
 {
     EnsureCapacity( 6 );
     Write( (short)skill );
     Write( (byte)type );
 }
示例#21
0
        override public float Run()
        {
            Player player = KickStarter.player;

            if (KickStarter.playerInput)
            {
                if (IsSingleLockMovement())
                {
                    doLeftLock  = doUpLock;
                    doRightLock = doUpLock;
                    doDownLock  = doUpLock;
                }

                if (doUpLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetUpLock(true);
                }
                else if (doUpLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetUpLock(false);
                }

                if (doDownLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetDownLock(true);
                }
                else if (doDownLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetDownLock(false);
                }

                if (doLeftLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetLeftLock(true);
                }
                else if (doLeftLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetLeftLock(false);
                }

                if (doRightLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetRightLock(true);
                }
                else if (doRightLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetRightLock(false);
                }

                if (KickStarter.settingsManager.movementMethod != MovementMethod.PointAndClick)
                {
                    if (doJumpLock == LockType.Disabled)
                    {
                        KickStarter.playerInput.SetJumpLock(true);
                    }
                    else if (doJumpLock == LockType.Enabled)
                    {
                        KickStarter.playerInput.SetJumpLock(false);
                    }
                }

                if (IsInFirstPerson())
                {
                    if (freeAimLock == LockType.Disabled)
                    {
                        KickStarter.playerInput.SetFreeAimLock(true);
                    }
                    else if (freeAimLock == LockType.Enabled)
                    {
                        KickStarter.playerInput.SetFreeAimLock(false);
                    }
                }

                if (cursorState == LockType.Disabled)
                {
                    KickStarter.playerInput.SetInGameCursorState(false);
                }
                else if (cursorState == LockType.Enabled)
                {
                    KickStarter.playerInput.SetInGameCursorState(true);
                }

                if (doRunLock != PlayerMoveLock.NoChange)
                {
                    KickStarter.playerInput.runLock = doRunLock;
                }
            }

            if (player)
            {
                if (movePath)
                {
                    player.SetLockedPath(movePath);
                    player.SetMoveDirectionAsForward();
                }
                else if (player.GetPath())
                {
                    player.EndPath();
                }

                if (doGravityLock == LockType.Enabled)
                {
                    player.ignoreGravity = false;
                }
                else if (doGravityLock == LockType.Disabled)
                {
                    player.ignoreGravity = true;
                }

                if (AllowHeadTurning())
                {
                    if (doHotspotHeadTurnLock == LockType.Disabled)
                    {
                        player.SetHotspotHeadTurnLock(true);
                    }
                    else if (doHotspotHeadTurnLock == LockType.Enabled)
                    {
                        player.SetHotspotHeadTurnLock(false);
                    }
                }
            }

            return(0f);
        }
 void Start()
 {
     lockStatus = LockType.NotLocked;
 }
示例#23
0
            private static Result UnlockRegionImpl(IntPtr thisPtr, long offset, long numberOfBytes, LockType lockType)
            {
                Result result = Result.Ok;

                try
                {
                    ((IStream)CppObjectShadow.ToShadow <ComStreamShadow>(thisPtr).Callback).UnlockRegion(offset, numberOfBytes, lockType);
                }
                catch (SharpDXException ex)
                {
                    result = ex.ResultCode;
                }
                catch (Exception ex)
                {
                    result = (Result)Result.Fail.Code;
                }
                return(result);
            }
示例#24
0
 /// <summary>
 /// Creates a operation based on a raw SQL statement.
 /// </summary>
 /// <param name="sqlStatement">The SQL statement.</param>
 /// <param name="argumentValue">The argument value.</param>
 /// <param name="lockType">Type of the lock.</param>
 /// <returns>SQLiteSqlCall.</returns>
 public MultipleTableDbCommandBuilder <SQLiteCommand, SQLiteParameter> Sql(string sqlStatement, object argumentValue, LockType lockType = LockType.Write)
 {
     return(new SQLiteSqlCall(this, sqlStatement, argumentValue, lockType));
 }
示例#25
0
 /// <summary>
 /// Creates a write-exlusive locking.
 /// </summary>
 public DAVLocking()
 {
     Type  = LockType.Write;
     Scope = LockScope.Exclusive;
 }
示例#26
0
 /// <summary>
 /// Creates a new locking object.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="scope"></param>
 public DAVLocking(LockType type, LockScope scope)
 {
     Type  = type;
     Scope = scope;
 }
示例#27
0
        /// <summary>
        /// Creates a new instance of <see cref="SQLiteSqlCall" />
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="sqlStatement">The SQL statement.</param>
        /// <param name="argumentValue">The argument value.</param>
        /// <param name="lockType">Type of the lock.</param>
        /// <exception cref="ArgumentException">SQL statement is null or empty.;sqlStatement</exception>
        public SQLiteSqlCall(SQLiteDataSourceBase dataSource, string sqlStatement, object?argumentValue, LockType lockType) :
            base(dataSource)
        {
            m_LockType = lockType;
            if (string.IsNullOrEmpty(sqlStatement))
            {
                throw new ArgumentException("SQL statement is null or empty.", nameof(sqlStatement));
            }

            m_SqlStatement  = sqlStatement;
            m_ArgumentValue = argumentValue;
        }
示例#28
0
 //creat Table, Record node
 private static XmlNode CreatRecord(XmlDocument xml, XmlNode nodeDBAlias, string TableName, string KeyFields, string KeyValues, string UserID, LockType lt)
 {
     XmlElement nodeTable = xml.CreateElement("Table");
     XmlAttribute attName = xml.CreateAttribute("Name");
     attName.Value = TableName;
     nodeTable.Attributes.Append(attName);
     nodeDBAlias.AppendChild(nodeTable);
     return CreatRecord(xml, nodeTable, KeyFields, KeyValues, UserID, lt);// call creat Record node
 }
示例#29
0
 public static LockType AddRecordLock(string DBAlias, string TableName, string KeyFields, string KeyValues, ref string UserID, LockType lt)
 {
     CheckTable();
     var result = LockType.Idle;
     using (var connection = AllocateConnection())
     {
         connection.Open();
         var transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
         var command = connection.CreateCommand();
         command.Transaction = transaction;
         try
         {
             var parameters = AddParameters(new string[] { "DBALIAS", "TABLENAME", "KEYFIELDS", "KEYVALUES" }, new object[] { DBAlias, TableName, KeyFields, KeyValues }, command);
             command.CommandText = string.Format("SELECT * FROM SYS_RECORDLOCK WHERE DBALIAS = {0} AND TABLENAME = {1} AND KEYFIELDS = {2} AND KEYVALUES = {3}", parameters);
             var adpater = DBUtils.CreateDbDataAdapter(command);
             var dataSet = new DataSet();
             adpater.Fill(dataSet);
             if (dataSet.Tables[0].Rows.Count > 0)
             {
                 var lockUser = dataSet.Tables[0].Rows[0]["USERID"].ToString();
                 if (string.Compare(lockUser, UserID, true) != 0)
                 {
                     UserID = lockUser;
                     result = (LockType)Enum.Parse(typeof(LockType), dataSet.Tables[0].Rows[0]["STATUS"].ToString(), true);
                 }
             }
             else
             {
                 command.Parameters.Clear();
                 parameters = AddParameters(new string[] { "USERID", "DBALIAS", "TABLENAME", "KEYFIELDS", "KEYVALUES", "STATUS" }, new object[] { UserID, DBAlias, TableName, KeyFields, KeyValues, lt.ToString() }, command);
                 command.CommandText = string.Format("INSERT INTO SYS_RECORDLOCK (USERID, DBALIAS, TABLENAME, KEYFIELDS, KEYVALUES, STATUS) VALUES ({0}, {1}, {2}, {3}, {4}, {5})", parameters);
                 command.ExecuteNonQuery();
             }
             transaction.Commit();
         }
         catch
         {
             transaction.Rollback();
             throw;
         }
     }
     return result;
 }
示例#30
0
 public DbTableSegment(DbExpression body, string alias, LockType @lock)
 {
     this.Body  = body;
     this.Alias = alias;
     this.Lock  = @lock;
 }
示例#31
0
    public void UnlockMovement(LockType type)
    {
        if ((MoveStates)CurrentState == MoveStates.moveLocked)
        {
            if (type == LockType.MovementLock)
            {
                _lockTime = Time.time;
            }

            else
            {
                _shiftLocked = false;
            }
        }
    }
示例#32
0
 public LockId(LockType lockType, string instanceName)
 {
     LockType     = lockType;
     InstanceName = instanceName;
 }
示例#33
0
 internal LockHandle(ReaderWriterLockSlim rwlock, LockType type)
 {
     this.rwlock = rwlock;
     this.type = type;
 }
        private static async Task <int> GetLockCount(AerospikeLockProvider lockProvider, string key, LockType lockType)
        {
            var settingProvider = GetSettingsProvider();
            var settings        = await settingProvider.GetSettings();

            var client = GetClientFactory().GetClient(settings.Host, settings.Port, new List <string>());
            var record = client.Get(null,
                                    new Key(settings.Namespace, settings.Set, key));

            var binName = lockType == LockType.Read ?
                          Keystore.AerospikeKeys.BinNames.ReadLocks :
                          Keystore.AerospikeKeys.BinNames.WriteLocks;

            return(record.GetInt(binName));
        }
示例#35
0
 public void Post([FromBody] LockType value)
 {
     lockTypeRepository.Test(value);
 }
 RootLock LockRoot(LockType ltype, string methodName)
 {
     return(new RootLock(this, ltype, false, methodName));
 }
示例#37
0
 private RootNode(Node copyFrom, LockType type) : base(copyFrom, type)
 {
 }
 RootLock LockRoot(LockType ltype, string methodName, bool exclusive)
 {
     return(new RootLock(this, ltype, exclusive, methodName));
 }
示例#39
0
		private static extern int ToLockType (Int16 value, out LockType rval);
示例#40
0
文件: Player.cs 项目: sumpurns/Razor
        public PlayerData(BinaryReader reader, int version) : base(reader, version)
        {
            int c;

            m_Str     = reader.ReadUInt16();
            m_Dex     = reader.ReadUInt16();
            m_Int     = reader.ReadUInt16();
            m_StamMax = reader.ReadUInt16();
            m_Stam    = reader.ReadUInt16();
            m_ManaMax = reader.ReadUInt16();
            m_Mana    = reader.ReadUInt16();
            m_StrLock = (LockType)reader.ReadByte();
            m_DexLock = (LockType)reader.ReadByte();
            m_IntLock = (LockType)reader.ReadByte();
            m_Gold    = reader.ReadUInt32();
            m_Weight  = reader.ReadUInt16();

            if (version >= 4)
            {
                Skill.Count = c = reader.ReadByte();
            }
            else if (version == 3)
            {
                long skillStart = reader.BaseStream.Position;
                c = 0;
                reader.BaseStream.Seek(7 * 49, SeekOrigin.Current);
                for (int i = 48; i < 60; i++)
                {
                    ushort Base, Cap, Val;
                    byte   Lock;

                    Base = reader.ReadUInt16();
                    Cap  = reader.ReadUInt16();
                    Val  = reader.ReadUInt16();
                    Lock = reader.ReadByte();

                    if (Base > 2000 || Cap > 2000 || Val > 2000 || Lock > 2)
                    {
                        c = i;
                        break;
                    }
                }

                if (c == 0)
                {
                    c = 52;
                }
                else if (c > 54)
                {
                    c = 54;
                }

                Skill.Count = c;

                reader.BaseStream.Seek(skillStart, SeekOrigin.Begin);
            }
            else
            {
                Skill.Count = c = 52;
            }

            m_Skills = new Skill[c];
            for (int i = 0; i < c; i++)
            {
                m_Skills[i]            = new Skill(i);
                m_Skills[i].FixedBase  = reader.ReadUInt16();
                m_Skills[i].FixedCap   = reader.ReadUInt16();
                m_Skills[i].FixedValue = reader.ReadUInt16();
                m_Skills[i].Lock       = (LockType)reader.ReadByte();
            }

            m_AR           = reader.ReadUInt16();
            m_StatCap      = reader.ReadUInt16();
            m_Followers    = reader.ReadByte();
            m_FollowersMax = reader.ReadByte();
            m_Tithe        = reader.ReadInt32();

            m_LocalLight  = reader.ReadSByte();
            m_GlobalLight = reader.ReadByte();
            m_Features    = reader.ReadUInt16();
            m_Season      = reader.ReadByte();

            if (version >= 4)
            {
                c = reader.ReadByte();
            }
            else
            {
                c = 8;
            }
            m_MapPatches = new int[c];
            for (int i = 0; i < c; i++)
            {
                m_MapPatches[i] = reader.ReadInt32();
            }
        }
示例#41
0
 public void LockRegion(long offset, long numberOfBytesToLock, LockType dwLockType)
 {
     throw new NotImplementedException();
 }
示例#42
0
 public IDisposable Lock(LockType type)
 {
     return(new LockSpec(type, this));
 }
示例#43
0
 private static XmlNode CreatRecord(XmlDocument xml, string DBAlias, string TableName, string KeyFields, string KeyValues, string UserID, LockType lt)
 {
     XmlElement nodeDBAlias = xml.CreateElement("DataBase");
     XmlAttribute attAlias = xml.CreateAttribute("Alias");
     attAlias.Value = DBAlias;
     nodeDBAlias.Attributes.Append(attAlias);
     xml.DocumentElement.AppendChild(nodeDBAlias);
     return CreatRecord(xml, nodeDBAlias, TableName, KeyFields, KeyValues, UserID, lt);// call creat Table, Record node
 }
示例#44
0
文件: Types.cs 项目: dongx-psu/FASTER
 public void Lock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, ref long lockContext)
 {
 }
示例#45
0
 //creat Record node
 private static XmlNode CreatRecord(XmlDocument xml, XmlNode nodeTable, string KeyFields, string KeyValues, string UserID, LockType lt)
 {
     XmlElement nodeRecord = xml.CreateElement("Record");
     XmlAttribute attKeyFields = xml.CreateAttribute("KeyFields");
     attKeyFields.Value = KeyFields;
     nodeRecord.Attributes.Append(attKeyFields);
     XmlAttribute attKeyValues = xml.CreateAttribute("KeyValues");
     attKeyValues.Value = KeyValues;
     nodeRecord.Attributes.Append(attKeyValues);
     XmlAttribute attUserID = xml.CreateAttribute("UserID");
     attUserID.Value = UserID;
     nodeRecord.Attributes.Append(attUserID);
     XmlAttribute attStatus = xml.CreateAttribute("Status");
     switch (lt)
     {
         case LockType.Updating: attStatus.Value = "Updating"; break;
         case LockType.Deleting: attStatus.Value = "Deleting"; break;
         default: attStatus.Value = ""; break;
     }
     nodeRecord.Attributes.Append(attStatus);
     nodeTable.AppendChild(nodeRecord);
     xml.Save(RecordFileName);
     return nodeRecord;
 }
示例#46
0
文件: Types.cs 项目: dongx-psu/FASTER
 public bool Unlock(ref RecordInfo recordInfo, ref Key key, ref Value value, LockType lockType, long lockContext) => true;
示例#47
0
        //public static LockType AddRecordLock(string DBAlias, string TableName, string KeyFields, string KeyValues, ref string UserID)
        //{
        //    return AddRecordLock(DBAlias, TableName, KeyFields, KeyValues, ref UserID, LockType.Updating);
        //}
        public static LockType AddRecordLock(string DBAlias,string TableName, string KeyFields, string KeyValues, ref string UserID, LockType lt)
        {
            if (ServerConfig.RecordLockInDatabase)
            {
                return RecordLockInDB.AddRecordLock(DBAlias, TableName, KeyFields, KeyValues, ref UserID, lt);
            }
            else
            {
                //while (lockinuse)
                //{
                //    Thread.Sleep(100);
                //}
                LockType retval;
                //lockinuse = true;
                XmlDocument xml = new XmlDocument();
                xml.Load(RecordFileName);
                XmlNode nodeDBAlias = FindAlias(xml, DBAlias);
                if (nodeDBAlias == null)
                {
                    CreatRecord(xml, DBAlias, TableName, KeyFields, KeyValues, UserID, lt);
                    return LockType.Idle;
                }
                else
                {
                    XmlNode nodeTable = FindTable(nodeDBAlias, TableName);
                    if (nodeTable == null)
                    {
                        CreatRecord(xml, nodeDBAlias, TableName, KeyFields, KeyValues, UserID, lt);
                        retval = LockType.Idle;
                    }
                    else
                    {
                        XmlNode nodeRecord = FindRecord(nodeTable, KeyFields, KeyValues);
                        if (nodeRecord == null)
                        {
                            CreatRecord(xml, nodeTable, KeyFields, KeyValues, UserID, lt);
                            retval = LockType.Idle;
                        }
                        else
                        {
                            if (nodeRecord.Attributes["UserID"].Value == UserID)
                            {
                                switch (lt)
                                {
                                    case LockType.Updating: nodeRecord.Attributes["Status"].Value = "Updating"; break;
                                    case LockType.Deleting: nodeRecord.Attributes["Status"].Value = "Deleting"; break;
                                    default: nodeRecord.Attributes["Status"].Value = ""; break;
                                }
                                retval = LockType.Idle;
                                xml.Save(RecordFileName);
                            }
                            else
                            {
                                UserID = nodeRecord.Attributes["UserID"].Value;
                                switch (nodeRecord.Attributes["Status"].Value)
                                {
                                    case "Updating": retval = LockType.Updating; break;
                                    case "Deleting": retval = LockType.Deleting; break;
                                    default: retval = LockType.Other; break;
                                }
                            }
                        }

                    }
                }
                //lockinuse = false;
                return retval;
            }
        }
 // Token: 0x06000C45 RID: 3141 RVA: 0x000365B8 File Offset: 0x000347B8
 private RemoteReplayConfiguration(IADDatabaseAvailabilityGroup dag, IADDatabase database, IADServer server, string activeFqdn, LockType lockType, ReplayConfigType type)
 {
     try
     {
         if (database == null)
         {
             throw new NullDatabaseException();
         }
         if (server == null)
         {
             throw new ErrorNullServerFromDb(database.Name);
         }
         if (activeFqdn == null)
         {
             throw new ArgumentException("Caller must provide the active node");
         }
         IADDatabaseCopy databaseCopy = database.GetDatabaseCopy(server.Name);
         if (databaseCopy == null)
         {
             throw new NullDbCopyException();
         }
         this.m_server                = server;
         this.m_database              = database;
         this.m_targetNodeFqdn        = server.Fqdn;
         this.m_sourceNodeFqdn        = activeFqdn;
         this.m_type                  = type;
         this.m_autoDatabaseMountDial = this.m_server.AutoDatabaseMountDial;
         if (type == ReplayConfigType.RemoteCopyTarget)
         {
             this.m_replayState = ReplayState.GetReplayState(this.m_targetNodeFqdn, this.m_sourceNodeFqdn, lockType, this.Identity, this.Database.Name);
         }
         else
         {
             this.m_replayState = ReplayState.GetReplayState(this.m_sourceNodeFqdn, this.m_sourceNodeFqdn, lockType, this.Identity, this.Database.Name);
         }
         this.m_replayLagTime        = databaseCopy.ReplayLagTime;
         this.m_truncationLagTime    = databaseCopy.TruncationLagTime;
         this.m_activationPreference = databaseCopy.ActivationPreference;
         base.PopulatePropertiesFromDag(dag);
     }
     finally
     {
         this.BuildDebugString();
     }
 }
示例#49
0
    public void LockMovement(LockType type, float duration = 0)
    {
        if (type == LockType.ShiftLock)
        {
            _shiftLocked = true;
        }

        else
        {
            _lockTime = Mathf.Max(_lockTime, Time.time + duration);
        }

        if ((MoveStates)CurrentState != MoveStates.moveLocked)
        {
            Transition(MoveStates.moveLocked);
        }
    }
示例#50
0
        /**
         * <summary>Creates a new instance of the 'Engine: Manage systems' Action</summary>
         * <param name = "newMovementMethod">The game's new movement method</param>
         * <param name = "cursorLock">Whether or not to disable the cursor system</param>
         * <param name = "inputLock">Whether or not to disable the input system</param>
         * <param name = "interactionLock">Whether or not to disable the interaction system</param>
         * <param name = "menuLock">Whether or not to disable the menu system</param>
         * <param name = "movementLock">Whether or not to disable the movement system</param>
         * <param name = "cameraLock">Whether or not to disable the camera system</param>
         * <param name = "triggerLock">Whether or not to disable the trigger system</param>
         * <param name = "playerLock">Whether or not to disable the player system</param>
         * <param name = "saveLock">Whether or not to disable the save system</param>
         * <param name = "directControlInGameMenusLock">Whether or not to allow direct-navigation of in-game menus</param>
         * <returns>The generated Action</returns>
         */
        public static ActionSystemLock CreateNew(MovementMethod newMovementMethod, LockType cursorLock = LockType.NoChange, LockType inputLock = LockType.NoChange, LockType interactionLock = LockType.NoChange, LockType menuLock = LockType.NoChange, LockType movementLock = LockType.NoChange, LockType cameraLock = LockType.NoChange, LockType triggerLock = LockType.NoChange, LockType playerLock = LockType.NoChange, LockType saveLock = LockType.NoChange, LockType directControlInGameMenusLock = LockType.NoChange)
        {
            ActionSystemLock newAction = (ActionSystemLock)CreateInstance <ActionSystemLock>();

            newAction.changeMovementMethod      = true;
            newAction.newMovementMethod         = newMovementMethod;
            newAction.cursorLock                = cursorLock;
            newAction.inputLock                 = inputLock;
            newAction.interactionLock           = interactionLock;
            newAction.menuLock                  = menuLock;
            newAction.movementLock              = movementLock;
            newAction.cameraLock                = cameraLock;
            newAction.triggerLock               = triggerLock;
            newAction.playerLock                = playerLock;
            newAction.saveLock                  = saveLock;
            newAction.keyboardGameplayMenusLock = directControlInGameMenusLock;
            return(newAction);
        }
        public override void ShowGUI()
        {
            changeMovementMethod = EditorGUILayout.BeginToggleGroup ("Change movement method?", changeMovementMethod);
            newMovementMethod = (MovementMethod) EditorGUILayout.EnumPopup ("Movement method:", newMovementMethod);
            EditorGUILayout.EndToggleGroup ();

            EditorGUILayout.Space ();

            cursorLock = (LockType) EditorGUILayout.EnumPopup ("Cursor:", cursorLock);
            inputLock = (LockType) EditorGUILayout.EnumPopup ("Input:", inputLock);
            interactionLock = (LockType) EditorGUILayout.EnumPopup ("Interactions:", interactionLock);
            menuLock = (LockType) EditorGUILayout.EnumPopup ("Menus:", menuLock);
            movementLock = (LockType) EditorGUILayout.EnumPopup ("Movement:", movementLock);
            cameraLock = (LockType) EditorGUILayout.EnumPopup ("Camera:", cameraLock);
            triggerLock = (LockType) EditorGUILayout.EnumPopup ("Triggers:", triggerLock);
            playerLock = (LockType) EditorGUILayout.EnumPopup ("Player:", playerLock);
            saveLock = (LockType) EditorGUILayout.EnumPopup ("Saving:", saveLock);

            AfterRunningOption ();
        }
示例#52
0
 public SuperLock(LockType lockType)
 {
 }
        public override float Run()
        {
            Player player = KickStarter.player;

            if (KickStarter.playerInput)
            {
                if (IsSingleLockMovement ())
                {
                    doLeftLock = doUpLock;
                    doRightLock = doUpLock;
                    doDownLock = doUpLock;
                }

                if (doUpLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetUpLock (true);
                }
                else if (doUpLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetUpLock (false);
                }

                if (doDownLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetDownLock (true);
                }
                else if (doDownLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetDownLock (false);
                }

                if (doLeftLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetLeftLock (true);
                }
                else if (doLeftLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetLeftLock (false);
                }

                if (doRightLock == LockType.Disabled)
                {
                    KickStarter.playerInput.SetRightLock (true);
                }
                else if (doRightLock == LockType.Enabled)
                {
                    KickStarter.playerInput.SetRightLock (false);
                }

                if (IsInFirstPerson ())
                {
                    if (freeAimLock == LockType.Disabled)
                    {
                        KickStarter.playerInput.SetFreeAimLock (true);
                    }
                    else if (freeAimLock == LockType.Enabled)
                    {
                        KickStarter.playerInput.SetFreeAimLock (false);
                    }
                }

                if (IsUltimateFPS ())
                {
                    return 0f;
                }

                if (doRunLock != PlayerMoveLock.NoChange)
                {
                    KickStarter.playerInput.runLock = doRunLock;
                }
            }

            if (player)
            {
                if (movePath)
                {
                    player.SetLockedPath (movePath);
                    player.SetMoveDirectionAsForward ();
                }
                else if (player.GetPath ())
                {
                    player.EndPath ();
                }

                if (doGravityLock == LockType.Enabled)
                {
                    player.ignoreGravity = false;
                }
                else if (doGravityLock == LockType.Disabled)
                {
                    player.ignoreGravity = true;
                }

                if (AllowHeadTurning ())
                {
                    if (doHotspotHeadTurnLock == LockType.Disabled)
                    {
                        player.SetHotspotHeadTurnLock (true);
                    }
                    else if (doHotspotHeadTurnLock == LockType.Enabled)
                    {
                        player.SetHotspotHeadTurnLock (false);
                    }
                }
            }

            return 0f;
        }
 public virtual SqlFragment BuildLockClause(SelectExpression selectExpression, LockType lockType)
 {
     return(null);
 }
示例#55
0
文件: LockHelper.cs 项目: radtek/vita
 public static bool HasLock(this LockType lockType)
 {
     return(lockType == LockType.SharedRead || lockType == LockType.ForUpdate);
 }
示例#56
0
 public LockEntry(LockScope scope, LockType type)
 {
     Scope = scope;
     Type  = type;
 }
示例#57
0
文件: LockHelper.cs 项目: radtek/vita
        public static IQueryable <TEntity> EntitySet <TEntity>(this IEntitySession session, LockType lockType) where TEntity : class
        {
            if (lockType == LockType.None)
            {
                return(session.EntitySet <TEntity>());
            }
            var entSession = (EntitySession)session;

            return(entSession.CreateEntitySet <TEntity>(lockType));
        }
示例#58
0
文件: LockHelper.cs 项目: radtek/vita
        /// <summary>Retrieves entity by type and primary key value and sets database lock on the underlying record. </summary>
        /// <typeparam name="TEntity">Entity type.</typeparam>
        /// <param name="primaryKey">The value of the primary key.</param>
        /// <param name="lockType">Lock type.</param>
        /// <returns>An entity instance.</returns>
        /// <remarks>For composite primary keys pass an instance of primary key
        /// created using the <see cref="EntitySessionExtensions.CreatePrimaryKey"/> extension method.
        /// </remarks>
        public static TEntity GetEntity <TEntity>(this IEntitySession session, object primaryKey, LockType lockType)
            where TEntity : class
        {
            if (lockType == LockType.None)
            {
                return(session.GetEntity <TEntity>(primaryKey)); //short path, no locks
            }
            Util.CheckParam(primaryKey, nameof(primaryKey));
            session.LogMessage("-- Locking entity {0}/{1}", typeof(TEntity).Name, primaryKey);
            var entInfo = session.Context.App.Model.GetEntityInfo(typeof(TEntity), throwIfNotFound: true);

            /*
             * var pkMembers = entInfo.PrimaryKey.KeyMembers;
             * Util.Check(pkMembers.Count == 1, "Cannot lock entity {0}: composite primary keys not supported.", entInfo.Name);
             * var pkMember = entInfo.PrimaryKey.KeyMembers[0].Member;
             * var prmEnt = Expression.Parameter(typeof(TEntity), "e");
             * var pkRead = Expression.MakeMemberAccess(prmEnt, pkMember.ClrMemberInfo);
             *
             * // PK box - we could use Constant expr to hold PK value directly, but the result is that PK is embedded into translated SQL as literal.
             * // (that's how Linq translation works). We want a query with parameter, so that translated linq command is cached and reused.
             * // So we add extra Convert expression to trick LINQ translator.
             * var pkValueExpr = Expression.Convert(Expression.Constant(primaryKey, typeof(object)), pkMember.DataType);
             * var eq = Expression.Equal(pkRead, pkValueExpr); // Expression.Constant(primaryKey, pkMember.DataType));
             * var filter = Expression.Lambda<Func<TEntity, bool>>(eq, prmEnt);
             */
            var       entSession = (EntitySession)session;
            EntityKey pk         = entInfo.CreatePrimaryKeyInstance(primaryKey);
            var       ent        = entSession.SelectByPrimaryKey(entInfo, pk.Values, lockType);

            return((TEntity)ent);

            /*
             * var query = session.EntitySet<TEntity>(lockType).Where(filter);
             * // We use ToList() on entire query instead of First() because we have already filter on PK value,
             * // and we want to avoid adding any paging (skip/take) clauses to the SQL.
             * // We use FirstOrDefult on entire list, and check that we got something; if not, we throw clear message.
             * var ent = query.ToList().FirstOrDefault();
             * Util.Check(ent != null, "Entity {0} with ID {1} does not exist, cannot set the lock.", entInfo.EntityType.Name,
             *  primaryKey);
             * return ent;
             */
        }
示例#59
0
 public ObjectLock(Core core, LockIntention intention)
 {
     this.core     = core;
     this.DiskPath = intention.DiskPath;
     this.LockType = intention.Type;
 }
示例#60
0
 public void UnLock(LockType tp = LockType.END)
 {
 }