Category Archives: Clarion News

LINQ to FILE Provider

Language Integrated Query (or LINQ, pronounced “link” for short), is a set of .NET technologies that provide built-in language querying functionality similar to SQL, not only for database access, but for accessing data from just about any source.  Simply put LINQ is a set of language changes and API’s that allow you to write SQL-like queries natively in your chosen .NET programming language. LINQ provides the same query model and operators for different data sources, such as LINQ to Objects, LINQ to XML, LINQ to SQL and now our new LINQ to FILE provider.  And LINQ isn’t limited to traditional data sources, there are many more LINQ to “xyz”  providers, for example here is a list of some non-typical LINQ providers;

  • LINQ to WebQueries by Hartmut Maennel handles searches in the SiteSeer and MSDN Web sites.
  • LINQ to Amazon by Fabrice Marguerie, a co-author of the LINQ in Action book. LINQ to Amazon returns lists of books meeting specific criteria.
  • LINQ to Flickr by Mohammed Hossam El-Din (Bashmohandes) uses the open-source FlickrNet C# library as its infrastructure.
  • LINQ to Google Desktop supports queries to the Google desktop search engine

and the full list of available providers is much longer, if you’re interested in seeing more LINQ providers follow this link

Part of the beauty of  LINQ is that the exact same syntax is used to query (and potentially update) any data source that implements IEnumerable.  LINQ defines a set of general purpose standard query operators that allow for traversal, filtering, and projection operations to be expressed in a direct, yet declarative way in any .NET-based programming language.  Let’s take a look at it in some Clarion# code using the new LINQ to FILE provider:

In the data declaration section you declare IFileQuery instances of a file’s record type:
!  ——Data declaration section——
ClassesQuery            IFileQuery<Classes.Record>
CoursesQuery            IfileQuery<Courses.Record>

CODE
myQuery? = from class in ClassesQuery |
where class.RoomNumber < 10 |
select class

The local variable myQuery? is initialized with a query expression. A query expression operates on one (or more) information sources by applying one or more query operators from either the standard query operators or any domain-specific operators.  This expression uses two of the standard query operators: Where, and Select, and its very obvious this query will return all records where the the RoomNumber column has a value < 10.

The arguments to the Where and Select operators are called lambda expressions, which are essentially fragments of code. They allow the standard query operators to be defined individually as methods and strung together, and these methods form the basis for an extensible query language.

Lambda expressions are one important piece of the LINQ query architecture. Extension methods are the other. Extension methods combine the flexibility of dynamic languages with the performance and compile-time validation of statically-typed languages. We’ll delve into extension methods in another post.

Let’s look at another example:

myQuery? = From class in ClassesQuery |
Where class.RoomNumber < 10 |
OrderBy class.ClassNumber, class.CourseNumber Descending |
Select New {class.ClassNumber, class.CourseNumber, |
class.RoomNumber}

This query introduces the OrderBy and Select New operators. If you’ve had any exposure to SQL then this is very easy to understand, and even if you have no SQL experience its still easy to see what this query will return; a sequence of data objects where roomNumber is < 10, ordered by Class/Course numbers descending. What isn’t obvious is that “Select New” is only returning the class.ClassNumber, class.CourseNumber, and  class.RoomNumber columns.

There are many more features provided for in the new LINQ to FILE provider, here is a complete list of operators that the LINQ to File provider implements:

  • Where
  • Select
  • SelectMany
  • OrderBy/OrderByDescending
  • ThenBy/ThenByDescending
  • GroupBy
  • Join (inner)
  • GroupJoin (left)
  • Sum
  • Average
  • Min/Max
  • Count/LongCount
  • DefaultIfEmpty (usually used to provide “flat” left join)
  • Skip
  • Take
  • First/FirstOrDefault
  • Last/LastOrDefault
  • ElementAt/ElementAtOrDefault
  • Single/SingleOrDefault
  • TakeWhile
  • SkipWhile

Certainly you can already write your own code and define your own Views to provide the same  functionality, but with LINQ you don’t have to.  Besides a very simple and elegant syntax, the LINQ To FILE Provider is fast.  In our testing comparing the LINQ to FILE Provider to our plain LINQ to FILE, and to a standard VIEW structure, the tests showed the LINQ to FILE Provider was often more then twice as fast as a standard VIEW, and it always provided at least equivalent performance..

If all the LINQ to FILE Provider did was implement great query functionality it would be very powerful and very useful.  But it does much more, under the covers it implements equivalent functionality to the ABC library, except in this case its a managed code equivalent to the ABC library functionality. In a future article we’ll take a look at how we work with auto-incrementing, Insert/Update and Delete(s), and maintaining RI relations using the new LINQ to FILE Provider.

