PageRenderTime 63ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/Tools/LinqPad/LINQPad/Repository.cs

https://github.com/vishalsh-spec/TestProject
C# | 1798 lines | 1777 code | 21 blank | 0 comment | 62 complexity | 9d02a699777d8c167a2c15693d12f1b0 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.0, Apache-2.0
  1. namespace LINQPad
  2. {
  3. using LINQPad.Extensibility.DataContext;
  4. using LINQPad.UI;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Data.Common;
  10. using System.Data.SqlClient;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Runtime.CompilerServices;
  15. using System.Runtime.Serialization;
  16. using System.Security.Cryptography;
  17. using System.Text;
  18. using System.Threading;
  19. using System.Windows.Forms;
  20. using System.Xml.Linq;
  21. [Serializable]
  22. internal class Repository : ISerializable, IConnectionInfo, IDatabaseInfo, ICustomTypeInfo, IDynamicSchemaOptions, INotifyPropertyChanged, ICustomMemberProvider
  23. {
  24. private DCDriverLoader _driverLoader;
  25. private List<LinkedDatabase> _linkedDbs;
  26. private static AutoResetEvent _openThrottler = new AutoResetEvent(true);
  27. private string _password;
  28. private static object _passwordChangeLocker = new object();
  29. private static int _serialCount;
  30. private static Dictionary<string, object> _servers = new Dictionary<string, object>();
  31. private IDictionary<string, object> _sessionData;
  32. private XElement _store;
  33. private static Timer _tmr;
  34. internal static string[] AssembliesNeedingPathQualification = new string[0];
  35. internal bool AutoGenAssemblyFailed;
  36. internal string AutoGenNamespace;
  37. internal string AutoGenTypeName;
  38. internal bool DoNotSave;
  39. private const string ElementName = "Connection";
  40. internal TempFileRef IntellicachePath;
  41. internal bool IsAutoGenAssemblyAvailable;
  42. internal static Dictionary<string, bool> TypesNeedingAssemblyQualification = new Dictionary<string, bool>();
  43. public event PropertyChangedEventHandler PropertyChanged;
  44. public Repository() : this(new XElement("Connection"))
  45. {
  46. }
  47. public Repository(XElement store)
  48. {
  49. this.AutoGenNamespace = "LINQPad.User";
  50. this.AutoGenTypeName = "TypedDataContext";
  51. this._linkedDbs = new List<LinkedDatabase>();
  52. this._driverLoader = DCDriverLoader.DefaultLoader;
  53. this.LoadFromStore(store);
  54. }
  55. private Repository(SerializationInfo info, StreamingContext context)
  56. {
  57. this.AutoGenNamespace = "LINQPad.User";
  58. this.AutoGenTypeName = "TypedDataContext";
  59. this._linkedDbs = new List<LinkedDatabase>();
  60. this._driverLoader = DCDriverLoader.DefaultLoader;
  61. this.LoadFromStore(XElement.Parse(info.GetString("data")));
  62. this._sessionData = (Dictionary<string, object>) info.GetValue("sessionData", typeof(Dictionary<string, object>));
  63. }
  64. public static bool AreEquivalent(Repository r1, Repository r2)
  65. {
  66. if ((r1 == null) && (r2 == null))
  67. {
  68. return true;
  69. }
  70. if ((r1 == null) || (r2 == null))
  71. {
  72. return false;
  73. }
  74. return ((r1 == r2) || r1.IsEquivalent(r2));
  75. }
  76. private bool ChangeSqlPassword()
  77. {
  78. using (UpdatePasswordForm form = new UpdatePasswordForm(this.Server, this.UserName))
  79. {
  80. if (form.ShowDialog() == DialogResult.OK)
  81. {
  82. Repository repository = this.Clone();
  83. repository.Password = form.OldPassword;
  84. try
  85. {
  86. SqlConnection.ChangePassword(repository.GetCxString(), form.NewPassword);
  87. }
  88. catch (Exception exception)
  89. {
  90. MessageBox.Show(exception.Message, "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
  91. return false;
  92. }
  93. this.Password = form.NewPassword;
  94. if (this.Parent == null)
  95. {
  96. this.SaveToDisk();
  97. }
  98. }
  99. }
  100. return true;
  101. }
  102. public void ClearDatabaseProperties()
  103. {
  104. string str;
  105. this.UserName = str = "";
  106. this.Server = str = str;
  107. this.Provider = str = str;
  108. this.Password = str = str;
  109. this.AttachFileName = this.Database = str;
  110. this.MaxDatabaseSize = 0;
  111. this.UserInstance = false;
  112. this.ShowServer = false;
  113. this.NoPluralization = false;
  114. this.NoCapitalization = false;
  115. this.ExcludeRoutines = false;
  116. this.AttachFile = false;
  117. }
  118. public Repository Clone()
  119. {
  120. return new Repository(new XElement(this.GetStore())) { _driverLoader = this._driverLoader };
  121. }
  122. public Repository CreateChild(string databaseName)
  123. {
  124. Repository repository = this.Clone();
  125. repository.Database = databaseName;
  126. repository.Parent = this;
  127. repository.ShowServer = true;
  128. return repository;
  129. }
  130. public Repository CreateParent()
  131. {
  132. Repository repository = this.Clone();
  133. repository.Database = "";
  134. this.Parent = repository;
  135. return repository;
  136. }
  137. public AppDomain CreateSchemaAndRunnerDomain(string name, bool shadowingActive, bool queryExecutionContext)
  138. {
  139. string configPath = this.DriverLoader.IsValid ? this.DriverLoader.Driver.GetAppConfigPath(this) : this.AppConfigPath;
  140. string data = null;
  141. if (((this.DriverLoader.InternalID == null) && this.DriverLoader.IsValid) && (this.DriverLoader.Driver is StaticDataContextDriver))
  142. {
  143. try
  144. {
  145. data = Path.GetDirectoryName(this.CustomAssemblyPath);
  146. }
  147. catch (ArgumentException)
  148. {
  149. }
  150. if (data == "")
  151. {
  152. data = null;
  153. }
  154. }
  155. string baseFolderOverride = ((data == null) || shadowingActive) ? (((data == null) || !shadowingActive) ? null : AppDomain.CurrentDomain.BaseDirectory) : data;
  156. AppDomain domain = this.DriverLoader.CreateNewDriverDomain(name, baseFolderOverride, configPath);
  157. if (data != null)
  158. {
  159. domain.SetData("LINQPad.UseLoadFileForDCDriver", true);
  160. domain.SetData("LINQPad.DCDriverFolder", this.DriverLoader.GetAssemblyFolder());
  161. domain.SetData("LINQPad.StaticDCFolder", data);
  162. if (!queryExecutionContext)
  163. {
  164. domain.DoCallBack(new CrossAppDomainDelegate(Repository.ResolveCustomAssemblies));
  165. }
  166. }
  167. return domain;
  168. }
  169. public string Decrypt(string s)
  170. {
  171. if (string.IsNullOrEmpty(s))
  172. {
  173. return "";
  174. }
  175. try
  176. {
  177. return Encoding.UTF8.GetString(ProtectedData.Unprotect(Convert.FromBase64String(s), base.GetType().Assembly.GetName().GetPublicKey(), DataProtectionScope.CurrentUser));
  178. }
  179. catch
  180. {
  181. return "";
  182. }
  183. }
  184. public string Encrypt(string s)
  185. {
  186. if (string.IsNullOrEmpty(s))
  187. {
  188. return "";
  189. }
  190. try
  191. {
  192. return Convert.ToBase64String(ProtectedData.Protect(Encoding.UTF8.GetBytes(s), base.GetType().Assembly.GetName().GetPublicKey(), DataProtectionScope.CurrentUser));
  193. }
  194. catch
  195. {
  196. return "";
  197. }
  198. }
  199. private static string FormatCustomCxString(string s)
  200. {
  201. try
  202. {
  203. DbConnectionStringBuilder builder = new DbConnectionStringBuilder {
  204. ConnectionString = s
  205. };
  206. if (builder.ContainsKey("password"))
  207. {
  208. builder.Remove("password");
  209. }
  210. if (builder.ContainsKey("pwd"))
  211. {
  212. builder.Remove("pwd");
  213. }
  214. string[] toRemove = new string[] { "true", "false", "enabled" };
  215. s = string.Join(";", (from v in builder.Values.OfType<string>()
  216. where !toRemove.Contains<string>(v.ToLowerInvariant()) && (v.Length > 2)
  217. select v).ToArray<string>());
  218. }
  219. catch
  220. {
  221. }
  222. if (s.Length > 0x55)
  223. {
  224. s = s.Substring(0, 80) + "...";
  225. }
  226. return s;
  227. }
  228. public static List<Repository> FromDisk()
  229. {
  230. List<Repository> list = new List<Repository>();
  231. using (Mutex mutex = GetMutex())
  232. {
  233. if (!mutex.WaitOne(TimeSpan.FromSeconds(3.0), false))
  234. {
  235. return list;
  236. }
  237. try
  238. {
  239. XElement xmlFromDisk = GetXmlFromDisk();
  240. if (xmlFromDisk == null)
  241. {
  242. return list;
  243. }
  244. foreach (XElement element2 in xmlFromDisk.Elements("Connection"))
  245. {
  246. try
  247. {
  248. list.Add(new Repository(element2));
  249. }
  250. catch
  251. {
  252. }
  253. }
  254. }
  255. finally
  256. {
  257. mutex.ReleaseMutex();
  258. }
  259. }
  260. return list;
  261. }
  262. private bool GetBool(string key)
  263. {
  264. bool? nullable = (bool?) this._store.Element(key);
  265. return (nullable.HasValue ? nullable.GetValueOrDefault() : false);
  266. }
  267. public IDbConnection GetConnection()
  268. {
  269. IDbConnection iDbConnection = this.DriverLoader.Driver.GetIDbConnection(this);
  270. if (iDbConnection == null)
  271. {
  272. throw new DisplayToUserException("The driver for this connection does not support SQL queries.");
  273. }
  274. return iDbConnection;
  275. }
  276. public string[] GetCustomTypesInAssembly()
  277. {
  278. return this.GetCustomTypesInAssembly(null);
  279. }
  280. public string[] GetCustomTypesInAssembly(string baseTypeName)
  281. {
  282. return AssemblyProber.GetTypeNames(this.CustomAssemblyPath, baseTypeName);
  283. }
  284. public string GetCxString()
  285. {
  286. string password;
  287. if (this.CustomCxString.Length > 0)
  288. {
  289. return this.CustomCxString;
  290. }
  291. if ((((this.DriverLoader != null) && (this.DriverLoader != null)) && (this.DriverLoader.SimpleAssemblyName != null)) && (this.DriverLoader.SimpleAssemblyName.ToLowerInvariant() == "iqdriver"))
  292. {
  293. throw new DisplayToUserException("Connection is missing a password or other information: right-click the connection and click 'Properties'");
  294. }
  295. if (this.IsSqlCE)
  296. {
  297. if (this.AttachFileName.Length == 0)
  298. {
  299. return "";
  300. }
  301. string str2 = "Data Source=" + this.AttachFileName;
  302. if (this.Password.Length > 0)
  303. {
  304. password = this.Password;
  305. if (password.Contains<char>(';'))
  306. {
  307. password = "'" + password + "'";
  308. }
  309. str2 = str2 + ";Password=" + password;
  310. }
  311. if (this.MaxDatabaseSize > 0)
  312. {
  313. str2 = str2 + ";Max Database Size=" + this.MaxDatabaseSize;
  314. }
  315. return str2;
  316. }
  317. if (this.Server.Length == 0)
  318. {
  319. return "";
  320. }
  321. string str4 = "Data Source=" + this.Server;
  322. if (this.SqlSecurity)
  323. {
  324. password = this.Password;
  325. if (password.Contains<char>('\''))
  326. {
  327. password = '"' + password + '"';
  328. }
  329. else if (password.Contains<char>(';') || password.Contains<char>('"'))
  330. {
  331. password = "'" + password + "'";
  332. }
  333. string str5 = str4;
  334. str4 = str5 + ";User ID=" + this.UserName + ";Password=" + password;
  335. }
  336. else
  337. {
  338. str4 = str4 + ";Integrated Security=SSPI";
  339. }
  340. if (!((!this.AttachFile || (this.AttachFileName.Length <= 0)) || this.IsAzure))
  341. {
  342. str4 = str4 + ";AttachDbFilename=" + this.AttachFileName;
  343. }
  344. if (!((!this.UserInstance || this.SqlSecurity) || this.IsAzure))
  345. {
  346. str4 = str4 + ";User Instance=True";
  347. }
  348. if (!((!this.AttachFile || this.IsAzure) ? (this.Database.Length <= 0) : true))
  349. {
  350. str4 = str4 + ";Initial Catalog=" + this.Database;
  351. }
  352. str4 = str4 + ";app=LINQPad";
  353. if (!string.IsNullOrEmpty(Util.CurrentQueryName))
  354. {
  355. str4 = str4 + " [" + Util.CurrentQueryName.Replace(";", "") + "]";
  356. }
  357. if (!this.IsAzure && !((!this.DriverLoader.IsValid || !(this.DriverLoader.Driver is EntityFrameworkDriver)) ? !Program.EnableMARS : false))
  358. {
  359. str4 = str4 + ";MultipleActiveResultSets=True";
  360. }
  361. if (this.IsAzure || this.EncryptTraffic)
  362. {
  363. str4 = str4 + ";Encrypt=true";
  364. }
  365. return str4;
  366. }
  367. public List<string> GetDatabaseList()
  368. {
  369. if (!this.IsSqlServer)
  370. {
  371. throw new NotSupportedException("This operation is supported only for SQL Server.");
  372. }
  373. List<string> list = new List<string>();
  374. string cmdText = this.IsAzure ? "select name from sys.databases" : "dbo.sp_MShasdbaccess";
  375. using (SqlConnection connection = new SqlConnection(this.GetCxString()))
  376. {
  377. connection.Open();
  378. using (SqlDataReader reader = new SqlCommand(cmdText, connection).ExecuteReader())
  379. {
  380. while (reader.Read())
  381. {
  382. list.Add(reader[0].ToString());
  383. }
  384. }
  385. }
  386. return list;
  387. }
  388. public string[] GetDriverAssemblies()
  389. {
  390. if (!this.DriverLoader.IsValid)
  391. {
  392. return new string[0];
  393. }
  394. string staticDataContextFolder = null;
  395. if ((this.DriverLoader.Driver is StaticDataContextDriver) && !string.IsNullOrEmpty(this.CustomAssemblyPath))
  396. {
  397. try
  398. {
  399. staticDataContextFolder = Path.GetDirectoryName(this.CustomAssemblyPath);
  400. }
  401. catch (ArgumentException)
  402. {
  403. }
  404. }
  405. return (this.DriverLoader.Driver.TryGetFullAssembliesToAdd(staticDataContextFolder, this) ?? new string[0]);
  406. }
  407. public string GetFriendlyName()
  408. {
  409. return this.GetFriendlyName(FriendlyNameMode.Normal);
  410. }
  411. public string GetFriendlyName(FriendlyNameMode mode)
  412. {
  413. string connectionDescription;
  414. if (this.DriverLoader.InternalID == null)
  415. {
  416. if (!this.DriverLoader.IsValid)
  417. {
  418. return ("(Unknown driver '" + this.DriverLoader.SimpleAssemblyName + "')");
  419. }
  420. if (!string.IsNullOrEmpty(this.DisplayName))
  421. {
  422. return this.DisplayName;
  423. }
  424. try
  425. {
  426. return this.DriverLoader.Driver.GetConnectionDescription(this);
  427. }
  428. catch (Exception exception)
  429. {
  430. Log.Write(exception);
  431. string message = exception.Message;
  432. if (((exception is TargetInvocationException) || (exception is TypeInitializationException)) && (exception.InnerException != null))
  433. {
  434. message = exception.InnerException.Message;
  435. }
  436. return ("(Error loading driver: " + message + ")");
  437. }
  438. }
  439. if (string.IsNullOrEmpty(this.DisplayName))
  440. {
  441. connectionDescription = this.DriverLoader.Driver.GetConnectionDescription(this);
  442. if (!string.IsNullOrEmpty(connectionDescription))
  443. {
  444. return connectionDescription;
  445. }
  446. }
  447. string customTypeName = "";
  448. string str5 = "";
  449. if (!this.DynamicSchema)
  450. {
  451. if (!string.IsNullOrEmpty(this.DisplayName))
  452. {
  453. return this.DisplayName;
  454. }
  455. string key = this.CustomTypeName.Split(new char[] { '.' }).Last<string>();
  456. if (mode == FriendlyNameMode.Short)
  457. {
  458. return key;
  459. }
  460. bool flag = true;
  461. bool flag2 = true;
  462. bool flag3 = false;
  463. if ((mode != FriendlyNameMode.FullTooltip) && (flag2 = TypesNeedingAssemblyQualification.TryGetValue(key, out flag)))
  464. {
  465. try
  466. {
  467. flag3 = !AssembliesNeedingPathQualification.Contains<string>(Path.GetFileName(this.CustomAssemblyPath));
  468. }
  469. catch (ArgumentException)
  470. {
  471. }
  472. }
  473. customTypeName = this.CustomTypeName;
  474. if (!flag)
  475. {
  476. customTypeName = customTypeName.Split(new char[] { '.' }).Last<string>();
  477. }
  478. if (flag2)
  479. {
  480. string customAssemblyPath = this.CustomAssemblyPath;
  481. if (flag3)
  482. {
  483. try
  484. {
  485. customAssemblyPath = Path.GetFileName(customAssemblyPath);
  486. }
  487. catch (ArgumentException)
  488. {
  489. }
  490. }
  491. customTypeName = customTypeName + " in " + customAssemblyPath;
  492. }
  493. if (mode == FriendlyNameMode.FullTooltip)
  494. {
  495. customTypeName = customTypeName + "\r\nDatabase = ";
  496. }
  497. else
  498. {
  499. customTypeName = customTypeName + " (";
  500. str5 = ")";
  501. }
  502. }
  503. if (this.CustomCxString.Length > 0)
  504. {
  505. if (!string.IsNullOrEmpty(this.DisplayName))
  506. {
  507. return this.DisplayName;
  508. }
  509. return FormatCustomCxString(this.CustomCxString);
  510. }
  511. if (this.AttachFile || this.IsSqlCE)
  512. {
  513. if (!string.IsNullOrEmpty(this.DisplayName))
  514. {
  515. return this.DisplayName;
  516. }
  517. bool flag4 = true;
  518. try
  519. {
  520. flag4 = Path.IsPathRooted(this.AttachFileName);
  521. }
  522. catch
  523. {
  524. }
  525. if (!(flag4 && (this.DynamicSchema || (mode == FriendlyNameMode.Short))))
  526. {
  527. return (customTypeName + this.AttachFileName + str5);
  528. }
  529. string attachFileName = this.AttachFileName;
  530. string str9 = "";
  531. try
  532. {
  533. attachFileName = Path.GetFileName(attachFileName);
  534. if (mode != FriendlyNameMode.Short)
  535. {
  536. str9 = " in " + PathHelper.EncodeFolder(Path.GetDirectoryName(this.AttachFileName));
  537. }
  538. }
  539. catch (ArgumentException)
  540. {
  541. }
  542. return (customTypeName + attachFileName + str9 + str5);
  543. }
  544. string str10 = string.Join(" + ", (from l in this._linkedDbs.Take<LinkedDatabase>(3) select l.ToString()).ToArray<string>());
  545. if (this._linkedDbs.Count > 3)
  546. {
  547. str10 = str10 + "...";
  548. }
  549. if (str10.Length > 0)
  550. {
  551. str10 = " + " + str10;
  552. }
  553. if (((mode == FriendlyNameMode.Normal) || (mode == FriendlyNameMode.Short)) && ((this.Database.Length > 0) && ((this.Parent != null) || (mode == FriendlyNameMode.Short))))
  554. {
  555. if (!string.IsNullOrEmpty(this.DisplayName))
  556. {
  557. return ((this.Parent == null) ? this.DisplayName : (this.Database + str10));
  558. }
  559. return (customTypeName + this.Database + str5);
  560. }
  561. if (!string.IsNullOrEmpty(this.DisplayName))
  562. {
  563. connectionDescription = this.DisplayName;
  564. if ((this.Parent != null) && (this.Database.Length > 0))
  565. {
  566. connectionDescription = connectionDescription + "." + this.Database;
  567. }
  568. return connectionDescription;
  569. }
  570. string server = this.Server;
  571. if (this.IsAzure && (mode != FriendlyNameMode.FullTooltip))
  572. {
  573. if (server.EndsWith(".database.windows.net", StringComparison.InvariantCultureIgnoreCase))
  574. {
  575. server = server.Substring(0, server.Length - ".database.windows.net".Length);
  576. }
  577. if (server.StartsWith("tcp:", StringComparison.InvariantCultureIgnoreCase))
  578. {
  579. server = server.Substring("tcp:".Length);
  580. }
  581. }
  582. string str12 = server + (this.SqlSecurity ? ("." + this.UserName) : "");
  583. if (this.Database.Length > 0)
  584. {
  585. str12 = str12 + "." + this.Database + str10;
  586. }
  587. return (customTypeName + str12 + str5);
  588. }
  589. private Guid GetGuid(string key)
  590. {
  591. return (Guid) this._store.Element(key);
  592. }
  593. private int GetInt(string key)
  594. {
  595. int? nullable = (int?) this._store.Element(key);
  596. return (nullable.HasValue ? nullable.GetValueOrDefault() : 0);
  597. }
  598. public List<LinkedDatabase> GetLinkedDatabaseList()
  599. {
  600. if (!this.IsSqlServer)
  601. {
  602. throw new NotSupportedException("This operation is supported only for SQL Server.");
  603. }
  604. StringBuilder builder = new StringBuilder();
  605. List<string> list = new List<string>();
  606. List<LinkedDatabase> list2 = new List<LinkedDatabase>();
  607. string cmdText = "select data_source from sys.servers where provider = 'SQLNCLI' and is_linked = 1";
  608. using (SqlConnection connection = new SqlConnection(this.GetCxString()))
  609. {
  610. SqlDataReader reader;
  611. connection.Open();
  612. using (reader = new SqlCommand(cmdText, connection).ExecuteReader())
  613. {
  614. while (reader.Read())
  615. {
  616. string item = reader[0].ToString();
  617. list.Add(item);
  618. builder.AppendLine("select name from [" + item + "].[master].[sys].[databases]");
  619. }
  620. }
  621. int num = 0;
  622. using (reader = new SqlCommand(builder.ToString(), connection).ExecuteReader())
  623. {
  624. while (reader.Read())
  625. {
  626. list2.Add(new LinkedDatabase(list[num], reader[0].ToString()));
  627. continue;
  628. Label_00D6:
  629. if (!reader.NextResult())
  630. {
  631. return list2;
  632. }
  633. num++;
  634. }
  635. goto Label_00D6;
  636. }
  637. }
  638. }
  639. private static Mutex GetMutex()
  640. {
  641. return new Mutex(true, "LINQPad.DefaultConnection");
  642. }
  643. public IEnumerable<string> GetNames()
  644. {
  645. List<string> list = new List<string>();
  646. Type[] typeArray2 = new Type[] { typeof(IDatabaseInfo), typeof(ICustomTypeInfo), typeof(IDynamicSchemaOptions) };
  647. foreach (Type t in typeArray2)
  648. {
  649. list.AddRange(from p in t.GetProperties() select t.Name.Substring(1) + "." + p.Name);
  650. }
  651. list.Add("AppConfigPath");
  652. list.Add("Persist");
  653. return list;
  654. }
  655. public IEnumerable<LinkedDatabase> GetOtherServerLinkedDatabases()
  656. {
  657. return (from l in this._linkedDbs
  658. where l.Server != null
  659. select l);
  660. }
  661. public DbProviderFactory GetProviderFactory()
  662. {
  663. return this.DriverLoader.Driver.GetProviderFactory(this);
  664. }
  665. public DbProviderFactory GetProviderFactory(DbConnection cx)
  666. {
  667. if (cx == null)
  668. {
  669. return this.GetProviderFactory();
  670. }
  671. PropertyInfo property = cx.GetType().GetProperty("DbProviderFactory", BindingFlags.NonPublic | BindingFlags.Instance);
  672. if (property == null)
  673. {
  674. return this.GetProviderFactory();
  675. }
  676. try
  677. {
  678. return (((DbProviderFactory) property.GetValue(cx, null)) ?? this.GetProviderFactory());
  679. }
  680. catch
  681. {
  682. return this.GetProviderFactory();
  683. }
  684. }
  685. private static Repository GetRepository(XElement e)
  686. {
  687. try
  688. {
  689. return new Repository(e);
  690. }
  691. catch
  692. {
  693. return null;
  694. }
  695. }
  696. public IEnumerable<Repository> GetSameServerLinkedRepositories()
  697. {
  698. XElement xe = this.GetStore();
  699. return (from db in this._linkedDbs
  700. where db.Server == null
  701. select new Repository(xe) { _linkedDbs = new List<LinkedDatabase>(), Database = db.Database, IncludeSystemObjects = false, AttachFile = false, AttachFileName = "" });
  702. }
  703. public string GetSortOrder()
  704. {
  705. if (this.DriverLoader.IsValid && (this.DriverLoader.Driver is LinqToSqlDynamicDriver))
  706. {
  707. return ((this.IsSqlCE ? "3" : (this.IsAzure ? "2" : "1")) + this.GetFriendlyName());
  708. }
  709. return this.GetFriendlyName();
  710. }
  711. public XElement GetStore()
  712. {
  713. this._store.Elements("LinkedDb").Remove<XElement>();
  714. this._store.Add(from db in this._linkedDbs select new XElement("LinkedDb", new object[] { db.Database, (db.Server == null) ? null : new XAttribute("Server", db.Server) }));
  715. if (this._store.Element("DriverData") != null)
  716. {
  717. this._store.Element("DriverData").Remove();
  718. }
  719. if ((this.DriverData != null) && (!this.DriverData.IsEmpty || this.DriverData.Attributes().Any<XAttribute>()))
  720. {
  721. this._store.Add(new XElement("DriverData", new object[] { this.DriverData.Elements(), this.DriverData.Attributes() }));
  722. }
  723. return this._store;
  724. }
  725. private string GetString(string key)
  726. {
  727. string str = (string) this._store.Element(key);
  728. return ((str == null) ? "" : str.Trim());
  729. }
  730. public IEnumerable<Type> GetTypes()
  731. {
  732. List<Type> list = new List<Type>();
  733. Type[] typeArray2 = new Type[] { typeof(IDatabaseInfo), typeof(ICustomTypeInfo), typeof(IDynamicSchemaOptions) };
  734. foreach (Type type in typeArray2)
  735. {
  736. list.AddRange(from p in type.GetProperties() select p.PropertyType);
  737. }
  738. list.Add(typeof(string));
  739. list.Add(typeof(bool));
  740. return list;
  741. }
  742. public IEnumerable<object> GetValues()
  743. {
  744. Func<PropertyInfo, object> selector = null;
  745. List<object> list = new List<object>();
  746. Type[] typeArray2 = new Type[] { typeof(IDatabaseInfo), typeof(ICustomTypeInfo), typeof(IDynamicSchemaOptions) };
  747. foreach (Type type in typeArray2)
  748. {
  749. if (selector == null)
  750. {
  751. selector = p => p.GetValue(this, null);
  752. }
  753. list.AddRange(type.GetProperties().Select<PropertyInfo, object>(selector));
  754. }
  755. list.Add(this.AppConfigPath);
  756. list.Add(this.Persist);
  757. return list;
  758. }
  759. private static XElement GetXmlFromDisk()
  760. {
  761. XElement element = new XElement("Connections");
  762. if (File.Exists(FilePath) || File.Exists(OldFilePath))
  763. {
  764. try
  765. {
  766. element = XElement.Load(File.Exists(FilePath) ? FilePath : OldFilePath);
  767. }
  768. catch
  769. {
  770. Thread.Sleep(200);
  771. try
  772. {
  773. element = XElement.Load(File.Exists(FilePath) ? FilePath : OldFilePath);
  774. }
  775. catch
  776. {
  777. return null;
  778. }
  779. }
  780. }
  781. return element;
  782. }
  783. public bool IsEquivalent(Repository other)
  784. {
  785. if (other == null)
  786. {
  787. return false;
  788. }
  789. if (!(this.DriverLoader.IsValid && other.DriverLoader.IsValid))
  790. {
  791. return (this.GetStore().ToString() == other.GetStore().ToString());
  792. }
  793. if (!this.DriverLoader.Equals(other.DriverLoader))
  794. {
  795. return false;
  796. }
  797. return this.DriverLoader.Driver.AreRepositoriesEquivalent(this, other);
  798. }
  799. string ICustomTypeInfo.GetCustomTypeDescription()
  800. {
  801. bool flag = true;
  802. bool flag2 = true;
  803. bool flag3 = false;
  804. string key = this.CustomTypeName.Split(new char[] { '.' }).Last<string>();
  805. if (flag2 = TypesNeedingAssemblyQualification.TryGetValue(key, out flag))
  806. {
  807. try
  808. {
  809. flag3 = !AssembliesNeedingPathQualification.Contains<string>(Path.GetFileName(this.CustomAssemblyPath));
  810. }
  811. catch (ArgumentException)
  812. {
  813. }
  814. }
  815. string customTypeName = this.CustomTypeName;
  816. if (!flag)
  817. {
  818. customTypeName = customTypeName.Split(new char[] { '.' }).Last<string>();
  819. }
  820. if (!flag2)
  821. {
  822. return customTypeName;
  823. }
  824. string customAssemblyPath = this.CustomAssemblyPath;
  825. if (flag3)
  826. {
  827. try
  828. {
  829. customAssemblyPath = Path.GetFileName(customAssemblyPath);
  830. }
  831. catch (ArgumentException)
  832. {
  833. }
  834. }
  835. return (customTypeName + " in " + customAssemblyPath);
  836. }
  837. bool ICustomTypeInfo.IsEquivalent(ICustomTypeInfo other)
  838. {
  839. if (other == null)
  840. {
  841. return false;
  842. }
  843. if (!string.Equals(this.CustomAssemblyPath, other.CustomAssemblyPath, StringComparison.OrdinalIgnoreCase))
  844. {
  845. return false;
  846. }
  847. if (!string.Equals(this.CustomMetadataPath, other.CustomMetadataPath, StringComparison.OrdinalIgnoreCase))
  848. {
  849. return false;
  850. }
  851. return (this.CustomTypeName == other.CustomTypeName);
  852. }
  853. string IDatabaseInfo.GetDatabaseDescription()
  854. {
  855. if (this.CustomCxString.Length > 0)
  856. {
  857. return FormatCustomCxString(this.CustomCxString);
  858. }
  859. if (this.AttachFile || this.IsSqlCE)
  860. {
  861. return this.AttachFileName;
  862. }
  863. string str2 = this.Server + (this.SqlSecurity ? ("." + this.UserName) : "");
  864. if (this.Database.Length > 0)
  865. {
  866. str2 = str2 + "." + this.Database;
  867. }
  868. return str2;
  869. }
  870. bool IDatabaseInfo.IsEquivalent(IDatabaseInfo other)
  871. {
  872. if (other == null)
  873. {
  874. return false;
  875. }
  876. if ((this.CustomCxString.Length > 0) != (other.CustomCxString.Length > 0))
  877. {
  878. return false;
  879. }
  880. if (this.CustomCxString.Length > 0)
  881. {
  882. return (this.CustomCxString.ToLowerInvariant() == other.CustomCxString.ToLowerInvariant());
  883. }
  884. if (this.IsSqlCE != other.IsSqlCE)
  885. {
  886. return false;
  887. }
  888. if (this.IsSqlCE)
  889. {
  890. return (string.Equals(this.Provider, other.Provider, StringComparison.OrdinalIgnoreCase) && string.Equals(this.AttachFileName, other.AttachFileName, StringComparison.OrdinalIgnoreCase));
  891. }
  892. if (!string.Equals(this.Server, other.Server, StringComparison.OrdinalIgnoreCase))
  893. {
  894. return false;
  895. }
  896. if (this.SqlSecurity != other.SqlSecurity)
  897. {
  898. return false;
  899. }
  900. if (!(!this.SqlSecurity || string.Equals(this.UserName, other.UserName, StringComparison.OrdinalIgnoreCase)))
  901. {
  902. return false;
  903. }
  904. if (this.AttachFile != other.AttachFile)
  905. {
  906. return false;
  907. }
  908. if (!(!this.AttachFile || string.Equals(this.AttachFileName, other.AttachFileName, StringComparison.OrdinalIgnoreCase)))
  909. {
  910. return false;
  911. }
  912. if (!(this.AttachFile || string.Equals(this.Database, other.Database, StringComparison.OrdinalIgnoreCase)))
  913. {
  914. return false;
  915. }
  916. Repository repository = other as Repository;
  917. if (!(from d in this._linkedDbs
  918. orderby d
  919. select d).SequenceEqual<LinkedDatabase>((from d in repository._linkedDbs
  920. orderby d
  921. select d)))
  922. {
  923. return false;
  924. }
  925. return true;
  926. }
  927. public void LoadFromStore(XElement store)
  928. {
  929. this._store = store;
  930. Guid? nullable = (Guid?) this._store.Element("ID");
  931. if (!nullable.HasValue)
  932. {
  933. this.ID = Guid.NewGuid();
  934. }
  935. string str = (string) this._store.Element("Password");
  936. if (!string.IsNullOrEmpty(str))
  937. {
  938. this._password = this.Decrypt(str);
  939. }
  940. this.AttachFileName = this.AttachFileName;
  941. XElement other = store.Element("DriverData");
  942. this.DriverData = (other == null) ? new XElement("DriverData") : new XElement(other);
  943. this._driverLoader = DCDriverLoader.FromXElement(store.Element("Driver"));
  944. this._linkedDbs = (from e in store.Elements("LinkedDb")
  945. select new LinkedDatabase((string) e.Attribute("Server"), e.Value) into e
  946. orderby e
  947. select e).ToList<LinkedDatabase>();
  948. }
  949. private void OnPropertyChanged(PropertyChangedEventArgs args)
  950. {
  951. if (this.PropertyChanged != null)
  952. {
  953. this.PropertyChanged(this, args);
  954. }
  955. }
  956. public IDbConnection Open()
  957. {
  958. return this.Open(false);
  959. }
  960. public IDbConnection Open(bool noThrottle)
  961. {
  962. object obj2;
  963. IDbConnection cx = this.GetConnection();
  964. if (!((!noThrottle && (this.CustomCxString.Length <= 0)) && this.Server.ToUpperInvariant().Contains("SQLEXPRESS")))
  965. {
  966. this.OpenCx(cx, noThrottle);
  967. return cx;
  968. }
  969. lock (_servers)
  970. {
  971. string server = this.Server;
  972. if (!_servers.ContainsKey(server))
  973. {
  974. _servers.Add(server, new object());
  975. }
  976. obj2 = _servers[server];
  977. }
  978. lock (obj2)
  979. {
  980. this.OpenCx(cx, noThrottle);
  981. }
  982. return cx;
  983. }
  984. private void OpenCx(IDbConnection cx, bool noThrottle)
  985. {
  986. if (!noThrottle && (Environment.Version.Major < 4))
  987. {
  988. lock (_openThrottler)
  989. {
  990. if (_tmr == null)
  991. {
  992. _tmr = new Timer(state => _openThrottler.Set(), null, 0x5dc, 500);
  993. }
  994. }
  995. _openThrottler.WaitOne();
  996. }
  997. string password = this.Password;
  998. Label_008D:
  999. try
  1000. {
  1001. try
  1002. {
  1003. cx.Open();
  1004. }
  1005. catch (IndexOutOfRangeException exception)
  1006. {
  1007. throw new DisplayToUserException("SqlConnection has reported an internal error in the connection pool.\r\nYou may need to restart LINQPad.", exception);
  1008. }
  1009. catch (SqlException exception2)
  1010. {
  1011. if (!UserOptions.Instance.NoSqlPasswordExpiryPrompts && ((exception2.Number == 0x4837) || (exception2.Number == 0x4838)))
  1012. {
  1013. lock (_passwordChangeLocker)
  1014. {
  1015. if (password != this.Password)
  1016. {
  1017. cx = this.GetConnection();
  1018. goto Label_008D;
  1019. }
  1020. if (!this.ChangeSqlPassword())
  1021. {
  1022. goto Label_008D;
  1023. }
  1024. cx = this.GetConnection();
  1025. cx.Open();
  1026. return;
  1027. }
  1028. }
  1029. throw;
  1030. }
  1031. return;
  1032. }
  1033. finally
  1034. {
  1035. _openThrottler.Set();
  1036. }
  1037. goto Label_008D;
  1038. }
  1039. private static void ResolveCustomAssemblies()
  1040. {
  1041. AppDomain.CurrentDomain.AssemblyResolve += delegate (object sender, ResolveEventArgs args) {
  1042. string str = new AssemblyName(args.Name).Name + ".dll";
  1043. string path = Path.Combine((string) AppDomain.CurrentDomain.GetData("LINQPad.DCDriverFolder"), str);
  1044. if (File.Exists(path))
  1045. {
  1046. return Assembly.LoadFrom(path);
  1047. }
  1048. return null;
  1049. };
  1050. }
  1051. public bool SaveToDisk()
  1052. {
  1053. Func<XElement, bool> predicate = null;
  1054. if (this.DoNotSave)
  1055. {
  1056. return false;
  1057. }
  1058. using (Mutex mutex = GetMutex())
  1059. {
  1060. if (!mutex.WaitOne(TimeSpan.FromSeconds(3.0), false))
  1061. {
  1062. return false;
  1063. }
  1064. try
  1065. {
  1066. if (!Directory.Exists(Program.UserDataFolder))
  1067. {
  1068. Directory.CreateDirectory(Program.UserDataFolder);
  1069. }
  1070. if (this.ID == Guid.Empty)
  1071. {
  1072. this.ID = Guid.NewGuid();
  1073. }
  1074. XElement xmlFromDisk = GetXmlFromDisk();
  1075. if (xmlFromDisk == null)
  1076. {
  1077. return false;
  1078. }
  1079. bool flag2 = false;
  1080. try
  1081. {
  1082. if (predicate == null)
  1083. {
  1084. predicate = delegate (XElement e) {
  1085. Guid? nullable = (Guid?) e.Element("ID");
  1086. return (nullable.HasValue ? nullable.GetValueOrDefault() : Guid.Empty) == this.ID;
  1087. };
  1088. }
  1089. XElement element2 = xmlFromDisk.Elements("Connection").FirstOrDefault<XElement>(predicate);
  1090. if (element2 != null)
  1091. {
  1092. element2.Remove();
  1093. flag2 = true;
  1094. }
  1095. }
  1096. catch
  1097. {
  1098. return false;
  1099. }
  1100. if (!(flag2 || this.Persist))
  1101. {
  1102. return true;
  1103. }
  1104. if (this.Persist)
  1105. {
  1106. xmlFromDisk.Add(this.GetStore());
  1107. }
  1108. try
  1109. {
  1110. xmlFromDisk.Save(FilePath);
  1111. }
  1112. catch
  1113. {
  1114. Thread.Sleep(200);
  1115. try
  1116. {
  1117. xmlFromDisk.Save(FilePath);
  1118. }
  1119. catch
  1120. {
  1121. return false;
  1122. }
  1123. }
  1124. }
  1125. finally
  1126. {
  1127. mutex.ReleaseMutex();
  1128. }
  1129. }
  1130. return true;
  1131. }
  1132. private void Set(string key, bool value)
  1133. {
  1134. if (!value)
  1135. {
  1136. this._store.Elements(key).Remove<XElement>();
  1137. }
  1138. else
  1139. {
  1140. this._store.SetElementValue(key, value);
  1141. }
  1142. this.OnPropertyChanged(new PropertyChangedEventArgs(key));
  1143. }
  1144. private void Set(string key, Guid value)
  1145. {
  1146. this._store.SetElementValue(key, value);
  1147. this.OnPropertyChanged(new PropertyChangedEventArgs(key));
  1148. }
  1149. private void Set(string key, int value)
  1150. {
  1151. if (value == 0)
  1152. {
  1153. this._store.Elements(key).Remove<XElement>();
  1154. }
  1155. else
  1156. {
  1157. this._store.SetElementValue(key, value);
  1158. }
  1159. this.OnPropertyChanged(new PropertyChangedEventArgs(key));
  1160. }
  1161. private void Set(string key, string value)
  1162. {
  1163. if ((value == null) || (value.Trim().Length == 0))
  1164. {
  1165. this._store.Elements(key).Remove<XElement>();
  1166. }
  1167. else
  1168. {
  1169. this._store.SetElementValue(key, value);
  1170. }
  1171. this.OnPropertyChanged(new PropertyChangedEventArgs(key));
  1172. }
  1173. void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
  1174. {
  1175. _serialCount++;
  1176. info.AddValue("data", this.GetStore().ToString());
  1177. IDictionary<string, object> dictionary = this._sessionData;
  1178. if ((dictionary != null) && (dictionary.Count == 0))
  1179. {
  1180. dictionary = null;
  1181. }
  1182. info.AddValue("sessionData", dictionary);
  1183. }
  1184. public override string ToString()
  1185. {
  1186. return this.GetFriendlyName(FriendlyNameMode.Standalone);
  1187. }
  1188. public void UpdateFromParent()
  1189. {
  1190. if (this.Parent != null)
  1191. {
  1192. this.Provider = this.Parent.Provider;
  1193. this.Server = this.Parent.Server;
  1194. this.AttachFile = this.Parent.AttachFile;
  1195. this.UserInstance = this.Parent.UserInstance;
  1196. this.AttachFileName = this.Parent.AttachFileName;
  1197. this.SqlSecurity = this.Parent.SqlSecurity;
  1198. this.UserName = this.Parent.UserName;
  1199. this.Password = this.Parent.Password;
  1200. this.NoPluralization = this.Parent.NoPluralization;
  1201. this.NoCapitalization = this.Parent.NoCapitalization;
  1202. this.ExcludeRoutines = this.Parent.ExcludeRoutines;
  1203. this.CustomCxString = this.Parent.CustomCxString;
  1204. this.MaxDatabaseSize = this.Parent.MaxDatabaseSize;
  1205. this.DisplayName = this.Parent.DisplayName;
  1206. this.IncludeSystemObjects = this.Parent.IncludeSystemObjects;
  1207. this.EncryptTraffic = this.Parent.EncryptTraffic;
  1208. }
  1209. }
  1210. public string AppConfigPath
  1211. {
  1212. get
  1213. {
  1214. return this.GetString("AppConfigPath");
  1215. }
  1216. set
  1217. {
  1218. this.Set("AppConfigPath", value);
  1219. }
  1220. }
  1221. public bool AttachFile
  1222. {
  1223. get
  1224. {
  1225. return this.GetBool("AttachFile");
  1226. }
  1227. set
  1228. {
  1229. this.Set("AttachFile", value);
  1230. }
  1231. }
  1232. public string AttachFileName
  1233. {
  1234. get
  1235. {
  1236. return PathHelper.DecodeFolder(this.GetString("AttachFileName"));
  1237. }
  1238. set
  1239. {
  1240. this.Set("AttachFileName", PathHelper.EncodeFolder(value));
  1241. }
  1242. }
  1243. public string CustomAssemblyPath
  1244. {
  1245. get
  1246. {
  1247. string str = PathHelper.DecodeFolder(this.GetString("CustomAssemblyPathEncoded"));
  1248. if (!string.IsNullOrEmpty(str))
  1249. {
  1250. return str;
  1251. }
  1252. return this.GetString("CustomAssemblyPath");
  1253. }
  1254. set
  1255. {
  1256. string str = PathHelper.EncodeFolder(value);
  1257. this.Set("CustomAssemblyPathEncoded", (str == value) ? null : str);
  1258. this.Set("CustomAssemblyPath", value);
  1259. }
  1260. }
  1261. public string CustomCxString
  1262. {
  1263. get
  1264. {
  1265. string s = this.GetString("CustomCxString");
  1266. if (this.EncryptCustomCxString)
  1267. {
  1268. s = this.Decrypt(s);
  1269. }
  1270. return s;
  1271. }
  1272. set
  1273. {
  1274. string s = value;
  1275. if (this.EncryptCustomCxString)
  1276. {
  1277. s = this.Encrypt(s);
  1278. }
  1279. this.Set("CustomCxString", s);
  1280. }
  1281. }
  1282. public string CustomMetadataPath
  1283. {
  1284. get
  1285. {
  1286. string str = PathHelper.DecodeFolder(this.GetString("CustomMetadataPathEncoded"));
  1287. if (!string.IsNullOrEmpty(str))
  1288. {
  1289. return str;
  1290. }
  1291. return this.GetString("CustomMetadataPath");
  1292. }
  1293. set
  1294. {
  1295. string str = PathHelper.EncodeFolder(value);
  1296. this.Set("CustomMetadataPathEncoded", (str == value) ? null : str);
  1297. this.Set("CustomMetadataPath", value);
  1298. }
  1299. }
  1300. public ICustomTypeInfo CustomTypeInfo
  1301. {
  1302. get
  1303. {
  1304. return this;
  1305. }
  1306. }
  1307. public string CustomTypeName
  1308. {
  1309. get
  1310. {
  1311. return this.GetString("CustomTypeName");
  1312. }
  1313. set
  1314. {
  1315. this.Set("CustomTypeName", value);
  1316. }
  1317. }
  1318. public string Database
  1319. {
  1320. get
  1321. {
  1322. return this.GetString("Database");
  1323. }
  1324. set
  1325. {
  1326. this.Set("Database", value);
  1327. }
  1328. }
  1329. public IDatabaseInfo DatabaseInfo
  1330. {
  1331. get
  1332. {
  1333. return this;
  1334. }
  1335. }
  1336. public string DbVersion
  1337. {
  1338. get
  1339. {
  1340. return this.GetString("DbVersion");
  1341. }
  1342. set
  1343. {
  1344. this.Set("DbVersion", value);
  1345. }
  1346. }
  1347. public string DisplayName
  1348. {
  1349. get
  1350. {
  1351. return this.GetString("DisplayName");
  1352. }
  1353. set
  1354. {
  1355. this.Set("DisplayName", value);
  1356. }
  1357. }
  1358. public XElement DriverData { get; set; }
  1359. public DCDriverLoader DriverLoader
  1360. {
  1361. get
  1362. {
  1363. return this._driverLoader;
  1364. }
  1365. set
  1366. {
  1367. if (!object.Equals(value, this._driverLoader))
  1368. {
  1369. this._driverLoader = value;
  1370. if (this._store.Element("Driver") != null)
  1371. {
  1372. this._store.Element("Driver").Remove();
  1373. }
  1374. XElement content = value.ToXElement();
  1375. if (content != null)
  1376. {
  1377. this._store.Add(content);
  1378. }
  1379. this.OnPropertyChanged(new PropertyChangedEventArgs("DriverLoader"));
  1380. }
  1381. }
  1382. }
  1383. public bool DynamicSchema
  1384. {
  1385. get
  1386. {
  1387. return (this._driverLoader.IsValid && (this._driverLoader.Driver is DynamicDataContextDriver));
  1388. }
  1389. }
  1390. public IDynamicSchemaOptions DynamicSchemaOptions
  1391. {
  1392. get
  1393. {
  1394. return this;
  1395. }
  1396. }
  1397. public bool EncryptCustomCxString
  1398. {
  1399. get
  1400. {
  1401. return this.GetBool("EncryptCustomCxString");
  1402. }
  1403. set
  1404. {
  1405. bool encryptCustomCxString = this.EncryptCustomCxString;
  1406. if (value != encryptCustomCxString)
  1407. {
  1408. string customCxString = this.CustomCxString;
  1409. this.Set("EncryptCustomCxString", value);
  1410. this.CustomCxString = customCxString;
  1411. }
  1412. }
  1413. }
  1414. public bool EncryptTraffic
  1415. {
  1416. get
  1417. {
  1418. return this.GetBool("EncryptTraffic");
  1419. }
  1420. set
  1421. {
  1422. this.Set("EncryptTraffic", value);
  1423. }
  1424. }
  1425. public bool ExcludeRoutines
  1426. {
  1427. get
  1428. {
  1429. return this.GetBool("ExcludeRoutines");
  1430. }
  1431. set
  1432. {
  1433. this.Set("ExcludeRoutines", value);
  1434. }
  1435. }
  1436. private static string FilePath
  1437. {
  1438. get
  1439. {
  1440. return Path.Combine(Program.UserDataFolder, "ConnectionsV2.xml");
  1441. }
  1442. }
  1443. public Guid ID
  1444. {
  1445. get
  1446. {
  1447. return this.GetGuid("ID");
  1448. }
  1449. set
  1450. {
  1451. this.Set("ID", value);
  1452. }
  1453. }
  1454. public bool IncludeSystemObjects
  1455. {
  1456. get
  1457. {
  1458. return this.GetBool("IncludeSystemObjects");
  1459. }
  1460. set
  1461. {
  1462. this.Set("IncludeSystemObjects", value);
  1463. }
  1464. }
  1465. public bool IsAzure
  1466. {
  1467. get
  1468. {
  1469. return this.DbVersion.StartsWith("Azure", StringComparison.InvariantCultureIgnoreCase);
  1470. }
  1471. }
  1472. public bool IsQueryable
  1473. {
  1474. get
  1475. {
  1476. return ((this._driverLoader.InternalID == null) || this._driverLoader.Driver.IsQueryable(this));
  1477. }
  1478. }
  1479. public bool IsSqlCE
  1480. {
  1481. get
  1482. {
  1483. return ProviderNames.IsSqlCE(this.Provider);
  1484. }
  1485. }
  1486. public bool IsSqlCE35
  1487. {
  1488. get
  1489. {
  1490. return ProviderNames.IsSqlCE35(this.Provider);
  1491. }
  1492. }
  1493. public bool IsSqlCE40
  1494. {
  1495. get
  1496. {
  1497. return ProviderNames.IsSqlCE40(this.Provider);
  1498. }
  1499. }
  1500. public bool IsSqlServer
  1501. {
  1502. get
  1503. {
  1504. return ProviderNames.IsSqlServer(this.Provider);
  1505. }
  1506. }
  1507. public IEnumerable<LinkedDatabase> LinkedDatabases
  1508. {
  1509. get
  1510. {
  1511. return this._linkedDbs;
  1512. }
  1513. set
  1514. {
  1515. this._linkedDbs = (value ?? Enumerable.Empty<LinkedDatabase>()).ToList<LinkedDatabase>();
  1516. }
  1517. }
  1518. public int MaxDatabaseSize
  1519. {
  1520. get
  1521. {
  1522. return this.GetInt("MaxDatabaseSize");
  1523. }
  1524. set
  1525. {
  1526. this.Set("MaxDatabaseSize", value);
  1527. }
  1528. }
  1529. public bool NoCapitalization
  1530. {
  1531. get
  1532. {
  1533. return this.GetBool("NoCapitalization");
  1534. }
  1535. set
  1536. {
  1537. this.Set("NoCapitalization", value);
  1538. }
  1539. }
  1540. public bool NoPluralization
  1541. {
  1542. get
  1543. {
  1544. return this.GetBool("NoPluralization");
  1545. }
  1546. set
  1547. {
  1548. this.Set("NoPluralization", value);
  1549. }
  1550. }
  1551. private static string OldFilePath
  1552. {
  1553. get
  1554. {
  1555. return Path.Combine(Program.UserDataFolder, "connections.xml");
  1556. }
  1557. }
  1558. public Repository Parent { get; private set; }
  1559. public string Password
  1560. {
  1561. get
  1562. {
  1563. return (this._password ?? "");
  1564. }
  1565. set
  1566. {
  1567. string s = (value == null) ? null : value.Trim();
  1568. if (!(this._password == s))
  1569. {
  1570. this._password = s;
  1571. this.Set("Password", this.Encrypt(s));
  1572. }
  1573. }
  1574. }
  1575. public bool Persist
  1576. {
  1577. get
  1578. {
  1579. return this.GetBool("Persist");
  1580. }
  1581. set
  1582. {
  1583. this.Set("Persist", value);
  1584. }
  1585. }
  1586. public string Provider
  1587. {
  1588. get
  1589. {
  1590. string str = this.GetString("Provider");
  1591. switch (str)
  1592. {
  1593. case "SQLCE":
  1594. str = "System.Data.SqlServerCe.3.5";
  1595. break;
  1596. case "":
  1597. str = "System.Data.SqlClient";
  1598. break;
  1599. }
  1600. return str;
  1601. }
  1602. set
  1603. {
  1604. if (string.Equals(value, "System.Data.SqlClient", StringComparison.InvariantCultureIgnoreCase))
  1605. {
  1606. this.Set("Provider", "");
  1607. }
  1608. else
  1609. {
  1610. this.Set("Provider", value);
  1611. }
  1612. }
  1613. }
  1614. public string Server
  1615. {
  1616. get
  1617. {
  1618. return this.GetString("Server");
  1619. }
  1620. set
  1621. {
  1622. this.Set("Server", value);
  1623. }
  1624. }
  1625. public IDictionary<string, object> SessionData
  1626. {
  1627. get
  1628. {
  1629. if (this._sessionData == null)
  1630. {
  1631. this._sessionData = new Dictionary<string, object>();
  1632. }
  1633. return this._sessionData;
  1634. }
  1635. internal set
  1636. {
  1637. this._sessionData = value;
  1638. }
  1639. }
  1640. public bool ShowServer
  1641. {
  1642. get
  1643. {
  1644. return this.GetBool("ShowServer");
  1645. }
  1646. set
  1647. {
  1648. this.Set("ShowServer", value);
  1649. }
  1650. }
  1651. public bool SqlSecurity
  1652. {
  1653. get
  1654. {
  1655. return this.GetBool("SqlSecurity");
  1656. }
  1657. set
  1658. {
  1659. this.Set("SqlSecurity", value);
  1660. }
  1661. }
  1662. public bool UserInstance
  1663. {
  1664. get
  1665. {
  1666. return this.GetBool("UserInstance");
  1667. }
  1668. set
  1669. {
  1670. this.Set("UserInstance", value);
  1671. }
  1672. }
  1673. public string UserName
  1674. {
  1675. get
  1676. {
  1677. return this.GetString("UserName");
  1678. }
  1679. set
  1680. {
  1681. this.Set("UserName", value);
  1682. }
  1683. }
  1684. public enum FriendlyNameMode
  1685. {
  1686. Normal,
  1687. Short,
  1688. Standalone,
  1689. FullTooltip
  1690. }
  1691. }
  1692. }