Major upgrade
This commit is contained in:
49
Source/ProgramPostBuild/ConfigFiles/NLog.config
Normal file
49
Source/ProgramPostBuild/ConfigFiles/NLog.config
Normal file
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
|
||||
|
||||
<!--
|
||||
See http://nlog-project.org/wiki/Configuration_file
|
||||
for information on customizing logging rules and outputs.
|
||||
-->
|
||||
<!-- add your targets here -->
|
||||
<targets>
|
||||
<default-wrapper xsi:type="AsyncWrapper" batchSize="1000" overflowAction="Grow" timeToSleepBetweenBatches="1"/>
|
||||
|
||||
<target type="FallbackGroup" name="FusionLogging" returnToFirstOnSuccess="true">
|
||||
<target type="File" name="FileBackup" fileName="${specialFolder:CommonApplicationData}/Raytheon/logs/${shortdate}/${logger}.log" layout="${longdate} | ${logger} | ${message} ${exception}"/>
|
||||
<target type="File" name="LocalFileBackup" fileName="${basedir}/logs/${shortdate}/${logger}.log" layout="${longdate} | ${logger} | ${message} ${exception}"/>
|
||||
</target>
|
||||
|
||||
<target name="logDashboard" type="Chainsaw" address="udp://127.0.0.1:7777" />
|
||||
|
||||
<target xsi:type="File" name="logFiles" fileName="${specialfolder:folder=CommonApplicationData}/Raytheon/logs/${shortdate}/${logger:fsNormalize=true}.log" layout="${log4jxmlevent}" />
|
||||
<target xsi:type="File" name="RunFile" filename="NLog\${shortdate}\nlog_${processinfo:StartTime:format=ddMMyyyy_HHmmss:cached=true}.log" layout="${log4jxmlevent}" />
|
||||
|
||||
<target name="console" type="ColoredConsole" layout="${longdate} | ${logger} | ${message} ${exception}"/>
|
||||
|
||||
<target name="blackHole" xsi:type="Null" />
|
||||
|
||||
</targets>
|
||||
|
||||
<!-- add your logging rules here
|
||||
Log level (lowest to highest):
|
||||
1. TRACE
|
||||
2. DEBUG
|
||||
3. INFO
|
||||
4. WARN
|
||||
5. ERROR
|
||||
6. FATAL
|
||||
-->
|
||||
<rules>
|
||||
<!-- Enable/Disable log level here
|
||||
To Disable a log level, set "enable" attribute to true
|
||||
To Enable a log level, set "enable" attribute to false -->
|
||||
<logger levels="Trace" name="*" writeTo="blackHole" final="true" enabled="false" />
|
||||
<logger levels="Info" name="*" writeTo="blackHole" final="true" enabled="false" />
|
||||
<logger levels="Debug" name="*" writeTo="blackHole" final="true" enabled="false" />
|
||||
<!-- ======================================= -->
|
||||
|
||||
<logger name="*" minlevel="Trace" writeTo="RunFile,console,LogDashboard" />
|
||||
</rules>
|
||||
</nlog>
|
||||
3
Source/ProgramPostBuild/ConfigFiles/config.ini
Normal file
3
Source/ProgramPostBuild/ConfigFiles/config.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
[TESTSTAND]
|
||||
DLL_PATH = ..\..\..\..\_Deployment\MTS
|
||||
TESTSTAND_SEQUENCE_PATH = ..\..\..\..\_Deployment\TestStand
|
||||
BIN
Source/ProgramPostBuild/Dependencies/NLogWrapper.Part.dll
Normal file
BIN
Source/ProgramPostBuild/Dependencies/NLogWrapper.Part.dll
Normal file
Binary file not shown.
190
Source/ProgramPostBuild/ProgramPostBuild.cs
Normal file
190
Source/ProgramPostBuild/ProgramPostBuild.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace ProgramPostBuild
|
||||
{
|
||||
/// <summary>
|
||||
/// Perform any needed function after Program project is built
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
private static ILogger _logger;
|
||||
private static object syncObj = new object();
|
||||
private static Dictionary<string, string> dllNameDict = new Dictionary<string, string>();
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
ModifyDllPathsInTestStandSequences();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modify paths to DLLs in TestStand sequence files
|
||||
/// </summary>
|
||||
static void ModifyDllPathsInTestStandSequences()
|
||||
{
|
||||
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
IConfigurationFile config = new ConfigurationFile(Path.Combine(assemblyFolder, "config.ini"));
|
||||
|
||||
string dllPath = config.ReadValue("TESTSTAND", "DLL_PATH");
|
||||
dllPath = Path.GetFullPath(Path.Combine(assemblyFolder, dllPath));
|
||||
string testStandSequencePath = config.ReadValue("TESTSTAND", "TESTSTAND_SEQUENCE_PATH");
|
||||
testStandSequencePath = Path.GetFullPath(Path.Combine(assemblyFolder, testStandSequencePath));
|
||||
|
||||
if (Directory.Exists(dllPath) && Directory.Exists(testStandSequencePath))
|
||||
{
|
||||
// get all DLL files
|
||||
string[] dllFileArray = Directory.GetFiles(dllPath, "*.dll");
|
||||
|
||||
// get all teststand sequence files
|
||||
List<string> seqFileList = Directory.GetFiles(testStandSequencePath, "*.seq", SearchOption.AllDirectories).ToList();
|
||||
|
||||
int maxTaskNum = Environment.ProcessorCount;
|
||||
List<Task> taskList = new List<Task>();
|
||||
|
||||
while (seqFileList.Count > 0)
|
||||
{
|
||||
if (taskList.Count < maxTaskNum)
|
||||
{
|
||||
string seqFilePath = seqFileList[0];
|
||||
taskList.Add(Task.Factory.StartNew(() => ModifyDllPathsInTestStandSequence(seqFilePath, dllFileArray)));
|
||||
seqFileList.RemoveAt(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = Task.WaitAny(taskList.ToArray());
|
||||
taskList.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
Task.WaitAll(taskList.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modify paths to DLLs in a TestStand sequence
|
||||
/// </summary>
|
||||
static void ModifyDllPathsInTestStandSequence(string seqFilePath, string[] dllFileArray)
|
||||
{
|
||||
string seqNewContent = "";
|
||||
FileStream fs = new FileStream(seqFilePath, FileMode.Open, FileAccess.Read);
|
||||
StreamReader reader = new StreamReader(fs, Encoding.Default);
|
||||
|
||||
string line;
|
||||
Console.WriteLine($"Processing {seqFilePath}");
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
Match regexMatch;
|
||||
|
||||
regexMatch = Regex.Match(line, @"<value>.+\\([^\.]+\.dll)</value>", RegexOptions.IgnoreCase);
|
||||
|
||||
if (regexMatch.Success)
|
||||
{
|
||||
string dllFile = regexMatch.Groups[1].Value;
|
||||
|
||||
bool dllExists = false;
|
||||
string[] dllStringArray = null;
|
||||
int index = 0;
|
||||
string[] seqStringArray = seqFilePath.Split('\\');
|
||||
|
||||
lock (syncObj)
|
||||
{
|
||||
if (dllNameDict.ContainsKey(dllFile))
|
||||
{
|
||||
dllStringArray = dllNameDict[dllFile].Split('\\');
|
||||
dllExists = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dllExists)
|
||||
{
|
||||
foreach (string dllFilePath in dllFileArray)
|
||||
{
|
||||
if (Regex.IsMatch(dllFilePath, Regex.Escape(dllFile) + @"$", RegexOptions.IgnoreCase))
|
||||
{
|
||||
lock (syncObj)
|
||||
{
|
||||
dllStringArray = dllFilePath.Split('\\');
|
||||
|
||||
if (!dllNameDict.ContainsKey(dllFile))
|
||||
{
|
||||
dllNameDict[dllFile] = dllFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (String.Equals(dllStringArray[index], seqStringArray[index], StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
index++;
|
||||
}
|
||||
|
||||
int numGoBacks = seqStringArray.Length - (index + 1);
|
||||
|
||||
string goBackString = String.Empty;
|
||||
for (int i = 1; i <= numGoBacks; i++)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(goBackString))
|
||||
goBackString += @"\";
|
||||
goBackString += "..";
|
||||
}
|
||||
|
||||
string goForwardString = String.Empty;
|
||||
|
||||
for (int i = index; i < dllStringArray.Length; i++)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(goForwardString))
|
||||
goForwardString += @"\";
|
||||
goForwardString += dllStringArray[i];
|
||||
}
|
||||
|
||||
string newRelPath = Path.Combine(goBackString, goForwardString);
|
||||
|
||||
line = Regex.Replace(line, @"<value>(.+\\[^\.]+\.dll)</value>", "<value>" + newRelPath + "</value>", RegexOptions.IgnoreCase);
|
||||
|
||||
}
|
||||
|
||||
seqNewContent += line + "\r\n";
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
fs.Close();
|
||||
|
||||
FileStream fs2 = null;
|
||||
StreamWriter writer = null;
|
||||
try
|
||||
{
|
||||
fs2 = new FileStream(seqFilePath, FileMode.Create, FileAccess.ReadWrite);
|
||||
writer = new StreamWriter(fs2, Encoding.Default);
|
||||
writer.Write(seqNewContent);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (writer != null)
|
||||
{
|
||||
writer.Close();
|
||||
fs2.Close();
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Completed {seqFilePath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
35
Source/ProgramPostBuild/ProgramPostBuild.csproj
Normal file
35
Source/ProgramPostBuild/ProgramPostBuild.csproj
Normal file
@@ -0,0 +1,35 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<OutputType>exe</OutputType>
|
||||
<Company>Raytheon Technologies</Company>
|
||||
<Product>Raytheon Common Library</Product>
|
||||
<Description>Raytheon Common Library</Description>
|
||||
<Authors>TEEC</Authors>
|
||||
<Copyright>Copyright © Raytheon Technologies $([System.DateTime]::get_now().ToString("yyyy"))</Copyright>
|
||||
|
||||
<!-- Dynamic Versioning (Suitable for Release) -->
|
||||
<!-- <Version>$(Version)$(Suffix)</Version> -->
|
||||
|
||||
<!-- Static Versioning (Suitable for Development) -->
|
||||
<Version>1.3.0</Version>
|
||||
<Configurations>Debug;Release;Deploy</Configurations>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyFilesToOutputDir" AfterTargets="AfterBuild">
|
||||
<ItemGroup>
|
||||
<FILES_1 Include="ConfigFiles\**\*.*" />
|
||||
<FILES_2 Include="Dependencies\*.*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(FILES_1)" DestinationFolder="$(OutDir)" />
|
||||
<Copy SourceFiles="@(FILES_2)" DestinationFolder="$(OutDir)" />
|
||||
<Exec Command="$(TargetPath)"/>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user