-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #367 from leekelleher/dev/v4.x
Preparing v4.5.1 release
- Loading branch information
Showing
18 changed files
with
436 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.5.0 | ||
4.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...mbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.NET472.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* Copyright © 2019 Lee Kelleher. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
/* NOTE: This code file is ONLY for Umbraco v8, .NET Framework 4.7.2. | ||
* For the .NET Core 5.0 version, please see file `SqlDataListSource.NET5_0.cs`. */ | ||
|
||
#if NET472 | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data.Common; | ||
using System.Data.SqlClient; | ||
using System.Data.SqlServerCe; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Umbraco.Core; | ||
using Umbraco.Core.IO; | ||
using UmbConstants = Umbraco.Core.Constants; | ||
|
||
namespace Umbraco.Community.Contentment.DataEditors | ||
{ | ||
public sealed partial class SqlDataListSource : IDataListSource | ||
{ | ||
private readonly string _codeEditorMode; | ||
private readonly IEnumerable<DataListItem> _connectionStrings; | ||
private readonly IIOHelper _ioHelper; | ||
|
||
public SqlDataListSource( | ||
IWebHostEnvironment webHostEnvironment, | ||
IIOHelper ioHelper) | ||
{ | ||
// NOTE: Umbraco doesn't ship with SqlServer mode, so we check if its been added manually, otherwise defaults to Razor. | ||
_codeEditorMode = webHostEnvironment.WebPathExists("~/umbraco/lib/ace-builds/src-min-noconflict/mode-sqlserver.js") == true | ||
? "sqlserver" | ||
: "razor"; | ||
|
||
_connectionStrings = ConfigurationManager.ConnectionStrings | ||
.Cast<ConnectionStringSettings>() | ||
.Select(x => new DataListItem | ||
{ | ||
Name = x.Name, | ||
Value = x.Name | ||
}); | ||
|
||
_ioHelper = ioHelper; | ||
} | ||
|
||
public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config) | ||
{ | ||
var items = new List<DataListItem>(); | ||
|
||
var query = config.GetValueAs("query", string.Empty); | ||
var connectionStringName = config.GetValueAs("connectionString", string.Empty); | ||
|
||
if (string.IsNullOrWhiteSpace(query) == true || string.IsNullOrWhiteSpace(connectionStringName) == true) | ||
{ | ||
return items; | ||
} | ||
|
||
var settings = ConfigurationManager.ConnectionStrings[connectionStringName]; | ||
if (settings == null) | ||
{ | ||
return items; | ||
} | ||
|
||
// NOTE: SQLCE uses a different connection/command. I'm trying to keep this as generic as possible, without resorting to using NPoco. [LK] | ||
if (settings.ProviderName.InvariantEquals(UmbConstants.DatabaseProviders.SqlCe) == true) | ||
{ | ||
items.AddRange(GetSqlItems<SqlCeConnection, SqlCeCommand>(query, settings.ConnectionString)); | ||
} | ||
else | ||
{ | ||
items.AddRange(GetSqlItems<SqlConnection, SqlCommand>(query, settings.ConnectionString)); | ||
} | ||
|
||
return items; | ||
} | ||
|
||
private IEnumerable<DataListItem> GetSqlItems<TConnection, TCommand>(string query, string connectionString) | ||
where TConnection : DbConnection, new() | ||
where TCommand : DbCommand, new() | ||
{ | ||
using (var connection = new TConnection() { ConnectionString = connectionString }) | ||
using (var command = new TCommand() { Connection = connection, CommandText = query }) | ||
{ | ||
connection.Open(); | ||
using (var reader = command.ExecuteReader()) | ||
{ | ||
while (reader.Read() == true) | ||
{ | ||
if (reader.FieldCount > 0) | ||
{ | ||
var item = new DataListItem | ||
{ | ||
Name = reader[0].TryConvertTo<string>().Result | ||
}; | ||
|
||
item.Value = reader.FieldCount > 1 | ||
? reader[1].TryConvertTo<string>().Result | ||
: item.Name; | ||
|
||
if (reader.FieldCount > 2) | ||
item.Description = reader[2].TryConvertTo<string>().Result; | ||
|
||
if (reader.FieldCount > 3) | ||
item.Icon = reader[3].TryConvertTo<string>().Result; | ||
|
||
if (reader.FieldCount > 4) | ||
item.Disabled = reader[4].ToString().TryConvertTo<bool>().Result; | ||
|
||
yield return item; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#endif |
121 changes: 121 additions & 0 deletions
121
...mbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.NET5_0.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* Copyright © 2019 Lee Kelleher. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | ||
|
||
/* NOTE: This code file is ONLY for Umbraco v9, .NET Core 5.0. | ||
* For the .NET Core 6.0 version, please see file `SqlDataListSource.NET6_0.cs`. */ | ||
|
||
#if NET5_0 | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using System.Data.SqlClient; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Umbraco.Cms.Core.IO; | ||
using Umbraco.Extensions; | ||
|
||
namespace Umbraco.Community.Contentment.DataEditors | ||
{ | ||
public sealed partial class SqlDataListSource : IDataListSource | ||
{ | ||
private readonly string _codeEditorMode; | ||
private readonly IEnumerable<DataListItem> _connectionStrings; | ||
private readonly IIOHelper _ioHelper; | ||
private readonly IConfiguration _configuration; | ||
|
||
public SqlDataListSource( | ||
IWebHostEnvironment webHostEnvironment, | ||
IConfiguration configuration, | ||
IIOHelper ioHelper) | ||
{ | ||
// NOTE: Umbraco doesn't ship with SqlServer mode, so we check if its been added manually, otherwise defaults to Razor. | ||
_codeEditorMode = webHostEnvironment.WebPathExists("~/umbraco/lib/ace-builds/src-min-noconflict/mode-sqlserver.js") == true | ||
? "sqlserver" | ||
: "razor"; | ||
|
||
_connectionStrings = configuration | ||
.GetSection("ConnectionStrings") | ||
.GetChildren() | ||
.Where(x => x.Key.InvariantEndsWith("_ProviderName") == false) | ||
.Select(x => new DataListItem | ||
{ | ||
Name = x.Key, | ||
Value = x.Key | ||
}); | ||
|
||
_configuration = configuration; | ||
_ioHelper = ioHelper; | ||
} | ||
|
||
public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config) | ||
{ | ||
var items = new List<DataListItem>(); | ||
|
||
var query = config.GetValueAs("query", string.Empty); | ||
var connectionStringName = config.GetValueAs("connectionString", string.Empty); | ||
|
||
if (string.IsNullOrWhiteSpace(query) == true || string.IsNullOrWhiteSpace(connectionStringName) == true) | ||
{ | ||
return items; | ||
} | ||
|
||
var connectionString = _configuration.GetConnectionString(connectionStringName); | ||
if (string.IsNullOrWhiteSpace(connectionString) == true) | ||
{ | ||
return items; | ||
} | ||
|
||
// TODO: [v9] [LK:2021-05-07] Review SQLCE | ||
// NOTE: SQLCE uses a different connection/command. I'm trying to keep this as generic as possible, without resorting to using NPoco. [LK] | ||
// I've tried digging around Umbraco's `IUmbracoDatabase` layer, but I couldn't get my head around it. | ||
// At the end of the day, if the user has SQLCE configured, it'd be nice for them to query it. | ||
// But I don't want to add an assembly dependency (for SQLCE) to Contentment itself. I'd like to leverage Umbraco's code. | ||
|
||
items.AddRange(GetSqlItems<SqlConnection, SqlCommand>(query, connectionString)); | ||
|
||
return items; | ||
} | ||
|
||
private IEnumerable<DataListItem> GetSqlItems<TConnection, TCommand>(string query, string connectionString) | ||
where TConnection : DbConnection, new() | ||
where TCommand : DbCommand, new() | ||
{ | ||
using (var connection = new TConnection() { ConnectionString = connectionString }) | ||
using (var command = new TCommand() { Connection = connection, CommandText = query }) | ||
{ | ||
connection.Open(); | ||
using (var reader = command.ExecuteReader()) | ||
{ | ||
while (reader.Read() == true) | ||
{ | ||
if (reader.FieldCount > 0) | ||
{ | ||
var item = new DataListItem | ||
{ | ||
Name = reader[0].TryConvertTo<string>().Result | ||
}; | ||
|
||
item.Value = reader.FieldCount > 1 | ||
? reader[1].TryConvertTo<string>().Result | ||
: item.Name; | ||
|
||
if (reader.FieldCount > 2) | ||
item.Description = reader[2].TryConvertTo<string>().Result; | ||
|
||
if (reader.FieldCount > 3) | ||
item.Icon = reader[3].TryConvertTo<string>().Result; | ||
|
||
if (reader.FieldCount > 4) | ||
item.Disabled = reader[4].ToString().TryConvertTo<bool>().Result; | ||
|
||
yield return item; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#endif |
Oops, something went wrong.