Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace WebMatrix.Data
{
internal class ConfigurationManagerWrapper : IConfigurationManager
{
private readonly string _dataDirectory = null;
private IDictionary<string, string> _appSettings;
private IDictionary<string, IDbFileHandler> _handlers;
public ConfigurationManagerWrapper(IDictionary<string, IDbFileHandler> handlers, string dataDirectory = null)
{
Debug.Assert(handlers != null, "handlers should not be null");
_dataDirectory = dataDirectory ?? Database.DataDirectory;
_handlers = handlers;
}
public IDictionary<string, string> AppSettings
{
get
{
if (_appSettings == null)
{
_appSettings = (from string key in ConfigurationManager.AppSettings
select key).ToDictionary(key => key, key => ConfigurationManager.AppSettings[key]);
}
return _appSettings;
}
}
private static IConnectionConfiguration GetConnectionConfigurationFromConfig(string name)
{
ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings[name];
if (setting != null)
{
return new ConnectionConfiguration(setting.ProviderName, setting.ConnectionString);
}
return null;
}
public IConnectionConfiguration GetConnection(string name)
{
return GetConnection(name, GetConnectionConfigurationFromConfig, File.Exists);
}
// For unit testing
internal IConnectionConfiguration GetConnection(string name, Func<string, IConnectionConfiguration> getConfigConnection, Func<string, bool> fileExists)
{
// First try config
IConnectionConfiguration configuraitonConfig = getConfigConnection(name);
if (configuraitonConfig != null)
{
return configuraitonConfig;
}
// Then try files under the |DataDirectory| with the supported extensions
// REVIEW: We sort because we want to process mdf before sdf (we only have 2 entries)
foreach (var handler in _handlers.OrderBy(h => h.Key))
{
string fileName = Path.Combine(_dataDirectory, name + handler.Key);
if (fileExists(fileName))
{
return handler.Value.GetConnectionConfiguration(fileName);
}
}
return null;
}
}
}

View File

@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
namespace WebMatrix.Data
{
internal class ConnectionConfiguration : IConnectionConfiguration
{
internal ConnectionConfiguration(string providerName, string connectionString)
: this(new DbProviderFactoryWrapper(providerName), connectionString)
{
}
internal ConnectionConfiguration(IDbProviderFactory providerFactory, string connectionString)
{
Debug.Assert(!String.IsNullOrEmpty(connectionString), "connectionString should not be null");
ProviderFactory = providerFactory;
ConnectionString = connectionString;
}
public IDbProviderFactory ProviderFactory { get; private set; }
public string ConnectionString { get; private set; }
}
}

View File

@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Data.Common;
namespace WebMatrix.Data
{
public class ConnectionEventArgs : EventArgs
{
public ConnectionEventArgs(DbConnection connection)
{
Connection = connection;
}
public DbConnection Connection { get; private set; }
}
}

View File

@@ -0,0 +1,304 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.Internal.Web.Utils;
using WebMatrix.Data.Resources;
namespace WebMatrix.Data
{
public class Database : IDisposable
{
internal const string SqlCeProviderName = "System.Data.SqlServerCe.4.0";
internal const string SqlServerProviderName = "System.Data.SqlClient";
private const string DefaultDataProviderAppSetting = "systemData:defaultProvider";
internal static string DataDirectory = (string)AppDomain.CurrentDomain.GetData("DataDirectory") ?? Directory.GetCurrentDirectory();
private static readonly IDictionary<string, IDbFileHandler> _databaseFileHandlers = new Dictionary<string, IDbFileHandler>(StringComparer.OrdinalIgnoreCase)
{
{ ".sdf", new SqlCeDbFileHandler() },
{ ".mdf", new SqlServerDbFileHandler() }
};
private static readonly IConfigurationManager _configurationManager = new ConfigurationManagerWrapper(_databaseFileHandlers);
private Func<DbConnection> _connectionFactory;
private DbConnection _connection;
internal Database(Func<DbConnection> connectionFactory)
{
_connectionFactory = connectionFactory;
}
public static event EventHandler<ConnectionEventArgs> ConnectionOpened
{
add { _connectionOpened += value; }
remove { _connectionOpened -= value; }
}
private static event EventHandler<ConnectionEventArgs> _connectionOpened;
public DbConnection Connection
{
get
{
if (_connection == null)
{
_connection = _connectionFactory();
}
return _connection;
}
}
public void Close()
{
Dispose();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (_connection != null)
{
_connection.Close();
_connection = null;
}
}
}
public dynamic QuerySingle(string commandText, params object[] args)
{
if (String.IsNullOrEmpty(commandText))
{
throw ExceptionHelper.CreateArgumentNullOrEmptyException("commandText");
}
return QueryInternal(commandText, args).FirstOrDefault();
}
public IEnumerable<dynamic> Query(string commandText, params object[] parameters)
{
if (String.IsNullOrEmpty(commandText))
{
throw ExceptionHelper.CreateArgumentNullOrEmptyException("commandText");
}
// Return a readonly collection
return QueryInternal(commandText, parameters).ToList().AsReadOnly();
}
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Users are responsible for ensuring the inputs to this method are SQL Injection sanitized")]
private IEnumerable<dynamic> QueryInternal(string commandText, params object[] parameters)
{
EnsureConnectionOpen();
DbCommand command = Connection.CreateCommand();
command.CommandText = commandText;
AddParameters(command, parameters);
using (command)
{
IEnumerable<string> columnNames = null;
using (DbDataReader reader = command.ExecuteReader())
{
foreach (DbDataRecord record in reader)
{
if (columnNames == null)
{
columnNames = GetColumnNames(record);
}
yield return new DynamicRecord(columnNames, record);
}
}
}
}
private static IEnumerable<string> GetColumnNames(DbDataRecord record)
{
// Get all of the column names for this query
for (int i = 0; i < record.FieldCount; i++)
{
yield return record.GetName(i);
}
}
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Users are responsible for ensuring the inputs to this method are SQL Injection sanitized")]
public int Execute(string commandText, params object[] args)
{
if (String.IsNullOrEmpty(commandText))
{
throw ExceptionHelper.CreateArgumentNullOrEmptyException("commandText");
}
EnsureConnectionOpen();
DbCommand command = Connection.CreateCommand();
command.CommandText = commandText;
AddParameters(command, args);
using (command)
{
return command.ExecuteNonQuery();
}
}
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This makes a database request")]
public dynamic GetLastInsertId()
{
// This method only support sql ce and sql server for now
return QueryValue("SELECT @@Identity");
}
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Users are responsible for ensuring the inputs to this method are SQL Injection sanitized")]
public dynamic QueryValue(string commandText, params object[] args)
{
if (String.IsNullOrEmpty(commandText))
{
throw ExceptionHelper.CreateArgumentNullOrEmptyException("commandText");
}
EnsureConnectionOpen();
DbCommand command = Connection.CreateCommand();
command.CommandText = commandText;
AddParameters(command, args);
using (command)
{
return command.ExecuteScalar();
}
}
private void EnsureConnectionOpen()
{
// If the connection isn't open then open it
if (Connection.State != ConnectionState.Open)
{
Connection.Open();
// Raise the connection opened event
OnConnectionOpened();
}
}
private void OnConnectionOpened()
{
if (_connectionOpened != null)
{
_connectionOpened(this, new ConnectionEventArgs(Connection));
}
}
private static void AddParameters(DbCommand command, object[] args)
{
if (args == null)
{
return;
}
// Create numbered parameters
IEnumerable<DbParameter> parameters = args.Select((o, index) =>
{
var parameter = command.CreateParameter();
parameter.ParameterName = index.ToString(CultureInfo.InvariantCulture);
parameter.Value = o ?? DBNull.Value;
return parameter;
});
foreach (var p in parameters)
{
command.Parameters.Add(p);
}
}
public static Database OpenConnectionString(string connectionString)
{
return OpenConnectionString(connectionString, providerName: null);
}
public static Database OpenConnectionString(string connectionString, string providerName)
{
if (String.IsNullOrEmpty(connectionString))
{
throw ExceptionHelper.CreateArgumentNullOrEmptyException("connectionString");
}
return OpenConnectionStringInternal(providerName, connectionString);
}
public static Database Open(string name)
{
if (String.IsNullOrEmpty(name))
{
throw ExceptionHelper.CreateArgumentNullOrEmptyException("name");
}
return OpenNamedConnection(name, _configurationManager);
}
internal static IConnectionConfiguration GetConnectionConfiguration(string fileName, IDictionary<string, IDbFileHandler> handlers)
{
string extension = Path.GetExtension(fileName);
IDbFileHandler handler;
if (handlers.TryGetValue(extension, out handler))
{
return handler.GetConnectionConfiguration(fileName);
}
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
DataResources.UnableToDetermineDatabase, fileName));
}
private static Database OpenConnectionStringInternal(string providerName, string connectionString)
{
return OpenConnectionStringInternal(new DbProviderFactoryWrapper(providerName), connectionString);
}
private static Database OpenConnectionInternal(IConnectionConfiguration connectionConfig)
{
return OpenConnectionStringInternal(connectionConfig.ProviderFactory, connectionConfig.ConnectionString);
}
internal static Database OpenConnectionStringInternal(IDbProviderFactory providerFactory, string connectionString)
{
return new Database(() => providerFactory.CreateConnection(connectionString));
}
internal static Database OpenNamedConnection(string name, IConfigurationManager configurationManager)
{
// Opens a connection using the connection string setting with the specified name
IConnectionConfiguration configuration = configurationManager.GetConnection(name);
if (configuration != null)
{
// We've found one in the connection string setting in config so use it
return OpenConnectionInternal(configuration);
}
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
DataResources.ConnectionStringNotFound, name));
}
internal static string GetDefaultProviderName()
{
string providerName;
// Get the default provider name from config if there is any
if (!_configurationManager.AppSettings.TryGetValue(DefaultDataProviderAppSetting, out providerName))
{
providerName = SqlCeProviderName;
}
return providerName;
}
}
}

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Data.Common;
namespace WebMatrix.Data
{
internal class DbProviderFactoryWrapper : IDbProviderFactory
{
private string _providerName;
private DbProviderFactory _providerFactory;
public DbProviderFactoryWrapper(string providerName)
{
_providerName = providerName;
}
public DbConnection CreateConnection(string connectionString)
{
if (String.IsNullOrEmpty(_providerName))
{
// If the provider name is null or empty then use the default
_providerName = Database.GetDefaultProviderName();
}
if (_providerFactory == null)
{
_providerFactory = DbProviderFactories.GetFactory(_providerName);
}
DbConnection connection = _providerFactory.CreateConnection();
connection.ConnectionString = connectionString;
return connection;
}
}
}