LINQ-style data access is available for all 3 .Net platforms (Winform, WebForm and Mobile). LINQ in general, and the new LINQ to FILE provider are key parts to the new templates for .Net code generation. And while you won’t need to write LINQ queries, (you’ll construct them visually and the templates will generate Dictionary related RI/AutoInc/CRUD statements for you) its still nice to know how easy it will be to create your own queries.

I’ll be doing a couple sessions on LINQ-style data access and the new LINQ to FILE provider at the upcoming Aussie DevCon, and I’ll be demonstrating how this technology fits into our code generation architecture using the new .Net templates.

New Properties for 7.1

Three new properties:

PROP:TextLeftMargin and PROP:TextRightMargin

The PROP:TextLeftMargin, PROP:TextRightMargin properties get or set the value of left and right margins for text in ENTRY, SPIN, COMBO, TEXT, RTF controls and in drop-down LIST controls.  The problem we had was that the old (pre-C7) fixed margin of 2 pixels wasn’t always correct for some of the newer fonts and font sizes.  The original C7 implementation calculated margin values based upon the control’s type, its font, and where the control is placed; in a WINDOW or REPORT, and some additional aspects.  However the new default margins could be incorrect in some specific situations like one which was described in the PTSS where large font sizes were not displayed correctly in a Entry control.  These two new properties allow you to justify margins in all cases, and they allow you to set different values for the left and right margins.

Syntax:

?control {PROP:TextLeftMargin} = n
?control {PROP:TextRightMargin} = n

Where, n is an integer constant or expression greater or equal to 0.  It sets the margin using the current units of the WINDOW or REPORT that owns the the control.
Negative values are treated as follows:
a value of -1 : the RTL uses the Windows default margin value which is dependent upon the control’s font
for all other negative values :  the RTL uses the C7 default margin value which is very close to Windows default value but takes into account some additional aspects such as the control type

PROP:LastChanceHook

This is a new write-only SYSTEM property which allows you to specify the hook function invoked if an exception has occurred. The hook function allows you to display
information about the exception and choose an action:

  • continue execution of the thread where exception occurred (if the exception isn’t fatal)
  • stop the thread (or entire process if the exception occurred in the main process thread) without invoking the RTL exception handler
  • execute the RTL exception handler

The RTL exception handler allows you to show information about the exception and asks for an action, possible actions:

  • stop the thread where exception occurred
  • stop the entire process
  • invoke the system debugger
  • generate a debug event if the program is already running under debugger

The implementation provides a far more intelligent way for handling program termination in case of some abnormal behavior then the existing ‘Do you want to GPF?” message.  It also allows you to set the exit code (error level) returned by the program to the OS upon program termination without the necessity to terminate the program immediately.

Summary; this allows end users to avoid having to terminate an entire program if some error occurred in one of its threads.

Freeze that control

Clarion 7.1 introduces two new functions; FREEZE and UNFREEZE.  FREEZE/UNFREEZE are used in tandem to suppress redrawing while you adjust multiple attributes of a control. For example, you would typically call the FREEZE method, then set the Size, Location, Text, or Color properties of the control, and then call the  UNFREEZE method to enable the changes to take effect.  This can increase the performance of applications with many controls, and eliminate screen flicker when dynamically creating controls or adjusting their properties.

The syntax is:

FREEZE (SIGNED feq),SIGNED

FREEZE suspends redrawing of the control which is identified by the feq parameter.
The return value must be passed to a paired UNFREEZE.

UNFREEZE (SIGNED feq, SIGNED state)

This function resumes redrawing of the control previously suspended by FREEZE.
The second parameter is a value returned by last FREEZE for that control which has not been closed
by paired UNFREEZE.

Calls to FREEZE can be nested. Every such call must have its paired UNFREEZE,
for example:

