Exemplo n.º 1
0
        public void InitializeDefaultGenerator()
        {
            List <Hint> hints = new List <Hint>();

            // Load user hints
            var hintPath = CommandLineUtilities.GetArgument <string>("hint", null);

            if (hintPath != null)
            {
                AddHintsFromFile(hintPath, hints);
            }

            // Load default hints
            AddHintsFromFile("hints.xml", hints);

            // Add generators by priority
            List <DataGenerator> dataGenerators = new List <DataGenerator>();

            dataGenerators.Add(new GuidGenerator());
            dataGenerators.Add(new NumberGenerator());
            dataGenerators.Add(new BooleanGenerator());
            dataGenerators.Add(new DateGenerator());
            dataGenerators.Add(new ForeignKeyGenerator());
            dataGenerators.Add(new LipsumGenerator());
            dataGenerators.Add(new BinaryGenerator());

            foreach (Table table in _database.Tables)
            {
                Logger.Log(LogType.Information, value: string.Format("Table {0}", table.FullName));
                foreach (Column column in table.Columns)
                {
                    if (column.IsIdentity)
                    {
                        continue;
                    }

                    bool set = false;
                    foreach (var hint in hints)
                    {
                        if (hint.Match(column) && hint.DataGenerator.CanGenerate(column))
                        {
                            SetDataGenerator(column, (DataGenerator)hint.DataGenerator.Clone());
                            set = true;
                            break;
                        }
                    }

                    if (!set)
                    {
                        foreach (var dataGenerator in dataGenerators)
                        {
                            if (dataGenerator.CanGenerate(column))
                            {
                                SetDataGenerator(column, (DataGenerator)dataGenerator.Clone());
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            _projectPath                    = CommandLineUtilities.GetArgument("path", (string)null) ?? CommandLineUtilities.GetArgument(0, (string)null);
            _schema                         = ConvertUtilities.Nullify(CommandLineUtilities.GetArgument("schema", (string)null) ?? CommandLineUtilities.GetArgument(1, (string)null), true);
            _changeTargetDirectory          = CommandLineUtilities.GetArgument("changeTargetDirectory", true);
            _disableNonPersistenceProducers = CommandLineUtilities.GetArgument("disableNonPersistenceProducers", true);

            // Load the model
            Project project = new Project();

            project.Entities.ListChanged += Entities_ListChanged; // Change schema as soon as the entity is loaded
            project.Load(_projectPath, ProjectLoadOptions.Default);

            // Update producer target directory
            if (!string.IsNullOrEmpty(_schema) && _changeTargetDirectory)
            {
                foreach (var producer in project.Producers)
                {
                    var sqlServerProducer = producer.Instance as SqlServerProducer;
                    if (sqlServerProducer != null)
                    {
                        sqlServerProducer.Production += SqlServerProducer_Production;
                    }

                    var databaseProducer = producer.Instance as DatabaseProducer;
                    if (databaseProducer != null)
                    {
                        databaseProducer.Production += DatabaseProducer_Production;
                    }
                }
            }

            // Generate code
            project.Producing += OnProjectProduction;
            ProductionOptions productionOptions = BuildProductionOptions(project);

            project.Produce(productionOptions);
            Console.WriteLine();
        }
Exemplo n.º 3
0
        private static ProductionOptions BuildProductionOptions(Project project)
        {
            ProductionOptions options = _disableNonPersistenceProducers ? new DatabaseProducerOnlyProductionOptions() : new ProductionOptions();

            options.Flags = CommandLineUtilities.GetArgument("opf", ProductionOptionsFlags.None);

            foreach (KeyValuePair <string, bool> kvp in new NameValueCollectionCollection(CommandLineUtilities.GetArgument <string>("ena", null),
                                                                                          '!', '"', '=', true, true, false, false
                                                                                          ).ToDictionary <bool>())
            {
                Producer producer = project.GetProducer(kvp.Key);
                if (producer != null)
                {
                    options.Enable(producer, kvp.Value);
                }
                else
                {
                    CodeFluent.Model.SubProducer sp = project.GetSubProducer(kvp.Key);
                    if (sp != null)
                    {
                        options.Enable(sp, kvp.Value);
                    }
                    else
                    {
                        Guid guid = ConvertUtilities.ChangeType(kvp.Key, Guid.Empty);
                        if (guid != Guid.Empty)
                        {
                            Node node = project.GetNode(guid);
                            if (node != null)
                            {
                                options.Enable(node, kvp.Value);
                            }
                        }
                    }
                }
            }
            return(options);
        }
Exemplo n.º 4
0
        static void SafeMain(string[] args)
        {
            int    count = 1;
            string t;
            var    etwProvider = CommandLineUtilities.GetArgument("etw", Guid.Empty);

            Console.WriteLine("TraceSpy Test.");
            Console.WriteLine();
            Console.WriteLine("Press Q (or CTRL-C) to quit");
            Console.WriteLine();
            Console.WriteLine("OutputDebugString");
            Console.WriteLine(" Press O to send an OutputDebugString trace.");

            if (etwProvider != Guid.Empty)
            {
                _etw = new EventProvider(etwProvider);
                Console.WriteLine();
                Console.WriteLine("ETW");
                Console.WriteLine(" Press E to send an ETW trace to provider '" + etwProvider + "'.");
                Console.WriteLine(" Press 1..9 to send 0..9 ETW traces to provider '" + etwProvider + "'.");
                Console.WriteLine("  Combine with Shift to multiply by 10");
                Console.WriteLine("  Combine with Control to multiply by 100");
                Console.WriteLine("  Combine with Alt to multiply by 1000");
            }

            Console.WriteLine();
            do
            {
                var info = Console.ReadKey(true);
                int key  = (int)info.Key;
                int num  = GetFinalNumber(info);
                switch (info.Key)
                {
                case ConsoleKey.Q:
                    if (_etw != null)
                    {
                        _etw.Dispose();
                    }
                    return;

                case ConsoleKey.O:
                    t = "Trace #" + count + " from TraceSpyTest. Date:" + DateTime.Now;
                    Console.WriteLine("Sending: '" + t + "'");
                    Trace.WriteLine(t);
                    count++;
                    break;

                case ConsoleKey.E:
                    t = "Trace #" + count + " from TraceSpyTest. Date:" + DateTime.Now;
                    Console.WriteLine("Sending: '" + t + "'");
                    _etw.WriteMessageEvent(t);
                    count++;
                    break;

                default:
                    if (num > 0)
                    {
                        for (int i = 1; i <= num; i++)
                        {
                            t = "Trace #" + count + ", " + i + "/" + num + " from TraceSpyTest. Date:" + DateTime.Now;
                            Console.WriteLine("Sending: '" + t + "'");
                            _etw.WriteMessageEvent(t);
                            count++;
                        }
                    }
                    break;
                }
            }while (true);
        }
Exemplo n.º 5
0
        static void SafeMain(string[] args)
        {
            int    count = 1;
            string t;
            var    etwProvider = CommandLineUtilities.GetArgument("etw", Guid.Empty);

            Console.WriteLine("TraceSpy Test.");
            Console.WriteLine();
            Console.WriteLine("Press Q, ESC, or CTRL-C to quit");
            Console.WriteLine();
            Console.WriteLine("OutputDebugString");
            Console.WriteLine(" Press O to send an OutputDebugString trace.");
            Console.WriteLine(" Press C to send an OutputDebugString trace every random interval, C again to stop.");

            if (etwProvider != Guid.Empty)
            {
                _etw = new EventProvider(etwProvider);
                Console.WriteLine();
                Console.WriteLine("ETW");
                Console.WriteLine(" Press E to send an ETW trace to provider '" + etwProvider + "'.");
                Console.WriteLine(" Press 1..9 to send 0..9 ETW traces to provider '" + etwProvider + "'.");
                Console.WriteLine("  Combine with Shift to multiply by 10");
                Console.WriteLine("  Combine with Control to multiply by 100");
                Console.WriteLine("  Combine with Alt to multiply by 1000");
            }

            Console.WriteLine();
            do
            {
                var info = Console.ReadKey(true);
                int key  = (int)info.Key;
                int num  = GetFinalNumber(info);
                switch (info.Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.Q:
                    if (_etw != null)
                    {
                        _etw.Dispose();
                    }
                    return;

                case ConsoleKey.O:
                    t = "ODSTrace #" + count + " from TraceSpyTest. Date:" + DateTime.Now;
                    Console.WriteLine("Sending: '" + t + "'");
                    Trace.WriteLine(t);
                    count++;
                    break;

                case ConsoleKey.C:
                    if (_timer == null)
                    {
                        _timer = new Timer((state) =>
                        {
                            t = "ODS Continuous Trace #" + count + " from TraceSpyTest. Date:" + DateTime.Now + ". " + GetSomeRandomText();
                            Console.WriteLine("Sending: '" + t + "'");
                            Trace.WriteLine(t);
                            count++;
                            _timer.Change(_rnd.Next(100, 2000), 0);
                        });
                        _timer.Change(_rnd.Next(100, 2000), 0);
                    }
                    else
                    {
                        _timer.Dispose();
                        _timer = null;
                    }
                    break;

                case ConsoleKey.E:
                    t = "ETWTrace #" + count + " from TraceSpyTest. Date:" + DateTime.Now;
                    Console.WriteLine("Sending: '" + t + "'");
                    _etw.WriteMessageEvent(t);
                    count++;
                    break;

                default:
                    if (num > 0)
                    {
                        for (int i = 1; i <= num; i++)
                        {
                            t = "Trace #" + count + ", " + i + "/" + num + " from TraceSpyTest. Date:" + DateTime.Now;
                            if (num < 1000 || (i % 1000) == 0)
                            {
                                Console.WriteLine("Sending: '" + t + "'");
                            }
                            _etw.WriteMessageEvent(t);
                            count++;
                        }
                    }
                    break;
                }
            }while (true);
        }