コード例 #1
0
 private void dgvDuplicated_SelectionChanged(object sender, EventArgs e)
 {
     dgvDuplicates.Rows.Clear();
     if (dgvDuplicated.CurrentRow != null)
     {
         var selectedRow = dgvDuplicated.CurrentRow;
         var matchingKey = selectedRow.Cells["key"].Value != null ? selectedRow.Cells["key"].Value.ToString() : string.Empty;
         if (!string.IsNullOrEmpty(matchingKey))
         {
             var duplicates = _duplicated[matchingKey];
             foreach (var item in duplicates)
             {
                 var rowIndex = dgvDuplicates.Rows.Add();
                 var row      = dgvDuplicates.Rows[rowIndex];
                 foreach (DataGridViewColumn col in dgvDuplicates.Columns)
                 {
                     var attr = col.Name;
                     row.Cells[attr].Value = GetAttributeDisplayValue(item, attr);
                 }
                 var url = CrmHelper.BuildRecordUrl(this.ConnectionDetail.WebApplicationUrl, _entities[item.LogicalName].ObjectTypeCode.Value, item.Id);
                 row.Cells["hiddenurl"].Value = url;
             }
         }
     }
 }
コード例 #2
0
 private void dgvDuplicated_SelectionChanged(object sender, EventArgs e)
 {
     dgvDuplicates.Rows.Clear();
     if (dgvDuplicated.CurrentRow != null && dgvDuplicated.SelectedRows.Count == 1)
     {
         var selectedRow = dgvDuplicated.CurrentRow;
         var matchingKey = selectedRow.Cells["key"].Value != null ? selectedRow.Cells["key"].Value.ToString() : string.Empty;
         if (!string.IsNullOrEmpty(matchingKey))
         {
             var duplicates = _dataProcessor.GetDuplicates(matchingKey);
             foreach (var item in duplicates)
             {
                 var entity   = item as IDictionary <string, object>;
                 var rowIndex = dgvDuplicates.Rows.Add();
                 var row      = dgvDuplicates.Rows[rowIndex];
                 foreach (DataGridViewColumn col in dgvDuplicates.Columns)
                 {
                     var attr = col.Name;
                     if (entity.ContainsKey(attr))
                     {
                         row.Cells[attr].Value = entity[attr];
                     }
                 }
                 var url = CrmHelper.BuildRecordUrl(this.ConnectionDetail.WebApplicationUrl, _entities[_dataProcessor.Config.TargetEntity].ObjectTypeCode.Value, (Guid)entity["Id"]);
                 row.Cells["hiddenurl"].Value = url;
             }
         }
     }
 }
コード例 #3
0
        public IEnumerable <DuplicatedDataModel> GetDuplicationGroups(IOrganizationService service)
        {
            var results = CrmHelper.GetAllData(service, Config.TargetEntity, _selectAttributes, Config.MatchAttributes, Config.ShouldIgnoreBlank);
            Func <Entity, IEnumerable <string>, string> groupingFunction = BuildMatchingKey;

            _duplicationGroups = results.ToLookup(e => groupingFunction(e, Config.MatchAttributes));
            //.SelectMany(g => g, (parent, child) => EntityToDynamic(child, parent.Key));

            return(_duplicationGroups.Where(g => g.Count() > 1)
                   .Select(g => new DuplicatedDataModel
            {
                MatchingKey = g.Key,
                DuplicatedData = EntityToDynamic(g.FirstOrDefault(), g.Key) as IDictionary <string, object>,
                DuplicatesCount = g.Count()
            }));
        }
コード例 #4
0
        private void LoadEntities()
        {
            WorkAsync(new WorkAsyncInfo
            {
                Message = "Loading entities...",
                Work    = (worker, args) =>
                {
                    args.Result = CrmHelper.GetEntitiesMetadata(Service);
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var result = args.Result as RetrieveMetadataChangesResponse;
                    if (result != null)
                    {
                        var entityMetadata = (EntityMetadataCollection)result.EntityMetadata;
                        _entities          = entityMetadata.ToDictionary(m => m.LogicalName);

                        var entities = entityMetadata.Select(m => new EntityMetadataModel()
                        {
                            DisplayName = GetEntityDisplayName(m),
                            LogicalName = m.LogicalName
                        })
                                       .OrderBy(e => e.DisplayName)
                                       .ThenBy(e => e.LogicalName).ToList();

                        entities.Insert(0, new EntityMetadataModel());

                        cbEntities.DataSource = entities;
                    }
                }
            });
        }