x1# = FREEZE (feq)
...
x2# = FREEZE (feq)
...
UNFREEZE (feq, x2#)
...
UNFREEZE (feq, x1#)

FREEZE and UNFREEZE must be properly paired: if there isn’t a paired call to UNFREEZE for an executed FREEZE, the control cannot be redrawn. The UNFREEZE function forces redrawing of the control.

(note: FREEZE/UNFREEZE cannot be used for menu items)

Precompile and Publish ASP.Net web apps

We’ve added some new functionality to the IDE in support for precompling and publishing a web app.  As you know by default, ASP.NET dynamically parses and compiles any ASPX page when the first request is made for the page. The .Net runtime caches the compilation outputs and does not need to recompile again unless someone edits a file. This behavior brings us a good amount of flexibility, including the flexibility to change code and markup. and instantly see the changes reflected in the next browser request.  ASP.NET 2.0 introduced the option of precompiling your website. Precompling offers the following advantages :

  • You do not need to deploy the source code to the server. The website is precompiled into binaries, which are then deployed to the server.
  • It allows you to identify any bugs during compilation rather then opening each page
  • The deployment process is a bit easier as all your aspx pages, user controls etc. are compiled into binaries.There are a few different ways you can precompile a website.
Precompiling websites at the command-line

When you have an ASP.Net project open the IDE command “Build” only validates the project and puts the assemblies into the ASP.NET temporary folder.

The values you enter on the new MSBuild tab of the Propect Properties are valid if you want to build the project from the command line. So at a command prompt you use this syntax:

MSBuild <projectfile>.aspxproj /target:Msbuild /property:ClaNetBinPath=<Clarion.Net BIN folder>

aspprocomp

Precompile and publish websites using the Clarion IDE

To precompile and publish your website using the IDE follow these steps:

1. Open your website project
2. In the Solution Explorer right-click on the Project and from the context menu choose “Publish Web Site”

asp1

3. You then get a Publish Web Site dialog like shown below where you can specify the path to publish. Clicking on the eplisis(…) lets you choose a folder.

asp2
4. Select your options in the dialog :

a. Allow this precompiled site to be updatable – This option allows you to change the markup and client side functionality of the .aspx pages.
b. Use Fixed Naming And Single Page Assemblies
c. Enable strong naming on precompiled assemblies – specifies that your assemblies are strong named using a key file or container.

5. Click Ok to compile and publish the website. Continue reading Precompile and Publish ASP.Net web apps

Manifest support for Windows 7

We’ve just added support for creating the new Windows 7 compatibility sections in the Application Manifest to both the Templates, and the Linker.

appmanifest

With the settings above your manifest is generated with these two new sections:

<compatibility xmlns=”urn:schemas-microsoft-com:compatibility.v1″>
<application>
<!–The ID below indicates application support for Windows Vista –>
<supportedOS Id=”{e2011457-1546-43c5-a5fe-008deee3d3f0}”/>
<!–The ID below indicates application support for Windows 7 –>
<supportedOS Id=”{35138b9a-5d96-4fbd-8e2d-a2440225f93a}”/>
</application>
</compatibility>

The Linker uses the MANIFEST directive and has been extended with the following options:

MANIFEST VISTA WINDOWS7
— The linker adds the default manifest to the executable compatible with records indicating application compatibility with both Windows Vista and Windows7

Note that Windows XP and Windows Vista ignore this manifest compatibility section and it has no impact on them.

Report Writer


This Friday we’re going to demonstrate the new Report Writer on Clarion Live!. Our thanks to John Hickey and Arnold Young for inviting us back!
I thought I’d take a few minutes to point out some of the features and give you a feel for the UI.  Here’s a scaled-down screen shot of the main view.

Report Writer - main view
Report Writer – main view

Everything is done from this main view, in this next shot I had just pressed the “Preview” button.

Preview the Report

As you can see, when you go into Preview mode a new toolbar appears that provides some great functionality, including the ability to search the report, save the report to a number of formats and even email the report in your desired format.

search1

There are some great options for saving the report to disk or for emailing.  The email button invokes the client
machine’s default email program.

export formats

Back into Design mode, one feature I think you’ll love is the support for “Styles”.  Styles let you define background colors, borders, fonts and text alignment which then makes its very easy to quickly set all your fields or static text to a nice uniform look.

styles

Styles can also be applied to Report Bands, for example that’s how I gave this report the the two different shades of blue for the odd and even rows.

styles2

The Group and Sort Pad makes it easy to apply grouping/sorting to any report.  Grouping and Sorting can be done by an end user with just a few mouse clicks.

groupsort

There are 17 controls available to build your report with:

toolbox1

The Report Wizard does a great job of getting you started, it allows you to select both a style (which you can customize), and a layout.

rptstyle2

layout1

And there is builtin support for creating labels:

labels

Hopefully this post gives you a good idea of what’s coming.  We’re working hard now on TXR conversions, which many Clarion developers have told us is very important to them, and we’re fixing bugs found internally, but it won’t be long before we make a beta version available.

Its worth mentioning that the new Report Writer will be shared by both Clarion 7 (win32) and Clarion.Net, and it includes support for doing advanced scripting using Clarion# at design time.  There is much more functionality, and great features to talk about, and as the documentation progresses we’ll post a detailed spec sheet on the web site.

Clarion 7 – new release

A new release for Clarion version 7 went out today, it includes some key bug fixes for recently identified problems, along with one new feature that seems to have some users up in arms when they found it missing, namely the “Block Indent dialog”.  Not sure what that means?  Well a picture should clear that up…

blockindent

sure to make a few developers happy, or at least happier 😉