private async Task SaveChangesAndReIndex(Farm farm)
        {
            //create/delete/update a product also means we need to reindex the farm entry, hence modify the UpdateDateTime 
            db.Entry(farm).State = EntityState.Modified;
            farm.UpdateDateTime = DateTime.Now;
            await db.SaveChangesAsync();

            //db was saved successfully, inform worker role via IndexUpdatingQueue
            QueueHelper.Send(farm, EUpdateMethod.Update);
        }
Exemple #2
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));
 }
Exemple #3
0
        private static Document CreateDocumentFromFarm(Farm farm)
        {
            var doc = new Document();
            doc.Add(new Field("id", farm.FarmId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));
            doc.Add(new Field("name", farm.Name, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
            doc.Add(new NumericField("latitude", Field.Store.YES, true).SetDoubleValue(farm.Latitude));
            doc.Add(new NumericField("longitude", Field.Store.YES, true).SetDoubleValue(farm.Longitude));
            AddFieldIfNotNullOrEmpty(doc, "website", farm.Website);
            AddFieldIfNotNullOrEmpty(doc, "phone_number", farm.PhoneNumber);

            foreach (var product in farm.Products)
            {
                doc.Add(new Field("product_id", product.ProductId.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
                doc.Add(new Field("product_inStock", product.InStock.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
                doc.Add(new Field("product_name", product.Name, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO));
                AddFieldIfNotNullOrEmpty(doc, "product_description", product.Description, Field.Index.ANALYZED);
            }
            return doc;
        }
Exemple #4
0
 private static void DeleteFarmFromIndex(Farm farm, IndexWriter indexWriter, ApplicationDbContext db)
 {
     indexWriter.DeleteDocuments(new Term("id", farm.FarmId.ToString()));
     db.Farms.Remove(farm);
 }
Exemple #5
0
 private static void UpdateFarmInIndex(Farm farm, IndexWriter indexWriter, ApplicationDbContext db)
 {
     var doc = CreateDocumentFromFarm(farm);
     indexWriter.UpdateDocument(new Term("id", farm.FarmId.ToString()), doc);
     db.Entry(farm).State = EntityState.Modified;
     farm.IndexDateTime = DateTime.Now;
 }
Exemple #6
0
 private void AddFarmToIndex(Farm farm, IndexWriter indexWriter, ApplicationDbContext db)
 {
     var doc = CreateDocumentFromFarm(farm);
     indexWriter.AddDocument(doc);
     db.Entry(farm).State = EntityState.Modified;
     farm.IndexDateTime = DateTime.Now;
 }