public override void CreateDatabase() { //writer = new StreamWriter("c:/Oracle.txt", false); var constr = string.Format(string.Format("Data Source=vpc1;User ID={0};password={1}", "System", "test")); var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Oracle.Odp.map")); var database = new OdpOracleNorthwind(constr, xmlMapping) { Log = Console.Out }; //new OdpOracleNorthwind(constr) { Log = Console.Out };// if (database.DatabaseExists()) { database.DeleteDatabase(); } try { database.CreateDatabase(); } catch (Exception) { database.Log.Flush(); database.Log.Close(); throw; } finally { database.Dispose(); } }
/// <summary> /// 创建一个数据提供者实例 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="repUri"></param> /// <returns></returns> public static T Create <T>(string connStr) where T : class { T instance = null; try { Assembly asm = Assembly.GetExecutingAssembly(); // Assembly.Load("LJH.Inventory.DAL"); if (asm != null) { foreach (Type t in asm.GetTypes()) { if (t.IsClass && !t.IsAbstract) { foreach (Type inter in t.GetInterfaces()) { if (inter == typeof(T)) { Stream stream = asm.GetManifestResourceStream("LJH.Inventory.DAL.LinqProvider.Inventory.xml"); MappingSource mappingSource = XmlMappingSource.FromStream(stream); instance = Activator.CreateInstance(t, connStr, mappingSource) as T; return(instance); } } } } } } catch { } throw new Exception(string.Format("没有找到 {0} ,请确保 {1} 已经存在!", typeof(T).FullName, typeof(T).FullName)); }
public override NorthwindDatabase CreateDataBaseInstace() { var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.SQLite.map")); writer = Console.Out; return(new SQLiteNorthwind(DbFileName) { Log = writer }); //xmlMapping }
/// <summary> /// Initializes a new instance of the <see cref="XmlMappingSourceManager"/> class. /// </summary> /// <param name="mappingStream"> /// The mapping stream. /// </param> public XmlMappingSourceManager(Stream mappingStream) { using (MemoryStream memoryStream = ReadAllToMemoryStream(mappingStream)) { this.NoAssociationsMappingSource = CreateNoAssociationsMappingSource(memoryStream); memoryStream.Position = 0; this.MappingSource = XmlMappingSource.FromStream(memoryStream); } }
public static ParkDataContext CreateParking(string connStr) { System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(connStr), "没有找到有效的数据库连接!"); Stream stream = typeof(ParkDataContextFactory).Assembly.GetManifestResourceStream("Ralid.Park.DAL.LinqDataProvider.ParkingMapping.xml"); MappingSource mappingSource = XmlMappingSource.FromStream(stream); ParkDataContext parking = new ParkDataContext(connStr, mappingSource); //parking.Log = System.Console.Out; return(parking); }
public override NorthwindDatabase CreateDataBaseInstace() { writer = Console.Out; var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.MySql.map")); return(new MySqlNorthwind(CreateConnection().ConnectionString) { Log = writer }); //xmlMapping }
public override NorthwindDatabase CreateDataBaseInstace() { var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Oracle.Odp.map")); //XmlMappingSource.FromUrl("Northwind.Oracle.Odp.map"); writer = Console.Out; return(new OdpOracleNorthwind("Data Source=vpc1;Persist Security Info=True;User ID=Northwind;Password=Test;", xmlMapping) { Log = writer }); }
public void TestInitialize() { var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.Access.map")); //db = new AccessNorthwind("C:/Northwind.mdb"); //db = new AccessNorthwind("C:/Northwind.mdb", xmlMapping); //db = new SQLiteNorthwind("C:/Northwind.db3"); db = new MySqlNorthwind(MySqlNorthwind.CreateConnection("root", "test", "Northwind", "localhost", 3306).ConnectionString); db.Log = Console.Out; }
public static XmlMappingSource GetMapping() { if (_Mapping == null) { using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HL.DomainModel.DataMapping.OperationalMap.xml")) { _Mapping = XmlMappingSource.FromStream(stream); } } return(_Mapping); }
public override NorthwindDemo.NorthwindDatabase CreateDataBaseInstace() { var writer = Console.Out; //var xmlMapping = XmlMappingSource.FromUrl("Northwind.Firebird.map"); var xmlMapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Firebird.map")); //return new FirebirdNorthwind("C:/Northwind.FDB") { Log = writer }; return(new FirebirdNorthwind("User=SYSDBA;Password=masterkey;Database=Northwind;DataSource=localhost;ServerType=0") { Log = writer }); }
/// <summary> /// Gets mapping to initialize Linq2Sql data context. /// </summary> /// <remarks> /// Fixture expects the linq2sql implementation contains one and only embedded resource file /// with mapping configuration. /// </remarks> protected virtual MappingSource GetMapping() { var executingAssembly = Assembly.GetAssembly(typeof(CustomerRepository)); var customerMappingFileName = (from r in executingAssembly.GetManifestResourceNames().AsEnumerable() where r.EndsWith(".linq2sql.xml") select r).Single(); var customerMappingFile = executingAssembly.GetManifestResourceStream(customerMappingFileName); return(XmlMappingSource.FromStream(customerMappingFile)); }
private AdventureWorks2008DataContext GetContext() { if (_mappingSourceFromXmlFile == null) { var modelAssembly = typeof(AdventureWorks2008DataContext).Assembly; var resourceStream = modelAssembly.GetManifestResourceStream("AdventureWorks2008.AdventureWorks2008Mappings.xml"); _mappingSourceFromXmlFile = XmlMappingSource.FromStream(resourceStream); } // pass in sql connection to make sure the profiler gathers the right information var factory = DbProviderFactories.GetFactory("System.Data.SqlClient"); var connection = factory.CreateConnection(); connection.ConnectionString = ConfigurationManager.ConnectionStrings["AdventureWorksConnectionString.SQL Server (SqlClient)"].ConnectionString; return(new AdventureWorks2008DataContext(connection, _mappingSourceFromXmlFile)); }
public override DataMapper CreateDataMapper() { if (mappingSource == null) { var mapping = Assembly.GetExecutingAssembly().GetManifestResourceStream( "NailsFramework.Tests.Persistence.LinqToSql.TestModel.Mappings.xml"); mappingSource = XmlMappingSource.FromStream(mapping); mapping.Dispose(); } var linq2Sql = new NailsFramework.Persistence.LinqToSql { MappingSource = mappingSource }; return(linq2Sql); }
public void GetCreateTableCommandTest() { LicenseManager.CurrentContext.SetSavedLicenseKey(typeof(ALinq.Access.AccessDbProvider), "ansiboy" + Environment.NewLine + "QO77626437CFA2FE9E"); //var obj = LicenseManager.CreateWithContext(typeof (ALinq.Access.AccessDbProvider), new LicenseContext()); //Console.Write(obj); var mapping = XmlMappingSource.FromStream(GetType().Assembly.GetManifestResourceStream("Test.Northwind.Access.map")); var db = new AccessNorthwind("c:/nrothwind.mdb", mapping); var target = new DatabaseSqlBuilder((SqlProvider)db.Provider); MetaTable table = db.Mapping.GetTable(typeof(Category)); //string expected = string.Empty; string actual; actual = target.GetCreateTableCommand(table); //Assert.AreEqual(expected, actual); //Assert.Inconclusive("Verify the correctness of this test method."); Console.WriteLine(actual); }
public static void Initialize(TestContext testContext) { //var type = typeof(SQLiteTest); //var path = type.Module.FullyQualifiedName; //var filePath = Path.GetDirectoryName(path) + @"\ALinq.SQLite.lic"; //File.Copy(@"E:\ALinqs\ALinq1.8\Test\ALinq.SQLite.lic", filePath); var xmlMapping = XmlMappingSource.FromStream(typeof(SQLiteTest).Assembly.GetManifestResourceStream("Test.Northwind.SQLite.map")); writer = new StreamWriter(LogFileName, false); var database = new SQLiteNorthwind(DbFileName) { Log = writer }; //, xmlMapping if (!database.DatabaseExists()) { database.CreateDatabase(); database.Connection.Close(); } }
public static AttendanceDataContext Createattendance(string connStr) { System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(connStr), "没有找到有效的数据库连接!"); IDbConnection connection = null; Stream stream = typeof(AttendanceDataContextFactory).Assembly.GetManifestResourceStream("LJH.Attendance.DAL.LinqDataProvider.DataMapping.xml"); XmlMappingSource mappingSource = XmlMappingSource.FromStream(stream); string sqlType = AppSettings.CurrentSetting.GetSQLType(); if (sqlType == "MSSQL") { connection = new SqlConnection(AppSettings.CurrentSetting.GetConnectString()); } else if (sqlType == "SQLITE") { connection = new SQLiteConnection(AppSettings.CurrentSetting.GetConnectString()); } System.Diagnostics.Debug.Assert(connection != null, "没有找到有效的数据库连接!"); AttendanceDataContext attendance = new AttendanceDataContext(connection, mappingSource); //attendance.Log = System.Console.Out; return(attendance); }
/// <summary> /// Creates the mapping source with no associations in mapping. /// </summary> /// <param name="mappingStream"> /// The mapping stream. /// </param> /// <returns> /// The mapping source with no associations /// </returns> private static MappingSource CreateNoAssociationsMappingSource(Stream mappingStream) { var stripAssociationsTransform = new XslCompiledTransform(); Stream sheetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("LogicSoftware.DataAccess.Repository.Mapping.StripAssociations.xslt"); using (XmlReader sheetReader = XmlReader.Create(sheetStream)) { stripAssociationsTransform.Load(sheetReader); } using (var buffer = new MemoryStream()) { using (XmlReader mappingReader = XmlReader.Create(mappingStream)) { stripAssociationsTransform.Transform(mappingReader, new XsltArgumentList(), buffer); } buffer.Position = 0; return(XmlMappingSource.FromStream(buffer)); } }
private static MappingSource GetMapping() { var mapping = XmlMappingSource.FromStream(typeof(EfzNorthwind).Assembly.GetManifestResourceStream("NorthwindDemo.Northwind.Efz.map")); return(mapping); }
public MailQWithOutTemplateDataContext(string conn) : base(conn, XmlMappingSource.FromStream(Assembly.GetExecutingAssembly() .GetManifestResourceStream("Genworth.SitecoreExt.MailSender.MailQWithOutTemplateMapping.xml"))) { this.Log = System.Console.Out; }
void Run() { Console.WriteLine("DbExtensions Sample Runner"); Console.WriteLine("=========================="); var connectionStrings = ConfigurationManager.ConnectionStrings .Cast <ConnectionStringSettings>() // Only connection strings defined in this application config file (not in machine.config) .Where(c => c.ElementInformation.Source != null && c.ElementInformation.Source.EndsWith("exe.config", StringComparison.OrdinalIgnoreCase)) .ToArray(); int connIndex = GetArrayOption(connectionStrings.Select(c => c.Name).ToArray(), "Select a connection string (or Enter to select the first one):"); ConnectionStringSettings connSettings = connectionStrings[connIndex]; DbProviderFactory provider = Database.GetProviderFactory(connSettings.ProviderName); string connectionString = "name=" + connSettings.Name; Console.WriteLine(); Console.WriteLine("Provider: {0}", provider.GetType().AssemblyQualifiedName); Console.WriteLine(); Console.WriteLine("Connecting..."); try { DbConnection conn = Database.CreateConnection(connectionString); using (conn.EnsureOpen()) Console.WriteLine("Server Version: {0}", conn.ServerVersion); } catch (Exception ex) { WriteError(ex, fatal: true); return; } string[] samplesLangs = GetSamplesLanguages(); int samplesLangIndex = GetArrayOption(samplesLangs, "Select the samples language (or Enter):"); string samplesLanguage = samplesLangs[samplesLangIndex]; MappingSource[] mappingSources = { new AttributeMappingSource(), XmlMappingSource.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("Samples.Northwind.Northwind.xml")) }; int mappingSourceIndex = GetArrayOption(mappingSources, "Select the mapping source (or Enter):"); MappingSource mappingSource = mappingSources[mappingSourceIndex]; object[] samples; try { samples = GetSamples(samplesLanguage, connectionString, mappingSource, Console.Out).ToArray(); } catch (Exception ex) { WriteError(ex, fatal: true); return; } string[] samplesOptions = (from s in samples let name = s.GetType().Name let friendlyName = name.Substring(0, name.Length - "Samples".Length) select friendlyName).Concat(new[] { "All" }).ToArray(); int samplesIndex = GetArrayOption(samplesOptions, "Select the samples category (or Enter to run all):", samplesOptions.Length - 1); object[] selectedSamples = (samplesIndex == samplesOptions.Length - 1) ? samples : new[] { samples[samplesIndex] }; string[] continueOnErrorOptions = { "Yes", "No" }; bool continueOnError = GetArrayOption(continueOnErrorOptions, "Continue on Error:") == 0; Console.WriteLine(); Console.WriteLine("Press key to begin..."); Console.ReadKey(); for (int i = 0; i < selectedSamples.Length; i++) { object sampl = selectedSamples[i]; RunSamples(sampl, continueOnError); IDisposable disp = sampl as IDisposable; if (disp != null) { disp.Dispose(); } Console.WriteLine(); Console.WriteLine((i == selectedSamples.Length - 1) ? "Press key to exit..." : "Press key to continue..."); Console.ReadKey(); } }