Results.DBase added.
This commit is contained in:
parent
89593b1dac
commit
76a54f41a7
63
Results/DBase.cs
Normal file
63
Results/DBase.cs
Normal file
@ -0,0 +1,63 @@
|
||||
///
|
||||
/// Copyright (c) 2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentNHibernate.Cfg;
|
||||
using FluentNHibernate.Cfg.Db;
|
||||
using log4net;
|
||||
using NHibernate;
|
||||
using NHibernate.Cfg;
|
||||
using NHibernate.Tool.hbm2ddl;
|
||||
using Results.Entities;
|
||||
|
||||
namespace Results
|
||||
{
|
||||
public class DBase
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(DBase));
|
||||
|
||||
/// <summary> Session factory for all regular sessions, not for CreateEmptyResultsDB(). </summary>
|
||||
public static IList<DBase> Databases;
|
||||
public static int Count { get { return Databases.Count; } }
|
||||
|
||||
static DBase()
|
||||
{
|
||||
Databases = new List<DBase>();
|
||||
}
|
||||
|
||||
|
||||
public readonly string Name;
|
||||
public readonly string ConnectionString;
|
||||
|
||||
ISessionFactory sessionFactory;
|
||||
|
||||
public DBase(string connectionString, string name)
|
||||
{
|
||||
this.ConnectionString = connectionString;
|
||||
this.Name = name;
|
||||
sessionFactory = Fluently.Configure()
|
||||
.Database(MySQLConfiguration.Standard.ConnectionString(connectionString))
|
||||
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entities.WaterMeterData>())
|
||||
.ExposeConfiguration(BuildSchema)
|
||||
.BuildSessionFactory();
|
||||
}
|
||||
|
||||
public DBase(string connectionString)
|
||||
: this(connectionString, string.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
private void BuildSchema(Configuration config)
|
||||
{
|
||||
/// This NHibernate tool takes a configuration with mapping info and exports a database schema
|
||||
new SchemaExport(config).SetOutputFile("db_schema");
|
||||
}
|
||||
|
||||
public ISession OpenSession()
|
||||
{
|
||||
return sessionFactory.OpenSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,6 +59,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BatchResults.cs" />
|
||||
<Compile Include="DBase.cs" />
|
||||
<Compile Include="Entities\Batch.cs" />
|
||||
<Compile Include="Entities\Components.cs" />
|
||||
<Compile Include="Entities\MeterTestRslt.cs" />
|
||||
|
||||
@ -377,7 +377,19 @@ namespace TBF.BenchControl.Sequences
|
||||
if (selection == Selection.Custom)
|
||||
{
|
||||
/// Load existing data from databases
|
||||
int a = 5;
|
||||
Results.DBase.Databases.Clear();
|
||||
try { Results.DBase.Databases.Add(new Results.DBase("SERVER=10.42.128.197; DATABASE=st-wr10-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "WR10")); }
|
||||
catch (Exception exc) { log.ErrorFormat("Cannot open WR10 result database: {0}", exc.Message); }
|
||||
try { Results.DBase.Databases.Add(new Results.DBase("SERVER=10.42.128.98; DATABASE=st-wr11-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "WR11")); }
|
||||
catch (Exception exc) { log.ErrorFormat("Cannot open WR11 result database: {0}", exc.Message); }
|
||||
try { Results.DBase.Databases.Add(new Results.DBase("SERVER=10.42.128.152; DATABASE=st-wr13-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "WR13")); }
|
||||
catch (Exception exc) { log.ErrorFormat("Cannot open WR13 result database: {0}", exc.Message); }
|
||||
try { Results.DBase.Databases.Add(new Results.DBase("SERVER=10.42.128.63; DATABASE=st-wr15-r; UID=vysledky; PASSWORD=GAqx76QUB6NbnpZP; CHARSET=utf8;", "WR15")); }
|
||||
catch (Exception exc) { log.ErrorFormat("Cannot open WR15 result database: {0}", exc.Message); }
|
||||
|
||||
foreach (var wm in BatchRslts.WaterMeters)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user