Пример #1
0
        public void TestGet()
        {
            SQLConnector.Enabled = true;
            SQLConnector.Connect();

            var cond = new RowList <TestDataModel>
            {
                new TestDataModel {
                    ID = 1, TestInt1 = 10, TestString1 = "a"
                },
                new TestDataModel {
                    ID = 1, TestInt1 = 20, TestInt2 = 6
                },
                new TestDataModel {
                    ID = 2, TestInt1 = 11, TestInt2 = 4
                },
                new TestDataModel {
                    ID = 2, TestInt1 = 21, TestString1 = "b"
                }
            };
            var data = SQLDatabase.Get(cond, "wpp_test");

            Assert.NotNull(data);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            // Read config options
            string[]       filters          = null;
            string[]       ignoreFilters    = null;
            bool           sqlOutput        = false;
            DumpFormatType dumpFormat       = DumpFormatType.Text;
            int            packetsToRead    = 0; // 0 -> All packets
            int            packetNumberLow  = 0; // 0 -> No low limit
            int            packetNumberHigh = 0; // 0 -> No high limit
            bool           prompt           = false;
            int            threads          = 0;

            try
            {
                ClientVersion.SetVersion(Settings.GetEnum <ClientVersionBuild>("ClientBuild"));

                packetNumberLow  = Settings.GetInt32("FilterPacketNumLow");
                packetNumberHigh = Settings.GetInt32("FilterPacketNumHigh");

                if (packetNumberLow > 0 && packetNumberHigh > 0 && packetNumberLow > packetNumberHigh)
                {
                    throw new Exception("FilterPacketNumLow must be less or equal than FilterPacketNumHigh");
                }

                string filtersString = Settings.GetString("Filters");
                if (filtersString != null)
                {
                    filters = filtersString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }

                filtersString = Settings.GetString("IgnoreFilters");
                if (filtersString != null)
                {
                    ignoreFilters = filtersString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }

                sqlOutput     = Settings.GetBoolean("SQLOutput");
                dumpFormat    = (DumpFormatType)Settings.GetInt32("DumpFormat");
                packetsToRead = Settings.GetInt32("PacketsNum");
                prompt        = Settings.GetBoolean("ShowEndPrompt");
                threads       = Settings.GetInt32("Threads");

                // Disable DB and DBCs when we don't need its data (dumping to a binary file)
                if (dumpFormat == DumpFormatType.Bin || dumpFormat == DumpFormatType.Pkt)
                {
                    DBCStore.Enabled     = false;
                    SQLConnector.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetType());
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }

            // Quit if no arguments are given
            if (args.Length == 0)
            {
                Console.WriteLine("No files specified.");
                EndPrompt(prompt);
                return;
            }

            // Read DBCs
            if (DBCStore.Enabled)
            {
                var startTime = DateTime.Now;
                Console.WriteLine("Loading DBCs...");

                new DBCLoader();

                var endTime = DateTime.Now;
                var span    = endTime.Subtract(startTime);
                Console.WriteLine("Finished loading DBCs - {0} Minutes, {1} Seconds and {2} Milliseconds.", span.Minutes, span.Seconds, span.Milliseconds);
                Console.WriteLine();
            }

            // Read DB
            if (SQLConnector.Enabled)
            {
                var startTime = DateTime.Now;
                Console.WriteLine("Loading DB...");

                try
                {
                    SQLConnector.Connect();
                    SQLDatabase.GrabData();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    SQLConnector.Enabled = false; // Something failed, disabling everything SQL related
                }

                var endTime = DateTime.Now;
                var span    = endTime.Subtract(startTime);
                Console.WriteLine("Finished loading DB - {0} Minutes, {1} Seconds and {2} Milliseconds.", span.Minutes, span.Seconds, span.Milliseconds);
                Console.WriteLine();
            }

            // Read binaries
            string[] files = args;
            if (args.Length == 1 && args[0].Contains('*'))
            {
                try
                {
                    files = Directory.GetFiles(@".\", args[0]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType());
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }

            if (threads == 0) // Number of threads is automatically choosen by the Parallel library
            {
                files.AsParallel().SetCulture().ForAll(file => ReadFile(file, filters, ignoreFilters, packetNumberLow, packetNumberHigh, packetsToRead, dumpFormat, threads, sqlOutput, prompt));
            }
            else
            {
                files.AsParallel().SetCulture().WithDegreeOfParallelism(threads).ForAll(file => ReadFile(file, filters, ignoreFilters, packetNumberLow, packetNumberHigh, packetsToRead, dumpFormat, threads, sqlOutput, prompt));
            }
        }