Example #1
0
        public static void DbCommaLoader <T>(DbDebugItem <T> debug, AttributeList list, DbCommaFunctionDelegate <T> function, TextFileHelper.TextFileHelperGetterDelegate getter, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

#if SDE_DEBUG
            Z.StopAndRemoveWithoutDisplay(-1);
            Z.StopAndRemoveWithoutDisplay(-2);
            CLHelper.CR(-2);
#endif
            foreach (string[] elements in getter(File.ReadAllBytes(debug.FilePath)))
            {
#if SDE_DEBUG
                CLHelper.CS(-2);
                CLHelper.CR(-1);
#endif
                try {
                    if (!addAutomatically)
                    {
                        T id = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                        if (!table.ContainsKey(id))
                        {
                            Z.F();
                            continue;
                        }
                    }

                    function(debug, list, elements, table);
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
#if SDE_DEBUG
                CLHelper.CS(-1);
                CLHelper.CR(-2);
#endif
            }
#if SDE_DEBUG
            CLHelper.CS(-2);
            CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms";
#endif
        }
Example #2
0
        public static void DbLoaderComma <T>(DbDebugItem <T> debug, AttributeList list, DbIOItems.DbCommaFunctionDelegate <T> function, TextFileHelper.TextFileHelperGetterDelegate getter, bool addAutomatically = true)
        {
            var table = debug.AbsractDb.Table;

            foreach (string[] elements in getter(FtpHelper.ReadAllBytes(debug.FilePath)))
            {
                try {
                    if (!addAutomatically)
                    {
                        T id = (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(elements[0]);

                        if (!table.ContainsKey(id))
                        {
                            TkDictionary <T, string[]> phantomTable;

                            if (!debug.AbsractDb.Attached.ContainsKey("Phantom." + debug.DbSource.Filename))
                            {
                                phantomTable = new TkDictionary <T, string[]>();
                                debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename] = phantomTable;
                            }
                            else
                            {
                                phantomTable = (TkDictionary <T, string[]>)debug.AbsractDb.Attached["Phantom." + debug.DbSource.Filename];
                            }

                            phantomTable[id] = elements;
                            continue;
                        }
                    }

                    function(debug, list, elements, table);
                }
                catch (Exception err) {
                    if (!debug.ReportException(err))
                    {
                        return;
                    }
                }
            }
        }
Example #3
0
        public static void DbLoaderAny <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, TextFileHelper.TextFileHelperGetterDelegate getter, bool uniqueKey = true)
        {
            List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes);
            int indexOffset      = uniqueKey ? 1 : 0;
            int attributesOffset = uniqueKey ? 0 : 1;

            if (!uniqueKey)
            {
                TextFileHelper.SaveLastLine = true;
            }

#if SDE_DEBUG
            Z.StopAndRemoveWithoutDisplay(-1);
            Z.StopAndRemoveWithoutDisplay(-2);
            CLHelper.CR(-2);
#endif
            foreach (string[] elements in getter(File.ReadAllBytes(debug.FilePath)))
            {
#if SDE_DEBUG
                CLHelper.CS(-2);
                CLHelper.CR(-1);
#endif
                try {
                    _guessAttributes(elements, attributes, -1, db);

                    TKey id;

                    if (uniqueKey)
                    {
                        id = (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFrom(elements[0]);
                    }
                    else
                    {
                        id = (TKey)(object)TextFileHelper.LastLineRead;
                    }

                    for (int index = indexOffset; index < elements.Length; index++)
                    {
                        DbAttribute property = attributes[index + attributesOffset];
                        db.Table.SetRaw(id, property, elements[index]);
                    }
                }
                catch {
                    if (!debug.ReportIdException(elements[0]))
                    {
                        return;
                    }
                }
#if SDE_DEBUG
                CLHelper.CS(-1);
                CLHelper.CR(-2);
#endif
            }
#if SDE_DEBUG
            CLHelper.CS(-2);
            CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms";
#endif
            if (!uniqueKey)
            {
                TextFileHelper.SaveLastLine = false;
            }
        }
Example #4
0
        public static void DbLoaderAny <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db, TextFileHelper.TextFileHelperGetterDelegate getter, bool uniqueKey = true)
        {
            List <DbAttribute> attributes = new List <DbAttribute>(db.AttributeList.Attributes);
            int  indexOffset          = uniqueKey ? 1 : 0;
            int  attributesOffset     = uniqueKey ? 0 : 1;
            bool hasGuessedAttributes = false;
            int  rndOffset            = 0;
            Func <string, TKey> keyConverter;

            if (typeof(TKey) == typeof(int))
            {
                keyConverter = q => (TKey)(object)Int32.Parse(q);
            }
            else
            {
                keyConverter = q => (TKey)(object)q;
            }

            if (!uniqueKey)
            {
                TextFileHelper.SaveLastLine = true;
            }

            foreach (string[] elements in getter(FtpHelper.ReadAllBytes(debug.FilePath)))
            {
                try {
                    if (!hasGuessedAttributes)
                    {
                        GuessAttributes(elements, attributes, -1, db);
                        hasGuessedAttributes = true;
                    }

                    TKey id;

                    if (uniqueKey)
                    {
                        id = keyConverter(elements[0]);
                    }
                    else
                    {
                        id = (TKey)(object)TextFileHelper.LastLineRead;

                        while (db.Table.ContainsKey(id))
                        {
                            id = (TKey)(object)((string)(object)id + "_" + rndOffset++);
                        }
                    }

                    db.Table.SetRawRange(id, attributesOffset, indexOffset, attributes, elements);
                    //for (int index = indexOffset; index < elements.Length; index++) {
                    //	db.Table.SetRaw(id, attributes[index + attributesOffset], elements[index]);
                    //}
                }
                catch {
                    if (elements.Length <= 0)
                    {
                        if (!debug.ReportIdException("#"))
                        {
                            return;
                        }
                    }
                    else if (!debug.ReportIdException(elements[0]))
                    {
                        return;
                    }
                }
            }

            if (!uniqueKey)
            {
                TextFileHelper.SaveLastLine = false;
            }
        }