public override DataItem LoadData(XElement element, UndoRedoManager undoRedo)
        {
            var key = element.Attribute(MetaNS + "RefKey")?.Value?.ToString();

            if (key == null)
            {
                key = element.Attribute("RefKey")?.Value?.ToString();
            }

            if (key == null && Definitions.Count == 1 && !IsNullable)
            {
                key = Definitions.First().Key;
            }

            ReferenceItem item = null;

            if (key != null && Definitions.ContainsKey(key))
            {
                var def = Definitions[key];

                item = new ReferenceItem(this, undoRedo);
                item.ChosenDefinition = def;

                var loaded = def.LoadData(element, undoRedo);
                item.WrappedItem = loaded;
            }
            else
            {
                item = CreateData(undoRedo) as ReferenceItem;
            }

            foreach (var att in Attributes)
            {
                var      el      = element.Attribute(att.Name);
                DataItem attItem = null;

                if (el != null)
                {
                    attItem = att.LoadData(new XElement(el.Name, el.Value.ToString()), undoRedo);
                }
                else
                {
                    attItem = att.CreateData(undoRedo);
                }
                item.Attributes.Add(attItem);
            }

            return(item);
        }
Ejemplo n.º 2
0
            private ImmutableArray <DefinitionItem> GetDefinitionsToCreateMissingReferenceItemsFor(
                bool whenGroupingByDefinition
                )
            {
                lock (Gate)
                {
                    var entries = whenGroupingByDefinition
                        ? EntriesWhenGroupingByDefinition
                        : EntriesWhenNotGroupingByDefinition;

                    // Find any definitions that we didn't have any references to. But only show
                    // them if they want to be displayed without any references.  This will
                    // ensure that we still see things like overrides and whatnot, but we
                    // won't show property-accessors.
                    var seenDefinitions = entries
                                          .Select(r => r.DefinitionBucket.DefinitionItem)
                                          .ToSet();
                    var q =
                        from definition in Definitions
                        where
                        !seenDefinitions.Contains(definition) &&
                        definition.DisplayIfNoReferences
                        select definition;

                    // If we find at least one of these types of definitions, then just return those.
                    var result = ImmutableArray.CreateRange(q);
                    if (result.Length > 0)
                    {
                        return(result);
                    }

                    // We found no definitions that *want* to be displayed.  However, we still
                    // want to show something.  So, if necessary, show at lest the first definition
                    // even if we found no references and even if it would prefer to not be seen.
                    if (entries.Count == 0 && Definitions.Count > 0)
                    {
                        return(ImmutableArray.Create(Definitions.First()));
                    }

                    return(ImmutableArray <DefinitionItem> .Empty);
                }
            }
Ejemplo n.º 3
0
        public List <Table> LoadBaseTables(string baseRomXmlId, List <string> inheritedRomIds)
        {
            if (string.IsNullOrEmpty(baseRomXmlId))
            {
                //No base table to load.
                return(null);
            }

            var rom    = Definitions.First(d => d.RomId.XmlId == baseRomXmlId);
            var tables = Clone(rom.Tables);

            inheritedRomIds.Add(baseRomXmlId);
            List <Table> output = LoadBaseTables(rom.Base, inheritedRomIds);

            if (output == null)
            {
                //No base tables to merge return tables.
                return(tables);
            }

            foreach (var sourceTable in tables)
            {
                var targetTable = output.FirstOrDefault(t => t.Name == sourceTable.Name);

                if (targetTable == null)
                {
                    //table doesn't exist in base definition. Assuming its a new definition.
                    output.Add(sourceTable);
                    continue;
                }

                CopyValues(targetTable, sourceTable);
                RecursiveLoadAxisMetaData(targetTable, sourceTable);
            }

            return(output);
        }