public IEventCacheReadObject JoinEvent(Guid accountId, Guid componentId, JoinEventData joinEventData) { // Проверим, что компонент вообще есть var componentRequest = new AccountCacheRequest() { AccountId = accountId, ObjectId = componentId }; var component = AllCaches.Components.Find(componentRequest); if (component == null) { throw new UnknownComponentIdException(componentId, accountId); } if (component.CanProcess == false) { throw new ResponseCodeException(Zidium.Api.ResponseCode.ObjectDisabled, "Компонент выключен"); } // проверка лимитов var accountDbContext = Context.GetAccountDbContext(accountId); var limitChecker = AccountLimitsCheckerManager.GetCheckerForAccount(accountId); limitChecker.CheckEventsRequestsPerDay(accountDbContext); // Проверим лимит размера хранилища var size = joinEventData.Message != null ? joinEventData.Message.Length * 2 : 0; limitChecker.CheckStorageSize(accountDbContext, size); var eventType = Context.EventTypeService.GetOneById(joinEventData.TypeId ?? Guid.Empty, accountId); // расчитаем важность joinEventData.Importance = GetEventImportance(joinEventData.Importance, eventType.Category); var localEvent = CreateEvent( accountId, joinEventData.StartDate, joinEventData.StartDate, joinEventData.Count, joinEventData.Version, joinEventData.Importance, TimeSpan.FromSeconds(joinEventData.JoinInterval ?? 0), joinEventData.Message, null, eventType, componentId, joinEventData.JoinKey ?? 0); var joinInterval = (joinEventData.JoinInterval.HasValue) ? TimeSpan.FromSeconds(joinEventData.JoinInterval.Value) : (eventType.JoinInterval ?? TimeSpan.Zero); var dbEvent = ProcessSimpleEvent(componentId, localEvent, joinEventData.EventId, joinInterval, accountId); limitChecker.AddEventsSizePerDay(accountDbContext, size); return(dbEvent); }
public static JoinEventDto GetJoinEventDto(JoinEventData data) { if (data == null) { return(null); } return(new JoinEventDto() { EventId = data.EventId, ComponentId = data.ComponentId, Count = data.Count, Importance = data.Importance, JoinInterval = GetSeconds(data.JoinInterval), JoinKey = data.JoinKey, Message = data.Message, StartDate = data.StartDate, TypeId = data.TypeId, Version = data.Version }); }