Archive

Archive for April, 2011

Comments in Models

April 29, 2011 Leave a comment

Using the Core Edition only, and consequently writing your model in plain XML, developers could embed XML comments in it explaining what they meant to do, or using them as reminders of what’s left to do.

In latest Modeler builds, you might have noticed that we introduced the an “Add Note” button in the modeler pad tab of the ribbon:

image

Well clicking this button allows you to place notes on the surface:

image

This way fans of XML comments in the Core Edition won’t be prejudiced!

Table-Valued Parameters

April 28, 2011 Leave a comment

Microsoft, starting with SQL Server 2008, added support for a new parameter type in SQL Server: Table-Valued parameters. Using them, you can send multiple rows of data to a T-SQL stored procedure, without creating a temporary table for instance.

Starting with the build 50204.579, the SQL Server producer now provides built-in support for those types. Thanks to this new feature you can now design CFQL queries such as:

<cf:method name="LoadCategories" body="load(int[] ints) where Id in (@ints)"/>

Which will generate the following code:

CREATE TYPE [dbo].[cf_type_Category_LoadCategories_0] AS TABLE(
[Item] [INT] NULL)
GO
CREATE PROCEDURE [dbo].[Category_LoadCategories]
(
@ints [dbo].[cf_type_Category_LoadCategories_0] READONLY,
@_orderBy0 [nvarchar] (64) = NULL,
@_orderByDirection0 [BIT] = 0
)
AS
SET NOCOUNT ON
DECLARE @_c_ints INT; SELECT @_c_ints= COUNT(*) FROM @ints
SELECT DISTINCT [Category].[Category_Id], [Category].[Category_Name], [Category].[_rowVersion]
FROM [Category]
WHERE [Category].[Category_Id] IN ((SELECT * FROM @ints))
RETURN
GO

The feature is actually broader than that, you can also:

  • In CFQL, use the ‘=’ operator on table-valued types, e.g. count(int[] ints) where @ints = Id,
  • Use .NET CLR types, e.g. raw(System.Uri[] uris),
  • Use already existing table-valued types in database,
  • Map table-valued types to .NET types such as DataTable, IDataReader and IEnumerable<SqlDataRecord>,
  • Map them to generated collection types you created in the model.

Want to know more about it? It’s all detailed in our product documentation, in the Array Parameters article.

Categories: SQL Server Tags: ,

Introduction to the SharePoint Producer

April 27, 2011 2 comments

The Microsoft SharePoint Producer is a user interface producer as its main purpose is to generate generic entity SharePoint Web Parts that can be used configured and deployed in SharePoint Web Part pages. All Web Parts are designed to be related to any entity from the Business Object Model (BOM).

The producer generates four kinds of Web Parts:

EntityDataSourcePart

The EntityDataSourcePart, unlike the three other Web Parts, doesn’t have a user interface. It’s an invisible Web Part (similar to the ObjectDataSource control in ASP.NET) designed to act as a data source for both EntityFormPart or EntityGridPart. If the EntityDataSourcePart is used as a data source to the EntityFormPart, the entity selected in the EntityDataSourcePart will be shown in the EntityFormPart. The same logic is true when used as an EntityGridPart data source. Furthermore, it can call parameterized methods. In such cases, parameters must be configured so they can be passed to the underlaying method. The EntityDataSourcePart can also use the query string in order to retrieve parameters and forward them to the underlaying method.

 

EntityMethodPart

The EntityMethodPart provides an interface so end-users can supply parameter values of a given method. It’s interface is a form composed of input fields. Typed-in values will be parsed and made available to connected Web Parts.

The EntityMethodPart is a “supplier-only" Web Part and is designed to supply values to a connected EntityGridPart; it doesn’t display data itself.

 

EntityGridPart

The EntityGridPart is a Web Part intended to display within a grid control, records of business entity instances. The EntityGridPart can “consume” parameters provided by an EntityMethodPart in order to load the collection to be displayed. It can also supply a selected entity instance to a connected EntityFormPart.

 

EntityFormPart

