public async Task AddOrUpdateUserAdEventLogAsync(UserAdEventLogDto log)
        {
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }
            var eventLogs = await _stateManager.GetOrAddAsync <IReliableDictionary <ItemId, List <UserAdEventLog> > >(DictionaryName);

            var item = new UserAdEventLog(log.UserId, log.EventType, log.SendedTime);
            var key  = log.UserId;

            using (var tx = _stateManager.CreateTransaction())
            {
                var logs = await eventLogs.TryGetValueAsync(tx, key);

                if (!logs.HasValue)
                {
                    await eventLogs.SetAsync(tx, key, new List <UserAdEventLog>() { item });
                }
                else
                {
                    var oldLog = logs.Value.FirstOrDefault(u => u.UserId.Equals(key) && u.EventType == log.EventType);
                    if (oldLog != null)
                    {
                        logs.Value.Remove(oldLog);
                    }
                    logs.Value.Add(item);
                    await eventLogs.SetAsync(tx, key, logs.Value);
                }
                await tx.CommitAsync();

                ServiceEventSource.Current.ServiceMessage(_serviceContext, "Created user Ad Operation,UserId:{0},Type:{1}", item.UserId.ToString(), item.EventType.ToString());
            }
        }
Beispiel #2
0
 public async Task AddUserAdEventLogAsync(UserAdEventLogDto log)
 {
     if (log == null)
     {
         throw new ArgumentNullException(nameof(log));
     }
     if (log.UserId == null)
     {
         log.UserId = new ItemId();
     }
     var appService = _remotingClient.CreateAdOperationAppService(log.UserId);
     await appService.AddOrUpdateUserAdEventLogAsync(log);
 }