protected static Dictionary <string, PhoneArea> GetAllPhoneDictionary() { List <SystemPhoneAreaWrapper> phoneAreaWrappers = SystemPhoneAreaWrapper.FindAll(); Dictionary <string, PhoneArea> allPhoneDictionar = new Dictionary <string, PhoneArea>(); foreach (SystemPhoneAreaWrapper phoneAreaWrapper in phoneAreaWrappers) { PhoneArea phoneArea = new PhoneArea(); phoneArea.City = phoneAreaWrapper.City; phoneArea.Province = phoneAreaWrapper.Province; phoneArea.OperatorType = phoneAreaWrapper.OperatorType; allPhoneDictionar.Add(phoneAreaWrapper.PhonePrefix, phoneArea); } return(allPhoneDictionar); }
private void bgwDataToNoSQL_DoWork(object sender, DoWorkEventArgs doWorkEventArg) { List <SystemPhoneAreaWrapper> phoneAreaWrappers = SystemPhoneAreaWrapper.FindAll(); rowCounts = phoneAreaWrappers.Count; string title = string.Format("正在从数据库导入手机号段信息,共(" + rowCounts.ToString() + "条)."); SetTitle(title, rowCounts); var client = new MongoClient(Program.NoSQL_DBConnString); var server = client.GetServer(); var database = server.GetDatabase(Program.NoSQL_DbName); var collection = database.GetCollection(Program.NoSQL_CollectionName); int i = 0; foreach (SystemPhoneAreaWrapper phoneAreaWrapper in phoneAreaWrappers) { i++; if (bgwDataToNoSQL.CancellationPending) { break; } bgwDataToNoSQL.ReportProgress(i, rowCounts); ////var query = Query<PhoneArea>.EQ(e => e.PhonePrefix, phoneAreaWrapper.PhonePrefix); ////if (collection.FindOne(query) != null) ////{ //// this.Invoke(new Action(delegate() //// { //// this.lblProcessProgress.Text = "号码数据导入中( " + i.ToString() + "/" + rowCounts.ToString() + ")。。。"; //// })); //// continue; ////} var entity = new PhoneArea() { PhonePrefix = phoneAreaWrapper.PhonePrefix, Province = phoneAreaWrapper.Province, City = phoneAreaWrapper.City, OperatorType = phoneAreaWrapper.OperatorType, }; MongoInsertOptions mongoInsert = new MongoInsertOptions() { WriteConcern = WriteConcern.Unacknowledged }; rowSuccessCounts++; this.Invoke(new Action(delegate() { this.lblProcessProgress.Text = "号码数据导入中( " + i.ToString() + "/" + rowCounts.ToString() + ")。。。"; })); collection.Save(entity, mongoInsert); } }