Quality Interior Design
 
EzTools Software Logo Quality Windows Programming Tools
Because Presentation is Everything
  
 
Home Buy Support About Us

 WebGen + WebStor Scripting Tools for Desktop Web Applications

 

  Products
WebGen  
SQLitePlus  
FileDb .NET Database  
ConfigDb  
EditListView Enhanced ListView  
WOW WebBrowser  

 

Download
Download WebGen + WebStor
   

There are some well known and widely used cross-platform desktop applications out there built with web interfaces, such as Slack, ICQ, WordPress Desktop, Atom, IconDrop, DesignArsenal, War Thunder, Smart Security, Norton 360, Norton Internet Security, Avast and BitDefender to name a few.  These apps are built using HTML rendering tools like Sciter and Electron.

Desktop webapps usually run locally with no webserver involved - the HTML content for the pages is generated locally.  This means developers don't have the benefit of the template style HTML generation tools like PHP and ASP.NET/Razor.  WebGen provides this capability in a Standard.NET DLL so you can use the same familiar coding style with these desktop tools to integrate scripting capabilities directly into your cross-platform .NET applications allowing you to generate HTML just like server side tools such as PHP or Classic ASP. WebGen is a Standard.NET Assembly tool which uses S# (aka Script.NET) - a powerful scripting tool for .NET by Petro Protsyk (www.github.com/PetroProtsyk/SSharp). S# is a very easy to use but powerful scripting language with a syntax very similar to C# and Javascript. WebGen adds text parsing features which allows you to write mixed HTML text and script code exactly like webserver products. And your scripts have access to the entire Standard.NET API plus ANY of your own application objects you want to inject - very powerful indeed.

Here are some important points about WebGen:

  • Uses the same template-style as PHP, ASPX and Classic ASP
  • Uses powerful S# scripting language, which is very simlar to C# and Javascript and which scripts .NET objects
  • Your script code has access to ALL of the same .NET objects that your application has access to.  This means you can pass ANY .NET object to RunScript and your script can use it just the same as any compiled .NET code.
  • WebGen is compiled in a Standard.NET assembly so its cross-platform - it will run the same on Windows, Mac and Linux.

Text Generation with WebGen

Running a script file and getting the output is simple. Note the use of .asp file extension.  You can use whatever extension you like.  I only use .asp because I think the script style most closely resembles classic ASP.

var uri = "file://c:/path to project/myScript.asp";
WebGen webgen = new WebGen();
var parameters = new List<Parameter>();
parameters.Add( new Parameter( "param1", "a string" ) );
parameters.Add( new Parameter( "param2", 123 ) );
parameters.Add(this);
webgen.RunScriptFile(uri, scriptParams);
var output = webGen.Output;

Then in your script file you could output parameter values like this:

<%
Host.WriteLine( string.Format( "param1: {0}", param1.ToString() ) );
Host.WriteLine( string.Format( "param2: {0}", param2.ToString() ) );
%>

Or you can use inline code in a more natural way

param1: <%=param1.ToString() %>
param2: <%=param2.ToString() %>

Or if you don't know the names of the input parameters you could output the entire contents of the input parameters collection, like this:

<%
foreach( param in Host.Parameters )
{
  Host.WriteLine( string.Format( "{0}: {1}", param.Name, param.Value.ToString() ) );
}
%>

Using the #include Directive to include other script files

Script writers often create libraries of functions that can be used in other scripts.  We have designed WebGen to be able to include other scripts with the #include directive.  Its very simple to use, eg.

#include mylib1.script

The ability to include other scripts in a script is a powerful feature, allowing you to build up script libraries and easily use them when needed.

Here's a simple example of generating an XML document.  Obviously it would be just the same for HTML documents (please see sample app in the download).

// custOrderDetails is passed to the script via the Parameters listt

foreach( cust in custOrderDetails )
{
  foreach( order in cust.Orders )
  {
    // call script method to generate
    GenXmlDoc( cust, order );
    // call OnXmlDoc on the app object passed in the Parameters list
    app.OnXmlDoc( order.OrderID );
  }
}

//-----------------------------------------------
function GenXmlDoc( cust, order )
{
  orderId = order.OrderID;
  custId = cust.CustomerID;
  custName = cust.CompanyName;
  total = 0;
%>
<?xml version="1.0" encoding="utf-8"?>
<ORDER>
  <ORDER_ID><%=orderId%></ORDER_ID>
  <CUST_ID><%=custId%></CUST_ID>
  <CUST_NAME><%=custName%></CUST_NAME>
  <ORDER_ITEMS>
  <% foreach( orderDetail in order.OrderDetails )
  {
    price = orderDetail.UnitPrice;
    qty = orderDetail.Quantity;
    amt = price * qty;
    total+= amt;
  %>
    <ORDER_ITEM>
    <PROD_ID><%= orderDetail.ProductID %></PROD_ID>
    <PROD_NAME><%= orderDetail.ProductName %></PROD_NAME>
    <PRICE><%=price%></PRICE>
    <QUANTITY><%= qty %></QUANTITY>
    <AMOUNT><%= amt %></AMOUNT>
    </ORDER_ITEM>
  <% } %>
  </ORDER_ITEMS>
  <TOTAL><%=total%></TOTAL>
</ORDER>
<% } %>

 

WebGen + WebStor Container files

Any web-enabled app is sure to have many template, javascript and graphics files.  These files would all be loose files on disk - very untidy not to mention unsecure.  You may not want to let anyone snoop through your proprietory source code files.  WebStor creates Container files to store all of your content files securely encrypted.  Think of WebStor files as like Zip files except that WebStor uses .web file extension.

The only difference when running the script file is that you include the .web file in the uri path, eg:

var uri = "file://c:/path to project/myfile.web/myScript.asp";
WebGen webgen = new WebGen();
var parameters = new List<Parameter>();
parameters.Add( new Parameter( "param1", "a string" ) );
parameters.Add( new Parameter( "param2", 123 ) );
parameters.Add(this);
webgen.RunScriptFile(uri, scriptParams);
data = Encoding.UTF8.GetBytes(webGen.Output);

Please see the example in the download which uses Sciter.

 




 

Copyright © EzTools Software All rights reserved. Trademarks and Disclaimer:
All trademarks belong to their respective companies.