private List <string> extractIdsFromArray(AValue array)
        {
            var ids = new List <string>();

            foreach (var el in array.castTo <AArray>().elements)
            {
                var value = el.castTo <AStruct>().get("Id").castTo <ASimpleValue>().Val;
                ids.Add(value);
            }
            return(ids);
        }
        private string extractId(AValue value)
        {
            var aval = value.castTo <ASimpleValue>();

            if (aval.unhashed != null)
            {
                return(aval.unhashed);
            }
            else
            {
                return(aval.Val);
            }
        }
 private string extractInRef(AValue value)
 {
     return(value.castTo <AIntRef>().instanceGuid);
 }
        private static TreeNode processField(String fieldName, AValue fieldValue, EbxDataContainers containers, TreeSettings settings)
        {
            TreeNode tnode = null;

            switch (fieldValue.Type)
            {
            case ValueTypes.SIMPLE:
                tnode = simpleFieldTNode(fieldName, fieldValue.castTo <ASimpleValue>().Val);
                break;

            case ValueTypes.NULL_REF:
                tnode = simpleFieldTNode(fieldName, "[null]");
                break;

            case ValueTypes.IN_REF:
                var aintref = fieldValue.castTo <AIntRef>();

                switch (aintref.refStatus)
                {
                case RefStatus.UNRESOLVED:
                    throw new Exception("At this point intrefs should be resolved!");

                case RefStatus.RESOLVED_SUCCESS:
                    if (settings.flatRefs)
                    {
                        var targetAStruct = settings.flattened
                                    ? containers.getFlattenedDataFor(aintref.instanceGuid)
                                    : containers.instances[aintref.instanceGuid].data;

                        tnode     = simpleFieldTNode(fieldName, targetAStruct.name);
                        tnode.Tag = new TNStructTag(targetAStruct);
                    }
                    else
                    {
                        tnode = simpleFieldTNode(fieldName, "INTREF");
                        var singletonContainerList = new List <DataContainer>();
                        singletonContainerList.Add(containers.instances[aintref.instanceGuid]);
                        tnode.Tag = new TNDataRootTag(singletonContainerList);
                    }
                    break;

                case RefStatus.RESOLVED_FAILURE:
                    tnode = simpleFieldTNode(fieldName, "Unresolved INTREF: " + aintref.instanceGuid);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                break;

            case ValueTypes.EX_REF:
                var aexref = fieldValue.castTo <AExRef>();

                var axrefStrRepr = settings.showGuids ? (aexref.instanceGuid + " ") : "";
                axrefStrRepr += (aexref.refStatus == RefStatus.RESOLVED_SUCCESS) ? $"[{aexref.refType}] {aexref.refName}" : "Unresolved";

                tnode = simpleFieldTNode(fieldName, axrefStrRepr);
                break;

            case ValueTypes.STRUCT:
                var astruct = fieldValue.castTo <AStruct>();

                var tnodeText = "";
                if (fieldName.Length > 0)
                {
                    tnodeText += fieldName + " -> ";
                }
                tnodeText += astruct.name;

                tnode     = new TreeNode(tnodeText);
                tnode.Tag = new TNStructTag(astruct);
                break;

            case ValueTypes.ARRAY:
                tnode     = new TreeNode(fieldName);
                tnode.Tag = new TNArrayTag(fieldValue.castTo <AArray>());
                break;
            }

            return(tnode);
        }
Beispiel #5
0
        public static void convertToText(string fieldName, AValue avalue, int indent, StringBuilder sb, List <string> partials)
        {
            if (avalue == null)
            {
                appendValue(fieldName, "null", indent, sb);
                return;
            }

            switch (avalue.Type)
            {
            case ValueTypes.SIMPLE:
                var asimpleval = avalue.castTo <ASimpleValue>();
                appendValue(fieldName, strB =>
                {
                    strB.Append(asimpleval.Val);
                    if (asimpleval.unhashed != null)
                    {
                        strB.Append(" / ").Append(asimpleval.unhashed);
                    }
                }, indent, sb);
                break;

            case ValueTypes.NULL_REF:
                appendTypeFieldname(fieldName, "NullRef", indent, sb);
                break;

            case ValueTypes.IN_REF:
                var ainref = avalue.castTo <AIntRef>();
                appendTypeFieldname(fieldName, "InRef", indent, sb);
                appendValue("instance", ainref.instanceGuid, indent + 1, sb);
                appendValue("status", ainref.refStatus.ToString(), indent + 1, sb);
                break;

            case ValueTypes.EX_REF:
                var aexref = avalue.castTo <AExRef>();
                appendTypeFieldname(fieldName, "ExRef", indent, sb);
                appendValue("ebx", aexref.fileGuid, indent + 1, sb);
                appendValue("instance", aexref.instanceGuid, indent + 1, sb);
                appendValue("refName", aexref.refName, indent + 1, sb);
                appendValue("refType", aexref.refType, indent + 1, sb);
                break;

            case ValueTypes.STRUCT:
                var astruct = avalue.castTo <AStruct>();
                appendTypeFieldname(fieldName, astruct.name, indent, sb);

                if (partials != null)
                {
                    foreach (var partial in partials)
                    {
                        appendWithIndent("- " + partial, indent + 2, sb);
                    }
                }

                foreach (var childField in astruct.fields)
                {
                    convertToText(childField.Key, childField.Value, indent + 1, sb, null);
                }

                break;

            case ValueTypes.ARRAY:
                var aarray = avalue.castTo <AArray>().elements;
                appendTypeFieldname(fieldName, "array", indent, sb);

                for (int i = 0; i < aarray.Count; i++)
                {
                    convertToText(i.ToString(), aarray[i], indent + 1, sb, null);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }