aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-07-29 21:12:47 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-07-29 21:12:47 +0300
commit08bd8bac1498b6aa3bd264e5c466dd65a4386fd2 (patch)
tree1fb311c11e4975663957aa218ab818beb90528ac /Software/Visual_Studio/PPC/Tango.PPC.Common/SQL
parentbdf7e5a2abc2c9d3b7889d2d71754c33ea3efbf6 (diff)
downloadTango-08bd8bac1498b6aa3bd264e5c466dd65a4386fd2.tar.gz
Tango-08bd8bac1498b6aa3bd264e5c466dd65a4386fd2.zip
Procedures SQL, Resources, Variables.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/SQL')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/DefaultRemoteSqlService.cs76
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/IRemoteSqlService.cs13
2 files changed, 89 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/DefaultRemoteSqlService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/DefaultRemoteSqlService.cs
new file mode 100644
index 000000000..986c4d062
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/DefaultRemoteSqlService.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.BL;
+using Tango.Core.DI;
+using Tango.Integration.ExternalBridge;
+using Tango.PPC.Common.ExternalBridge;
+using Tango.PPC.Shared.SQL;
+
+namespace Tango.PPC.Common.SQL
+{
+ [TangoCreateWhenRegistered]
+ public class DefaultRemoteSqlService : IRemoteSqlService, IExternalBridgeRequestHandler
+ {
+ public bool Enabled { get; set; } = true;
+
+ public DefaultRemoteSqlService(IPPCExternalBridgeService externalBridge)
+ {
+ externalBridge.RegisterRequestHandler(this);
+ }
+
+ [ExternalBridgeRequestHandlerMethod(typeof(ExecuteSqlRequest), RequestHandlerLoggingMode.LogRequestNameAndContent)]
+ public async Task OnExecuteSqlRequest(ExecuteSqlRequest request, String token, ExternalBridgeReceiver receiver)
+ {
+ this.ThrowIfDisabled();
+
+ List<Dictionary<String, Object>> rows = new List<Dictionary<string, object>>();
+ int affected = 0;
+
+ using (ObservablesContext db = ObservablesContext.CreateDefault())
+ {
+ using (SqlConnection connection = new SqlConnection(db.Database.Connection.ConnectionString))
+ {
+ SqlCommand command = new SqlCommand(request.SQL, connection);
+ connection.Open();
+
+ SqlDataReader reader = command.ExecuteReader();
+ affected = reader.RecordsAffected;
+
+ try
+ {
+ while (reader.Read())
+ {
+ Dictionary<String, Object> row = new Dictionary<string, object>();
+
+ for (int i = 0; i < reader.FieldCount; i++)
+ {
+ row[reader.GetName(i)] = reader.GetValue(i);
+ }
+
+ rows.Add(row);
+ }
+ }
+ finally
+ {
+ reader.Close();
+ }
+ }
+ }
+
+ await receiver.SendGenericResponse(new ExecuteSqlResponse()
+ {
+ Rows = rows,
+ AffectedRecords = affected
+ }, token);
+ }
+
+ public void OnReceiverDisconnected(ExternalBridgeReceiver receiver)
+ {
+
+ }
+ }
+}
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/IRemoteSqlService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/IRemoteSqlService.cs
new file mode 100644
index 000000000..f70589090
--- /dev/null
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/SQL/IRemoteSqlService.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.PPC.Common.SQL
+{
+ public interface IRemoteSqlService : IPPCService
+ {
+
+ }
+}