Skip to content

Commit

Permalink
Merge pull request #67 from RapidScada/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
2mik committed Jul 30, 2018
2 parents fa4616d + 3c81325 commit 4c81d1c
Show file tree
Hide file tree
Showing 88 changed files with 1,557 additions and 430 deletions.
4 changes: 2 additions & 2 deletions HowToBuild.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
How to Build Rapid SCADA
------------------------
Microsoft Visual Studio 2015 or higher is needed. Visual Studio Community is OK.
Microsoft Visual Studio 2017 is needed. Visual Studio Community is OK.

1. Download the source code from SCADA and DLL repositories:
https://github.com/RapidScada/scada
Expand All @@ -17,6 +17,6 @@ Microsoft Visual Studio 2015 or higher is needed. Visual Studio Community is OK.
ScadaWeb,
ScadaScheme.

Use the Release configuration so that the links are correct.
Switch to the Release configuration so that the references are correct.

3. Enjoy the binaries built by yourself.
10 changes: 6 additions & 4 deletions ScadaComm/OpenKPs/KpModbus/KpModbusLogic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Mikhail Shiryaev
* Copyright 2018 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 : 2012
* Modified : 2017
* Modified : 2018
*/

using Scada.Comm.Devices.Modbus.Protocol;
Expand All @@ -29,6 +29,7 @@
using Scada.Data.Tables;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

namespace Scada.Comm.Devices
Expand Down Expand Up @@ -293,9 +294,10 @@ public override void OnAddedToCommLine()
"{0} Загрузка шаблона устройства из файла {1}" :
"{0} Load device template from file {1}", CommUtils.GetNowDT(), fileName));
DeviceTemplate template = new DeviceTemplate();
string errMsg;
string filePath = Path.IsPathRooted(fileName) ?
fileName : Path.Combine(AppDirs.ConfigDir, fileName);

if (template.Load(AppDirs.ConfigDir + fileName, out errMsg))
if (template.Load(filePath, out string errMsg))
{
deviceTemplate = template;
templates.Add(fileName, template);
Expand Down
2 changes: 1 addition & 1 deletion ScadaComm/OpenKPs/KpModbus/KpModbusView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class KpModbusView : KPView
/// <summary>
/// Версия библиотеки КП
/// </summary>
internal const string KpVersion = "5.1.0.2";
internal const string KpVersion = "5.1.0.3";


/// <summary>
Expand Down
27 changes: 23 additions & 4 deletions ScadaComm/OpenKPs/KpModbus/Modbus/UI/FrmDevProps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,26 @@ private void EditDevTemplate(string fileName)
FrmDevTemplate.ShowDialog(appDirs, true, ref fileName);

if (!string.IsNullOrEmpty(fileName))
txtDevTemplate.Text = Path.GetFileName(fileName);
txtDevTemplate.Text = MakeRelative(fileName);
}

/// <summary>
/// Преобразовать имя файла, которое задано относительно директории конфигурации, в абсолютное
/// </summary>
private string MakeAbsolute(string fileName)
{
return Path.IsPathRooted(fileName) ?
fileName : Path.Combine(appDirs.ConfigDir, fileName);
}

/// <summary>
/// Преобразовать имя файла в относительное по отношению к директории конфигурации,
/// если файл находится внутри этой директоии
/// </summary>
private string MakeRelative(string fileName)
{
return fileName.StartsWith(appDirs.ConfigDir, StringComparison.OrdinalIgnoreCase) ?
fileName.Substring(appDirs.ConfigDir.Length) : fileName;
}

/// <summary>
Expand Down Expand Up @@ -115,7 +134,7 @@ private void btnBrowseDevTemplate_Click(object sender, EventArgs e)
{
openFileDialog.FileName = "";
if (openFileDialog.ShowDialog() == DialogResult.OK)
txtDevTemplate.Text = Path.GetFileName(openFileDialog.FileName);
txtDevTemplate.Text = MakeRelative(openFileDialog.FileName);
txtDevTemplate.Select();
}

Expand All @@ -127,14 +146,14 @@ private void btnCreateDevTemplate_Click(object sender, EventArgs e)

private void btnEditDevTemplate_Click(object sender, EventArgs e)
{
EditDevTemplate(appDirs.ConfigDir + txtDevTemplate.Text);
EditDevTemplate(MakeAbsolute(txtDevTemplate.Text));
txtDevTemplate.Select();
}

