コード例 #1
0
ファイル: Defect.cs プロジェクト: svanxxx/taskmanager
 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));
     }
 }
コード例 #2
0
 private void Awake()
 {
     if (evnt == null)
     {
         evnt = new LockEvent();
     }
 }
コード例 #3
0
        public void SendEvent(LockEvent lockEvent)
        {
            int sizeOfMsg = lockEvent.CalculateSize();

            tcpConnector.Client.GetStream().Write(BitConverter.GetBytes(IPAddress.HostToNetworkOrder(sizeOfMsg)));
            lockEvent.WriteTo(tcpConnector.Client.GetStream());
        }
コード例 #4
0
        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();
        }
コード例 #5
0
 public void AddListener(UnityAction <bool> call)
 {
     if (evnt == null)
     {
         evnt = new LockEvent();
     }
     evnt.AddListener(call);
 }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: Defect.cs プロジェクト: svanxxx/taskmanager
    public static bool Locked(string ttid)
    {
        if (!locker.Keys.Contains(ttid))
        {
            return(false);
        }

        LockEvent ev = locker[ttid];

        return(!ev.Obsolete);
    }
コード例 #8
0
ファイル: Defect.cs プロジェクト: svanxxx/taskmanager
 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);
         }
     }
 }
コード例 #9
0
        /// <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));
        }
コード例 #10
0
 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();
     }
 }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        /// <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);
            }
        }
コード例 #14
0
        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;
            }
        }
コード例 #15
0
        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();
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: GuessGameplay.cs プロジェクト: Wow-Doge/ColorWord
    //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());
            }
        }
    }
コード例 #18
0
        /// <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);
        }
コード例 #19
0
        /// <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);
        }
コード例 #20
0
ファイル: Player.cs プロジェクト: Sergey1116/Player_2
 public void Lock()
 {
     _isLocked = true;
     LockEvent?.Invoke(this);
 }
コード例 #21
0
        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);
 }
コード例 #23
0
 public static void Awake(this LockEvent self, long key)
 {
     self.key = key;
 }
コード例 #24
0
 public void OnLock(LockEvent @event)
 {
     log.Debug("OnLock :" + @event);
 }
コード例 #25
0
ファイル: Player.cs プロジェクト: Sergey1116/Player_2
 public void Unlock()
 {
     _isLocked = false;
     LockEvent?.Invoke(this);
 }