Skip to content

Commit

Permalink
Merge pull request #86 from RapidScada/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
2mik authored Jun 6, 2019
2 parents cfae856 + e28c071 commit 56aa650
Show file tree
Hide file tree
Showing 18 changed files with 802 additions and 80 deletions.
4 changes: 2 additions & 2 deletions ScadaAdmin/ScadaAdmin5/ScadaAdminCommon/ImportExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,14 @@ public void ExportToArchive(string destFileName, ScadaProject project, Instance
}

// add the Communicator settings to the archive
if (uploadSettings.IncludeServer && instance.ServerApp.Enabled)
if (uploadSettings.IncludeComm && instance.CommApp.Enabled)
{
PackDirectory(zipArchive, instance.CommApp.AppDir,
DirectoryBuilder.GetDirectory(ConfigParts.Comm, '/'), ignoreRegKeys);
}

// add the Webstation settings to the archive
if (uploadSettings.IncludeServer && instance.ServerApp.Enabled)
if (uploadSettings.IncludeWeb && instance.WebApp.Enabled)
{
PackDirectory(zipArchive, Path.Combine(instance.WebApp.AppDir, "config"),
DirectoryBuilder.GetDirectory(ConfigParts.Web, AppFolder.Config, '/'), ignoreRegKeys);
Expand Down
29 changes: 27 additions & 2 deletions ScadaComm/OpenKPs/KpDbImport/DbImport/Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Mikhail Shiryaev
* Copyright 2019 Mikhail Shiryaev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,11 @@
*
* Author : Mikhail Shiryaev
* Created : 2018
* Modified : 2018
* Modified : 2019
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;

Expand Down Expand Up @@ -69,6 +70,11 @@ public Config()
/// </summary>
public int TagCount { get; set; }

/// <summary>
/// Gets the export commands.
/// </summary>
public List<ExportCmd> ExportCmds { get; private set; }


/// <summary>
/// Sets the default values.
Expand All @@ -80,6 +86,7 @@ private void SetToDefault()
SelectQuery = "";
AutoTagCount = true;
TagCount = 0;
ExportCmds = new List<ExportCmd>();
}


Expand All @@ -105,6 +112,18 @@ public bool Load(string fileName, out string errMsg)
AutoTagCount = rootElem.GetChildAsBool("AutoTagCount");
TagCount = rootElem.GetChildAsInt("TagCount");

if (rootElem.SelectSingleNode("ExportCmds") is XmlNode exportCmdsNode)
{
foreach (XmlNode exportCmdNode in exportCmdsNode.SelectNodes("ExportCmd"))
{
ExportCmd exportCmd = new ExportCmd();
exportCmd.LoadFromXml(exportCmdNode);
ExportCmds.Add(exportCmd);
}

ExportCmds.Sort();
}

errMsg = "";
return true;
}
Expand Down Expand Up @@ -135,6 +154,12 @@ public bool Save(string fileName, out string errMsg)
rootElem.AppendElem("AutoTagCount", AutoTagCount);
rootElem.AppendElem("TagCount", TagCount);

XmlElement exportCmdsElem = rootElem.AppendElem("ExportCmds");
foreach (ExportCmd exportCmd in ExportCmds)
{
exportCmd.SaveToXml(exportCmdsElem.AppendElem("ExportCmd"));
}

xmlDoc.Save(fileName);
errMsg = "";
return true;
Expand Down
106 changes: 106 additions & 0 deletions ScadaComm/OpenKPs/KpDbImport/DbImport/Configuration/ExportCmd.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2019 Mikhail Shiryaev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* Product : Rapid SCADA
* Module : KpDBImport
* Summary : Configuration of a data export command
*
* Author : Mikhail Shiryaev
* Created : 2019
* Modified : 2019
*/

using System;
using System.Xml;

namespace Scada.Comm.Devices.DbImport.Configuration
{
/// <summary>
/// Configuration of a data export command.
/// <para>Конфигурация команды экспорта данных.</para>
/// </summary>
internal class ExportCmd : IComparable<ExportCmd>
{
/// <summary>
/// Initializes a new instance of the class.
/// </summary>
public ExportCmd()
{
CmdNum = 1;
Name = "";
Query = "";
}


/// <summary>
/// Gets or sets the command number.
/// </summary>
public int CmdNum { get; set; }

/// <summary>
/// Gets or sets the command name.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the SQL-query of the command.
/// </summary>
public string Query { get; set; }


/// <summary>
/// Loads the command from the XML node.
/// </summary>
public void LoadFromXml(XmlNode xmlNode)
{
if (xmlNode == null)
throw new ArgumentNullException("xmlNode");

CmdNum = xmlNode.GetChildAsInt("CmdNum");
Name = xmlNode.GetChildAsString("Name");
Query = xmlNode.GetChildAsString("Query");
}

/// <summary>
/// Saves the command into the XML node.
/// </summary>
public void SaveToXml(XmlElement xmlElem)
{
if (xmlElem == null)
throw new ArgumentNullException("xmlElem");

xmlElem.AppendElem("CmdNum", CmdNum);
xmlElem.AppendElem("Name", Name);
xmlElem.AppendElem("Query", Query);
}

/// <summary>
/// Compares the current instance with another object of the same type.
/// </summary>
public int CompareTo(ExportCmd other)
{
return CmdNum.CompareTo(other.CmdNum);
}

/// <summary>
/// Returns a string that represents the current object.
/// </summary>
public override string ToString()
{
return string.Format("[{0}] {1}", CmdNum, Name);
}
}
}
41 changes: 39 additions & 2 deletions ScadaComm/OpenKPs/KpDbImport/DbImport/Data/DataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

