Automation


Automation is the process of launching another application and controlling it programmatically through a public interface. All Office applications support automation and provide a COM interface that is accessible from ColdFusion. However, when an Office application is launched through automation, the resources and effect are the same as when launching the application as a logged-in user.

This poses many problems for server-side integration, as with ColdFusion. The fact that there is no logged-in user can in some circumstances cause the Office application to lock up on launch, and it will cause lock-ups at any point during use if an error occurs that presents a modal dialog box. The dialog will pop up and wait for a user to dismiss it. This can pose a serious problem if you're not sitting at the server constantly. The same is true if the application runs into a feature that isn't installed and presents the "Install on first use" dialog box.

Besides these serious problems, automation also presents concerns over scalability and security. The best recommendation regarding server-side automation of Microsoft Office applications comes directly from Microsoft:

NOTE

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when run in this environment.

http://support.microsoft.com/default.aspx?scid=kb;en-us;257757


Microsoft makes this recommendation regarding ASP, but it applies equally to ColdFusion, Java, and all other server-side programming technologies.

To get some clarity about automation, review Listing 27.7, which shows code that is typically involved in automation. This listing is provided for demonstration only and should not be used on a production server.

CAUTION

Don't use Listing 27.7 on a production server.


Listing 27.7. AutomationBad.cfmDemonstrate Automation for Clarity
 <!---   Filename: AutomationBad.cfm   Purpose: Clarify what is meant by automation and thus should be avoided   Requires: Excel installed on server ---> <cfscript>   fileName = GetTempFile(GetTempDirectory(), "xls");   excel = CreateObject("COM", "Excel.Application");   wb = excel.Workbooks.Add();   ws = wb.Worksheets.Add();   ws.Range("A1").Value2 = "This is bad";   ws.Range("A2").Value2 = "Don't do this from any server-side code.";   wb.SaveAs(fileName);   wb.Close();   excel.Quit();   ReleaseComObject(ws);   ReleaseComObject(wb);   ReleaseComObject(excel); </cfscript> <cfheader   name="Content-Disposition"   value="attachment; filename=""AutomationBad.xls"""> <cfcontent   reset="yes"   type="application/vnd.ms-excel"   file="#fileName#"   deleteFile="yes"> 

The key identifier is the CreateObject call passing Excel.Application as the second parameter. Any call to CreateObject or <cfobject> that instantiates or connects to an Excel.Application, PowerPoint.Application, or Word.Application object is automation and should be avoided if at all possible.

The lure of automation is its power. Through automation, developers can accomplish programmatically anything that an Office user could do while interacting with the programming in a desktop environment. That power comes at a high price, however, in terms of the problems mentioned earlier, as well as drastically decreased performancetasks completed in milliseconds through the other techniques described in this chapter can take several seconds through automation.

If an application requires functionality that is only available through automation, the associated risks can be minimized by offloading the actual automated operations to a separate server or cluster of servers. The primary ColdFusion server can send a message to the separate automation server via DCOM, Sockets, Web services, or even the file system. The automation server can process requests and drop the generated file in an expected location. The advantage of using separate server(s) is that they can be programmatically restarted if they become unresponsive.



Advanced Macromedia ColdFusion MX 7 Application Development
Advanced Macromedia ColdFusion MX 7 Application Development
ISBN: 0321292693
EAN: 2147483647
Year: 2006
Pages: 240
Authors: Ben Forta, et al

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net