Esempio n. 1
0
 public TextRKContainer(string fieldPath, AApiVersionedFields rootField, 
     TextReader reader, string absolutePath, Predicate<IResourceKey> validate,
     bool checkAltKeyFields = false)
     : base(fieldPath, rootField, absolutePath, validate)
 {
     this.SlurpReferenceRKs(reader, checkAltKeyFields);
 }
Esempio n. 2
0
 public RKContainer(string fieldPath, AApiVersionedFields rootField,
     string absolutePath, Predicate<IResourceKey> validate)
 {
     this.contentFieldPath = fieldPath;
     this.rootField = rootField;
     this.absolutePath = absolutePath;
     this.validate = validate;
 }
Esempio n. 3
0
        public void SetField(AApiVersionedFields owner, string field, DependentList<TGIBlock> tgiBlocks)
        {
            this.owner = owner;
            this.field = field;
            this.tgiBlocks = tgiBlocks;

            tgiBlockCombo1.TGIBlocks = this.tgiBlocks;
            tgiBlockCombo1.SelectedIndex = Convert.ToInt32(this.owner[this.field].Value);
        }
 public static TypedValue GetFieldValue(AApiVersionedFields owner, string field)
 {
     try
     {
         string index = GetFieldIndex(field);
         if (index == null)
         {
             TypedValue tv = owner[field];
             return(tv.Type == typeof(Double) || tv.Type == typeof(Single) ? new TypedValue(tv.Type, tv.Value, "R") : tv);
         }
         else if (owner is ArrayOwner)
         {
             return(owner[index]);
         }
         else
         {
             object o = ((IGenericAdd)owner[GetFieldName(field)].Value)[Convert.ToInt32("0x" + index.Substring(1, index.Length - 2), 16)];
             return(new TypedValue(o.GetType(), o));
         }
     }
     catch (Exception ex) { throw ex; }
 }
        public void SetField(AApiVersionedFields owner, string field)
        {
            type = AApiVersionedFields.GetContentFieldTypes(0, owner.GetType())[field];
            if (!(typeof(TextReader).IsAssignableFrom(type) || typeof(BinaryReader).IsAssignableFrom(type)))
                throw new InvalidCastException();
            this.owner = owner;
            this.field = field;
            btnImport.Enabled = owner.GetType().GetProperty(field).CanWrite;
            btnExport.Enabled = owner.GetType().GetProperty(field).CanRead;

            //TextReader does not have BaseStream, which is needed for ViewHex
            btnViewHex.Enabled = typeof(BinaryReader).IsAssignableFrom(type);

            btnEdit.Enabled = false;
            if (btnExport.Enabled && btnImport.Enabled)
            {
                bool hasText = S4PIDemoFE.Properties.Settings.Default.TextEditorCmd != null && S4PIDemoFE.Properties.Settings.Default.TextEditorCmd.Length > 0;
                bool hasHex = S4PIDemoFE.Properties.Settings.Default.HexEditorCmd != null && S4PIDemoFE.Properties.Settings.Default.HexEditorCmd.Length > 0;

                btnEdit.Enabled = (typeof(TextReader).IsAssignableFrom(type) && hasText) || (typeof(BinaryReader).IsAssignableFrom(type) && hasHex);
            }
        }
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            try
            {
                if (value == null)
                {
                    value = (AApiVersionedFields)GetFieldValue(owner, field).Value;
                }

                List <string> filter        = new List <string>(new string[] { "Stream", /*"AsBytes",/**/ "Value", });
                List <string> contentFields = value.ContentFields;
                List <TypedValuePropertyDescriptor> ltpdc = new List <TypedValuePropertyDescriptor>();
                foreach (string f in contentFields)
                {
                    if (filter.Contains(f))
                    {
                        continue;
                    }
                    if (!canWrite(value, f))
                    {
                        continue;
                    }
                    TypedValuePropertyDescriptor tvpd = new TypedValuePropertyDescriptor(value, f, null);
                    ltpdc.Add(new TypedValuePropertyDescriptor(value, f, new Attribute[] { new CategoryAttribute(tvpdToCategory(tvpd.PropertyType)) }));
                }
                List <PropertyDescriptor> lpdc = new List <PropertyDescriptor>(ltpdc.ToArray());
                int i = 0; while (i < ltpdc.Count && ltpdc[i].Priority < int.MaxValue)
                {
                    i++;
                }
                if (typeof(IDictionary).IsAssignableFrom(value.GetType()))
                {
                    lpdc.Insert(i, new IDictionaryPropertyDescriptor((IDictionary)value, "(this)", new Attribute[] { new CategoryAttribute("Lists") }));
                }
                return(new PropertyDescriptorCollection(lpdc.ToArray()));
            }
            catch (Exception ex) { throw ex; }
        }
