Initial check-in
This commit is contained in:
120
Source/Program/Common/Misc/FileAndFolderManager.cs
Normal file
120
Source/Program/Common/Misc/FileAndFolderManager.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// UNCLASSIFIED
|
||||
/*-------------------------------------------------------------------------
|
||||
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
COMPANY.
|
||||
|
||||
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
|
||||
GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Raytheon.Common;
|
||||
|
||||
namespace ProgramLib
|
||||
{
|
||||
/// <summary>
|
||||
/// Partial class... this is the main class responsible for parsing config.ini in order
|
||||
/// to construct file paths and folder paths
|
||||
/// </summary>
|
||||
internal partial class FileAndFolderManager
|
||||
{
|
||||
private Dictionary<Folders, string> foldersDict = new Dictionary<Folders, string>();
|
||||
private Dictionary<Files, string> filesDict = new Dictionary<Files, string>();
|
||||
|
||||
private IConfigurationFile _programConfig;
|
||||
|
||||
/// <summary>
|
||||
/// The private constructor
|
||||
/// </summary>
|
||||
/// <param name="programConfig">the UUT part number</param>
|
||||
public FileAndFolderManager(IConfigurationFile programConfig)
|
||||
{
|
||||
_programConfig = programConfig;
|
||||
|
||||
buildFolders();
|
||||
createFolders();
|
||||
buildFiles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build folder paths so we can acccess them later
|
||||
/// </summary>
|
||||
/// <param name="iniObj"></param>
|
||||
/// <returns></returns>
|
||||
private void buildFolders()
|
||||
{
|
||||
string dataBasePath = _programConfig.ReadValue(ProgramConfigIni.GENERAL.ToString(), ProgramConfigIni.DATA_BASE_PATH.ToString(), "NOT SET");
|
||||
foldersDict[Folders.DATA] = dataBasePath;
|
||||
|
||||
string val = _programConfig.ReadValue(ProgramConfigIni.GENERAL.ToString(), ProgramConfigIni.DATA_TEMP_PATH.ToString(), "NOT SET");
|
||||
foldersDict[Folders.DATA_TEMP] = Path.Combine(dataBasePath, val);
|
||||
|
||||
string appBasePath = _programConfig.ReadValue(ProgramConfigIni.GENERAL.ToString(), ProgramConfigIni.APP_BASE_PATH.ToString(), "NOT SET");
|
||||
foldersDict[Folders.APP] = dataBasePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We create all the necessary folders
|
||||
/// </summary>
|
||||
/// <param name="iniObj"></param>
|
||||
/// <returns></returns>
|
||||
private void createFolders()
|
||||
{
|
||||
Directory.CreateDirectory(foldersDict[Folders.DATA_TEMP]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build file paths so we can acccess them later
|
||||
/// </summary>
|
||||
/// <param name="iniObj"></param>
|
||||
/// <returns></returns>
|
||||
private void buildFiles()
|
||||
{
|
||||
string val = _programConfig.ReadValue(ProgramConfigIni.GENERAL.ToString(), ProgramConfigIni.POWER_SUPPLY_SELF_TEST_DATETIME.ToString(), "NOT SET");
|
||||
filesDict[Files.POWER_SUPPLY_SELF_TEST_DATETIME] = Path.Combine(foldersDict[Folders.DATA_TEMP], val);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the full folder path
|
||||
/// </summary>
|
||||
/// <param name="folder"></param>
|
||||
/// <returns></returns>
|
||||
public string getFolder(Folders folder)
|
||||
{
|
||||
if (foldersDict.ContainsKey(folder))
|
||||
{
|
||||
return foldersDict[folder];
|
||||
}
|
||||
else
|
||||
throw new Exception($"{folder.ToString()} is invalid");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the full file path
|
||||
/// </summary>
|
||||
/// <param name="iniObj"></param>
|
||||
/// <returns></returns>
|
||||
public string getFile(Files file)
|
||||
{
|
||||
if (filesDict.ContainsKey(file))
|
||||
{
|
||||
return filesDict[file];
|
||||
}
|
||||
else
|
||||
throw new Exception($"{file.ToString()} is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user