Exemple #1
0
    public static void AppendToDB(DataboxObject _database, string _tableName, List <Entry> _entries)
    {
        // Add entries
        for (int e = 0; e < _entries.Count; e++)
        {
            for (int a = 0; a < _entries[e].values.Count; a++)
            {
                var _type     = System.Type.GetType(_entries[e].types[a]);
                var _instance = System.Activator.CreateInstance(_type) as DataboxType;

                // Convert csv string value to DataboxType value
                _instance.Convert(_entries[e].values[a]);

                _database.AddData(_tableName, _entries[e].entryName, _entries[e].fields[a], _instance as DataboxType);
            }
        }
    }
Exemple #2
0
    public static void ReplaceDB(DataboxObject _database, string _tableName, List <Entry> _entries)
    {
        if (firstTimeReplace)
        {
            _database.DB     = new Databox.Dictionary.OrderedDictionary <string, DataboxObject.Database>();
            firstTimeReplace = false;
        }

        // Add entries
        for (int e = 0; e < _entries.Count; e++)
        {
            for (int a = 0; a < _entries[e].values.Count; a++)
            {
                var _type     = System.Type.GetType(_entries[e].types[a]);
                var _instance = System.Activator.CreateInstance(_type) as DataboxType;

                // Convert csv string value to DataboxType value
                _instance.Convert(_entries[e].values[a]);

                _database.AddData(_tableName, _entries[e].entryName, _entries[e].fields[a], _instance as DataboxType);
            }
        }
    }
Exemple #3
0
    public static void ReplaceDB(DataboxObject _database, string _tableName, List <Entry> _entries, bool _isLocalizationTable)
    {
        if (firstTimeReplace)
        {
            _database.DB     = new Databox.Dictionary.OrderedDictionary <string, DataboxObject.Database>();
            firstTimeReplace = false;
        }

        if (_isLocalizationTable)
        {
            bool _isLanguageType     = false;
            bool _isLocalizationType = false;



            if (_entries[0].types[0].Contains("LanguagesType"))
            {
                _isLanguageType = true;
            }
            else if (_entries[0].types[0].Contains("LocalizationType"))
            {
                _isLocalizationType = true;
            }


            // LANGUAGE TYPE
            if (_isLanguageType)
            {
                for (int e = 0; e < _entries.Count; e++)
                {
                    System.Type _foundType = null;

                    foreach (System.Reflection.Assembly a in System.AppDomain.CurrentDomain.GetAssemblies())
                    {
                        System.Type[] assemblyTypes = a.GetTypes();
                        for (int j = 0; j < assemblyTypes.Length; j++)
                        {
                            if (assemblyTypes[j].Name == "LanguagesType")
                            {
                                _foundType = assemblyTypes[j];
                            }
                        }
                    }

                    var _instance = System.Activator.CreateInstance(_foundType) as DataboxType;

                    _instance.ConvertRow(_entries[e]);

                    _database.AddData(_tableName, _entries[e].entryName, _entries[e].entryName, _instance as DataboxType);
                }
            }


            // LOCALIZATION TYPE
            if (_isLocalizationType)
            {
                for (int e = 0; e < _entries.Count; e++)
                {
                    System.Type _foundType = null;

                    foreach (System.Reflection.Assembly a in System.AppDomain.CurrentDomain.GetAssemblies())
                    {
                        System.Type[] assemblyTypes = a.GetTypes();
                        for (int j = 0; j < assemblyTypes.Length; j++)
                        {
                            if (assemblyTypes[j].Name == "LocalizationType")
                            {
                                _foundType = assemblyTypes[j];
                            }
                        }
                    }

                    var _instance = System.Activator.CreateInstance(_foundType) as DataboxType;

                    // Convert csv string value to DataboxType value
                    _instance.ConvertRow(_entries[e]);

                    _database.AddData(_tableName, _entries[e].entryName, _entries[e].entryName, _instance as DataboxType);
                }
            }
        }
        else
        {
            // Add entries
            for (int e = 0; e < _entries.Count; e++)
            {
                for (int a = 0; a < _entries[e].values.Count; a++)
                {
                    Dictionary <string, System.Type> _collectedTypes = new Dictionary <string, System.Type>();

                    foreach (System.Reflection.Assembly b in System.AppDomain.CurrentDomain.GetAssemblies())
                    {
                        System.Type[] assemblyTypes = b.GetTypes();
                        for (int j = 0; j < assemblyTypes.Length; j++)
                        {
                            var _str = _entries[e].types[a].Trim();
                            if (assemblyTypes[j].Name == _str)
                            {
                                string _namespace = "databox";
                                if (!string.IsNullOrEmpty(assemblyTypes[j].Namespace))
                                {
                                    _namespace = assemblyTypes[j].Namespace;
                                }

                                _collectedTypes.Add(_namespace, assemblyTypes[j]);
                            }
                        }
                    }

                    if (_collectedTypes.Count == 0)
                    {
                        Debug.LogError("Databox - type: " + _entries[e].types[a] + " does not exist in project");
                        return;
                    }

                    // There could be more than one type with the same name in different namespaces
                    // In this case we use the most obvious one which is in no namespace
                    // Occurs with ResourceType. Which conflicts with:
                    //.....
                    // ResourceType in namespace System.Security.AccessControl
                    // ResourceType in namespace Mono.Cecil
                    //.....
                    System.Type _foundType = null;
                    if (_collectedTypes.Count > 1)
                    {
                        _foundType = _collectedTypes["databox"];
                    }
                    else
                    {
                        _foundType = _collectedTypes.FirstOrDefault().Value;
                    }


                    var _instance = System.Activator.CreateInstance(_foundType) as DataboxType;

                    // Convert csv string value to DataboxType value
                    _instance.Convert(_entries[e].values[a]);

                    _database.AddData(_tableName, _entries[e].entryName, _entries[e].fields[a], _instance as DataboxType);
                }
            }
        }
    }