public static void FixtureSetup(TestContext ctx)
        {
            var driver = new MongoDynamicDataContextDriver();
            var code   = new[] { driver.GenerateDynamicCode(mConnectionProperties, new List <Assembly>(), "testns", "driver") }
            .Concat(driver.GetStaticCodeFiles());

            var assName = new AssemblyName
            {
                CodeBase = Path.GetTempFileName(),
            };

            driver.BuildAssembly(mConnectionProperties, code, assName, () => "");
            GeneratedAssembly = Assembly.LoadFrom(assName.CodeBase);

            Console.WriteLine("Code:");
            foreach (string c in code)
            {
                Console.WriteLine(c);
                Console.WriteLine("------------------");
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            ConsoleColor old = Console.ForegroundColor;

            try{
                var props = new ConnectionProperties();
                using (var frm = new ConnectionDialog(props, true, Assembly.LoadFrom))
                {
                    var result = frm.ShowDialog();
                    if (result != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }
                }

                var cxi = new FakeConnection();
                new ConnectionPropertiesSerializer().Serialize(cxi.DriverData, props);

                var driver = new MongoDynamicDataContextDriver();


                List <Assembly> assemblies = props.AssemblyLocations.Select(Assembly.LoadFrom).ToList();
                var             code       = driver.GetStaticCodeFiles()
                                             .Concat(new string[] { driver.GenerateDynamicCode(props, assemblies, "", "driver") });
                if (props.InitializationQuery != null)
                {
                    code = code.Concat(new string[] { driver.GenerateCustomInitQuery(props.InitializationQuery, "driver") });
                }

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("------------------------------------------------");
                foreach (string s in code)
                {
                    Console.WriteLine(s);
                    Console.WriteLine("------------------------------------------------");
                }
                Console.ForegroundColor = old;

                using (var frm = new SaveFileDialog())
                {
                    var result = frm.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        using (StreamWriter writer = new StreamWriter(frm.OpenFile()))
                        {
                            foreach (string s in code)
                            {
                                writer.WriteLine(s);
                                writer.WriteLine("---------------------------------------------------");
                            }

                            writer.Flush();
                        }
                    }
                }
            }catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
            }
            finally{
                Console.ForegroundColor = old;
            }
        }