private void btnOK_Click(object sender, EventArgs e)
{
// проверка существования файла шаблона устройства
if (!File.Exists(appDirs.ConfigDir + txtDevTemplate.Text))
if (!File.Exists(MakeAbsolute(txtDevTemplate.Text)))
{
ScadaUiUtils.ShowError(KpPhrases.TemplNotExists);
return;
Expand Down
46 changes: 35 additions & 11 deletions ScadaData/ScadaData.Dao/BaseDAO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Mikhail Shiryaev
* Copyright 2018 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 : 2017
* Modified : 2017
* Modified : 2018
*/

using System;
Expand Down Expand Up @@ -48,18 +48,10 @@ public BaseDAO()
}


/// <summary>
/// Удалить все начальные и конечные знаки пробелов, заменить null на пустую строку
/// </summary>
protected void Trim(ref string s)
{
s = s == null ? "" : s.Trim();
}

/// <summary>
/// Получить шаблон для поиска с помощью выражения LIKE
/// </summary>
protected string GetLikePattern(string filter)
protected string BuildLikePattern(string filter)
{
return filter == null ?
"" :
Expand Down Expand Up @@ -89,5 +81,37 @@ protected DateTime ConvertToDateTime(object value)
{
return value == null || value == DBNull.Value ? DateTime.MinValue : (DateTime)value;
}

/// <summary>
/// Получить значение строки для записи в БД
/// </summary>
protected object GetParamValue(string s)
{
return string.IsNullOrEmpty(s) ? DBNull.Value : (object)s.Trim();
}

/// <summary>
/// Получить значение идентификатора для записи в БД
/// </summary>
protected object GetParamValue(int id)
{
return id <= 0 ? DBNull.Value : (object)id;
}

/// <summary>
/// Получить значение вещественного числа для записи в БД
/// </summary>
protected object GetParamValue(double value)
{
return double.IsNaN(value) ? DBNull.Value : (object)value;
}

/// <summary>
/// Получить значение даты и времени для записи в БД
/// </summary>
protected object GetParamValue(DateTime value)
{
return value == DateTime.MinValue ? DBNull.Value : (object)value;
}
}
}
2 changes: 1 addition & 1 deletion ScadaData/ScadaData.Dao/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rapid SCADA")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyCopyright("Copyright © 2017-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
143 changes: 143 additions & 0 deletions ScadaData/ScadaData.Dao/RequestParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright 2018 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 : ScadaData.Dao
* Summary : The class to simplify work with parameters of an SQL command
*
* Author : Mikhail Shiryaev
* Created : 2018
* Modified : 2018
*/

using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;

namespace Scada.Dao
{
/// <summary>
/// The class to simplify work with parameters of an SQL command
/// <para>Класс для упрощения работы с параметрами SQL-команды</para>
/// </summary>
public class RequestParams
{
/// <summary>
/// Parameter of SQL command
/// </summary>
protected class Param
{
/// <summary>
/// Gets or sets the statement to insert into an SQL clause
/// </summary>
public string SqlStatement { get; set; }
/// <summary>
/// Gets or sets the parameter name of used by a command
/// </summary>
public string ParameterName { get; set; }
/// <summary>
/// Gets or sets the parameter value
/// </summary>
public object Value { get; set; }

/// <summary>
/// Adds the parameter to the command
/// </summary>
public virtual void AddToCommand(DbCommand command)
{
DbParameter dbParam = command.CreateParameter();
dbParam.ParameterName = ParameterName;
dbParam.Value = Value;
command.Parameters.Add(dbParam);
}
}


/// <summary>
/// Initializes a new instance of the class
/// </summary>
public RequestParams()
{
ParamList = new List<Param>();
}


/// <summary>
/// Gets or sets the list of the request parameters
/// </summary>
protected List<Param> ParamList { get; set; }


/// <summary>
/// Adds a new parameter with the specified properties
/// </summary>
public void Add(string sqlStatement, string parameterName, object value, bool condition = true)
{
if (condition)
{
ParamList.Add(new Param()
{
SqlStatement = sqlStatement,
ParameterName = parameterName,
Value = value
});
}
}

/// <summary>
/// Builds a string contains WHERE clause that includes the parameters
/// </summary>
public string BuildWhereClause()
{
if (ParamList.Count > 0)
{
StringBuilder sb = new StringBuilder("WHERE ");
bool first = true;

foreach (Param param in ParamList)
{
if (first)
first = false;
else
sb.Append(" AND ");

sb.Append(param.SqlStatement);
}

return sb.ToString();
}
else
{
return "";
}
}

/// <summary>
/// Adds the parameters to the command
/// </summary>
public void AddToCommand(DbCommand command)
{
if (command == null)
throw new ArgumentNullException("command");

foreach (Param param in ParamList)
{
param.AddToCommand(command);
}
}
}
}
2 changes: 2 additions & 0 deletions ScadaData/ScadaData.Dao/ScadaData.Dao.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\ScadaData.Dao.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Npgsql">
Expand All @@ -40,6 +41,7 @@
<Compile Include="BaseDAO.cs" />
<Compile Include="PgSqlDAO.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequestParams.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
15 changes: 13 additions & 2 deletions ScadaData/ScadaData/Cache.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Mikhail Shiryaev
* Copyright 2018 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 : 2016
* Modified : 2017
* Modified : 2018
*/

using System;
Expand Down Expand Up @@ -310,6 +310,17 @@ public void RemoveOutdatedItems(DateTime nowDT)
}
}

/// <summary>
/// Удалить элемент по ключу
/// </summary>
public void RemoveItem(TKey key)
{
lock (this)
{
items.Remove(key);
}
}

/// <summary>
/// Очистить кэш
/// </summary>
Expand Down
Loading

0 comments on commit 4c81d1c

Please sign in to comment.