Example #1
0
        private void SavePriorityKeyword(int newPriority)
        {
            if (MessageBox.Show("Bạn có muốn lưu khôn=g?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
            {
                MessageBox.Show("Vui lòng đợi hoàn thành");
                Thread threadHideData = new Thread(() =>
                {
                    MongoDbRaoVat mongoDb = new MongoDbRaoVat();
                    try
                    {
                        int iRowCount = this.gridView1.DataRowCount;
                        for (int iRow = 0; iRow < iRowCount; iRow++)
                        {
                            KeywordSaleNew keyword = this.gridView1.GetRow(iRow) as KeywordSaleNew;
                            if (keyword.is_selected)
                            {
                                //SaveMongoDb.
                                bool bOK = this.monoDbAdapter.UpdatePriorityKeyword(keyword._id, newPriority);
                                if (bOK == false)
                                {
                                    WriteLog("MongoUpdate", string.Format("Fail keyword:{0}", keyword.name));
                                }
                                else
                                {
                                    WriteLog("MongoUpdate", string.Format("Success keyword:{0}", keyword.name));
                                    //Sync item in mongo and solr.
                                    string Webdomain      = "raovat";
                                    string URLSolrConnect = "http://183.91.14.85:8983/solr/keywords";
                                    var slr = SolrRaoVatKeywordDriver.GetDriver(SolrRaoVatKeywordDriver.GetInstance());

                                    BsonDocument document = mongoDb.GetKeyWordID(keyword._id).Result;
                                    if (document != null)
                                    {
                                        KeywordSaleNew keyword1 = mongoDb.ParseKeyWord(document);
                                        bool bOKSolr            = slr.UpdateData(keyword1);
                                        if (!bOKSolr)
                                        {
                                            WriteLog("SolrUpdate", string.Format("Fail keyword:{0}", keyword1.name));
                                        }
                                    }
                                }
                            }
                        }
                        this.Invoke(new Action(() =>
                        {
                            MessageBox.Show("Saved priority keyword!");
                        }));
                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat(ex.Message);
                    }
                });
                threadHideData.Start();
                this.btnLoadData.PerformClick();
            }
        }
Example #2
0
 private void SyncKeywordMongoAndSolr()
 {
     try
     {
         int iCount = 0;
         while (!bPause)
         {
             var           slr     = SolrRaoVatKeywordDriver.GetDriver(SolrRaoVatKeywordDriver.GetInstance());
             MongoDbRaoVat mongoDb = new MongoDbRaoVat();
             while (!this.bPause)
             {
                 List <KeywordSaleNew> lstKeywordNeedUpdate = mongoDb.GetListKeywordNeedUpdate();
                 if (lstKeywordNeedUpdate.Count > 0)
                 {
                     foreach (var item in lstKeywordNeedUpdate)
                     {
                         bool bOK = slr.UpdateData(item);
                         if (bOK)
                         {
                             long iOK = mongoDb.colKeyWord.UpdateOneAsync(Builders <BsonDocument> .Filter.Eq("_id", ObjectId.Parse(item._id)),
                                                                          Builders <BsonDocument> .Update.Set("is_solr_updated", true)
                                                                          .CurrentDate("solr_updated_at")).Result.ModifiedCount;
                             if (iOK > 0)
                             {
                                 iCount++;
                                 WriteLog(string.Format("Updated keyword {0}: {1}", iCount, item.name));
                             }
                         }
                     }
                 }
                 else
                 {
                     this.Invoke(new Action(() =>
                     {
                         WriteLog(string.Format("\r\nNot item need upload. Sleep 10s"));
                     }));
                     Thread.Sleep(10000);
                 }
             }
             Thread.Sleep(5000);
         }
     }
     catch (ThreadAbortException threadAbortEx)
     {
         return;
     }
     catch (Exception ex)
     {
         log.ErrorFormat(ex.Message);
     }
 }