View File

@@ -0,0 +1,199 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using WebMatrix.Data.Resources;
namespace WebMatrix.Data
{
public sealed class DynamicRecord : DynamicObject, ICustomTypeDescriptor
{
internal DynamicRecord(IEnumerable<string> columnNames, IDataRecord record)
{
Debug.Assert(record != null, "record should not be null");
Debug.Assert(columnNames != null, "columnNames should not be null");
Columns = columnNames.ToList();
Record = record;
}
public IList<string> Columns { get; private set; }
private IDataRecord Record { get; set; }
public object this[string name]
{
get
{
VerifyColumn(name);
return GetValue(Record[name]);
}
}
public object this[int index]
{
get { return GetValue(Record[index]); }
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = this[binder.Name];
return true;
}
private static object GetValue(object value)
{
return DBNull.Value == value ? null : value;
}
public override IEnumerable<string> GetDynamicMemberNames()
{
return Columns;
}
private void VerifyColumn(string name)
{
// REVIEW: Perf
if (!Columns.Contains(name, StringComparer.OrdinalIgnoreCase))
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
DataResources.InvalidColumnName, name));
}
}
AttributeCollection ICustomTypeDescriptor.GetAttributes()
{
return AttributeCollection.Empty;
}
string ICustomTypeDescriptor.GetClassName()
{
return null;
}
string ICustomTypeDescriptor.GetComponentName()
{
return null;
}
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return null;
}
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
{
return null;
}
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
{
return null;
}
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return null;
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
{
return EventDescriptorCollection.Empty;
}
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
{
return EventDescriptorCollection.Empty;
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
{
return ((ICustomTypeDescriptor)this).GetProperties();
}
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
// Get the name and type for each column name
var properties = from columnName in Columns
let columnIndex = Record.GetOrdinal(columnName)
let type = Record.GetFieldType(columnIndex)
select new DynamicPropertyDescriptor(columnName, type);
return new PropertyDescriptorCollection(properties.ToArray(), readOnly: true);
}
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
return this;
}
private class DynamicPropertyDescriptor : PropertyDescriptor
{
private static readonly Attribute[] _empty = new Attribute[0];
private readonly Type _type;
public DynamicPropertyDescriptor(string name, Type type)
: base(name, _empty)
{
_type = type;
}
public override Type ComponentType
{
get { return typeof(DynamicRecord); }
}
public override bool IsReadOnly
{
get { return true; }
}
public override Type PropertyType
{
get { return _type; }
}
public override bool CanResetValue(object component)
{
return false;
}
public override object GetValue(object component)
{
DynamicRecord record = component as DynamicRecord;
// REVIEW: Should we throw if the wrong object was passed in?
if (record != null)
{
return record[Name];
}
return null;
}
public override void ResetValue(object component)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
DataResources.RecordIsReadOnly, Name));
}
public override void SetValue(object component, object value)
{
throw new InvalidOperationException(
String.Format(CultureInfo.CurrentCulture,
DataResources.RecordIsReadOnly, Name));
}
public override bool ShouldSerializeValue(object component)
{
return false;
}
}
}
}

