Skip to content

Commit

Permalink
Merge pull request #1 from arnab-sen/master
Browse files Browse the repository at this point in the history
Created a small working example
  • Loading branch information
arnab-sen authored Jun 16, 2020
2 parents 3f2effb + 037c386 commit 970371e
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 47 deletions.
102 changes: 55 additions & 47 deletions Application/Application.cs
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using Libraries;
using ProgrammingParadigms;
using DomainAbstractions;

namespace Application
{
public class Application
{
private MainWindow mainWindow = new MainWindow("AUT-Workshop-2020");

private Application Initialize()
{
Wiring.PostWiringInitialize();
return this;
}

[STAThread]
public static void Main()
{
Application app = new Application();
app.Initialize().mainWindow.Run();
}

private Application()
{
// BEGIN AUTO-GENERATED INSTANTIATIONS FOR WiringDiagram.xmind
// END AUTO-GENERATED INSTANTIATIONS FOR WiringDiagram.xmind

// BEGIN AUTO-GENERATED WIRING FOR WiringDiagram.xmind
// END AUTO-GENERATED WIRING FOR WiringDiagram.xmind

// BEGIN manual instantiations

// END manual instantiations

// BEGIN manual wiring
mainWindow.WireTo(new Text("Hello world.") { FontSize = 200 } );
// END manual wiring
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using Libraries;
using ProgrammingParadigms;
using DomainAbstractions;

namespace Application
{
public class Application
{
private MainWindow mainWindow = new MainWindow("ALASandbox");

private Application Initialize()
{
Wiring.PostWiringInitialize();
return this;
}

[STAThread]
public static void Main()
{
Application app = new Application();
app.Initialize().mainWindow.Run();
}

private Application()
{
// BEGIN AUTO-GENERATED INSTANTIATIONS FOR WiringDiagram.xmind
FileReaderWriter id_ff00492ce4024f618f7632899e5f2568 = new FileReaderWriter("F:\\Projects\\Test\\test.txt" ) { InstanceName = "Default", WatchFile = true };
TextBox id_1a43d927cb44461e9c9419008b26dcbe = new TextBox() { InstanceName = "Default", Height = 300 };
TextBox id_2aeaeca5cbd147dc80410e3b98f6c9a3 = new TextBox() { InstanceName = "Default", Height = 300 };
Vertical id_60081e709ce64a2da8baae542eff69e0 = new Vertical() { InstanceName = "Default" };
// END AUTO-GENERATED INSTANTIATIONS FOR WiringDiagram.xmind

// BEGIN AUTO-GENERATED WIRING FOR WiringDiagram.xmind
mainWindow.WireTo(id_60081e709ce64a2da8baae542eff69e0, "iuiStructure"); // (@MainWindow (mainWindow).iuiStructure) -- [IUI] --> (Vertical (id_60081e709ce64a2da8baae542eff69e0).NEEDNAME)
id_60081e709ce64a2da8baae542eff69e0.WireTo(id_1a43d927cb44461e9c9419008b26dcbe, "children"); // (Vertical (id_60081e709ce64a2da8baae542eff69e0).children) -- [List<IUI>] --> (TextBox (id_1a43d927cb44461e9c9419008b26dcbe).NEEDNAME)
id_60081e709ce64a2da8baae542eff69e0.WireTo(id_2aeaeca5cbd147dc80410e3b98f6c9a3, "children"); // (Vertical (id_60081e709ce64a2da8baae542eff69e0).children) -- [List<IUI>] --> (TextBox (id_2aeaeca5cbd147dc80410e3b98f6c9a3).NEEDNAME)
id_1a43d927cb44461e9c9419008b26dcbe.WireTo(id_ff00492ce4024f618f7632899e5f2568, "textOutput"); // (TextBox (id_1a43d927cb44461e9c9419008b26dcbe).textOutput) -- [IDataFlow<string>] --> (FileReaderWriter (id_ff00492ce4024f618f7632899e5f2568).contents)
id_ff00492ce4024f618f7632899e5f2568.WireTo(id_2aeaeca5cbd147dc80410e3b98f6c9a3, "textContentOutput"); // (FileReaderWriter (id_ff00492ce4024f618f7632899e5f2568).textContentOutput) -- [IDataFlow<string>] --> (TextBox (id_2aeaeca5cbd147dc80410e3b98f6c9a3).NEEDNAME)
// END AUTO-GENERATED WIRING FOR WiringDiagram.xmind

// BEGIN manual instantiations

// END manual instantiations

// BEGIN manual wiring
// END manual wiring
}
}
}
Binary file modified Application/Diagrams/WiringDiagram.xmind
Binary file not shown.
88 changes: 88 additions & 0 deletions DomainAbstractions/FileReaderWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Libraries;
using ProgrammingParadigms;

namespace DomainAbstractions
{
/// <summary>
///
/// </summary>
public class FileReaderWriter : IDataFlow<string>, IEvent
{
// Public fields and properties
public string InstanceName = "Default";

public bool WatchFile
{
get => watcher.EnableRaisingEvents;
set => watcher.EnableRaisingEvents = value;
}

// Private fields
private string fullPath = "";
private string textContent = "";
private FileSystemWatcher watcher = new FileSystemWatcher();

// Ports
private IDataFlow<string> textContentOutput;

public FileReaderWriter(string url)
{
fullPath = url;

watcher.Path = Path.GetDirectoryName(fullPath);
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = Path.GetFileName(fullPath);
watcher.Changed += (sender, args) =>
{
try
{
var contents = File.ReadAllText(fullPath);
if (contents != textContent)
{
textContent = contents;
Push(contents);
}
}
catch (IOException)
{
}
};
}

private void WriteFileContents(string contents)
{
textContent = contents;

if (!File.Exists(fullPath)) File.WriteAllText(fullPath, "");

File.WriteAllText(fullPath, contents);
}

private void Push(string output)
{
if (textContentOutput != null) textContentOutput.Data = output;
}

// IDataFlow<string> implementation
string IDataFlow<string>.Data
{
get => textContent;
set
{
WriteFileContents(value);
}
}

// IEvent implementation
void IEvent.Execute()
{
WriteFileContents("");
}
}
}

0 comments on commit 970371e

Please sign in to comment.