Search
Feeds
May 8 2008

.NET and ColdFusion: Yes, We Can Work Together!

While working on a ColdFusion project, you might find a library someone has made that does exactly what you need and will save you lots of development time and money, but it’s written in .NET. Problem right? Not with ColdFusion 8. You can now access .NET assemblies as easily you can other ColdFusion components.

Take a look at the following C# class:

using System;
using System.IO;
using System.Text;

namespace Sanative
{
public class TempFolder
{
private string tempPath = Environment.GetEnvironmentVariable("TEMP");
private DirectoryInfo tempDirectory;

public TempFolder()
{
tempDirectory = new DirectoryInfo(tempPath);
}

public long GetSize()
{
return GetSize(tempDirectory);
}

public long GetSize(DirectoryInfo directory)
{
long size = 0;
foreach (FileInfo file in directory.GetFiles())
{
size += file.Length;
}
foreach (DirectoryInfo dir in directory.GetDirectories())
{
size += GetSize(dir);
}
return size;
}
}
}

Whenever GetSize() is called in the code, it will look at the folder that is set in the TEMP system variable in Windows and then return the amount of space on the disk that its files and folders take up. This class will need to be compiled into a DLL so ColdFusion can access it. I compiled it to “F:\assemblies\TempFolder.dll”. It’s probably a good idea to keep your .NET assemblies in a central location outside of your webroot.


As you can see in the following ColdFusion code it’s very easy to consume the TempFolder class.

<cfscript>	
tempFolder = CreateObject(".NET","Sanative.TempFolder",
"F:\assemblies\TempFolder.dll");
Writeoutput(tempFolder.getSize());
</cfscript>

The argument for the object type can either be “.NET” or “dotnet”. The second argument, for the class name, must include the namespace for the class or an exception will be thrown. The last argument is the full path to the assembly which contains the class. (Note: you can reference more than one assembly, if needed, separated by commas. Also, if you need to access any of the .NET core classes, such as “System.Environment” core classes, or any classes that are contained in assemblies in the global assembly cache, you do not need to specify the assembly argument.)

The first time a .NET class is called, ColdFusion will generate proxy Java classes to use with its built in Java/.NET bridge. The .NET Integration service will need stopped if any updates need to be made to the assembly.


There are some data conversion gotchas as well as some limitations because of going back and forth from Java to .NET. Full information about them as well as how to call .NET classes and assemblies that are located on a different server can be located on the Adobe ColdFusion 8 Livedocs at http://livedocs.adobe.com/coldfusion/8/htmldocs/dotNet_01.html

 

Sample Files

0 comments - Posted by Jeff Anderson at 4:23 PM - Categories:

May 8 2008

SysToast: A System Tray Notifier for AIR Applications

EverythingFlex has an excellent SysTray notification class called NativeAlertWindow. What it does is create a ‘toast’ window in the bottom right corner of your screen. When an event happens, a window will pop up, literally like toast, on your screen next to the system tray. This is very similar to what MSN Messenger, Norton, McAfee, and countless other programs do.


The problem with NativeAlertWindow is it is part of a SWC (a precompiled Flash file that is not editable) called everythingflexairlib. So you aren’t able to look at the code or change things easily if you need to. This is a very basic replica of NativeAlertWindow but not compiled in a SWC. It will get you started on creating toast windows. Extending it is up to you.

Copy the SysToast class file to the appropriate location in your project. The following is all that is needed in your MXML file.

import net.sanative.SysToast;
    public function callToast():void
    {
        var mytoast:SysToast = new SysToast("mymessage", "mytitle", mydelay, 
            mywidth, myheight, mylifetime, "mychrome", "mytype", mygap);
    }



That is all that is needed to create a toast window. The ‘my’ variables would be replaced with actual values according to your application.

 

  •     mymessage (Required) (String) - Message to display in the toast window. Default is null.
  •     mytitle (String) - Text to display in the title of the toast window. Default is 'Alert'.
  •     mydelay (Number) - Amount of delay between the time the toast was called until it is created. This is a millisecond number value. 1000 = 1 second. Default is 0.
  •     mywidth (Number) - Width of the toast window. This is a pixel number value. Default is 200.
  •     myheight (Number) - Height of the toast window. This is a pixel number value. Default is 100.
  •     mylifetime (Number) - Time that the toast window will be visible for. This is a millisecond number value. 1000 = 1 second. Default is 8000.
  •     mychrome (String) - System chrome to use for the toast window. Possible values are 'none' and 'standard'. Default is 'standard'.
  •     mytype (String) - Type of window the toast window will be considered. Possible values are 'lightweight', 'normal', and 'utility'. NOTE: 'lightweight' ONLY works with 'none'. Default is 'normal'.
  •     mygap (Number) - Gap between the bottom and right side of the screen to position the toast window. This is a pixel number value. Default is 10.

As I stated before, this is a very basic class. We will update the class over time to eliminate some of the limiations and make it full-featured. That being said here are the current limitations:

  •     This is not a toast window manager. This means that it can only show one toast window at a time for each variable reference.
  •     Each toast window created is placed in the bottom right corner.
  •     It does not apply stacking for better viewing.
  •     There are no transition in or out effects. Windows Vista has its own native window open and close effect which fakes a transition effect for me in the mean time.
  •     Toast windows cannot be minimized, maximized, or resized. More than likely this will not change. Allowing those defeats the purpose of a toast window.
  •     Icons and/or images are not utilized in the titlebar or on the toast itself.
  •     The style of the text cannot be changed with CSS unless it is changed in the class itself.

If you have recommendations or suggestions please feel free to drop us an email!

SysToast Files

0 comments - Posted by David Freerksen at 3:23 PM - Categories: Adobe AIR

Jan 3 2008

Sanative Sponsors Northern California Flex and AIR Pre-release with Adobe's Ryan Stewart

Flex 3 and AIR are getting close to launch and in preparation, Ryan Stewart from the Adobe Flex/AIR product team is traveling to select cities to show off the great new features and help prepare us for this exciting launch. Ryan Stewart will be in Sacramento to speak on January 23rd at 6:30 PM.

Flex 3 is a feature-packed release, adding new UI components like the advanced datagrid and improved CSS capabilities; powerful tooling additions like refactoring; and extensive testing tools including memory and performance profiling, plus the addition of the automated testing framework to Flex Builder.

Adobe AIR is game-changing in so many ways, extending rich applications to the desktop, enabling access to the local file system, system tray, notifications and much more. Now you can write desktop applications using the same skills that you’ve been already using to create great web apps including both Flex and AJAX.

Read more about the event, and RSVP, at the NorCal Flex User Group website. All are welcome, the event is casual and there will be food and drink provided by Adobe and Sanative!

0 comments - Posted by TJ Downes at 11:52 AM - Categories: Adobe AIR | Cool Stuff

Previous Posts

Jan 3 2008
Oct 2 2007

Taking Your Website to the Next Level

0 comments - Posted by TJ Downes at 8:23 AM - Categories: Technical Articles

Aug 12 2007

Adobe Flex for Web Applications

0 comments - Posted by TJ Downes at 9:39 AM - Categories: Technical Articles | Cool Stuff

May 10 2007

Why Use ColdFusion?

0 comments - Posted by TJ Downes at 6:34 PM - Categories: Technical Articles | Cool Stuff