Ejemplo n.º 1
0
 public static void Send(Farm farm, EUpdateMethod updateMethod)
 {
     var dto = new UpdateIndexDto
     {
         FarmId = farm.FarmId,
     //                UpdateTime = farm.UpdateDateTime,
         UpdateMethod = updateMethod
     };
     QueueClient.Send(new BrokeredMessage(dto));
 }
Ejemplo n.º 2
0
 private async Task HandleMessage(UpdateIndexDto dto)
 {
     using (var db = new ApplicationDbContext())
     {
         Farm farm;
         switch (dto.UpdateMethod)
         {
             case EUpdateMethod.Create:
                 farm =
                     await db.Farms.Include(f => f.Products).Where(f => f.FarmId == dto.FarmId).FirstAsync();
                 //good idea but different time zone or system time on different servers do not allow to use a timestamp to filter out old messages
                 if (farm != null && farm.UpdateDateTime > farm.IndexDateTime) // && farm.UpdateDateTime == dto.UpdateTime) 
                 {
                     AddFarmToIndex(farm, _indexWriter, db);
                     await db.SaveChangesAsync();
                     _indexWriter.Commit();
                 }
                 break;
             case EUpdateMethod.Update:
                 farm =
                     await db.Farms.Include(f => f.Products).Where(f => f.FarmId == dto.FarmId).FirstAsync();
                 if (farm != null && farm.UpdateDateTime > farm.IndexDateTime) // && farm.UpdateDateTime == dto.UpdateTime)
                 {
                     UpdateFarmInIndex(farm, _indexWriter, db);
                     await db.SaveChangesAsync();
                     _indexWriter.Commit();
                 }
                 break;
             case EUpdateMethod.Delete:
                 farm = await db.Farms.FindAsync(dto.FarmId);
                 if (farm != null)
                 {
                     DeleteFarmFromIndex(farm, _indexWriter, db);
                     await db.SaveChangesAsync();
                     _indexWriter.Commit();
                 }
                 break;
         }
     }
 }