Пример #1
0
        private static void _loadItemsGroupdDb(AbstractDb <int> db, ServerDbs serverDb, string file)
        {
            int numberOfErrors = 3;

            TextFileHelper.LatestFile = file;

            if (String.IsNullOrEmpty(file))
            {
                DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "File not found " + ServerDbs.ItemGroups + ".", ErrorLevel.NotSpecified);
                return;
            }

            var itemDb1 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items);
            var itemDb2 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items2);

            if (!itemDb1.IsLoaded)
            {
                itemDb1.LoadDb();
            }

            if (!itemDb2.IsLoaded)
            {
                itemDb2.LoadDb();
            }

            var itemDb = new MetaTable <int>(ServerItemAttributes.AttributeList);

            itemDb.AddTable(itemDb1.Table);
            itemDb.AddTable(itemDb2.Table);
            itemDb.MergeOnce();

            Dictionary <string, ReadableTuple <int> > bufferredTuples = new Dictionary <string, ReadableTuple <int> >();

            foreach (var tuple in itemDb.FastItems)
            {
                bufferredTuples[tuple.GetStringValue(ServerItemAttributes.AegisName.Index)] = tuple;
            }

            var table = db.Table;

            if (db.Attached[serverDb] == null)
            {
                db.Attached[serverDb] = new Utilities.Extension.Tuple <ServerDbs, HashSet <int> >(serverDb, new HashSet <int>());
            }

            HashSet <int> loadedIds = ((Utilities.Extension.Tuple <ServerDbs, HashSet <int> >)db.Attached[serverDb]).Item2;

            foreach (string[] elements in TextFileHelper.GetElementsByCommas(IOHelper.ReadAllBytes(file)))
            {
                try {
                    int itemId;
                    int iItemId;

                    if (Int32.TryParse(elements[0], out iItemId))
                    {
                        itemId = iItemId;
                    }
                    else
                    {
                        var constantDb = db.ProjectDatabase.GetDb <string>(ServerDbs.Constants);

                        if (!constantDb.IsLoaded)
                        {
                            constantDb.LoadDb();
                        }

                        var tuple = constantDb.Table.TryGetTuple(elements[0]);

                        if (tuple == null)
                        {
                            if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0]))
                            {
                                return;
                            }
                            continue;
                        }

                        itemId = tuple.GetValue <int>(1);
                    }

                    string orate = elements[2];

                    int nameId;
                    int rate;

                    if (Int32.TryParse(elements[1], out nameId))
                    {
                    }
                    else
                    {
                        var tuple = bufferredTuples[elements[1]];

                        if (tuple == null)
                        {
                            if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0]))
                            {
                                return;
                            }
                            continue;
                        }

                        nameId = tuple.Key;
                    }

                    Int32.TryParse(orate, out rate);

                    var id = (object)itemId;
                    loadedIds.Add((int)id);

                    if (!table.ContainsKey(itemId))
                    {
                        ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, db.AttributeList);
                        tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >());
                        table.Add(itemId, tuple);
                    }

                    Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table);

                    ReadableTuple <int> newTuple   = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList);
                    List <DbAttribute>  attributes = new List <DbAttribute>(ServerItemGroupSubAttributes.AttributeList.Attributes);

                    for (int i = 2; i < elements.Length; i++)
                    {
                        newTuple.SetRawValue(attributes[i - 1], elements[i]);
                    }

                    newTuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, itemId);

                    dico[nameId] = newTuple;
                }
                catch {
                    if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0]))
                    {
                        return;
                    }
                }
            }
        }