using Scada.Comm.Devices.DbImport.Configuration;
using System;
using System.Collections.Generic;
using System.Data.Common;

namespace Scada.Comm.Devices.DbImport.Data
Expand All @@ -42,6 +43,7 @@ protected DataSource()
{
Connection = null;
SelectCommand = null;
ExportCommands = new SortedList<int, DbCommand>();
}


Expand All @@ -55,6 +57,11 @@ protected DataSource()
/// </summary>
public DbCommand SelectCommand { get; protected set; }

/// <summary>
/// Gets the export commands.
/// </summary>
public SortedList<int, DbCommand> ExportCommands { get; protected set; }


/// <summary>
/// Creates a database connection.
Expand All @@ -66,6 +73,11 @@ protected DataSource()
/// </summary>
protected abstract DbCommand CreateCommand();

/// <summary>
/// Adds the command parameter containing the value.
/// </summary>
protected abstract void AddCmdParamWithValue(DbCommand cmd, string paramName, object value);

/// <summary>
/// Clears the connection pool.
/// </summary>
Expand Down Expand Up @@ -128,14 +140,39 @@ public void Disconnect()
/// <summary>
/// Initializes the data source.
/// </summary>
public void Init(string connectionString, string selectQuery)
public void Init(string connectionString, Config config)
{
if (config == null)
throw new ArgumentNullException("config");

Connection = CreateConnection();
Connection.ConnectionString = connectionString;

SelectCommand = CreateCommand();
SelectCommand.CommandText = selectQuery;
SelectCommand.CommandText = config.SelectQuery;
SelectCommand.Connection = Connection;

foreach (ExportCmd exportCmd in config.ExportCmds)
{
DbCommand exportCommand = CreateCommand();
exportCommand.CommandText = exportCmd.Query;
exportCommand.Connection = Connection;
ExportCommands[exportCmd.CmdNum] = exportCommand;
}
}

/// <summary>
/// Sets the command parameter.
/// </summary>
public void SetCmdParam(DbCommand cmd, string paramName, object value)
{
if (cmd == null)
throw new ArgumentNullException("cmd");

if (cmd.Parameters.Contains(paramName))
cmd.Parameters[paramName].Value = value;
else
AddCmdParamWithValue(cmd, paramName, value);
}
}
}
18 changes: 16 additions & 2 deletions ScadaComm/OpenKPs/KpDbImport/DbImport/Data/MySqlDataSource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Mikhail Shiryaev
* Copyright 2019 Mikhail Shiryaev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@
*
* Author : Mikhail Shiryaev
* Created : 2018
* Modified : 2018
* Modified : 2019
*/

using MySql.Data.MySqlClient;
Expand Down Expand Up @@ -58,6 +58,20 @@ protected override DbCommand CreateCommand()
return new MySqlCommand();
}

/// <summary>
/// Adds the command parameter containing the value.
/// </summary>
protected override void AddCmdParamWithValue(DbCommand cmd, string paramName, object value)
{
if (cmd == null)
throw new ArgumentNullException("cmd");
if (!(cmd is MySqlCommand))
throw new ArgumentException("MySqlCommand is required.", "cmd");

MySqlCommand mySqlCmd = (MySqlCommand)cmd;
mySqlCmd.Parameters.AddWithValue(paramName, value);
}

/// <summary>
/// Clears the connection pool.
/// </summary>
Expand Down
19 changes: 17 additions & 2 deletions ScadaComm/OpenKPs/KpDbImport/DbImport/Data/OleDbDataSource.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Mikhail Shiryaev
* Copyright 2019 Mikhail Shiryaev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,11 @@
*
* Author : Mikhail Shiryaev
* Created : 2018
* Modified : 2018
* Modified : 2019
*/

using Scada.Comm.Devices.DbImport.Configuration;
using System;
using System.Data.Common;
using System.Data.OleDb;

Expand Down Expand Up @@ -51,6 +52,20 @@ protected override DbCommand CreateCommand()
return new OleDbCommand();
}

/// <summary>
/// Adds the command parameter containing the value.
/// </summary>
protected override void AddCmdParamWithValue(DbCommand cmd, string paramName, object value)
{
if (cmd == null)
throw new ArgumentNullException("cmd");
if (!(cmd is OleDbCommand))
throw new ArgumentException("OleDbCommand is required.", "cmd");

OleDbCommand oleDbCmd = (OleDbCommand)cmd;
oleDbCmd.Parameters.AddWithValue(paramName, value);
}

/// <summary>
/// Clears the connection pool.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions ScadaComm/OpenKPs/KpDbImport/DbImport/Data/OraDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
using System.Data.Common;
using System.Data.OracleClient;

#pragma warning disable 618 // disable the warning about obsolete Oracle classes

namespace Scada.Comm.Devices.DbImport.Data
{
/// <summary>
Expand All @@ -52,6 +54,20 @@ protected override DbCommand CreateCommand()
return new OracleCommand();
}

/// <summary>
/// Adds the command parameter containing the value.
/// </summary>
protected override void AddCmdParamWithValue(DbCommand cmd, string paramName, object value)
{
if (cmd == null)
throw new ArgumentNullException("cmd");
if (!(cmd is OracleCommand))
throw new ArgumentException("OracleCommand is required.", "cmd");

OracleCommand oraCmd = (OracleCommand)cmd;
oraCmd.Parameters.AddWithValue(paramName, value);
}

/// <summary>
/// Clears the connection pool.
/// </summary>
Expand Down
Loading

0 comments on commit 56aa650

Please sign in to comment.