private void Initialise()
        {
            EntityFilter     = Settings.EntityDataFilterArray.GetSelectedFilter();
            EntityDataFilter = EntityFilter.EntityFilterList.FirstOrDefault(filter => filter.LogicalName == LogicalName);

            if (EntityDataFilter == null)
            {
                EntityDataFilter = new EntityDataFilter(LogicalName);
                EntityFilter.EntityFilterList.Add(EntityDataFilter);
            }

            //Dispatcher.Invoke(() => TextBoxEnglishLabelField.DataContext = EntityDataFilter);

            new Thread(() =>
            {
                try
                {
                    ShowBusy("Building lists ...");

                    if (AttributeMetadataCache == null)
                    {
                        AttributeMetadataCache = Settings.ProfileAttributeMetadataCache;
                    }

                    if (!AttributeMetadataCache.ContainsKey(LogicalName))
                    {
                        AttributeMetadataCache[LogicalName] =
                            GetEntityMetadata().EntityMetadata.FirstOrDefault();
                        Settings.ProfileAttributeMetadataCache = AttributeMetadataCache;
                    }

                    Dispatcher.Invoke(GenerateLists);
                }
                catch (Exception ex)
                {
                    PopException(ex);
                }
                finally
                {
                    HideBusy();
                }
            }).Start();
        }
Beispiel #2
0
        private void InitEntityList()
        {
            Dispatcher.Invoke(Entities.Clear);

            var rowList = new List <EntityGridRow>();

            foreach (var entity in EntityMetadataCache)
            {
                var entityAsync = entity;

                Dispatcher.Invoke(() =>
                {
                    var dataFilter = EntityFilter.EntityFilterList
                                     .FirstOrDefault(filter => filter.LogicalName == entityAsync.LogicalName);

                    if (dataFilter == null)
                    {
                        dataFilter = new EntityDataFilter(entityAsync.LogicalName);
                        EntityFilter.EntityFilterList.Add(dataFilter);
                    }

                    var row = new EntityGridRow
                    {
                        IsSelected  = !dataFilter.IsExcluded,
                        Name        = entityAsync.LogicalName,
                        DisplayName =
                            entity.DisplayName?.UserLocalizedLabel == null || !Settings.UseDisplayNames
                                                                                            ? Naming.GetProperHybridName(entity.SchemaName, entity.LogicalName)
                                                                                            : Naming.Clean(entity.DisplayName.UserLocalizedLabel.Label),
                        Rename            = dataFilter.EntityRename,
                        IsGenerateMeta    = dataFilter.IsGenerateMeta,
                        IsOptionsetLabels = dataFilter.IsOptionsetLabels,
                        IsLookupLabels    = dataFilter.IsLookupLabels,
                        ValueClearMode    = dataFilter.ValueClearMode == null
                                                                                                     ? ClearModeEnumUi.Default
                                                                                                     : (ClearModeEnumUi)dataFilter.ValueClearMode
                    };

                    row.PropertyChanged += (sender, args) =>
                    {
                        if (args.PropertyName == "IsSelected")
                        {
                            dataFilter.IsExcluded = !row.IsSelected;
                        }
                        else if (args.PropertyName == "IsGenerateMeta")
                        {
                            dataFilter.IsGenerateMeta = row.IsGenerateMeta;
                        }
                        else if (args.PropertyName == "IsOptionsetLabels")
                        {
                            dataFilter.IsOptionsetLabels = row.IsOptionsetLabels;
                        }
                        else if (args.PropertyName == "IsLookupLabels")
                        {
                            dataFilter.IsLookupLabels = row.IsLookupLabels;
                        }
                        else if (args.PropertyName == "Rename")
                        {
                            dataFilter.EntityRename = row.Rename;
                        }
                        else if (args.PropertyName == "ValueClearMode")
                        {
                            switch (row.ValueClearMode)
                            {
                            case ClearModeEnumUi.Default:
                                dataFilter.ValueClearMode = null;
                                break;

                            default:
                                dataFilter.ValueClearMode =
                                    (ClearModeEnum?)row.ValueClearMode;
                                break;
                            }
                        }
                    };

                    rowList.Add(row);
                });
            }

            foreach (var row in rowList.OrderByDescending(row => row.IsSelected).ThenBy(row => row.Name))
            {
                Dispatcher.Invoke(() => Entities.Add(row));
            }

            // if no filter, select all
            if (EntityFilter.EntityFilterList.Count(filter => !filter.IsExcluded)
                == EntityMetadataCache.Count)
            {
                Dispatcher.Invoke(() => EntitiesSelectAll = true);
            }

            if (EntityFilter.EntityFilterList.Count(filter => filter.IsOptionsetLabels)
                == EntityMetadataCache.Count)
            {
                Dispatcher.Invoke(() => IsOptionsetLabelsSelectAll = true);
            }

            if (EntityFilter.EntityFilterList.Count(filter => filter.IsLookupLabels)
                == EntityMetadataCache.Count)
            {
                Dispatcher.Invoke(() => IsLookupLabelsSelectAll = true);
            }
        }