SambaPOS 3 Documentation
repository·master·Indexed 19 days ago
https://github.com/emreeren/sambapos-3Source code and technical documentation for version 3 of SambaPOS, a Touch Screen Point of Sale (POS) software system. Includes details on FluentScript integration for registering C# types, the TemplateEngineDefault for script templating, and UI command implementations such as CaptionCommand, CustomCommand, and ICategoryCommand.
What's inside SambaPOS 3
- For development information and historical context, visit the GitHub repository. For stable, production-ready releases of SambaPOS, visit the official website.
How TemplateEngineDefault parsing works
masterThe engine works by iterating through the input script and categorizing segments into
CodeBlockobjects with specificStatetypes:Html,Expression,CodeBlock, orComment.When
Render()is called, the engine:- Parses the script into a buffer of these blocks.
- Builds a final string that initializes a JavaScript variable
bufferand uses string concatenation (+=) to append HTML segments and execute code blocks.
This results in a single executable string that can be used to build dynamic content.
Use the 'def' keyword to declare functions in FluentScript
masterThe
DefPluginallows you to use thedefkeyword as an alias for thefunctionkeyword when declaring functions in FluentScript. This provides a more concise syntax for function definitions.def add( a, b ) { return a + b }Create a CustomCommand for UI interaction
masterThe
CustomCommandclass is used to implement command logic for UI elements (like buttons) within the SambaPOS presentation layer. It inherits fromDelegateCommand<object>and implementsICaptionCommand, allowing it to carry both an execution method and a displayable caption.You can instantiate a
CustomCommandusing two primary patterns:- Basic Execution: Provide a caption, a data object, and an action to execute.
- Conditional Execution: Provide a caption, an action, a data object, and a
canExecuteMethod(aFunc<object, bool>) to determine if the command is currently valid (e.g., to enable/disable a button).
CustomCommandautomatically hooks into theCommandManager.RequerySuggestedevent, meaning the command's ability to execute will be re-evaluated whenever the UI requests a requery.// Pattern 1: Basic execution var command = new CustomCommand("Click Me", myDataObject, (obj) => { // Execute logic here }); // Pattern 2: Conditional execution (canExecute) var conditionalCommand = new CustomCommand( "Submit", (obj) => { /* execute logic */ }, myDataObject, (obj) => { // Return true if the command can be executed return obj != null; } );Create instances of registered types
masterOnce a type is registered via
Register, you can instantiate it within the FluentScript environment using theCreatemethod. You can provide an optional array of objects (object[] args) to serve as constructor arguments.// Create an instance using the default parameterless constructor object instance = registeredTypes.Create("MyCustomClass"); // Create an instance passing constructor arguments object instanceWithArgs = registeredTypes.Create("MyCustomClass", new object[] { "arg1", 42 });Use TemplateEngineDefault for script templating
masterThe
TemplateEngineDefaultclass provides a templating engine with syntax similar to jQuery templates or Python-Django templates. It parses a script containing HTML and embedded code blocks (expressions, code blocks, or comments) and converts them into a JavaScript-like string concatenation format.To use it, instantiate the engine with your script and call
Render()to get the processed output.var engine = new TemplateEngineDefault("<div><%= name %></div>"); string result = engine.Render();Register custom C# types in FluentScript
masterThe
RegisteredTypesclass allows you to bridge C# types into the FluentScript interpreter, enabling the language to call C# functions and interact with custom objects. You can register a type by providing itsTypeand aFunc<object>creator that defines how a new instance of that type is instantiated.Note:
DateTimeis treated as a basic type with a specialized creator that usesDateTime.Now.Ticks.// Assuming an instance of RegisteredTypes named 'registeredTypes' registeredTypes.Register(typeof(MyCustomClass), () => new MyCustomClass());Check for and retrieve registered types
masterYou can verify if a type is available in the interpreter and retrieve its underlying .NET
Typeusing the following methods:Contains(string nameOrFullName): Returnstrueif the type (by short name or full name) is registered.Get(string nameOrFullName): Returns theSystem.Typeassociated with the provided name or full name.
if (registeredTypes.Contains("MyCustomClass")) { Type type = registeredTypes.Get("MyCustomClass"); // Proceed with logic using the retrieved Type }Implement a CaptionCommand for UI actions
masterThe
CaptionCommand<T>is a specialized implementation ofDelegateCommand<T>used to bind UI actions to executable logic while providing a human-readableCaptionproperty. This is useful for commands that need to display text (like button labels) that can change dynamically.It supports:
- Execution logic: An
Action<T>that defines what happens when the command is triggered. - Conditional execution: An optional
Func<T, bool>to determine if the command is currently allowed to run. - Dynamic Captions: A
Captionstring property that notifies the UI when it changes viaINotifyPropertyChanged. - Automatic Re-evaluation: It hooks into
CommandManager.RequerySuggestedto automatically refresh the command'sCanExecutestate based on UI changes.
// Example: Creating a command for a button that displays "Save" // and is only enabled if the data object 'myData' is valid. var saveCommand = new CaptionCommand<MyDataModel>( "Save", (data) => SaveData(data), (data) => data.IsValid ); // You can update the caption dynamically: saveCommand.Caption = "Updating...";- Execution logic: An
Template syntax for TemplateEngineDefault
masterThe
TemplateEngineDefaultengine uses specific delimiters to distinguish between plain text (HTML), expressions, code blocks, and comments:Feature Syntax Description Expression <%= expression %>Evaluates an expression and appends the result to the output. Code Block <% code %>Executes a block of code (e.g., loops, conditionals). Comment <%- comment %>Adds a comment block /* comment */to the output.Escape %%Escapes the %character.Note: The engine treats everything outside these delimiters as standard HTML/text.
/* Syntax Reference */ <%= expression %> // Expression <% code %> // Code Block <%- comment %> // Comment %% // Escape %Properties of CustomCommand
masterThe
CustomCommandclass exposes the following properties for managing command state and display:Caption(string): The text label associated with the command, used for UI display.DataObject(object): The data context or object passed to the execution and validation methods.CanExecuteChanged(event): An event that notifies the UI when the command's execution status changes. It is wired toCommandManager.RequerySuggestedto ensure automatic UI updates.
Implement ICategoryCommand for category-related commands
masterThe
ICategoryCommandinterface is used to define commands that operate on or represent a specific category within the SambaPOS system. Any implementation of this interface must provide properties for the category name, its associated image source, and its display order. It inherits fromICaptionCommand, implying it also supports captioning functionality.public interface ICategoryCommand : ICaptionCommand { string Category { get; set; } string ImageSource { get; set; } int Order { get; set; } }