/// <summary> /// Displays the details of a single object. /// </summary> private void DisplaySingleObject(ObjectArguments objectArgs) { object obj = objectArgs.Object; int rootIndentLevel = objectArgs.RootIndentLevel; string title = objectArgs.Title; string objectName = objectArgs.ObjectName; Dictionary <Type, int> recursionTypeCount = objectArgs.RecursionTypeCount; object[] titleArgs = objectArgs.TitleArgs; int indentLevel = rootIndentLevel; bool objectIsNull = (obj == null); if (title != null && title.Trim().Length > 0) { // Do not write newline if object is null - will append to line. bool includeNewLine = !objectIsNull; this.DisplayHeadedText(indentLevel, title, false, includeNewLine, titleArgs); indentLevel++; } if (objectIsNull) { // Only add leading space if a title was written. bool addLeadingSpace = (indentLevel > rootIndentLevel); this.DisplayAppendedText(_nullDisplayText, addLeadingSpace, true); return; } List <MemberDetails> memberDetails = new List <MemberDetails>(); PropertyInfo[] properties = obj.GetType().GetProperties(); foreach (PropertyInfo property in properties) { memberDetails.Add(new MemberDetails(property.Name, property.MemberType, property.PropertyType, property.GetValue(obj, null), new Dictionary <Type, int>(recursionTypeCount))); } FieldInfo[] fields = obj.GetType().GetFields(); foreach (FieldInfo field in fields) { memberDetails.Add(new MemberDetails(field.Name, field.MemberType, field.FieldType, field.GetValue(obj), new Dictionary <Type, int>(recursionTypeCount))); } for (int i = 0; i < memberDetails.Count; i++) { MemberDetails member = memberDetails[i]; DisplayObjectMember(member, obj, indentLevel); } }
/// <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 }
/// <summary> /// Displays the details of a property or field of an object. /// </summary> /// <remarks>Helper method for DisplaySingleObject.</remarks> private void DisplayObjectMember(MemberDetails memberDetails, object parentObj, int rootIndentLevel, bool simpleDataTypesOnly, Dictionary <Type, List <object> > referenceTypeObjectRegister) { int indentLevel = rootIndentLevel; string memberName = memberDetails.Name; object memberValue = memberDetails.Value; Type memberType = memberDetails.Type; bool memberValueIsNull = (memberValue == null); bool memberIsEnumerable = !(memberValue is string) && memberValue is IEnumerable; bool memberIsEmptyEnumerable = false; bool memberIsReferenceType = this.TypeIsReferenceType(memberType); if (!memberValueIsNull && memberIsEnumerable) { memberIsEmptyEnumerable = true; IEnumerable enumerable = memberValue as IEnumerable; foreach (object item in enumerable) { memberIsEmptyEnumerable = false; break; } } Dictionary <Type, int> recursionTypeCount = memberDetails.RecursionTypeCount; if (recursionTypeCount.ContainsKey(memberType)) { recursionTypeCount[memberType]++; } else { recursionTypeCount[memberType] = 1; } bool maxRecursionDepthReached = (recursionTypeCount[memberType] >= _maxRecursionDepth); string displayValue = (memberValue == null) ? _nullDisplayText : memberValue.ToString(); string displayMemberType = (memberDetails.MemberType == MemberTypes.Field) ? " (field)" : string.Empty; // Value tyeps and strings - just write value then stop because the member can't be // an object with its own members. if (!memberIsReferenceType) { this.DisplayHeadedText(indentLevel, "{0}{1}: {2}", false, true, memberName, displayMemberType, displayValue); return; } bool memberObjectAlreadyDisplayed = false; object previousReferenceToObject = null; List <object> previouslyDisplayedObjectsOfSameType = null; if (referenceTypeObjectRegister.TryGetValue(memberType, out previouslyDisplayedObjectsOfSameType)) { previousReferenceToObject = previouslyDisplayedObjectsOfSameType.Find(item => (item == memberValue)); } else { previouslyDisplayedObjectsOfSameType = new List <object>(); referenceTypeObjectRegister.Add(memberType, previouslyDisplayedObjectsOfSameType); } if (previousReferenceToObject != null) { memberObjectAlreadyDisplayed = true; } else { previouslyDisplayedObjectsOfSameType.Add(memberValue); } // Do not write newline in the following cicumstances (will want to add further text // to the same line): // Member value is null; or // Member is an empty collection; or // We don't want to display the details of complex members; or // Member object has already been displayed because of circular references; or // Maximum recursion depth has been reached. bool includeNewLine = (!memberValueIsNull && !memberIsEmptyEnumerable && !simpleDataTypesOnly && !memberObjectAlreadyDisplayed && !maxRecursionDepthReached); string displayFormat; if (displayMemberType.ToLower().Contains("field")) { displayFormat = "{0} (field, type: {1}):"; } else { displayFormat = "{0} (type: {1}):"; } this.DisplayHeadedText(indentLevel, displayFormat, false, includeNewLine, memberName, memberType.FullName); indentLevel++; if (memberValueIsNull) { this.DisplayAppendedText(_nullDisplayText, true, true); return; } if (memberIsEmptyEnumerable) { this.DisplayAppendedText(_emptyEnumerableDisplayText, true, true); return; } // We would have exited above if the member was a value type or string so the member // must be a complex type. if (simpleDataTypesOnly) { this.DisplayAppendedText(_simpleTypesOnlyText, true, true); return; } if (memberObjectAlreadyDisplayed) { this.DisplayAppendedText(_referenceObjectAlreadyDisplayedText, true, true); return; } if (maxRecursionDepthReached) { this.DisplayAppendedText(_maxRecursionDepthText, true, true); return; } if (memberIsEnumerable) { int i = 0; IEnumerable enumerable = memberValue as IEnumerable; foreach (object item in enumerable) { if (!this.ObjectIsReferenceType(item)) { this.DisplayHeadedText(indentLevel, "{0}[{1}]: {2}", false, true, memberName, i, item.ToString()); } else { this.DisplayHeadedText(indentLevel, "{0}[{1}] (type: {2}):", false, true, memberName, i, item.GetType().FullName); ObjectArguments itemObjectArguments = new ObjectArguments(item, indentLevel + 1, referenceTypeObjectRegister, null); itemObjectArguments.SimpleDataTypesOnly = simpleDataTypesOnly; DisplaySingleObject(itemObjectArguments); } i++; } return; } ObjectArguments objectArguments = new ObjectArguments(memberValue, indentLevel, null, recursionTypeCount, simpleDataTypesOnly, referenceTypeObjectRegister, memberName); DisplaySingleObject(objectArguments); }
/// <summary> /// Displays the details of a single object. /// </summary> private void DisplaySingleObject(ObjectArguments objectArgs) { object obj = objectArgs.Object; int rootIndentLevel = objectArgs.RootIndentLevel; string objectName = objectArgs.ObjectName; Dictionary <Type, int> recursionTypeCount = objectArgs.RecursionTypeCount; Dictionary <Type, List <object> > referenceTypeObjectRegister = objectArgs.ReferenceTypeObjectRegister; bool simpleDataTypesOnly = objectArgs.SimpleDataTypesOnly; string title = objectArgs.Title; object[] titleArgs = objectArgs.TitleArgs; int indentLevel = rootIndentLevel; bool objectIsNull = (obj == null); if (title != null && title.Trim().Length > 0) { // Do not write newline if object is null - will append to line. bool includeNewLine = !objectIsNull; this.DisplayHeadedText(indentLevel, title, false, includeNewLine, titleArgs); indentLevel++; } if (objectIsNull) { // Only add leading space if a title was written. bool addLeadingSpace = (indentLevel > rootIndentLevel); this.DisplayAppendedText(_nullDisplayText, addLeadingSpace, true); return; } if (this.ObjectIsReferenceType(obj)) { if (!this.ObjectHasPreviouslyBeenDisplayed(referenceTypeObjectRegister, obj)) { this.AddObjectToRegister(referenceTypeObjectRegister, obj); } } List <MemberDetails> memberDetails = new List <MemberDetails>(); PropertyInfo[] properties = obj.GetType().GetProperties(); foreach (PropertyInfo property in properties) { if (!property.GetGetMethod().IsStatic) { object value = null; try { value = property.GetValue(obj, null); } catch (Exception ex) { value = string.Format("[UNABLE TO READ VALUE] {0}: {1}", ex.GetType().Name, ex.Message); } memberDetails.Add(new MemberDetails(property.Name, property.MemberType, property.PropertyType, value, new Dictionary <Type, int>(recursionTypeCount))); } } FieldInfo[] fields = obj.GetType().GetFields(); foreach (FieldInfo field in fields) { if (!field.IsStatic) { object value = null; try { value = field.GetValue(obj); } catch (Exception ex) { value = string.Format("[UNABLE TO READ VALUE] {0}: {1}", ex.GetType().Name, ex.Message); } memberDetails.Add(new MemberDetails(field.Name, field.MemberType, field.FieldType, value, new Dictionary <Type, int>(recursionTypeCount))); } } for (int i = 0; i < memberDetails.Count; i++) { MemberDetails member = memberDetails[i]; DisplayObjectMember(member, obj, indentLevel, simpleDataTypesOnly, referenceTypeObjectRegister); } }
/// <summary> /// Displays the details of a property or field of an object. /// </summary> /// <remarks>Helper method for DisplaySingleObject.</remarks> private void DisplayObjectMember(MemberDetails memberDetails, object parentObj, int rootIndentLevel) { int indentLevel = rootIndentLevel; string memberName = memberDetails.Name; object memberValue = memberDetails.Value; Type memberType = memberDetails.Type; bool memberValueIsNull = (memberValue == null); bool memberIsEnumerable = !(memberValue is string) && memberValue is IEnumerable; bool memberIsEmptyEnumerable = false; if (!memberValueIsNull && memberIsEnumerable) { memberIsEmptyEnumerable = true; IEnumerable enumerable = memberValue as IEnumerable; foreach (object item in enumerable) { memberIsEmptyEnumerable = false; break; } } Dictionary <Type, int> recursionTypeCount = memberDetails.RecursionTypeCount; if (recursionTypeCount.ContainsKey(memberType)) { recursionTypeCount[memberType]++; } else { recursionTypeCount[memberType] = 1; } bool maxRecursionDepthReached = (recursionTypeCount[memberType] >= _maxRecursionDepth); string displayValue = (memberValue == null) ? _nullDisplayText : memberValue.ToString(); string displayMemberType = (memberDetails.MemberType == MemberTypes.Field) ? " (field)" : string.Empty; if (memberType.IsValueType || memberType == typeof(string)) { this.DisplayHeadedText(indentLevel, "{0}{1}: {2}", false, true, memberName, displayMemberType, displayValue); return; } // Do not write newline if member value is null, member is an empty collection or // maximum recursion depth has been reached - will append to line. bool includeNewLine = (!memberValueIsNull && !memberIsEmptyEnumerable && !maxRecursionDepthReached); string displayFormat; if (displayMemberType.ToLower().Contains("field")) { displayFormat = "{0} (field, type: {1}):"; } else { displayFormat = "{0} (type: {1}):"; } this.DisplayHeadedText(indentLevel, displayFormat, false, includeNewLine, memberName, memberType.FullName); indentLevel++; if (maxRecursionDepthReached) { this.DisplayAppendedText(_maxRecursionDepthText, true, true); return; } if (memberValueIsNull) { this.DisplayAppendedText(_nullDisplayText, true, true); return; } if (memberIsEmptyEnumerable) { this.DisplayAppendedText(_emptyEnumerableDisplayText, true, true); return; } if (memberIsEnumerable) { int i = 0; IEnumerable enumerable = memberValue as IEnumerable; foreach (object item in enumerable) { if (item.GetType().IsValueType || item is string) { this.DisplayHeadedText(indentLevel, "{0}[{1}]: {2}", false, true, memberName, i, item.ToString()); } else { this.DisplayHeadedText(indentLevel, "{0}[{1}] (type: {2}):", false, true, memberName, i, item.GetType().FullName); ObjectArguments itemObjectArguments = new ObjectArguments(item, indentLevel + 1, null); DisplaySingleObject(itemObjectArguments); } i++; } return; } ObjectArguments objectArguments = new ObjectArguments(memberValue, indentLevel, null, memberName, recursionTypeCount); DisplaySingleObject(objectArguments); }