Esempio n. 7
0
            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
            {
                EnumFlagsCTD ctd      = (EnumFlagsCTD)value;
                string       name     = ctd.field.Split(' ').Length == 1 ? ctd.field : ctd.field.Split(new char[] { ' ' }, 2)[1].Trim();
                Type         enumType = AApiVersionedFields.GetContentFieldTypes(0, ctd.owner.GetType())[name];
                int          bits     = underlyingTypeToBits(Enum.GetUnderlyingType(enumType));

                EnumFlagPropertyDescriptor[] enumFlags = new EnumFlagPropertyDescriptor[bits];
                string fmt = "[{0:X" + bits.ToString("X").Length + "}] ";

                for (int i = 0; i < bits; i++)
                {
                    ulong  u = (ulong)1 << i;
                    string s = (Enum)Enum.ToObject(enumType, u) + "";
                    if (s == u.ToString())
                    {
                        s = "-";
                    }
                    s            = String.Format(fmt, i) + s;
                    enumFlags[i] = new EnumFlagPropertyDescriptor(ctd.owner, ctd.field, u, s);
                }
                return(new PropertyDescriptorCollection(enumFlags));
            }
Esempio n. 8
0
        public void SetField(AApiVersionedFields owner, string field)
        {
            type = AApiVersionedFields.GetContentFieldTypes(0, owner.GetType())[field];
            if (!(typeof(TextReader).IsAssignableFrom(type) || typeof(BinaryReader).IsAssignableFrom(type)))
            {
                throw new InvalidCastException();
            }
            this.owner        = owner;
            this.field        = field;
            btnImport.Enabled = owner.GetType().GetProperty(field).CanWrite;
            btnExport.Enabled = owner.GetType().GetProperty(field).CanRead;

            //TextReader does not have BaseStream, which is needed for ViewHex
            btnViewHex.Enabled = typeof(BinaryReader).IsAssignableFrom(type);

            btnEdit.Enabled = false;
            if (btnExport.Enabled && btnImport.Enabled)
            {
                bool hasText = S4PIDemoFE.Properties.Settings.Default.TextEditorCmd != null && S4PIDemoFE.Properties.Settings.Default.TextEditorCmd.Length > 0;
                bool hasHex  = S4PIDemoFE.Properties.Settings.Default.HexEditorCmd != null && S4PIDemoFE.Properties.Settings.Default.HexEditorCmd.Length > 0;

                btnEdit.Enabled = (typeof(TextReader).IsAssignableFrom(type) && hasText) || (typeof(BinaryReader).IsAssignableFrom(type) && hasHex);
            }
        }
 public TypedValuePropertyDescriptor(AApiVersionedFields owner, string field, Attribute[] attrs)
     : base(field, attrs)
 {
     try
     {
         this.owner = owner;
         if (typeof(ArrayOwner).Equals(owner.GetType()))
         {
             fieldType = ((ArrayOwner)owner).ElementType;
         }
         else if (typeof(AsKVP).Equals(owner.GetType()))
         {
             fieldType = ((AsKVP)owner).GetType(Name);
         }
         else
         {
             string name = GetFieldName(field);
             fieldType = GetFieldType(owner, field);
             priority  = ElementPriorityAttribute.GetPriority(owner.GetType(), name);
             tgiBlocks = owner.GetTGIBlocks(name);
         }
     }
     catch (Exception ex) { throw ex; }
 }
 public AApiVersionedFieldsCTD(AApiVersionedFields value)
 {
     this.value = value;
 }
