MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
EntitiesConnection.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Data.SqlClient;
6using System.Data.Entity.Core.EntityClient;
7using System.Data.Entity;
8using MyCaffe.basecode;
9using System.Data.Entity.SqlServer;
10using System.Data.Entity.Infrastructure;
11
12namespace MyCaffe.db.image
13{
17 public partial class DNNEntities
18 {
23 public DNNEntities(string strConnectionString)
24 : base(strConnectionString)
25 {
26 }
27 }
28
35 public class DNNConfiguration : DbConfiguration
36 {
41 {
42 SetExecutionStrategy("System.Data.SqlClient", () => new SqlAzureExecutionStrategy());
43 SetDefaultConnectionFactory(new LocalDbConnectionFactory("mssqllocaldb"));
44 }
45 }
46
50 public class EntitiesConnection
51 {
55 static protected ConnectInfo g_connectInfo = new ConnectInfo(".", "DNN");
56 static Dictionary<int, string> m_rgstrConnections = new Dictionary<int, string>();
57 static Dictionary<int, ConnectInfo> m_rgciConnections = new Dictionary<int, ConnectInfo>();
58
63 {
64 }
65
70 {
71 get { return g_connectInfo; }
72 set { g_connectInfo = value; }
73 }
74
81 public static string CreateConnectionString(string strDb)
82 {
83 return CreateConnectionString(new ConnectInfo(null, strDb));
84 }
85
91 public static string CreateConnectionString(ConnectInfo ci)
92 {
93 if (ci == null)
94 ci = g_connectInfo;
95
96 string strDb = ci.Database;
97 string strServerName = g_connectInfo.Server;
98
99 if (ci.Server != null)
100 strServerName = ci.Server;
101
102 if (strServerName == "NONE" || strServerName == "DEFAULT")
103 strServerName = ".";
104
105 string strKey = strDb + strServerName;
106 int nKey = strKey.GetHashCode();
107
108 if (m_rgstrConnections.ContainsKey(nKey) && m_rgciConnections.ContainsKey(nKey) && m_rgciConnections[nKey].Compare(ci))
109 return m_rgstrConnections[nKey];
110
111 string strProviderName = "System.Data.SqlClient";
112 string strDatabaseName = strDb;
113 SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
114 EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
115
116 sqlBuilder.DataSource = strServerName;
117 sqlBuilder.InitialCatalog = strDatabaseName;
118
119 if (string.IsNullOrEmpty(ci.Password))
120 {
121 sqlBuilder.IntegratedSecurity = true;
122 }
123 else
124 {
125 sqlBuilder.PersistSecurityInfo = false;
126 sqlBuilder.UserID = ci.Username;
127 sqlBuilder.Password = ci.Password;
128 sqlBuilder.MultipleActiveResultSets = false;
129 sqlBuilder.Encrypt = true;
130 sqlBuilder.TrustServerCertificate = true;
131 sqlBuilder.ConnectTimeout = 180;
132 }
133
134 string strProviderString = sqlBuilder.ToString();
135
136 builder.Provider = strProviderName;
137 builder.ProviderConnectionString = strProviderString;
138 builder.Metadata = @"res://*/" + strDb + "Model.csdl|" +
139 "res://*/" + strDb + "Model.ssdl|" +
140 "res://*/" + strDb + "Model.msl";
141
142 string strConnection = builder.ToString();
143
144 if (!m_rgstrConnections.ContainsKey(nKey))
145 m_rgstrConnections.Add(nKey, strConnection);
146 else
147 m_rgstrConnections[nKey] = strConnection;
148
149 if (!m_rgciConnections.ContainsKey(nKey))
150 m_rgciConnections.Add(nKey, ci);
151 else
152 m_rgciConnections[nKey] = ci;
153
154 return strConnection;
155 }
156
162 public static DNNEntities CreateEntities(ConnectInfo ci = null)
163 {
164 return new DNNEntities(CreateConnectionString(ci));
165 }
166 }
167}
The ConnectInfo class specifies the server, database and username/password used to connect to a datab...
Definition: ConnectInfo.cs:14
string Server
Get/set the server.
Definition: ConnectInfo.cs:127
string Username
Returns the username.
Definition: ConnectInfo.cs:145
string Database
Get/set the database.
Definition: ConnectInfo.cs:136
string Password
Returns the password.
Definition: ConnectInfo.cs:153
The DNNConfiguration class used to define the connection strategy.
DNNConfiguration()
The DNNConfiguration constructor.
The DNNEntities class defines the entities used to connecto the database via Entity Frameworks.
DNNEntities(string strConnectionString)
The DNNEntities constructor.
The EntitiesConnection class defines how to connect to the database via Entity Frameworks.
static DNNEntities CreateEntities(ConnectInfo ci=null)
Returns the DNNEntities to use.
EntitiesConnection()
The EntitiesConnection constructor.
static string CreateConnectionString(ConnectInfo ci)
Creates the connection string used.
static ConnectInfo GlobalDatabaseConnectInfo
Get/set the global database connection info.
static string CreateConnectionString(string strDb)
Creates the connection string used.
static ConnectInfo g_connectInfo
Specifies the default database connection info.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.db.image namespace contains all image database related classes.
Definition: Database.cs:18
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12