Commit 0d9a5a81 authored by Alexander Dietsch's avatar Alexander Dietsch

-Corrected post-build event to also include the correct dll after each

building
-Deleted a legacy file
parent c3dc2cd9
......@@ -184,8 +184,8 @@
<PropertyGroup>
<PostBuildEvent>xcopy /Y "$(TargetDir)LWSimulatorGUI.exe" "$(SolutionDir)LWSimulatorCons\bin\Debug\"
xcopy /Y "$(TargetDir)LWSimulatorGUI.exe" "$(SolutionDir)LWSimulatorCons\bin\Release\"
xcopy /Y "$(TargetDir)LWSimulatorGUI.exe" "$(SolutionDir)LWSimulatorCons\bin\Debug\"
xcopy /Y "$(TargetDir)LWSimulatorGUI.exe" "$(SolutionDir)LWSimulatorCons\bin\Release\"</PostBuildEvent>
xcopy /Y "$(TargetDir)MainLWSimulator.dll" "$(SolutionDir)LWSimulatorCons\bin\Debug\"
xcopy /Y "$(TargetDir)MainLWSimulator.dll" "$(SolutionDir)LWSimulatorCons\bin\Release\"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
using System;
using System.IO;
using System.Threading;
using System.Runtime.Caching;
using System.Collections.Generic;
using System.Linq;
namespace MainLWSimulator
{
internal class LWParser
{
private LWCoordinator parent;
private FileSystemWatcher watcher = null;
private bool reloadFile = false;
private int line =-1;
private List<string> program;
private string path;
private object pathLock = new object();
internal LWParser(LWCoordinator parent)
{
this.parent = parent;
}
/// <summary>
/// Sets the path the File that needs to be parsed and sets a FileWatcher on it.
/// </summary>
/// <param name="path">Path the file is at</param>
/// <returns>False if file does not exists</returns>
internal bool setFilePath(string path)
{
if (!File.Exists(path))
{
parent.writeLogMessage("ERROR: Tried to set a non existant file as path.");
return false;
}
lock(pathLock)
{
if (this.path == path)
return true;
if (watcher != null)
watcher.EnableRaisingEvents = false;
else
{
watcher = new FileSystemWatcher();
// Add event handlers.
watcher.Changed += OnChanged;
watcher.Created += OnChanged;
watcher.Deleted += OnChanged;
watcher.Renamed += OnRenamed;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
}
watcher.Filter = Path.GetFileName(path);
watcher.Path = Path.GetDirectoryName(path);
watcher.EnableRaisingEvents = true;
this.path = path;
reloadFile = true;
return true;
}
}
/// <summary>
/// Reads program of the file specified in the private variable path.
/// Use setFilePath to change the specified path.
/// NOT THREAD SAFE
/// </summary>
/// <returns>True on success; false otherwise</returns>
internal bool importProgram()
{
lock(pathLock)
{
if (String.IsNullOrEmpty(path))
{
parent.writeLogMessage("ERROR: Location of code file was not specified.");
return false;
}
if (!File.Exists(path))
{
parent.writeLogMessage("ERROR: Specified code file does not exist.");
return false;
}
if (!reloadFile)
{
line = -1;
return true;
}
try
{
program = new List<string>(File.ReadAllLines(path));
}
catch (Exception e)
{
parent.writeLogMessage("ERROR: An exception occured when trying to load program: " + e.Message);
return false;
}
line = -1; // Set line to very beginning
reloadFile = false;
}
return true;
}
/// <summary>
/// Increases the variable 'line' until a command (= line not consisting of only whitespace chars or a comment symbol as first character) is found
/// </summary>
private void skipNonCommandLines()
{
while (line < program.Count)
{
int firstNonWhiteSpace = program[line].TakeWhile(char.IsWhiteSpace).Count();
if (firstNonWhiteSpace == program[line].Length || program[line].ElementAt(firstNonWhiteSpace) == '#')
line++;
else
break;
}
}
/// <summary>
/// Returns the line of the command that was just returned by 'getNextCommand'.
/// </summary>
/// <returns>Line of the current command.</returns>
internal int getCurrentLine()
{
return line;
}
/// <summary>
/// Gets the next command line or null.
/// NOT THREAD-SAFE
/// </summary>
/// <returns>Null if no program loaded; empty string if last command of a program was already returned once; otherwise the next command in the program</returns>
internal string getNextCommand()
{
if (program == null)
{
parent.writeLogMessage("WARNING: Tried to read non-loaded program");
return null;
}
line++;
skipNonCommandLines();
if (line >= program.Count)
return "";
return program[line];
}
/// <summary>
/// Sets variable line to a value so the line with the index 'newLine' (or later lines if some lines are sorted out by 'skipNonCommandLines')
/// is returned on next call of getNextCommand.
/// </summary>
/// <param name="newLine">Index of line to return on next call of 'getNextCommand'</param>
internal void setCurrentLine(int newLine)
{
if(newLine < 0)
{
parent.writeLogMessage("WARNING: Tried to set line of program to negative value.");
return;
}
line = newLine - 1;
}
/// <summary>
/// Handler for about-to-be-disposed Callback methods so a late call won't do any damage
/// </summary>
/// <param name="state">The state of the dependant object that was changed</param>
private void emptyMethod(object state)
{
return;
}
/// <summary>
/// Event Handler if a change occurs on the file.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="e">Arguments of the type <see cref="FileSystemEventArgs">FileSystemEventArgs</see></param>
private void OnChanged(object sender, FileSystemEventArgs e)
{
lock(pathLock)
{
parent.writeLogMessage("WARNING: Detected a change in file or path.");
reloadFile = true;
}
}
/// <summary>
/// Event Handler if a rename occurs on the file or path.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="e">Arguments of the type <see cref="RenamedEventArgs">RenamedEventArgs</see></param>
private void OnRenamed(object sender, RenamedEventArgs e)
{
lock (pathLock)
{
parent.writeLogMessage("WARNING: Detected a change in file or path.");
reloadFile = true;
}
}
}
}
......@@ -43,7 +43,6 @@
<ItemGroup>
<Compile Include="LWCoordinator.cs" />
<Compile Include="LWInterpreter.cs" />
<Compile Include="LWParser.cs" />
<Compile Include="LWRegisters.cs" />
<Compile Include="LWTimer.cs" />
<Compile Include="Parser.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment