-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Db service changed from EntityFramework to M.D.SqlClient. Works on Wi…
…n and Android. Needed workaround from dotnet/SqlClient#1656 (comment)
- Loading branch information
Showing
10 changed files
with
210 additions
and
111 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using Java.Net; | ||
using Java.Security; | ||
using Java.Security.Cert; | ||
using Javax.Net.Ssl; | ||
|
||
namespace Magazynek.Platforms.Android | ||
{ | ||
internal class DangerousTrustProvider : Provider | ||
{ | ||
private const string TRUST_PROVIDER_ALG = "DangerousTrustAlgorithm"; | ||
private const string TRUST_PROVIDER_ID = "DangerousTrustProvider"; | ||
|
||
public DangerousTrustProvider() : base(TRUST_PROVIDER_ID, 1, string.Empty) | ||
{ | ||
var key = "TrustManagerFactory." + DangerousTrustManagerFactory.GetAlgorithm(); | ||
var val = Java.Lang.Class.FromType(typeof(DangerousTrustManagerFactory)).Name; | ||
Put(key, val); | ||
} | ||
|
||
public static void Register() | ||
{ | ||
Provider registered = Security.GetProvider(TRUST_PROVIDER_ID); | ||
if (null == registered) | ||
{ | ||
Security.InsertProviderAt(new DangerousTrustProvider(), 1); | ||
Security.SetProperty("ssl.TrustManagerFactory.algorithm", TRUST_PROVIDER_ALG); | ||
} | ||
} | ||
|
||
public class DangerousTrustManager : X509ExtendedTrustManager | ||
{ | ||
public override void CheckClientTrusted(X509Certificate[] chain, string authType, Socket socket) { } | ||
public override void CheckClientTrusted(X509Certificate[] chain, string authType, SSLEngine engine) { } | ||
public override void CheckClientTrusted(X509Certificate[] chain, string authType) { } | ||
public override void CheckServerTrusted(X509Certificate[] chain, string authType, Socket socket) { } | ||
public override void CheckServerTrusted(X509Certificate[] chain, string authType, SSLEngine engine) { } | ||
public override void CheckServerTrusted(X509Certificate[] chain, string authType) { } | ||
public override X509Certificate[] GetAcceptedIssuers() => Array.Empty<X509Certificate>(); | ||
} | ||
|
||
public class DangerousTrustManagerFactory : TrustManagerFactorySpi | ||
{ | ||
protected override void EngineInit(IManagerFactoryParameters mgrparams) { } | ||
protected override void EngineInit(KeyStore keystore) { } | ||
protected override ITrustManager[] EngineGetTrustManagers() => new ITrustManager[] { new DangerousTrustManager() }; | ||
public static string GetAlgorithm() => TRUST_PROVIDER_ALG; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Magazynek.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SqlClient; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Data.SqlClient; | ||
|
||
namespace Magazynek.Services | ||
{ | ||
public class DatabaseService | ||
{ | ||
public DatabaseService() | ||
{ | ||
|
||
|
||
} | ||
public List<AsortymentyModel> GetYourData() | ||
{ | ||
string srvrdbname = "Nexo_demo_1"; | ||
string srvrname = "192.168.2.164"; | ||
string srvrusername = "borys"; | ||
string srvrpassword = "admin"; | ||
|
||
string sqlconn = $"Data Source={srvrname};Initial Catalog={srvrdbname};MultipleActiveResultSets=true; User Id={srvrusername};Password={srvrpassword};Persist Security Info=True;TrustServerCertificate=True;Connection Timeout=30;"; | ||
|
||
List<AsortymentyModel> data = new List<AsortymentyModel>(); | ||
|
||
try | ||
{ | ||
using (SqlConnection connection = new SqlConnection(sqlconn)) | ||
{ | ||
connection.Open(); | ||
|
||
string sqlQuery = "SELECT Id, Nazwa FROM ModelDanychContainer.Asortymenty"; | ||
using (SqlCommand command = new SqlCommand(sqlQuery, connection)) | ||
{ | ||
using (SqlDataReader reader = command.ExecuteReader()) | ||
{ | ||
while (reader.Read()) | ||
{ | ||
AsortymentyModel item = new AsortymentyModel | ||
{ | ||
Id = reader.GetInt32(0), | ||
Nazwa = reader.GetString(1), | ||
// Map other properties as needed | ||
}; | ||
data.Add(item); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
string message = ex.Message; | ||
} | ||
|
||
return data; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.