Esempio n. 11
0
 /*public override bool SetParentReferenceRK(IResourceKey newKey)
 {
     string[] fieldNames = this.contentFieldPath.Split(new char[] { '.' },
         StringSplitOptions.RemoveEmptyEntries);
     if (fieldNames.Length == 1)
     {
         IResourceKey rk = this.rootField as IResourceKey;
         rk.Instance = newKey.Instance;
     }
     int i, j, index, indexStrStart, indexStrLength;
     TypedValue tv;
     string name;
     AApiVersionedFields field = this.rootField;
     for (i = 1; i < fieldNames.Length; i++)
     {
         name = fieldNames[i];
         indexStrStart = name.IndexOf('[');
         if (indexStrStart == -1)
         {
             tv = field[name];
             // TODO: Should we account for the possibility of value type resource keys?
             if (typeof(IResourceKey).IsAssignableFrom(tv.Type))
             {
                 IResourceKey rk = tv.Value as IResourceKey;
                 rk.Instance = newKey.Instance;
                 field[name] = tv;
                 return true;
             }
             if (typeof(TextReader).IsAssignableFrom(tv.Type))
             {
                 this.textFieldHelper.SetReferenceRK(base.OriginalChildKey, newKey);
                 field[name] = new TypedValue(tv.Type, this.textFieldHelper.FlushReferenceRKs());
             }
             field = tv.Value as AApiVersionedFields;
         }
         else
         {
             indexStrLength = name.IndexOf(']');
             if (indexStrLength == -1)
                 indexStrLength = name.Length - 1 - indexStrStart;
             else
                 indexStrLength = indexStrLength - 1 - indexStrStart;
             index = int.Parse(name.Substring(indexStrStart, indexStrLength));
             tv = field[name.Substring(0, indexStrStart)];
             j = -1;
             foreach (var e in tv.Value as IEnumerable)
             {
                 if (index == ++j)
                 {
                     if (e is IResourceKey)
                     {
                         IResourceKey rk = e as IResourceKey;
                         rk.Instance = newKey.Instance;
                         return true;
                     }
                     else if (e is IEnumerable)
                     {
                         IEnumerable list = e as IEnumerable;
                         string suffix = name.Substring(indexStrStart + indexStrLength + 1);
                         indexStrStart = suffix.IndexOf('[');
                         while (indexStrStart != -1)
                         {
                             indexStrLength = suffix.IndexOf(']');
                             if (indexStrLength == -1)
                                 indexStrLength = suffix.Length - 1 - indexStrStart;
                             else
                                 indexStrLength = indexStrLength - 1 - indexStrStart;
                             int subIndex = int.Parse(suffix.Substring(indexStrStart, indexStrLength));
                             int k = -1;
                             foreach (var f in list)
                             {
                                 if (index == ++k)
                                 {
                                     if (f is IResourceKey)
                                     {
                                         IResourceKey rk = f as IResourceKey;
                                         rk.Instance = newKey.Instance;
                                         return true;
                                     }
                                     else if (f is IEnumerable)
                                     {
                                         list = f as IEnumerable;
                                         suffix = suffix.Substring(indexStrStart + indexStrLength + 1);
                                         indexStrStart = suffix.IndexOf('[');
                                     }
                                     else
                                     {
                                         field = f as AApiVersionedFields;
                                     }
                                 }
                             }
                         }
                     }
                     else
                     {
                         field = e as AApiVersionedFields;
                     }
                 }
             }
         }
     }
     return false;
 }/**/
 public DefaultConnection(IResourceKey rk,
     AApiVersionedFields rkField, ResourceDataActions childActions,
     string absolutePath, string rkFieldPath = "root",
     Predicate<IResourceKey> validate = null)
     : base(rk, absolutePath, childActions)
 {
     this.rkContainer = new RKContainer(rkFieldPath, rkField, absolutePath, validate);
 }
Esempio n. 12
0
 public NewGridForm(AApiVersionedFields field) : this(field, false) { }
Esempio n. 13
0
 public ArrayOwner(AApiVersionedFields owner, string field)
 {
     this.owner = owner; this.field = field; tv = owner[field]; list = (IList)tv.Value;
 }
Esempio n. 14
0
        /// <summary>
        /// Recursively searches the given field and all its fields for
        /// <see cref="T:s3pi.Interfaces.TGIBlock"/> instances,
        /// and compiles them into a dictionary with the content field path
        /// to access them from the given root field.
        /// </summary>
        public static Dictionary <string, R> SlurpRKsFromField <R>(string key,
                                                                   AApiVersionedFields field, bool includeDDSes = true)
            where R : class, IResourceKey
        {
            //.FindAll(key, x => x is TGIBlock || x is GenericRCOLResource.ChunkEntry)//Don't look inside ChunkEntries
            //.Where(x =>
            //    x.Item2 is TGIBlock//but we only actually want TGIBlocks
            //http://dino.drealm.info/develforums/s3pi/index.php?topic=1190.0 and maybe not DDSes
            //    && (includeDDSes || (!ddsResources.Contains((x.Item2 as TGIBlock).ResourceType))))

            Dictionary <string, R> subKeys, keys = new Dictionary <string, R>();

            if (field is R && (includeDDSes || !IsDDS((field as R).ResourceType)))
            {
                keys.Add(key, field as R);
            }

            List <string> contentFields = field.ContentFields;
            TypedValue    tv;
            string        contentField, elem, name;
            int           i, j;

            for (i = 0; i < contentFields.Count; i++)
            {
                contentField = contentFields[i];
                if (IsExcludedContentField(contentField))
                {
                    continue;
                }
                tv   = field[contentField];
                name = key + "." + contentField;

                // string is enumerable but we want to treat it as a single value
                if (typeof(string).IsAssignableFrom(tv.Type))
                {
                    continue;
                }

                else if (typeof(IEnumerable).IsAssignableFrom(tv.Type))
                {
                    j = 0;
                    foreach (var e in tv.Value as IEnumerable)
                    {
                        elem = name + "[" + (j++) + "]";
                        if (e is AApiVersionedFields)
                        {
                            subKeys = SlurpRKsFromField <R>(elem, e as AApiVersionedFields, includeDDSes);
                            foreach (KeyValuePair <string, R> subKey in subKeys)
                            {
                                keys.Add(subKey.Key, subKey.Value);
                            }
                        }
                        else if (e is R && (includeDDSes || !IsDDS((e as R).ResourceType)))
                        {
                            keys.Add(elem, e as R);
                        }
                    }
                }
                else if (typeof(AApiVersionedFields).IsAssignableFrom(tv.Type))
                {
                    subKeys = SlurpRKsFromField <R>(name, tv.Value as AApiVersionedFields, includeDDSes);
                    foreach (KeyValuePair <string, R> subKey in subKeys)
                    {
                        keys.Add(subKey.Key, subKey.Value);
                    }
                }
                else if (tv.Value is R && (includeDDSes || !IsDDS((tv.Value as R).ResourceType)))
                {
                    keys.Add(name, tv.Value as R);
                }
            }

            return(keys);
        }
