public static LockInfo _Locktask(string ttid, string lockid, string userid, bool force = false) { if (locker.Keys.Contains(ttid)) { LockEvent ev = locker[ttid]; if (ev.Obsolete || force) { LockEvent newev = new LockEvent(lockid, userid); locker[ttid] = newev; return(new LockInfo(newev.usr, newev.lockid)); } else { if (ev.lockid == lockid) { ev.Prolongate(); locker[ttid] = ev; } return(new LockInfo(ev.usr, ev.lockid)); } } else { LockEvent ev = new LockEvent(lockid, userid); locker[ttid] = ev; return(new LockInfo(ev.usr, ev.lockid)); } }
private void Awake() { if (evnt == null) { evnt = new LockEvent(); } }
public void SendEvent(LockEvent lockEvent) { int sizeOfMsg = lockEvent.CalculateSize(); tcpConnector.Client.GetStream().Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(sizeOfMsg))); lockEvent.WriteTo(tcpConnector.Client.GetStream()); }
public static void Destroy(this LockEvent self) { var cacheProxyComponent = Game.Scene.GetComponent <CacheProxyComponent>(); cacheProxyComponent.UnlockEvent(self.key.ToString(), self.Id.ToString()).Coroutine(); //Game.Scene.GetComponent<LocationProxyComponent>().UnlockEvent(self.Id, self.key).Coroutine(); }
public void AddListener(UnityAction <bool> call) { if (evnt == null) { evnt = new LockEvent(); } evnt.AddListener(call); }
private void SendEvent(string cmd) { LockEvent lockEvent = new LockEvent(); lockEvent.EventTime = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp(); lockEvent.DeviceEvent = ModelUtils.StringEvent2Enum(cmd); lockEvent.LockDeviceId = LockDevice.DeviceId; lockEvent.RequestReferenceNumber = Utils.GetRandomRequestReferenceNumber(); tcpDataSendReceiver.SendEvent(lockEvent); }
public static bool Locked(string ttid) { if (!locker.Keys.Contains(ttid)) { return(false); } LockEvent ev = locker[ttid]; return(!ev.Obsolete); }
public static void _UnLocktask(string ttid, string lockid) { if (locker.Keys.Contains(ttid)) { LockEvent ev = locker[ttid]; if (ev.lockid == lockid) { locker.TryRemove(ttid, out ev); } } }
/// <summary> /// Asynchronously inserts the lock event. /// </summary> /// <param name="lockEvent">The lock event.</param> /// <returns></returns> public Task InsertAsync(LockEvent lockEvent) { if (lockEvent == null) { throw new ArgumentNullException(nameof(lockEvent)); } var entity = this.mapper.Map <LockEventEntity>(lockEvent); return(this.genericLockEventRepository.InsertAsync(entity)); }
private void CascadeOnLock(LockEvent @event, IEntityPersister persister, object entity) { IEventSource source = @event.Session; source.PersistenceContext.IncrementCascadeLevel(); try { new Cascade(CascadingAction.Lock, CascadePoint.AfterLock, source).CascadeOn(persister, entity, @event.LockMode); } finally { source.PersistenceContext.DecrementCascadeLevel(); } }
public static async ETTask <LockEvent> Wait(this LockEvent self, long timeout = 60000) { var cacheProxyComponent = Game.Scene.GetComponent <CacheProxyComponent>(); self.Id = IdGenerater.GenerateId(); // 模擬自旋鎖 while (!await cacheProxyComponent.LockEvent(self.key.ToString(), self.Id.ToString(), timeout)) { await Game.Scene.GetComponent <TimerComponent>().WaitForSecondAsync(0.5f); } //await Game.Scene.GetComponent<LocationProxyComponent>().LockEvent(self.Id, self.key, timeout); return(self); }
/// <summary>Handle the given lock event. </summary> /// <param name="event">The lock event to be handled.</param> /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param> public virtual Task OnLockAsync(LockEvent @event, CancellationToken cancellationToken) { if (@event.Entity == null) { throw new NullReferenceException("attempted to lock null"); } if (@event.LockMode == LockMode.Write) { throw new HibernateException("Invalid lock mode for lock()"); } if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <object>(cancellationToken)); } return(InternalOnLockAsync()); async Task InternalOnLockAsync() { ISessionImplementor source = @event.Session; if (@event.LockMode == LockMode.None && source.PersistenceContext.ReassociateIfUninitializedProxy(@event.Entity)) { // NH-specific: shortcut for uninitialized proxies - reassociate // without initialization return; } object entity = await(source.PersistenceContext.UnproxyAndReassociateAsync(@event.Entity, cancellationToken)).ConfigureAwait(false); //TODO: if object was an uninitialized proxy, this is inefficient,resulting in two SQL selects EntityEntry entry = source.PersistenceContext.GetEntry(entity); if (entry == null) { IEntityPersister persister = source.GetEntityPersister(@event.EntityName, entity); object id = persister.GetIdentifier(entity); if ((await(ForeignKeys.IsTransientFastAsync(@event.EntityName, entity, source, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault()) { throw new TransientObjectException("cannot lock an unsaved transient instance: " + persister.EntityName); } entry = await(ReassociateAsync(@event, entity, id, persister, cancellationToken)).ConfigureAwait(false); await(CascadeOnLockAsync(@event, persister, entity, cancellationToken)).ConfigureAwait(false); } await(UpgradeLockAsync(entity, entry, @event.LockMode, source, cancellationToken)).ConfigureAwait(false); } }
public static void EventHandler(string script) { var e = new LockEvent(script); switch (script) { case OBJECT_LOCK_BEFORE: LockBefore(e); break; case OBJECT_LOCK_AFTER: LockAfter(e); break; } }
private async Task CascadeOnLockAsync(LockEvent @event, IEntityPersister persister, object entity, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); IEventSource source = @event.Session; source.PersistenceContext.IncrementCascadeLevel(); try { await(new Cascade(CascadingAction.Lock, CascadePoint.AfterLock, source).CascadeOnAsync(persister, entity, @event.LockMode, cancellationToken)).ConfigureAwait(false); } finally { source.PersistenceContext.DecrementCascadeLevel(); } }
private async Task <bool> ProcessEvent(object lockEventpbj) { try { LockEvent lockEvent = (LockEvent)lockEventpbj; LockDeviceBson lockDeviceBson = new LockDeviceBson() { IsActive = true, LastActiveTime = lockEvent.EventTime.ToDateTime(), LockDeviceId = lockEvent.LockDeviceId }; await MongoDriver.MongoDbRepo.UpsertLockDeviceBson(lockDeviceBson); LockEventBson lockEventBson = new LockEventBson() { DeviceEvent = lockEvent.DeviceEvent, EventTime = lockEvent.EventTime.ToDateTime(), LockDeviceBson = lockDeviceBson, RequestReferenceNumber = lockEvent.RequestReferenceNumber }; await MongoDriver.MongoDbRepo.InsertLockEventBson(lockEventBson); if (lockEvent.DeviceEvent == LockEvent.Types.DeviceEventEnum.Open) { //publish a msg for another queu to set lock to passive if spesified amount time is passed since last event LockActivityCheck lockActivityCheck = new LockActivityCheck(); lockActivityCheck.LockDeviceId = lockDeviceBson.LockDeviceId; lockActivityCheck.EventDate = lockEventBson.EventTime; string lockActivityCheckJson = JsonConvert.SerializeObject(lockActivityCheck); byte[] binaryObject = Encoding.UTF8.GetBytes(lockActivityCheckJson); checkEventMqBroker.DelayedQueu($"Activity check event {lockDeviceBson.LockDeviceId}", binaryObject, 30 * 1000); } Console.WriteLine($"Event processed to be processed {lockEvent}"); return(true); } catch (Exception e) { Console.WriteLine($"err {e}"); } return(false); }
//when player press a button public void InputSystem(Button button) { char letter = button.GetComponentInChildren <TextMeshProUGUI>().text.ToCharArray()[0]; UpdateAnswer(letter); LockEvent?.Invoke(this, EventArgs.Empty); if (!userInput.Contains(placeholder)) { if (!CheckWinCondition()) { ResetUserInput(); } else { StartCoroutine(ShowTextWhenCorrect()); StartCoroutine(ShowCompleteScreen()); } } }
/// <summary>Handle the given lock event. </summary> /// <param name="event">The lock event to be handled.</param> public virtual void OnLock(LockEvent @event) { if (@event.Entity == null) { throw new NullReferenceException("attempted to lock null"); } if (@event.LockMode == LockMode.Write) { throw new HibernateException("Invalid lock mode for lock()"); } ISessionImplementor source = @event.Session; if (@event.LockMode == LockMode.None && source.PersistenceContext.ReassociateIfUninitializedProxy(@event.Entity)) { // NH-specific: shortcut for uninitialized proxies - reassociate // without initialization return; } object entity = source.PersistenceContext.UnproxyAndReassociate(@event.Entity); //TODO: if object was an uninitialized proxy, this is inefficient,resulting in two SQL selects EntityEntry entry = source.PersistenceContext.GetEntry(entity); if (entry == null) { IEntityPersister persister = source.GetEntityPersister(@event.EntityName, entity); object id = persister.GetIdentifier(entity); if (!ForeignKeys.IsNotTransient(@event.EntityName, entity, false, source)) { throw new TransientObjectException("cannot lock an unsaved transient instance: " + persister.EntityName); } entry = Reassociate(@event, entity, id, persister); CascadeOnLock(@event, persister, entity); } UpgradeLock(entity, entry, @event.LockMode, source); }
/// <summary>Handle the given lock event. </summary> /// <param name="event">The lock event to be handled.</param> public virtual void OnLock(LockEvent @event) { if (@event.Entity == null) { throw new NullReferenceException("attempted to lock null"); } if (@event.LockMode == LockMode.Write) { throw new HibernateException("Invalid lock mode for lock()"); } ISessionImplementor source = @event.Session; if (@event.LockMode == LockMode.None && source.PersistenceContext.ReassociateIfUninitializedProxy(@event.Entity)) { // NH-specific: shortcut for uninitialized proxies - reassociate // without initialization return; } object entity = source.PersistenceContext.UnproxyAndReassociate(@event.Entity); //TODO: if object was an uninitialized proxy, this is inefficient,resulting in two SQL selects EntityEntry entry = source.PersistenceContext.GetEntry(entity); if (entry == null) { IEntityPersister persister = source.GetEntityPersister(entity); object id = persister.GetIdentifier(entity, source.EntityMode); if (!ForeignKeys.IsNotTransient(@event.EntityName, entity, false, source)) { throw new TransientObjectException("cannot lock an unsaved transient instance: " + persister.EntityName); } entry = Reassociate(@event, entity, id, persister); CascadeOnLock(@event, persister, entity); } UpgradeLock(entity, entry, @event.LockMode, source); }
public void Lock() { _isLocked = true; LockEvent?.Invoke(this); }
public async Task <bool> ProcessEvent(byte[] data) { LockEvent lockEvent = LockEvent.Parser.ParseFrom(data); return(await LockEventProcessHandler.Invoke(lockEvent)); }
public void OnLock(LockEvent @event) { SetReadOnlyEntity(@event.Session, @event.Entity); }
public static void Awake(this LockEvent self, long key) { self.key = key; }
public void OnLock(LockEvent @event) { log.Debug("OnLock :" + @event); }
public void Unlock() { _isLocked = false; LockEvent?.Invoke(this); }