View File

@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "WebMatrix.Data", Justification = "WebMatrix.Data is a logical grouping of data-related helpers, and thus it belongs in its own namespace")]

View File

@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace WebMatrix.Data
{
internal interface IConfigurationManager
{
IDictionary<string, string> AppSettings { get; }
IConnectionConfiguration GetConnection(string name);
}
}

View File

@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
namespace WebMatrix.Data
{
internal interface IConnectionConfiguration
{
string ConnectionString { get; }
IDbProviderFactory ProviderFactory { get; }
}
}

View File

@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
namespace WebMatrix.Data
{
internal interface IDbFileHandler
{
IConnectionConfiguration GetConnectionConfiguration(string fileName);
}
}

View File

@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Data.Common;
namespace WebMatrix.Data
{
internal interface IDbProviderFactory
{
DbConnection CreateConnection(string connectionString);
}
}

View File

@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Reflection;
using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WebMatrix.Data")]
[assembly: AssemblyDescription("")]
[assembly: InternalsVisibleTo("WebMatrix.Data.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("WebMatrix.WebData.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

View File

@@ -0,0 +1,99 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WebMatrix.Data.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class DataResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal DataResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WebMatrix.Data.Resources.DataResources", typeof(DataResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Connection string &quot;{0}&quot; was not found..
/// </summary>
internal static string ConnectionStringNotFound {
get {
return ResourceManager.GetString("ConnectionStringNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid column name &quot;{0}&quot;..
/// </summary>
internal static string InvalidColumnName {
get {
return ResourceManager.GetString("InvalidColumnName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unable to modify the value of column &quot;{0}&quot; because the record is read only..
/// </summary>
internal static string RecordIsReadOnly {
get {
return ResourceManager.GetString("RecordIsReadOnly", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unable to determine the provider for the database file &quot;{0}&quot;..
/// </summary>
internal static string UnableToDetermineDatabase {
get {
return ResourceManager.GetString("UnableToDetermineDatabase", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ConnectionStringNotFound" xml:space="preserve">
<value>Connection string "{0}" was not found.</value>
</data>
<data name="InvalidColumnName" xml:space="preserve">
<value>Invalid column name "{0}".</value>
</data>
<data name="RecordIsReadOnly" xml:space="preserve">
<value>Unable to modify the value of column "{0}" because the record is read only.</value>
</data>
<data name="UnableToDetermineDatabase" xml:space="preserve">
<value>Unable to determine the provider for the database file "{0}".</value>
</data>
</root>

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
namespace WebMatrix.Data
{
internal class SqlCeDbFileHandler : IDbFileHandler
{
private const string SqlCeConnectionStringFormat = @"Data Source={0};File Access Retry Timeout=10";
public IConnectionConfiguration GetConnectionConfiguration(string fileName)
{
// Get the default provider name
string providerName = Database.GetDefaultProviderName();
Debug.Assert(!String.IsNullOrEmpty(providerName), "Provider name should not be null or empty");
string connectionString = GetConnectionString(fileName);
return new ConnectionConfiguration(providerName, connectionString);
}
public static string GetConnectionString(string fileName)
{
if (Path.IsPathRooted(fileName))
{
return String.Format(CultureInfo.InvariantCulture, SqlCeConnectionStringFormat, fileName);
}
// Use |DataDirectory| if the path isn't rooted
string dataSource = @"|DataDirectory|\" + Path.GetFileName(fileName);
return String.Format(CultureInfo.InvariantCulture, SqlCeConnectionStringFormat, dataSource);
}
}
}

View File

@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Globalization;
using System.IO;
namespace WebMatrix.Data
{
internal class SqlServerDbFileHandler : IDbFileHandler
{
private const string SqlServerConnectionStringFormat = @"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Initial Catalog={1};Integrated Security=True;User Instance=True;MultipleActiveResultSets=True";
private const string SqlServerProviderName = "System.Data.SqlClient";
public IConnectionConfiguration GetConnectionConfiguration(string fileName)
{
return new ConnectionConfiguration(SqlServerProviderName, GetConnectionString(fileName, Database.DataDirectory));
}
internal static string GetConnectionString(string fileName, string dataDirectory)
{
if (Path.IsPathRooted(fileName))
{
// Attach the db as the file name if it is rooted
return String.Format(CultureInfo.InvariantCulture, SqlServerConnectionStringFormat, fileName, fileName);
}
// Use |DataDirectory| if the path isn't rooted
string dataSource = @"|DataDirectory|\" + Path.GetFileName(fileName);
// Set the full path for the initial catalog so we attach as that
string initialCatalog = Path.Combine(dataDirectory, Path.GetFileName(fileName));
return String.Format(CultureInfo.InvariantCulture, SqlServerConnectionStringFormat, dataSource, initialCatalog);
}
}
}

View File

@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Runtime.sln))\tools\WebStack.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<CodeAnalysis Condition=" '$(CodeAnalysis)' == '' ">false</CodeAnalysis>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4D39BAAF-8A96-473E-AB79-C8A341885137}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>WebMatrix.Data</RootNamespace>
<AssemblyName>WebMatrix.Data</AssemblyName>
<FileAlignment>512</FileAlignment>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;ASPNETWEBPAGES</DefineConstants>
<CodeAnalysisRuleSet>..\Strict.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>TRACE;ASPNETWEBPAGES</DefineConstants>
<CodeAnalysisRuleSet>..\Strict.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>$(CodeAnalysis)</RunCodeAnalysis>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'CodeCoverage|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\bin\CodeCoverage\</OutputPath>
<DefineConstants>TRACE;DEBUG;CODE_COVERAGE;ASPNETWEBPAGES</DefineConstants>
<DebugType>full</DebugType>
<CodeAnalysisRuleSet>..\Strict.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\CommonResources.Designer.cs">
<Link>Common\CommonResources.Designer.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CommonResources.resx</DependentUpon>
</Compile>
<Compile Include="..\ExceptionHelper.cs">
<Link>Common\ExceptionHelper.cs</Link>
</Compile>
<Compile Include="..\GlobalSuppressions.cs">
<Link>Common\GlobalSuppressions.cs</Link>
</Compile>
<Compile Include="..\TransparentCommonAssemblyInfo.cs">
<Link>Properties\TransparentCommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ConfigurationManagerWrapper.cs" />
<Compile Include="ConnectionConfiguration.cs" />
<Compile Include="ConnectionEventArgs.cs" />
<Compile Include="Database.cs" />
<Compile Include="DbProviderFactoryWrapper.cs" />
<Compile Include="DynamicRecord.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IConfigurationManager.cs" />
<Compile Include="IConnectionConfiguration.cs" />
<Compile Include="IDbFileHandler.cs" />
<Compile Include="IDbProviderFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\DataResources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>DataResources.resx</DependentUpon>
</Compile>
<Compile Include="SqlCeDbFileHandler.cs" />
<Compile Include="SqlServerDbFileHandler.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\CommonResources.resx">
<Link>Common\CommonResources.resx</Link>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>CommonResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\DataResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>DataResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CodeAnalysisDictionary.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>