コード例 #5
0
        private void LoadData(string entity)
        {
            var matchAttributes = dgvFields.Rows.Cast <DataGridViewRow>()
                                  .Where(r => (bool)(r.Cells["colMatch"] as DataGridViewCheckBoxCell).Value)
                                  .Select(r => r.Cells["colLogicalName"].Value.ToString());

            var viewAttritues = dgvFields.Rows.Cast <DataGridViewRow>()
                                .Where(r => (bool)(r.Cells["colView"] as DataGridViewCheckBoxCell).Value)
                                .Select(r => r.Cells["colLogicalName"].Value.ToString());

            //TODO: check at least one column is cheked to match, and view
            if (matchAttributes.Count() == 0 || viewAttritues.Count() == 0)
            {
                MessageBox.Show("Please select at least one field to match and view", "Select Fields", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // add duplicated view columns
            AddViewColumns(dgvDuplicated, matchAttributes);
            dgvDuplicated.Columns.Add("count", "Duplicates Count");
            dgvDuplicated.Columns.Add("key", "Key");
            dgvDuplicated.Columns["key"].Visible = false;

            // add duplicates view columns
            AddViewColumns(dgvDuplicates, viewAttritues);
            dgvDuplicates.Columns.Add(new DataGridViewLinkColumn()
            {
                Name       = "url",
                HeaderText = "Record URL",
                Text       = "Link",
                UseColumnTextForLinkValue = true
            });
            dgvDuplicates.Columns.Add("hiddenurl", "hiddenurl");
            dgvDuplicates.Columns["hiddenurl"].Visible = false;

            // get selected attributes
            var attributes = new List <string>(matchAttributes.Count() + viewAttritues.Count());

            attributes.AddRange(matchAttributes);
            attributes.AddRange(viewAttritues);
            attributes = attributes.Distinct().ToList();

            WorkAsync(new WorkAsyncInfo
            {
                Message = string.Format($"Loading data..."),
                Work    = (worker, args) =>
                {
                    args.Result = CrmHelper.GetAllData(Service, entity, attributes, matchAttributes, chkIgnoreBlank.Checked);
                },
                PostWorkCallBack = (args) =>
                {
                    if (args.Error != null)
                    {
                        MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var result = args.Result as IEnumerable <Entity>;
                    if (result != null)
                    {
                        EntityMetadata metadata = null;
                        if (_entities.TryGetValue(entity, out metadata))
                        {
                            FindDuplicated(result, matchAttributes);
                        }
                    }
                }
            });
        }
コード例 #6
0
        private void LoadFields(string entity)
        {
            EntityMetadata metadata = null;

            if (_entities.TryGetValue(entity, out metadata))
            {
                var displayName = GetEntityDisplayName(metadata);
                WorkAsync(new WorkAsyncInfo
                {
                    Message = string.Format($"Loading {displayName}..."),
                    Work    = (worker, args) =>
                    {
                        args.Result = CrmHelper.GetEntityAttributes(Service, entity);
                    },
                    PostWorkCallBack = (args) =>
                    {
                        if (args.Error != null)
                        {
                            MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        var result = args.Result as RetrieveMetadataChangesResponse;
                        if (result != null)
                        {
                            var entityMetadata = (EntityMetadataCollection)result.EntityMetadata;
                            if (entityMetadata.Count == 1)
                            {
                                var entMetadata = entityMetadata[0];

                                _attributes = entMetadata.Attributes.ToDictionary(m => m.LogicalName);

                                var attritbutes = entMetadata.Attributes.Select(a => new AttributeMetadataModel()
                                {
                                    DisplayName = GetAttributeDisplayName(a),
                                    LogicalName = a.LogicalName,
                                    IsView      = a.IsPrimaryName ?? false
                                })
                                                  .OrderBy(a => a.DisplayName)
                                                  .ThenBy(a => a.LogicalName).ToList();

                                // use unbound grid to support column sorting
                                foreach (var item in attritbutes)
                                {
                                    var rowIndex = dgvFields.Rows.Add(item.DisplayName, item.LogicalName, item.IsMatch, item.IsView);
                                    // disable matching on primary id column
                                    if (_attributes[item.LogicalName].IsPrimaryId ?? false)
                                    {
                                        DisableCheckboxCell(dgvFields.Rows[rowIndex].Cells["colMatch"] as DataGridViewCheckBoxCell);
                                    }
                                    if (!(_attributes[item.LogicalName].IsValidForRead ?? true))
                                    {
                                        DisableCheckboxCell(dgvFields.Rows[rowIndex].Cells["colMatch"] as DataGridViewCheckBoxCell);

                                        DisableCheckboxCell(dgvFields.Rows[rowIndex].Cells["colView"] as DataGridViewCheckBoxCell);
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Metadata not found for entity " + displayName, "Load attribute metadata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Metadata not found for entity " + displayName, "Load attribute metadata", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                });
            }
        }