public void StartFuzzyMatch() { try { this.Invoke(new MethodInvoker(delegate { lblProgressTitle.Text = "Initializing ..."; })); this.Invoke(new MethodInvoker(delegate { pbFuzzyMatch.Position = 0; pbFuzzyMatch.Properties.Maximum = AccountIds.Count; })); DataImportUtility.ClearFuzzyLookupAccountMatches(ImportListId, AccountIds, true); SSISPackageMessage _PackageMsg = new SSISPackageMessage() { PackageID = Guid.NewGuid().ToString(), PackageType = "Account", Fuzzy_Match_Field = FuzzyMatchField, UserID = UserSession.CurrentUser.UserId, ImportFileID = FuzzyMatchArgs.import_file_id, Country = FuzzyMatchArgs.country, Similarity = FuzzyMatchArgs.similarity, Confidence = FuzzyMatchArgs.confidence, SimilarityOperator = FuzzyMatchArgs.similarity_operator, ConfidenceOperator = FuzzyMatchArgs.confidence_operator, Validated = FuzzyMatchArgs.validated }; m_Repository = new UserTextNotificationRepository(); m_PackageQueue = new SSISPackageQueue(); m_PackageQueue.AddMessage(_PackageMsg); string _NotificationTitle = string.Empty; if (_PackageMsg.Fuzzy_Match_Field == SSISPackageMessage.Fuzzy_Company_Name) _NotificationTitle = "AccountNotification_FuzzyCompanyName"; System.Threading.Thread.Sleep(500); this.Invoke(new MethodInvoker(delegate { lblProgressTitle.Text = "Processing fuzzy matches ..."; })); System.Threading.Thread.Sleep(500); /** * we will loop until the ssis package returns a message */ while (true) { try { this.Invoke(new MethodInvoker(delegate { lblProgressTitle.Text = "Processing fuzzy matches ... Getting queue message ..."; })); System.Threading.Thread.Sleep(3000); UserTextNotification[] userToasts = m_Repository.GetNotificationsForUser(UserSession.CurrentUser.UserId.ToString()); if (userToasts != null && userToasts.Length > 0) { var data = ( from UserTextNotification toast in userToasts where toast.Title == _NotificationTitle orderby toast.Timestamp descending select toast ).ToArray(); if (data != null) { this.Invoke(new MethodInvoker(delegate { lblProgressTitle.Text = "Processing fuzzy matches ... Getting processed items ..."; })); if (data[0].MessageText.ToLower().Equals("success")) { while (true) { System.Threading.Thread.Sleep(1000); BrightVision.Model.CTProcessedFuzzyLookupAccount _FuzzyMatching = DataImportUtility.CheckProcessedFuzzyMatchesCompanies(ImportListId); this.Invoke(new MethodInvoker(delegate { pbFuzzyMatch.Position = (int)_FuzzyMatching.items_processed; pbFuzzyMatch.Update(); })); if (_FuzzyMatching.items_processed == _FuzzyMatching.total_items) break; } this.Invoke(new MethodInvoker(delegate { lblProgressTitle.Text = "Done fuzzy matching ..."; })); m_Repository.DeleteNotification(data[0]); //m_objBrightPlatformEntity = new BrightPlatformEntities(UserSession.EntityConnection); //this.PopulateFuzzyLookupAccountList(); this.Invoke(new MethodInvoker(delegate { msgPopupRegular.Show(this, "Bright Manager", "Fuzzy matching successfully finished ..."); })); break; } } } } catch { } } } catch { } }
/// <summary> /// Execute fuzzy match /// </summary> private void ExecuteFuzzyMatch() { //gcma.DataSource = null; //gridControlSimilarity.DataSource = null; //lblConfidenceRowCount.Text = "Total Rows: 0"; //lblSimilarityRowCount.Text = "Total Rows: 0"; //richTextBoxMessageLog.Text = ""; //this.SetFocusedViewInstance(); //m_objGridView = (DevExpress.XtraGrid.Views.Grid.GridView) gcImportFile.FocusedView; //m_objImportProfileList = (ObjectImport.ImportListInstance)m_objGridView.GetFocusedRow(); if (m_objImportList == null) { tcManageImport.SelectedTabPage = tpProfiling; return; } WaitDialog.Show("Queueing process ..."); current_profile_list_id = m_objImportList.id; int _confidence = 0, _similarity = 0; int.TryParse(trackBarControlConfidence.EditValue.ToString(), out _confidence); int.TryParse(trackBarControlSimilarity.EditValue.ToString(), out _similarity); string _confidence_operator = comboBoxEditConfidence.EditValue.ToString(); string _similarity_operator = comboBoxEditSimilarity.EditValue.ToString(); byte _validated = (byte)m_MatchByAccountType; //string _fuzzy_ids = "'" + string.Join(",", m_FuzzyLookupAccountIds.ToArray()) + "'"; //todo: add value to this member; this is the selected ids to match. string _country = DataImportUtility.GetCountryCode(Convert.ToInt32(m_objImportList.country_id)); //todo: add value to this member; this is the country of search results string _fuzzy_match_field = SSISPackageMessage.Fuzzy_Company_Name; //check if combobox is match by fuzzy_company_name //Forms.FrmFuzzyMatching _frmFuzzyMatching = new Forms.FrmFuzzyMatching() { // FuzzyMatchArgs = new Forms.FrmFuzzyMatching.FuzzyMatchArguments() { // user_id = UserSession.CurrentUser.UserId, // import_file_id = m_objImportList.id, // country = _country, // confidence = _confidence, // similarity = _similarity, // confidence_operator = _confidence_operator, // similarity_operator = _similarity_operator, // validated = _validated // }, // ImportListId = m_objImportList.id, // AccountIds = m_FuzzyLookupAccountIds, // FuzzyMatchField = _fuzzy_match_field, // StartPosition = FormStartPosition.CenterParent //}; //_frmFuzzyMatching.ShowDialog(this.ParentForm); DataImportUtility.ClearFuzzyLookupAccountMatches(m_objImportList.id, m_FuzzyLookupAccountIds, true); ObjectArguments objArg = new ObjectArguments() { user_id = UserSession.CurrentUser.UserId, import_file_id = m_objImportList.id, country = _country, //fuzzy_ids = _fuzzy_ids, confidence = _confidence, similarity = _similarity, confidence_operator = _confidence_operator, similarity_operator = _similarity_operator, validated = _validated }; //simpleButtonStartMatching.Enabled = false; //simpleButtonSave.Enabled = false; // This snippet is used if the implementation is when using Azure Message Queue or Azure Storage API try { //SetMessage("Loading SSIS account package...", true); var packageMsg = new SSISPackageMessage(); packageMsg.PackageID = Guid.NewGuid().ToString(); packageMsg.PackageType = "Account"; packageMsg.Fuzzy_Match_Field = _fuzzy_match_field; packageMsg.UserID = UserSession.CurrentUser.UserId; packageMsg.ImportFileID = objArg.import_file_id; packageMsg.Country = objArg.country; packageMsg.Similarity = objArg.similarity; packageMsg.Confidence = objArg.confidence; packageMsg.SimilarityOperator = objArg.similarity_operator; packageMsg.ConfidenceOperator = objArg.confidence_operator; packageMsg.Validated = objArg.validated; /** / string _SSISPackageName = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SSISPackageName"]); string _SSISPackageServer = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SSISPackageServer"]); string _SSISPackageServerUsername = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SSISPackageServerUsername"]); string _SSISPackageServerPassword = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["SSISPackageServerPassword"]); Microsoft.SqlServer.Dts.Runtime.Application _app = new Microsoft.SqlServer.Dts.Runtime.Application(); //Microsoft.SqlServer.Dts.Runtime.Package pkg = _app.LoadFromDtsServer(_SSISPackageName, _SSISPackageServer, null); //new Microsoft.SqlServer.Dts.Runtime.Package(); Microsoft.SqlServer.Dts.Runtime.Package pkg = _app.LoadFromSqlServer(_SSISPackageName, _SSISPackageServer, _SSISPackageServerUsername, _SSISPackageServerPassword, null); pkg.Variables["import_file_id"].Value = objArg.import_file_id; pkg.Variables["country"].Value = objArg.country; pkg.Variables["similarity"].Value = objArg.similarity; pkg.Variables["confidence"].Value = objArg.confidence; pkg.Variables["similarity_operator"].Value = objArg.similarity_operator; pkg.Variables["confidence_operator"].Value = objArg.confidence_operator; pkg.Variables["validated"].Value = objArg.validated; DTSExecResult _result = pkg.Execute(); /**/ //SetMessage("Enqueuing account package to message queue...", true); m_oPackageQueue.AddMessage(packageMsg); gvImportFile.SetRowCellValue(gvImportFile.FocusedRowHandle, "fuzzy_match_status", "On Progress"); alertControlSSISPackage.Show(this.ParentForm, "Bright Manager", string.Format("Fuzzy matching now processed at background.{0}You can now proceed with other task.", Environment.NewLine)); WaitDialog.Close(); return; /** * temporarily commented so we can test the new implementation logic. * we will manually need to clear the UserTextNotification table on azure storage weekly. */ #region Commented /** / //SetMessage("Account package enqueued successfully.", true); //SetMessage("Please wait while the account package is being processed...", true); string notificationTitle = string.Empty; if (packageMsg.Fuzzy_Match_Field == SSISPackageMessage.Fuzzy_Company_Name) { WaitDialog.Show(ParentForm, "Processing..."); notificationTitle = "AccountNotification_FuzzyCompanyName"; } while (true) { try { System.Threading.Thread.Sleep(3000); //retrieve notifications UserTextNotification[] userToasts = m_oRepository.GetNotificationsForUser(UserSession.CurrentUser.UserId.ToString()); if (userToasts != null && userToasts.Length > 0) { var data = (from UserTextNotification toast in userToasts where toast.Title == notificationTitle orderby toast.Timestamp descending select toast).ToArray(); if (data != null) { int _MaxChecking = 0; if (data[0].MessageText.ToLower() == "success") { while (true) { System.Threading.Thread.Sleep(2000); CTProcessedFuzzyLookupAccount _item = ObjectImport.CheckProcessedFuzzyMatchesCompanies(m_objImportList.id); if (_item.items_processed == _item.total_items) break; //if (ObjectImport.DoneFuzzyMatchingCompanies(m_objImportList.id)) // break; _MaxChecking++; if (_MaxChecking == 10) break; } //delete notification after use m_oRepository.DeleteNotification(data[0]); //SetMessage("Loading results to grids...", true); //System.Threading.Thread.Sleep(10000); m_objBrightPlatformEntity = new BrightPlatformEntities(UserSession.EntityConnection); this.PopulateFuzzyLookupAccountList(); //gcMatchingCompany.DataSource = m_objBrightPlatformEntity.FIGetFuzzyAccounts(UserSession.CurrentUser.UserId, m_objImportList.id).ToList(); //gridControlConfidence.DataSource = m_objBrightPlatformEntity.FIGetFuzzyConfidenceAccounts(UserSession.CurrentUser.UserId).ToList(); //gridControlSimilarity.DataSource = m_objBrightPlatformEntity.FIGetFuzzySimilarityAccounts(UserSession.CurrentUser.UserId).ToList(); //lblConfidenceRowCount.Text = "Total Rows: " + gvMatchingCompany.RowCount.ToString("N0"); //lblSimilarityRowCount.Text = "Total Rows: " + gridViewSimilarity.RowCount.ToString("N0"); System.Threading.Thread thread = new System.Threading.Thread(ShowAccountAlerter); thread.Start(); WaitDialog.Close(); //simpleButtonStartMatching.Invoke((MethodInvoker)delegate //{ // simpleButtonStartMatching.Enabled = true; //}); //simpleButtonSave.Invoke((MethodInvoker)delegate //{ // simpleButtonSave.Enabled = true; //}); break; } } } } catch { } } /**/ #endregion } catch { // do nothing ... } #region Commented //catch //(Exception ex) //{ //simpleButtonStartMatching.Invoke((MethodInvoker)delegate //{ // simpleButtonStartMatching.Enabled = true; //}); //simpleButtonSave.Invoke((MethodInvoker)delegate //{ // simpleButtonSave.Enabled = true; //}); //} //[@jeff 09.28.2011]: http://brightvision.jira.com/browse/PLATFORM-562 //finally //{ //simpleButtonStartMatching.Invoke((MethodInvoker)delegate //{ // simpleButtonStartMatching.Enabled = true; //}); //simpleButtonSave.Invoke((MethodInvoker)delegate //{ // simpleButtonSave.Enabled = true; //}); //} //SetMessage("Package executed successfully.", true); //SetMessage("All completed.", false); //backgroundWorker1.RunWorkerAsync(objArg); #endregion }