Getting started

Patrik Svensson edited this page May 7, 2014 · 5 revisions

Let's assume (for simplicity and demonstration) that we want to

  1. Import assets with the file extension .txt.
  2. Reverse the text content.
  3. Write it back to disc as a binary representation.

###1. Implementing an importer

[DisplayName("Text Importer")]
public class TextImporter : Importer<string>
	public override string Import(Context context, IFile source)
		using (var stream = source.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
		using (var reader = new StreamReader(stream))
			return reader.ReadToEnd();

###2. Implementing a processor

[DisplayName("Text Reverser")]
public class TextReverser : Processor<string>
	public override string Process(Context context, string value)
		char[] charArray = value.ToCharArray();
		return new string(charArray);

###3. Implementing a writer

[DisplayName("Text Writer")]
public sealed class TextWriter : Writer<string>
	public override void Write(Context context, IFile target, string value)
		using (var stream = target.Open(FileMode.Create, FileAccess.Write, FileShare.None))
		using (var writer = new BinaryWriter(stream))

###4. Building assets

The Lunt kernel is built without a specific hosting provider in mind, but in this example we simply use the console host. The configuration schema you see here is the default one for Lunt, but you can easily create your own schema or write an adapter for an existing such as csproj or vcxproj.

To build the assets, we'll run Lunt Make (Lake.exe) with the input directory, output directory and build configuration as parameters. For the Lunt kernel to know what to build, we need to create a build configuration. The assembly containing the pipeline components should reside in the same directory as the console host.

<?xml version="1.0" encoding="utf-8"?>
<build version="1.0">
	<asset path="text/asset.txt" processor="Text Reverser" />

If we want to build all assets in the input directory c:/input/ (that are defined in the configuration file), and write them to c:/output, we would call the console host like this:

Lake.exe -input=c:/input/ -output=c:/output/ -verbosity=diagnostic c:/build.config

When running the application, you should see the following output:

Lake Version

[D] Examining assembly Lunt.dll...
[D] Examining assembly TextPipeline.dll...
[V] Loading assembly TextPipeline.dll...
[V] Found component 'TextImporter'
[V] Found component 'TextReverser'
[V] Found component 'TextWriter'
[I] Building @text/asset.txt
[V] Text Importer: Importing @text/asset.txt
[V] Text Reverser: Processing @text/asset.txt
[V] Text Writer: Writing @text/asset.txt
[I] Built @text/asset.txt

========== Build: 2 succeeded, 0 failed, 0 skipped ==========
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.