Esempio n. 1
0
 public static bool UserExists(string username, string password)
 {
     using (var context = new TimerContext())
     {
         return(context.Users.Any(u => u.Username == username && u.Password == password));
     }
 }
 public Task HandlingEventAsync(IEvent @event)
 {
     _handlingActivity = ClaptrapActivitySource.Instance.StartActivity(HandleEvent)
                         .AddClaptrapTags(_claptrapDesign, _identity);
     _eventHandlingTimer = ClaptrapMetrics.MeasureEventHandling(_identity, @event);
     return(Task.CompletedTask);
 }
Esempio n. 3
0
 public static List <Group> GetUserGroups(Guid userId)
 {
     using (var context = new TimerContext())
     {
         return(context.Groups.Where(o => o.UserId == userId).ToList());
     }
 }
Esempio n. 4
0
 Task ICommandUnitOfWork.Begin()
 {
     _commandsMeter.Mark();
     _commandsConcurrent.Increment();
     _timerContext = _commandsTimer.NewContext();
     return(Task.FromResult(true));
 }
Esempio n. 5
0
        public ResolvedEvent[] Flush()
        {
            if (!Live || _waitingEvents.Count == 0)
            {
                return new ResolvedEvent[] { }
            }
            ;

            var age = DateTime.UtcNow - _waitingEvents.First().Event.Created;

            if (_waitingEvents.Count < 100 && age < TimeSpan.FromSeconds(30))
            {
                return new ResolvedEvent[] { }
            }
            ;

            List <ResolvedEvent> discovered;

            lock (_lock)
            {
                discovered = _waitingEvents.GetRange(0, Math.Min(500, _waitingEvents.Count));

                _waitingEvents.RemoveRange(0, Math.Min(500, _waitingEvents.Count));
            }

            Queued.Decrement(Id, discovered.Count);
            _idleContext = Idle.NewContext(Id);

            return(discovered.ToArray());
        }
    }
}
Esempio n. 6
0
 public static bool IsUserUnique(string username, string email)
 {
     using (var context = new TimerContext())
     {
         return(!context.Users.Any(u => u.Username == username || u.Email == email));
     }
 }
        /// <summary>
        /// Waits until the synchronization semaphore is available, creates a new operation and handles resolution.
        /// </summary>
        /// <param name="createTimerContext">Creates a <see cref="TimerContext"/> to measure operation latency.</param>
        /// <param name="resultProducer">Producer to generate operation calls as a producer-consumer.</param>
        /// <param name="onSuccess">Event handler for operation success.</param>
        /// <param name="onFailure"></param>
        /// <param name="logDiagnostics">Event handler for tracking diagnostics when latency goes above the threshold.</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public static async Task PerformOperationAsync(
            Func <TimerContext> createTimerContext,
            ICTLResultProducer <T> resultProducer,
            Action onSuccess,
            Action <Exception> onFailure,
            Action <T, TimeSpan> logDiagnostics)
        {
            while (resultProducer.HasMoreResults)
            {
                using (TimerContext timerContext = createTimerContext())
                {
                    await resultProducer.GetNextAsync().ContinueWith(task =>
                    {
                        if (task.IsCompletedSuccessfully)
                        {
                            logDiagnostics(task.Result, timerContext.Elapsed);

                            if (!resultProducer.HasMoreResults)
                            {
                                onSuccess();
                            }
                        }
                        else
                        {
                            onFailure(task.Exception);
                        }
                    });
                }
            }
        }
Esempio n. 8
0
 internal Timer(
     IntPtr loopHandle,
     Action <object> callback,
     object state)
 {
     _timerContext = new TimerContext(loopHandle, callback, state);
 }
 public Task DeactivatingAsync()
 {
     _deactivatingActivity = ClaptrapActivitySource.Instance.StartActivity(Deactivate)
                             .AddClaptrapTags(_claptrapDesign, _identity);
     _deactivationTimer = ClaptrapMetrics.MeasureDeactivation(_identity);
     return(Task.CompletedTask);
 }
Esempio n. 10
0
        public static void UpdateUser(User user, string[] update_fields)
        {
            using (var context = new TimerContext())
            {
                User n_user = context.Users.FirstOrDefault(u => u.Id == user.Id);
                foreach (string p in update_fields)
                {
                    switch (p)
                    {
                    case "Username":
                        n_user.Username = user.Username;
                        break;

                    case "Name":
                        n_user.Name = user.Name;
                        break;

                    case "Surname":
                        n_user.Surname = user.Surname;
                        break;

                    case "Email":
                        n_user.Email = user.Email;
                        break;

                    case "Password":
                        n_user.Password = user.Password;
                        break;
                    }
                }
                context.SaveChanges();
            }
        }
Esempio n. 11
0
 public static User GetUserByGuid(Guid guid)
 {
     using (var context = new TimerContext())
     {
         return(context.Users.FirstOrDefault(u => u.Id == guid));
     }
 }
Esempio n. 12
0
        private void ResetLimit(object sender, ElapsedEventArgs e)
        {
            TimerContext context = (TimerContext)sender;

            context.CanUseCommand = true;
            context.Stop();
        }
Esempio n. 13
0
    private static TimerEntity TimerEntity(TimerContext context, float time)
    {
        var e = context.CreateEntity();

        e.AddTimer(time);
        return(e);
    }
Esempio n. 14
0
 public static User GetUser(string username, string password)
 {
     using (var context = new TimerContext())
     {
         return(context.Users.FirstOrDefault(u => u.Username == username && u.Password == password));
     }
 }
Esempio n. 15
0
 Task IEventUnitOfWork.Begin()
 {
     _eventsMeter.Mark();
     _eventsConcurrent.Increment();
     _timerContext = _eventsTimer.NewContext();
     return(Task.FromResult(true));
 }
Esempio n. 16
0
 public static void AddGroups(List <Group> groups)
 {
     using (var context = new TimerContext())
     {
         context.Groups.AddRange(groups);
         context.SaveChanges();
     }
 }
Esempio n. 17
0
    public static TimerEntity FinishCutSceneTimer(this TimerContext context, float time)
    {
        var e = TimerEntity(context, time);

        e.isFinishCutSceneEvent = true;

        return(e);
    }
Esempio n. 18
0
 public static void AddRecords(List <Record> records)
 {
     using (var context = new TimerContext())
     {
         context.Records.AddRange(records);
         context.SaveChanges();
     }
 }
Esempio n. 19
0
    public static TimerEntity PrepareToLoseTimer(this TimerContext context, float time)
    {
        var e = TimerEntity(context, time);

        e.isPrepareToLoseEvent = true;

        return(e);
    }
Esempio n. 20
0
 public static void AddUser(User user)
 {
     using (var context = new TimerContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Esempio n. 21
0
        public void TimerContext_Message_PopulatesTimerMessage()
        {
            TimerContext context = new TimerContext("some-name", new Logger(), LogLevelEnum.LOG_DEBUG);

            var result = context.Message("some-message");

            Assert.Equal(context, result);
            Assert.Equal("some-message", context.TimerMessage);
        }
Esempio n. 22
0
        public static List <Record> GetUserRecords(Guid userId)
        {
            using (var context = new TimerContext())
            {
                var a = context.Records.Include(r => r.Group).Where(o => o.UserId == userId).ToList();

                return(a);
            }
        }
Esempio n. 23
0
        public BaseService(TimerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("Timer context may not be null");
            }

            _ctx = context;
        }
Esempio n. 24
0
 public static void DeleteGroups(List <Guid> groupIds)
 {
     using (var context = new TimerContext())
     {
         var toDelete = context.Groups.Where(r => groupIds.Contains(r.Id));
         context.Groups.RemoveRange(toDelete);
         context.SaveChanges();
     }
 }
Esempio n. 25
0
 public TimerSystem(Contexts contexts)
 {
     timer         = contexts.timer;
     runningTimers = timer.GetGroup(
         TimerMatcher.AllOf(
             TimerMatcher.Timer,
             TimerMatcher.TimerRunning
             )
         );
 }
Esempio n. 26
0
        public override void SetValue <TObject>(string key, TObject value, DistributedCacheEntryOptions options = null)
        {
            TimerContext timer = this.Helper.GetWriteTimer(Metrics.Distributed.WriteTimer);

            using (timer)
            {
                base.SetValue(key, value, options);
                timer.TrackUserValue("ok");
            }
        }
Esempio n. 27
0
 public static void AddGroup(Group group)
 {
     using (var context = new TimerContext())
     {
         context.Users.Attach(group.User);
         context.Groups.Add(group);
         context.SaveChanges();
         context.Entry(group).State = System.Data.Entity.EntityState.Unchanged;
     }
 }
Esempio n. 28
0
        public void TimerContext_Start_RunsTimer()
        {
            TimerContext context = new TimerContext("some-name", new Logger(), LogLevelEnum.LOG_DEBUG);

            var result = context.Start();

            Thread.Sleep(5);

            Assert.Equal(context, result);
            Assert.True(context.GetElapsedTime() > 0);  // Indicates that the timer has been started
        }
Esempio n. 29
0
        public override async Task SetValueAsync <TObject>(string key, TObject value, DistributedCacheEntryOptions options = null,
                                                           CancellationToken token = default(CancellationToken))
        {
            TimerContext timer = this.Helper.GetWriteTimer(Metrics.Distributed.WriteTimer);

            using (timer)
            {
                await base.SetValueAsync(key, value, options, token);

                timer.TrackUserValue("ok");
            }
        }
Esempio n. 30
0
 public static void DeleteRecords(List <Guid> record_ids)
 {
     using (var context = new TimerContext())
     {
         var toDelete = context.Records.Where(r => record_ids.Contains(r.Id)).ToList();
         foreach (Record record in toDelete)
         {
             context.Records.Remove(record);
         }
         context.SaveChanges();
     }
 }
Esempio n. 31
0
 public void Schedule(IThreadRunnable task, long delay)
 {
     TimerCallback cb = new TimerCallback(this.OnTimedEvent);
     TimerContext context = new TimerContext {
         task = task
     };
     Timer timer = new Timer(cb, context, -1, 0);
     context.timer = timer;
     lock (this)
     {
         this._timers.Add(timer);
     }
     timer.Change((delay < 1L) ? 1L : delay, 0L);
 }