Skip to content

Commit

Permalink
Merge pull request #63 from RapidScada/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
2mik authored Sep 25, 2023
2 parents 150e3ea + 9522fc9 commit f0783ee
Show file tree
Hide file tree
Showing 133 changed files with 7,586 additions and 1,821 deletions.
Binary file modified Database/ConfigDatabase/scada_6.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Database/ConfigDatabase/scada_6.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
<COLUMN ID="2344" ColName="Code" PrevColName="" Pos="20" idDatatype="20" DatatypeParams="" Width="-1" Prec="-1" PrimaryKey="0" NotNull="0" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="0" />
</OPTIONSELECTED>
</COLUMN>
<COLUMN ID="1928" ColName="DataLen" PrevColName="" Pos="17" idDatatype="5" DatatypeParams="" Width="-1" Prec="-1" PrimaryKey="0" NotNull="0" AutoInc="0" IsForeignKey="0" DefaultValue="" Comments="">
<OPTIONSELECTED>
<OPTIONSELECT Value="1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DeviceMap(ILog log, ConfigDatabase configDatabase)


/// <summary>
/// Writes channels having the specified index key.
/// Writes devices having the specified index key.
/// </summary>
private static void WriteDevices(StreamWriter writer, ITableIndex index, int indexKey)
{
Expand Down
10 changes: 10 additions & 0 deletions ScadaAdmin/OpenExtensions/ExtProjectTools/Code/ExtensionPhrases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ internal class ExtensionPhrases
public static string ImportTableCompleted { get; private set; }
public static string ImportTableError { get; private set; }

// Scada.Admin.Extensions.ExtProjectTools.Code.ObjectMap
public static string ObjectMapTitle { get; private set; }
public static string NoObjects { get; private set; }
public static string GenerateObjectMapError { get; private set; }

public static void Init()
{
LocaleDict dict = Locale.GetDictionary("Scada.Admin.Extensions.ExtProjectTools.Code.ChannelMap");
Expand Down Expand Up @@ -85,6 +90,11 @@ public static void Init()
ImportTableFilter = dict["ImportTableFilter"];
ImportTableCompleted = dict["ImportTableCompleted"];
ImportTableError = dict["ImportTableError"];

dict = Locale.GetDictionary("Scada.Admin.Extensions.ExtProjectTools.Code.ObjectMap");
ObjectMapTitle = dict["ObjectMapTitle"];
NoObjects = dict["NoObjects"];
GenerateObjectMapError = dict["GenerateObjectMapError"];
}
}
}
84 changes: 84 additions & 0 deletions ScadaAdmin/OpenExtensions/ExtProjectTools/Code/ObjectMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Rapid Software LLC. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Scada.Admin.Project;
using Scada.Data.Entities;
using Scada.Data.Tables;
using Scada.Forms;
using Scada.Lang;
using Scada.Log;
using System.Text;

namespace Scada.Admin.Extensions.ExtProjectTools.Code
{
/// <summary>
/// Generates an object map of the configuration database.
/// <para>Генерирует карту объектов базы конфигурации.</para>
/// </summary>
internal class ObjectMap
{
/// <summary>
/// The file name of newly created maps.
/// </summary>
public const string MapFileName = "ScadaAdmin_ObjectMap.txt";

private readonly ILog log; // the application log
private readonly ConfigDatabase configDatabase; // the configuration database


/// <summary>
/// Initializes a new instance of the class.
/// </summary>
public ObjectMap(ILog log, ConfigDatabase configDatabase)
{
this.log = log ?? throw new ArgumentNullException(nameof(log));
this.configDatabase = configDatabase ?? throw new ArgumentNullException(nameof(configDatabase));
}


/// <summary>
/// Writes objects recursively.
/// </summary>
private static void WriteChildObjects(StreamWriter writer, ITableIndex parentObjIndex,
int parentObjNum, int level)
{
// infinite recursion is not possible for objects
foreach (Obj childObj in parentObjIndex.SelectItems(parentObjNum))
{
if (level > 0)
writer.Write(new string('-', level * 2) + " ");

writer.WriteLine(string.Format(CommonPhrases.EntityCaption, childObj.ObjNum, childObj.Name));
WriteChildObjects(writer, parentObjIndex, childObj.ObjNum, level + 1);
}
}

/// <summary>
/// Generates an object map.
/// </summary>
public void Generate(string mapFileName)
{
try
{
using (StreamWriter writer = new(mapFileName, false, Encoding.UTF8))
{
writer.WriteLine(ExtensionPhrases.ObjectMapTitle);
writer.WriteLine(new string('-', ExtensionPhrases.ObjectMapTitle.Length));

if (configDatabase.ObjTable.ItemCount == 0)
writer.WriteLine(ExtensionPhrases.NoObjects);
else if (configDatabase.ObjTable.TryGetIndex("ParentObjNum", out ITableIndex parentObjIndex))
WriteChildObjects(writer, parentObjIndex, 0, 0);
else
throw new ScadaException(CommonPhrases.IndexNotFound);
}

ScadaUiUtils.StartProcess(mapFileName);
}
catch (Exception ex)
{
log.HandleError(ex, ExtensionPhrases.GenerateObjectMapError);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f0783ee

Please sign in to comment.