Esempio n. 15
0
        // This is meant to be used to retrieve and change the part of the resource data
        // referenced by a node created with the SlurpRKsFromField function.
        // The path string should be stored in the connection itself,
        // since it's code in the connection that actually alters its parent's resource data.
        public static R GetRKfromField <R>(AApiVersionedFields field, string path)
            where R : class, IResourceKey
        {
            string[] fieldNames = path.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            if (fieldNames.Length == 0)
            {
                return(null);
            }
            if (fieldNames.Length == 1)
            {
                return(field as R);
            }
            int        i, j, index, indexStrStart, indexStrLength;
            TypedValue tv;
            string     name;

            for (i = 1; i < fieldNames.Length; i++)
            {
                name          = fieldNames[i];
                indexStrStart = name.IndexOf('[');
                if (indexStrStart == -1)
                {
                    try
                    {
                        tv = field[name];
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                    field = tv.Value as AApiVersionedFields;
                    if (field == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    indexStrLength = name.IndexOf(']');
                    if (indexStrLength == -1)
                    {
                        indexStrLength = name.Length - 1 - indexStrStart;
                    }
                    else
                    {
                        indexStrLength = indexStrLength - 1 - indexStrStart;
                    }
                    if (!int.TryParse(name.Substring(indexStrStart, indexStrLength), out index))
                    {
                        return(null);
                    }
                    try
                    {
                        tv = field[name.Substring(0, indexStrStart)];
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                    if (!typeof(IEnumerable).IsAssignableFrom(tv.Type))
                    {
                        return(null);
                    }
                    j = 0;
                    foreach (var e in tv.Value as IEnumerable)
                    {
                        if (j == index)
                        {
                            field = e as AApiVersionedFields;
                            break;
                        }
                        j++;
                    }
                    if (field == null)
                    {
                        return(null);
                    }
                }
            }
            return(field as R);
        }
Esempio n. 16
0
 public EnumChooserCTD(AApiVersionedFields owner, string field, object component)
 {
     this.owner = owner; this.field = field; this.component = component;
 }
Esempio n. 17
0
 public EnumFlagPropertyDescriptor(AApiVersionedFields owner, string field, ulong mask, string value) : base(value, null)
 {
     this.owner = owner; this.field = field; this.mask = mask;
 }
Esempio n. 18
0
 public TGIBlockListCTD(AApiVersionedFields owner, string field, object component)
 {
     this.owner = owner; this.field = field; this.component = component;
 }
Esempio n. 19
0
 public NewGridForm(AApiVersionedFields field) : this(field, false)
 {
 }
Esempio n. 20
0
        /// <param name="rkContainer">The container of the new resource key data;
        /// See remarks for currently supported types.</param>
        /// <param name="fieldPath">The string path of content fields
        /// and IEnumerable indices to follow to get to the Resource Key container
        /// to set to the value of the given container.</param>
        /// <remarks>
        /// Currently supported types for <paramref name="rkContainer"/>:
        /// <list type="bullet">
        /// <item><description>
        /// <see cref="T:s3pi.Interfaces.IResourceKey"/></description></item>
        /// <item><description>
        /// <see cref="T:System.IO.TextReader"/></description></item>
        /// <item><description>
        /// <see cref="T:System.IO.BinaryReader"/></description></item>
        /// </list>
        /// WARNING: The latter two items should be used with care,
        /// as they could result in an ArgumentException,
        /// TargetException, or TargetInvocationException
        /// if the content field uses a derived type instead of the base type.
        /// </remarks>
        public static bool SetRKInField(object rkContainer,
                                        string fieldPath, AApiVersionedFields rootField)
        {
            string[] fieldNames = fieldPath.Split(new char[] { '.' },
                                                  StringSplitOptions.RemoveEmptyEntries);
            IResourceKey newKey = rkContainer as IResourceKey;

            if (fieldNames.Length == 1)
            {
                IResourceKey rk = rootField as IResourceKey;
                rk.ResourceType  = newKey.ResourceType;
                rk.ResourceGroup = newKey.ResourceGroup;
                rk.Instance      = newKey.Instance;
            }
            int                 i, j, index, indexStrStart, indexStrLength;
            bool                endOfPath = false;
            object              elem, list = null;
            TypedValue          tv;
            string              name;
            AApiVersionedFields field = rootField;

            for (i = 1; i < fieldNames.Length; i++)
            {
                endOfPath     = (i == (fieldNames.Length - 1));
                name          = fieldNames[i];
                indexStrStart = name.IndexOf('[');
                if (indexStrStart == -1)
                {
                    tv = field[name];
                    if (typeof(IResourceKey).IsAssignableFrom(tv.Type) && endOfPath)
                    {
                        IResourceKey rk = (IResourceKey)tv.Value;
                        rk.ResourceType  = newKey.ResourceType;
                        rk.ResourceGroup = newKey.ResourceGroup;
                        rk.Instance      = newKey.Instance;
                        if (!tv.Type.IsClass)
                        {
                            field[name] = new TypedValue(tv.Type, rk);
                        }
                        return(true);
                    }
                    else if (typeof(AApiVersionedFields).IsAssignableFrom(tv.Type))
                    {
                        field = tv.Value as AApiVersionedFields;
                    }
                    // TODO: Is there a danger of type mismatch?
                    else if (typeof(TextReader).IsAssignableFrom(tv.Type) &&
                             rkContainer is TextReader)
                    {
                        field[name] = new TypedValue(tv.Type, rkContainer);
                    }
                    else if (typeof(BinaryReader).IsAssignableFrom(tv.Type) &&
                             rkContainer is BinaryReader)
                    {
                        field[name] = new TypedValue(tv.Type, rkContainer);
                    }
                }
                else
                {
                    tv   = field[name.Substring(0, indexStrStart)];
                    list = tv.Value;
                }
                while (indexStrStart != -1)
                {
                    indexStrLength = name.IndexOf(']');
                    if (indexStrLength == -1)
                    {
                        indexStrLength = name.Length - 1 - indexStrStart;
                    }
                    else
                    {
                        indexStrLength = indexStrLength - 1 - indexStrStart;
                    }
                    index = int.Parse(name.Substring(indexStrStart, indexStrLength));
                    if (list is IList)
                    {
                        elem = (list as IList)[index];
                        if (elem is IResourceKey && endOfPath)
                        {
                            IResourceKey rk = (IResourceKey)elem;
                            rk.ResourceType  = newKey.ResourceType;
                            rk.ResourceGroup = newKey.ResourceGroup;
                            rk.Instance      = newKey.Instance;
                            if (!elem.GetType().IsClass)
                            {
                                (list as IList)[index] = elem;
                            }
                            return(true);
                        }
                        else if (elem is IEnumerable)
                        {
                            name          = name.Substring(indexStrStart + indexStrLength + 1);
                            indexStrStart = name.IndexOf('[');
                            list          = elem;
                        }
                        else if (elem is AApiVersionedFields)
                        {
                            field = elem as AApiVersionedFields;
                        }
                        else if (elem is TextReader && rkContainer is TextReader)
                        {
                            (list as IList)[index] = rkContainer;
                        }
                        else if (elem is BinaryReader && rkContainer is BinaryReader)
                        {
                            (list as IList)[index] = rkContainer;
                        }
                    }
                    else // IEnumerable is last resort: value type & reader elements can't be changed
                    {
                        j = -1;
                        foreach (var e in list as IEnumerable)
                        {
                            if (index == ++j)
                            {
                                if (e is IResourceKey && endOfPath)
                                {
                                    IResourceKey rk = (IResourceKey)e;
                                    rk.ResourceType  = newKey.ResourceType;
                                    rk.ResourceGroup = newKey.ResourceGroup;
                                    rk.Instance      = newKey.Instance;
                                    return(true);
                                }
                                else if (e is IEnumerable)
                                {
                                    name          = name.Substring(indexStrStart + indexStrLength + 1);
                                    indexStrStart = name.IndexOf('[');
                                    list          = e;
                                }
                                else if (e is AApiVersionedFields)
                                {
                                    field = e as AApiVersionedFields;
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 21
0
 public NewGridForm(AApiVersionedFields field, bool main) : this(main) { FieldList = null; s4piPropertyGrid1.s4piObject = field; }
Esempio n. 22
0
 public NewGridForm(AApiVersionedFields field, bool main) : this(main) { FieldList = null; s4piPropertyGrid1.s4piObject = field; }
Esempio n. 23
0
        /// <summary>
        /// Recursively searches the given field and all its fields for 
        /// <see cref="T:s3pi.Interfaces.IResource"/> instances,
        /// and compiles them into a dictionary with the content field path
        /// to access them from the given root field.
        /// </summary>
        public static List<IResourceConnection> SlurpRKsFromField(string absolutePath,
            AApiVersionedFields rootField, List<RKContainer> containers,
            Predicate<IResourceKey> validate = null)
        {
            List<IResourceConnection> subKeys, keys = new List<IResourceConnection>();

            if (rootField is IResourceKey && (validate == null || validate(rootField as IResourceKey)))
                keys.Add(new DefaultConnection(rootField as IResourceKey, rootField,
                    ResourceDataActions.FindWrite, absolutePath));

            List<string> contentFields = rootField.ContentFields;
            TypedValue tv;
            string contentField, name, absoluteName;
            for (int i = 0; i < contentFields.Count; i++)
            {
                contentField = contentFields[i];
                if (IsExcludedContentField(contentField))
                    continue;
                tv = rootField[contentField];
                name = "root." + contentField;
                absoluteName = absolutePath + "." + contentField;

                // string is enumerable but we want to treat it as a single value
                if (typeof(string).IsAssignableFrom(tv.Type))
                    continue;

                else if (typeof(IEnumerable).IsAssignableFrom(tv.Type))
                {
                    subKeys = SlurpRKsFromIEnumerable(absoluteName, name, rootField,
                        tv.Value as IEnumerable, containers, validate);
                    keys.AddRange(subKeys);
                }
                else if (typeof(AApiVersionedFields).IsAssignableFrom(tv.Type))
                {
                    subKeys = SlurpRKsFromField(absoluteName,
                        tv.Value as AApiVersionedFields, containers, validate);
                    keys.AddRange(subKeys);
                }
                else if (typeof(TextReader).IsAssignableFrom(tv.Type))
                {
                    TextRKContainer textHelper = new TextRKContainer(name, rootField,
                        tv.Value as TextReader, absoluteName, validate);
                    keys.AddRange(textHelper.Owners);
                }
                else if (tv.Value is IResourceKey && (validate == null || validate(tv.Value as IResourceKey)))
                {
                    keys.Add(new DefaultConnection(tv.Value as IResourceKey, rootField,
                        ResourceDataActions.FindWrite, name));
                }
            }

            return keys;
        }
Esempio n. 24
0
 public static List<IResourceConnection> SlurpRKsFromIEnumerable(string absolutePath,
     string path, AApiVersionedFields rootField, IEnumerable list,
     List<RKContainer> containers, Predicate<IResourceKey> validate = null)
 {
     List<IResourceConnection> subKeys, keys = new List<IResourceConnection>();
     string elem, absoluteElem;
     int j = 0;
     foreach (var e in list)
     {
         elem = path + "[" + (j++) + "]";
         absoluteElem = absolutePath + "[" + j + "]";
         if (e is string)
         {
             continue;
         }
         if (e is IEnumerable)
         {
             subKeys = SlurpRKsFromIEnumerable(absoluteElem, elem, rootField,
                 e as IEnumerable, containers, validate);
             keys.AddRange(subKeys);
         }
         if (e is AApiVersionedFields)
         {
             subKeys = SlurpRKsFromField(absoluteElem, e as AApiVersionedFields,
                 containers, validate);
             keys.AddRange(subKeys);
         }
         else if (e is TextReader)
         {
             /* It is not possible to commit changes to any TextReader, BinaryReader,
                or value type element of an IEnumerable
                without replacing the entire IEnumerable instance in the content field,
                and that isn't possible without prior knowledge
                of the IEnumerable content field's type and constructor. */
         }
         else if (e is BinaryReader)
         {
         }
         else if (e is IResourceKey && (validate == null || validate(e as IResourceKey)))
         {
             keys.Add(new DefaultConnection(e as IResourceKey, rootField, ResourceDataActions.FindWrite, elem));
         }
     }
     return keys;
 }
Esempio n. 25
0
        public static List <IResourceConnection> SlurpRKsFromIEnumerable(string absolutePath,
                                                                         string path, AApiVersionedFields rootField, IEnumerable list,
                                                                         List <RKContainer> containers, Predicate <IResourceKey> validate = null)
        {
            List <IResourceConnection> subKeys, keys = new List <IResourceConnection>();
            string elem, absoluteElem;
            int    j = 0;

            foreach (var e in list)
            {
                elem         = path + "[" + (j++) + "]";
                absoluteElem = absolutePath + "[" + j + "]";
                if (e is string)
                {
                    continue;
                }
                if (e is IEnumerable)
                {
                    subKeys = SlurpRKsFromIEnumerable(absoluteElem, elem, rootField,
                                                      e as IEnumerable, containers, validate);
                    keys.AddRange(subKeys);
                }
                if (e is AApiVersionedFields)
                {
                    subKeys = SlurpRKsFromField(absoluteElem, e as AApiVersionedFields,
                                                containers, validate);
                    keys.AddRange(subKeys);
                }
                else if (e is TextReader)
                {
                    /* It is not possible to commit changes to any TextReader, BinaryReader,
                     * or value type element of an IEnumerable
                     * without replacing the entire IEnumerable instance in the content field,
                     * and that isn't possible without prior knowledge
                     * of the IEnumerable content field's type and constructor. */
                }
                else if (e is BinaryReader)
                {
                }
                else if (e is IResourceKey && (validate == null || validate(e as IResourceKey)))
                {
                    keys.Add(new DefaultConnection(e as IResourceKey, rootField, ResourceDataActions.FindWrite, elem));
                }
            }
            return(keys);
        }
Esempio n. 26
0
 /// <param name="rkContainer">The container of the new resource key data;
 /// See remarks for currently supported types.</param>
 /// <param name="fieldPath">The string path of content fields
 /// and IEnumerable indices to follow to get to the Resource Key container
 /// to set to the value of the given container.</param>
 /// <remarks>
 /// Currently supported types for <paramref name="rkContainer"/>:
 /// <list type="bullet">
 /// <item><description>
 /// <see cref="T:s3pi.Interfaces.IResourceKey"/></description></item>
 /// <item><description>
 /// <see cref="T:System.IO.TextReader"/></description></item>
 /// <item><description>
 /// <see cref="T:System.IO.BinaryReader"/></description></item>
 /// </list>
 /// WARNING: The latter two items should be used with care,
 /// as they could result in an ArgumentException, 
 /// TargetException, or TargetInvocationException
 /// if the content field uses a derived type instead of the base type.
 /// </remarks>
 public static bool SetRKInField(object rkContainer,
     string fieldPath, AApiVersionedFields rootField)
 {
     string[] fieldNames = fieldPath.Split(new char[] { '.' },
         StringSplitOptions.RemoveEmptyEntries);
     IResourceKey newKey = rkContainer as IResourceKey;
     if (fieldNames.Length == 1)
     {
         IResourceKey rk = rootField as IResourceKey;
         rk.ResourceType = newKey.ResourceType;
         rk.ResourceGroup = newKey.ResourceGroup;
         rk.Instance = newKey.Instance;
     }
     int i, j, index, indexStrStart, indexStrLength;
     bool endOfPath = false;
     object elem, list = null;
     TypedValue tv;
     string name;
     AApiVersionedFields field = rootField;
     for (i = 1; i < fieldNames.Length; i++)
     {
         endOfPath = (i == (fieldNames.Length - 1));
         name = fieldNames[i];
         indexStrStart = name.IndexOf('[');
         if (indexStrStart == -1)
         {
             tv = field[name];
             if (typeof(IResourceKey).IsAssignableFrom(tv.Type) && endOfPath)
             {
                 IResourceKey rk = (IResourceKey)tv.Value;
                 rk.ResourceType = newKey.ResourceType;
                 rk.ResourceGroup = newKey.ResourceGroup;
                 rk.Instance = newKey.Instance;
                 if (!tv.Type.IsClass)
                     field[name] = new TypedValue(tv.Type, rk);
                 return true;
             }
             else if (typeof(AApiVersionedFields).IsAssignableFrom(tv.Type))
             {
                 field = tv.Value as AApiVersionedFields;
             }
             // TODO: Is there a danger of type mismatch?
             else if (typeof(TextReader).IsAssignableFrom(tv.Type)
                 && rkContainer is TextReader)
             {
                 field[name] = new TypedValue(tv.Type, rkContainer);
             }
             else if (typeof(BinaryReader).IsAssignableFrom(tv.Type)
                 && rkContainer is BinaryReader)
             {
                 field[name] = new TypedValue(tv.Type, rkContainer);
             }
         }
         else
         {
             tv = field[name.Substring(0, indexStrStart)];
             list = tv.Value;
         }
         while (indexStrStart != -1)
         {
             indexStrLength = name.IndexOf(']');
             if (indexStrLength == -1)
                 indexStrLength = name.Length - 1 - indexStrStart;
             else
                 indexStrLength = indexStrLength - 1 - indexStrStart;
             index = int.Parse(name.Substring(indexStrStart, indexStrLength));
             if (list is IList)
             {
                 elem = (list as IList)[index];
                 if (elem is IResourceKey && endOfPath)
                 {
                     IResourceKey rk = (IResourceKey)elem;
                     rk.ResourceType = newKey.ResourceType;
                     rk.ResourceGroup = newKey.ResourceGroup;
                     rk.Instance = newKey.Instance;
                     if (!elem.GetType().IsClass)
                         (list as IList)[index] = elem;
                     return true;
                 }
                 else if (elem is IEnumerable)
                 {
                     name = name.Substring(indexStrStart + indexStrLength + 1);
                     indexStrStart = name.IndexOf('[');
                     list = elem;
                 }
                 else if (elem is AApiVersionedFields)
                 {
                     field = elem as AApiVersionedFields;
                 }
                 else if (elem is TextReader && rkContainer is TextReader)
                 {
                     (list as IList)[index] = rkContainer;
                 }
                 else if (elem is BinaryReader && rkContainer is BinaryReader)
                 {
                     (list as IList)[index] = rkContainer;
                 }
             }
             else // IEnumerable is last resort: value type & reader elements can't be changed
             {
                 j = -1;
                 foreach (var e in list as IEnumerable)
                 {
                     if (index == ++j)
                     {
                         if (e is IResourceKey && endOfPath)
                         {
                             IResourceKey rk = (IResourceKey)e;
                             rk.ResourceType = newKey.ResourceType;
                             rk.ResourceGroup = newKey.ResourceGroup;
                             rk.Instance = newKey.Instance;
                             return true;
                         }
                         else if (e is IEnumerable)
                         {
                             name = name.Substring(indexStrStart + indexStrLength + 1);
                             indexStrStart = name.IndexOf('[');
                             list = e;
                         }
                         else if (e is AApiVersionedFields)
                         {
                             field = e as AApiVersionedFields;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
 public ICollectionAApiVersionedFieldsCTD(AApiVersionedFields owner, string field, object component)
 {
     this.owner = owner; this.field = field; this.component = component;
 }
 public ConverterPropertyDescriptor(AApiVersionedFields owner, string field, object component, Attribute[] attr)
     : base(field, attr)
 {
     this.owner = owner; this.field = field; this.component = component;
 }
Esempio n. 29
0
        static void ReadConfig()
        {
            keywords.AddRange(reserved.ToArray());
            keywords.AddRange(AApiVersionedFields.GetContentFields(0, typeof(IResourceKey)).ToArray()); // must be correct case

            helpers = new Dictionary <string, Dictionary <string, string> >();

            // Parse *.helper in Helpers/ in folder where this assembly lives.

            string folder = Path.Combine(Path.GetDirectoryName(typeof(HelperManager).Module.FullyQualifiedName), "Helpers");

            foreach (string file in Directory.GetFiles(folder, "*.helper"))
            {
                StreamReader sr = new StreamReader(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read));
                Dictionary <string, string> target = new Dictionary <string, string>();
                target.Add("file", Path.GetFileNameWithoutExtension(file));

                bool inCommentBlock = false;

                for (string s = sr.ReadLine(); s != null; s = sr.ReadLine())
                {
                    s = s.Trim();

                    #region Comments
                    if (inCommentBlock)
                    {
                        int i = s.IndexOf("*/");
                        if (i > -1)
                        {
                            s = s.Substring(i + 2).Trim();
                            inCommentBlock = false;
                        }
                    }

                    string[] commentMarks = { "#", ";", "//" };
                    for (int i = 0; s.Length > 0 && i < commentMarks.Length; i++)
                    {
                        int j = s.IndexOf(commentMarks[i]);
                        if (j > -1)
                        {
                            s = s.Substring(0, j).Trim();
                        }
                    }

                    if (inCommentBlock || s.Length == 0)
                    {
                        continue;
                    }

                    if (s.Contains("/*"))
                    {
                        s = s.Substring(0, s.IndexOf("/*")).Trim();
                        inCommentBlock = true;
                    }
                    #endregion

                    string[] headtail = s.Trim().Split(new char[] { ':', '=' }, 2);
                    if (headtail.Length != 2)
                    {
                        continue;
                    }
                    string keyword = headtail[0].Trim();
                    if (reserved.Contains(keyword.ToLower()))
                    {
                        keyword = keyword.ToLower();
                    }
                    if (!keywords.Contains(keyword))
                    {
                        continue;
                    }
                    if (target.ContainsKey(keyword))
                    {
                        continue;
                    }
                    target.Add(keyword, headtail[1].Trim());
                }

                sr.Close();

                if (target.Count > 0 && target.ContainsKey("command"))
                {
                    helpers.Add(Path.GetFileNameWithoutExtension(file), target);
                }
            }
        }
Esempio n. 30
0
 public IResourceKeyCTD(AApiVersionedFields owner, string field, object component) : base(owner, field, component)
 {
 }