Beispiel #1
0
 public static async Task<bool> AddOrUpdateLogEventAsync(LogEvent obj)
 {
     try
     {
         var result = await _client.SearchAsync<LogEvent>(s => s.Query(q => q.QueryString(ss => ss.Query("Id:" + obj.Id))));
         LogEvent l = obj;
         if (result.Total >= 1)
         {
             string _id = result.Hits.First().Id;
             var r = await _client.UpdateAsync<LogEvent>((u) =>
             {
                 u.Id(_id);
                 u.Doc(obj);
                 u.Index(_config.IndexName);
                 return u;
             });
             return r.IsValid;
         }
         else
         {
             var resoponse = await _client.IndexAsync<LogEvent>(l, (i) => { i.Index(_config.IndexName); return i; });
             return resoponse.Created;
         }
     }
     catch (Exception ex)
     {
         LogError(ex);
     }
     return false;
 }
Beispiel #2
0
 public static LogEvent CopyFromLogEventMQ(LogEventMQ mq)
 {
     if (mq == null || string.IsNullOrEmpty(mq.Id) || Guid.Parse(mq.Id).Equals(Guid.Empty))
         return null;
     LogEvent ret = new LogEvent();
     foreach (System.Reflection.PropertyInfo pi in ret.GetType().GetProperties())
     {
         object value = mq.GetType().GetProperty(pi.Name).GetValue(mq);
         if(value!=null)
             pi.SetValue(ret, value);
     }
     return ret;
 }