The EntityFormPart is a form Web Part which displays the properties of a selected instance of business entity. Using this part, not only end-users can get a detailed view of an instance, but they can also update or delete the current instance. The EntityFormPart is a “consumer-only” Web Part. Consequently, it needs a data source from which to consume data. The data provider may be a connected EntityGridPart as well as an EntityDataSourcePart. Finally, it’s also possible to configure the EntityFormPart to use the query string as input.

The following screenshot actually shows different Web Parts, configured to manipulate an Account entity, and connected to one-another:

WebPartExample

 

Going from top to bottom, the first Web Part is an EntityMethodPart configured to use the LoadByName method of the Account entity. Moreover, this Web Part was configured to supply typed-in values to the second Web Part: an EntityGridPart.

The second Web Part is an EntityGridPart which is mapped to the same LoadByName method, and uses the parameter values provided by the first Web Part (EntityMethodPart) when invoking the method. Data returned by the method are then displayed in the grid.

The third and last Web Part is an EntityFormPart configured to show in a form, the currently selected instance in the EntityGridPart.

All those web parts are generated, and more than just generating web parts as we’ve seen in this post, CodeFluent Entities provides an extensive set of features made to ease the developer’s task when it comes to developing SharePoint applications, such as:

  • Site Creator,
  • Binary Large Object Management,
  • Office Synchronizable Lists Integration,
  • Runtime Model,
  • and more (localization, authorization, validation, etc.).

Check-out our documentation for more information!

Generating Documentation

April 26, 2011 Leave a comment

CodeFluent Entities provides a documentation sub-producer which allows you to:

  • Decorate all members with XML comments (usable by Visual Studio IntelliSense and help tools),
  • Generate XML, batch and configuration files to create a .CHM documentation using Sandcastle.

To benefit from it, you first need to add an instance of the sub-producer. To do so, select the Business Object Model Producer instance of your project, right-click on it and select “Add New SubProducer”. Then in the “Add New SubProducer” dialog, select “Documentation” in the tree view and configure it:

DocumentationProducer

Note: the only required property is the “Sandcastle Target Directory “which needs to be specified so the producer knows where to generate its output files. If producing Sandcastle files, you need to have Sandcastle installed before generating and ensure the Sandcastle path is correct so you’ll be able to use the generated files right away.

Since decorating all members of all your generated classes all the time can be quite an overkill during developments, it is disabled by default in the Business Object Model producer, so you need to enable it as well. Double-click on your Business Object Model producer instance to open its configuration and set “Generate Xml Documentation” to “True”:

GenerateDocumentation

In the XML this looks like something like that:

<cf:producer typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
  <cf:configuration targetDirectory="..\Sample" outputName="{0}.dll" generateDocumentation="true">
    <subProducer typeName="CodeFluent.Producers.Documentation.DocumentationProducer, CodeFluent.Producers.Documentation"
                 targetDirectory="..\Doc" sourceDirectory="%CF_TEMPLATES_PATH%\Documentation" />
  </cf:configuration>
</cf:producer>

Build over your project and you’ll see that all your members have XML remarks on them! Moreover, in the Sandcastle Target Directory you specified, you’ll see a set of files allowing you to generate a .CHM file documenting the generated objet model Smile

Razor Syntax Support

April 12, 2011 Leave a comment

We introduced the Text Template Engine in previous posts such as this one, or this one; and both posts feature some quick examples of how to use the default syntax to create templates:

  • use [%= foo %] to print the value of the foo variable,
  • use [% foreach (string value in values) %] to embed C# statements.

Starting with the next CodeFluent Entities build (> 50401.587), the CodeFluent Template Engine now supports Razor.

Razor, is basically a new view engine for ASP.NET MVC developed by Microsoft and shipped with ASP.NET MVC 3. Basically, the main goal of Razor is that it’s compact, expressive and fluid. To quote Scott Guthrie (view source):

Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.

To generate files from templates using the Razor syntax you need:

  • To be in .NET 4,
  • References to the CodeFluent.Runtime.dll and CodeFluent.Model.Common.dll (versions strictly upper than 50401.587),
  • A reference to System.Web.Razor

As an example, here’s a template which loads from its context a string array containing all NBA teams, and lists them in a text file:

@ template engine=”razor”

Generated @System.DateTime.Now

@{
    string[] nbaTeams = (string[])Context["NbaTeams"];
}

Current NBA Teams:
@foreach (string team in nbaTeams) {
    <text>- @team</text>
}

