private void AddEntry(DatabaseEntry entry)
    {
        DatabaseTable table;

        if (!tables.TryGetValue(entry.GetType(), out table))
        {
            Debug.Log("Created table for : " + entry.GetType().ToString());

            table = new DatabaseTable();

            tables.Add(entry.GetType(), table);
        }

        if (ID.IsNullOrNoID(entry.DatabaseID))
        {
            Debug.LogError("Database Entry has no ID: " + entry.GetType().ToString());
            return;
        }

        if (!table.ContainsKey(entry.DatabaseID))
        {
            table.Add(entry.DatabaseID, entry);
        }
        else
        {
            Debug.LogWarning("Duplicate database entry: " + entry.DatabaseID);
        }
    }
Exemple #2
0
    public void Add(DatabaseEntry entry, bool remote = false)
    {
        if (entry != null)
        {
            var exists = _entries.ContainsKey(entry.ID);
            _entries[entry.ID] = entry;
            var type  = entry.GetType();
            var types = type.GetParentTypes();
            foreach (var t in types)
            {
                if (!_types.ContainsKey(t))
                {
                    _types[t] = new Dictionary <Guid, DatabaseEntry>();
                }
                _types[t][entry.ID] = entry;
            }

            if (remote)
            {
                if (exists)
                {
                    OnDataUpdateRemote?.Invoke(entry);
                }
                else
                {
                    OnDataInsertRemote?.Invoke(entry);
                }
            }
            else
            {
                if (exists)
                {
                    OnDataUpdateLocal?.Invoke(entry);
                }
                else
                {
                    OnDataInsertLocal?.Invoke(entry);
                }
            }
        }
    }
Exemple #3
0
 public override void Activate(DatabaseEntry o, object g)
 {
     if (o is T t && g is K k)
     {
         Activator(t, k);
     }
     throw new ArgumentException(
               $"Entry group activation failed! Expected: object type {typeof(T)}, group type {typeof(K)}; received: object type {o.GetType()}, group type {g.GetType()}");
 }