public async Task CompleteAdEventAsync(ItemId userId, UserAdEventType type) { var logDto = await this.GetUserAdEventLogAsync(userId, type); if (logDto == null) { return; } var eventLogs = await _stateManager.GetOrAddAsync <IReliableDictionary <ItemId, List <UserAdEventLog> > >(DictionaryName); var users = await _stateManager.GetOrAddAsync <IReliableDictionary <ItemId, UserItem> >(UserDictionaryName); using (var tx = _stateManager.CreateTransaction()) { var user = await users.TryGetValueAsync(tx, userId); var logs = await eventLogs.TryGetValueAsync(tx, userId); var log = logs.HasValue ? logs.Value.FirstOrDefault(u => u.EventType == type) : null; if (!user.HasValue || log == null) { return; } var itemUser = user.Value.UpdateHasAdUser(true); var itemLog = log.UpdateRecived(true, DateTimeOffset.Now); logs.Value.Remove(log); logs.Value.Add(itemLog); await users.SetAsync(tx, userId, itemUser); await eventLogs.SetAsync(tx, userId, logs.Value); await tx.CommitAsync(); } }
public async Task <UserAdEventLogDto> GetUserAdEventLogAsync(ItemId Id, UserAdEventType type) { var eventLogs = await _stateManager.GetOrAddAsync <IReliableDictionary <ItemId, List <UserAdEventLog> > >(DictionaryName); using (var tx = _stateManager.CreateTransaction()) { var logs = await eventLogs.TryGetValueAsync(tx, Id); if (!logs.HasValue) { return(null); } var log = logs.Value.FirstOrDefault(u => u.EventType == type); if (log == null) { return(null); } return(this._mapper.Map <UserAdEventLogDto>(log)); } }
public UserAdEventLog(ItemId userId, UserAdEventType eventType, DateTimeOffset sendedTime) { this._userId = userId; this._eventType = eventType; this._sendedTime = sendedTime; }
public async Task CompleteAdEventLogAsync(ItemId Id, UserAdEventType type) { var appService = _remotingClient.CreateAdOperationAppService(Id); await appService.CompleteAdEventAsync(Id, type); }
public async Task <(UserAdEventLogDto, IAdOperationAppService)> GetUserAdEventLogAsync(ItemId Id, UserAdEventType type) { try { var appService = this._remotingClient.CreateAdOperationAppService(Id); var userItemDto = await appService.GetUserAdEventLogAsync(Id, type); return(userItemDto, appService); } catch (Exception e) { Trace.TraceError(e.Message); return(default((UserAdEventLogDto, IAdOperationAppService))); } }