Check-out this nice blog post for a quick reference on the Razor syntax.

Then here’s the code using CodeFluent’s Template Engine which runs the template and prints its output on the console:

class Program
{
    private static string[] _nbaTeams = { /* All Teams...*/ };

    static void Main(string[] args)
    {
        Template template = new Template();
        template.Load("Sample.txt", TemplateOptions.Default);
        template.Build();
        Hashtable context = new Hashtable();
        context["NbaTeams"] = _nbaTeams;
        template.Run(Console.Out, context);
    }
}

Here’s the output:

Generated 04/12/2011 14:42:13

Current NBA Teams:
        – Boston Celtics
        – New Jersey Nets
        – New York Knicks
        – Philadelphia 76ers
        – Toronto Raptors
        – Dallas Mavericks
        – Houston Rockets
        – Memphis Grizzlies
        – New Orleans Hornets
        – San Antonio Spurs
        – Chicago Bulls
        – Cleveland Cavaliers
        – Detroit Pistons
        – Indiana Pacers
        – Milwaukee Bucks
        – Denver Nuggets
        – Minnoseta Timberwolves
        – Portland Trail Blazers
        – Oklahoma City Thunder
        – Utah Jazz
        – Atlanta Hawks
        – Charlotte Bobcats
        – Miami Heat
        – Orlando Magic
        – Washington Wizards
        – Golden State Warriors
        – Los Angeles Clippers
        – Los Angeles Lakers
        – Phoenix Suns
        – Sacramento Kings

Categories: Templates Tags: ,

Default Persistence Server

April 11, 2011 3 comments

By default CodeFluent Entities uses the following connection string:

Application Name=[DefaultNamespace];server=[DefaultPersistenceServer];database=[DefaultNamespace];Integrated Security=true

Where [DefaultNamespace] is the default namespace of your CodeFluent Entities project, and [DefaultPersistenceServer] the default persistence server. By default, the default persistence server is configured to be 127.0.0.1.

Of course, you can override the default connection string at the project level thanks to the Default Connection String property (defaultConnectionString attribute in XML):

image

Or at the producer level by specifying its connection string explicitly:

image

However, to keep your model as portable as possible the best practice is definitely that each developer sets his default persistence server to their server. To set this up, you need to:

  • run Visual Studio with administrator privileges,
  • get in Tools > Options… > CodeFluent Entities,
  • in the advanced tab of the property grid (click the button with the yellow plus sign to access it), set the Default Persistence Server property to your server.

image

Doing this ensures the default connection string used by CodeFluent Entities is valid. As a consequence, developers won’t have to override the default connection string in their models anymore, and this way a model can easily be shared between one another.

Carl

Blob Storage

April 8, 2011 Leave a comment

As announced in this previous post, a couple builds ago we released a new feature which lets you store your Binary Large Objects (a.k.a. blobs) in Windows Azure’s Blob Storage instead of inside your database.

As seen in this video, developers can now specify through their application configuration, at run time and without having to generate over nor compile over their sources, where they’d like their blobs to be loaded and stored from. Available configurations or either to store their blobs in database, in a Windows Azure Blob Storage Account, or on the server’s file system.

Here’s a set of application configuration illustrating how to configure the runtime where to store your blobs.

Here’s the default configuration of my Sample application: no specific binary service is specified, blobs are stored in my database.

<configuration>
  <configSections>
     <section name="Sample"type="CodeFluent.Runtime.CodeFluentConfigurationSectionHandler, CodeFluent.Runtime" />
  </configSections>
  <Sample connectionString="server=(local);database=Sample;Trusted_Connection=true" />
</configuration>

Now here’s the configuration but modified to use the Windows Azure Blob Storage for all my entities:

<configuration>
(…)
<Sample connectionString="server=(local);database=Sample;Trusted_Connection=true" binaryServicesTypeName="azure"
cloudStorageAccountConnectionString="DefaultEndpointsProtocol=http;AccountName=MyAccount;AccountKey=9K5cXEs+9zEcBXz9gqjp==" />
(…)
</configuration>

And now here’s the equivalent but to store them on the file system:

<configuration>
(…)
<Sample connectionString="server=(local);database=Sample;Trusted_Connection=true" binaryServicesTypeName="filesystem" fileSystemBlobStorageRootPath="C:\Blobs" />
(…)
</configuration>

Please note that the binary service both for file system and Windows Azure blob storage can be specified per entity as well:

<configuration>
(…)
<Sample connectionString="server=(local);database=Sample;Trusted_Connection=true">
  <binaryServices entityFullTypeName="Sample.Customer" binaryServicesTypeName="fileSystem" fileSystemBlobStorageRootPath="C:\Blobs" />
</Sample>
(…)
</configuration>
Categories: Oracle Database, SQL Server, SQLAzure Tags:

The Platform Independent Form Editor

April 7, 2011 6 comments

As announced in this post, the newest version (50401.587) of the Modeler features a Platform Independent Form Editor. This editor allows developers to define forms on their entities which will then be translated into actual screens by user interface producers.

For instance, let’s say I have the following Product entity:

01 - Entity

Well, instead of having all my properties aligned in a single column I’d like to have the picture on one side, and the rest of my properties on the other side. I could override the default inferred form by defining my own, such as this one:

02 - Form

The following screenshot shows the Form Editor in which you can define tabs, zones, columns, drag and drop fields and commands wherever you’d like.  At this stage we’re completely agnostic of the targeted platform: it may become Windows Forms, ASP.NET, WPF, or SharePoint screens.

For instance, defining the following form in my model and generating SharePoint web parts using the Microsoft SharePoint Producer generates the following screens:

  • To create a new product:

03 - Create

  • To view an existing product:

04 - View

  • To edit an existing product:

05 - Edit

The Starter Wizard

April 6, 2011 1 comment

As announced in this post, the newest version (50401.587) of the Modeler now includes a new project type which is a wizard.

In Microsoft Visual Studio, click on File > New Project… and in the CodeFluent Entities project type, you’ll see a new template: Starter Wizard.

This wizard allows you to select a model as usual, but in addition to creating the corresponding CodeFluent Entities project, you can select your application type and it’ll automatically add the corresponding Visual Studio projects to your solution as well as configure the selected producers.

For instance choosing an ASP.NET MVC application will create:

  • your CodeFluent Entities project,
  • a Database project to contain your persistence scripts,
  • a Class Library project to contain your Business Object Model,
  • as well as a ASP.NET MVC application referencing the class library.

Furthermore, as said earlier, producers will be configured which in this case will be:

  • a persistence producer (SQL Server, SQL Azure or Oracle Database depending on what you choose in the wizard),
  • as well as the Business Object Model producer.

If ever a user interface producer supports the selected application type, this one will be automatically added.

Note: As of today, the only one added by the wizard is the SharePoint Web Parts producer.

By the end of the wizard your entire solution was created: you’re now ready to develop your application from data to UI Smile

The next step is then to design your application in the default surface of the CodeFluent Entities project. Define your business logic by creating entities, properties, relations and generate!

Note: If wondering how to do this, check-out this video Winking smile

As you’ll see, the configured producers will update the targeted projects of your solution by including the generated files as well as adding the required references. In the end, all you need to do is compile the generated code and you can use it right away in your application.

Finally, a key point in using CodeFluent Entities is that it allows you to generate continuously throughout developments, so don’t be afraid to try stuff, go back in the model, tweak it, generate over and see the result until it looks good Smile

Search capabilities of the Modeler

April 4, 2011 Leave a comment

On top of Microsoft Visual Studio’s search, the modeler adds its own searching capabilities which get to be very convenient when working on large models.

The first one is the Model Search, accessible from the Modeler Pad tab of the ribbon or from the surface context menu:

A Model Search is a “Google-like” search of a string within your entire model. It’ll then display all matching results in a hierarchical grid. For instance, I can type-in a string like “order” and the grid will contain all concepts matching the “order” string. However, instead of having a big list of the matching results, I get a tree view filtered by the string:

The second one is the Shape Search, also accessible from the Modeler Pad tab of the ribbon or from the surface context menu:

image

This time, a small dialog will pop-up and when typing the shape your looking for (entity or enumeration), and it’ll automatically take you to the corresponding shape by zooming on it and setting the focus on it.

image

Follow

Get every new post delivered to your Inbox.

Join 49 other followers