private void WorkerMethod()
        {
            //
            // Thread sleep for debugging purposes only. Se conditional attribute.
            //
            ThreadSleep(15000);

            try
            {
                //
                // Get/Load Settings
                //
                Settings settings = new Settings();

                //
                // Delete temporary flow files, temp files and folders
                //
                DeleteTemporaryFiles(settings);

                //
                // Create controller object.
                //
                Controller <Settings, TransparentPublisher, RealPublisher, HostRuntimeSettings> controller = new Controller <Settings, TransparentPublisher, RealPublisher, HostRuntimeSettings>(settings, false);

                //
                // Status Information Host
                //
                StatusInformationHost <Settings, TransparentPublisher, RealPublisher, HostRuntimeSettings> statusInformationHost = new StatusInformationHost <Settings, TransparentPublisher, RealPublisher, HostRuntimeSettings>(controller, "net.pipe://localhost/ItSoftware.CompuFlow.Publisher");

                //
                // Worker loop.
                //
                MessageQueue mq = new MessageQueue(settings.SourceMsmqPath);
                mq.Formatter = new BinaryMessageFormatter();
                System.Messaging.Message sourceMsg = null;
                do
                {
                    try
                    {
                        if (this.Paused)
                        {
                            Thread.Sleep(new TimeSpan(0, 0, 5));
                        }
                        else
                        {
                            try
                            {
                                sourceMsg = null;
                                sourceMsg = mq.Receive(new TimeSpan(0, 0, 5));
                            }
                            catch (MessageQueueException mqe)
                            {
                                if (mqe.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
                                {
                                    PublisherException ge = new PublisherException("MessageQueue.Receive threw an unexpected exception.", mqe);
                                    ExceptionManager.PublishException(ge, "Log Warning Policy");

                                    Thread.Sleep(new TimeSpan(0, 0, 5));
                                }
                            }
                            if (sourceMsg != null)
                            {
                                FlowManifest flowManifest = new FlowManifest(sourceMsg.Body as string);
                                controller.ExecuteFlow(flowManifest);
                            }
                        }
                    }
                    catch (OutOfMemoryException)
                    {
                        throw;
                    }
                    catch (StackOverflowException)
                    {
                        throw;
                    }
                    catch (ThreadAbortException)
                    {
                        controller.Stop();
                        throw;
                    }
                    catch (Exception x)
                    {
                        ExceptionManager.PublishException(x, "Error");
                    }
                } while (!this.Stopped);
                controller.Stop();
            }
            catch (ThreadAbortException tae)
            {
                if (!this.Stopped)
                {
                    ExceptionManager.PublishException(tae, "Error");
                    System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(base.ServiceName);
                    sc.Stop();
                }
            }
            catch (SettingsException se)
            {
                PublisherException ge = new PublisherException("Publisher could not continue execution.", se);
                ExceptionManager.PublishException(ge, "Error");

                System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(base.ServiceName);
                sc.Stop();
            }
            catch (PublisherException ge)
            {
                ExceptionManager.PublishException(ge, "Error");

                System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(base.ServiceName);
                sc.Stop();
            }
            catch (RuntimeWrappedException rwe)
            {
                PublisherException ge = new PublisherException("An unhandled RuntimeWrappedException exception was thrown.\r\nPublisher could not continue execution.", rwe);
                ExceptionManager.PublishException(ge, "Error");

                System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(base.ServiceName);
                sc.Stop();
            }
            catch (Exception x)
            {
                PublisherException ge = new PublisherException("An unhandled CLS complient exception was thrown.\r\nPublisher could not continue execution.", x);
                ExceptionManager.PublishException(ge, "Error");

                System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(base.ServiceName);
                sc.Stop();
            }
        }
        //
        // Initialize the generator.
        //
        protected override void Initialize( )
        {
            this.GUID      = Guid.NewGuid( ).ToString( );
            this.Directory = Path.Combine(Settings.TemporaryPublisherFilesDirectory, this.GUID);

            //
            // Unpack
            //
            try {
                System.IO.Directory.CreateDirectory(this.Directory);
                Zip.Unpack(this.Flow.FilenameFullPath, this.Directory);

                //
                // Verify Bin and Config directories.
                //
                if (!System.IO.Directory.Exists(Path.Combine(this.Directory, "Bin")))
                {
                    string msg = string.Format("The flow file {0} does not contain a Bin directory.", this.Flow.FilenameFullPath);
                    throw new PublisherException(msg);
                }
                if (!System.IO.Directory.Exists(Path.Combine(this.Directory, "Config")))
                {
                    string msg = string.Format("The flow file {0} does not contain a Config directory.", this.Flow.FilenameFullPath);
                    throw new PublisherException(msg);
                }

                /* Do not check for data directory, it does not have to bee there. data directory argument in interface then becomes null.
                 * if ( !System.IO.Directory.Exists( Path.Combine( this.Directory, "Data" ) ) ) {
                 *  string msg = string.Format( "The flow file {0} does not contain a Data directory.", this.Flow.FilenameFullPath );
                 *  throw new PublisherException( msg );
                 * }
                 * */
                /* Do not check for config.xml file, it does not have to be there.
                 * if ( !File.Exists( Path.Combine( Path.Combine( this.Directory, "Config" ), "Config.xml" ) ) ) {
                 *  string msg = string.Format("The flow file {0} does not contain the required Config\\Config.xml file.", this.Flow.FilenameFullPath);
                 *  throw new PublisherException( msg );
                 * }
                 */
                if (!File.Exists(Path.Combine(Path.Combine(this.Directory, "Config"), "Binding.xml")))
                {
                    string msg = string.Format("The flow file {0} does not contain the required Config\\Binding.xml file.", this.Flow.FilenameFullPath);
                    throw new PublisherException(msg);
                }
            }
            catch (StackOverflowException) {
                throw;
            }
            catch (OutOfMemoryException) {
                throw;
            }
            catch (ThreadAbortException) {
                throw;
            }
            catch (Exception x) {
                PublisherException ge = new PublisherException("Catastophics failure. Error while unpacking flow.", x);
                throw ge;
            }

            //
            // Copy needed assemblies.
            //
            try {
                string[] files = new string[] { "ItSoftware.CompuFlow.Publisher.HostRuntime.dll",
                                                "ItSoftware.ExceptionHandler.dll",
                                                "ItSoftware.CompuFlow.Manifest.dll",
                                                "ItSoftware.CompuFlow.Publisher.Interfaces.dll",
                                                "ItSoftware.CompuFlow.Util.dll",
                                                "ItSoftware.CompuFlow.Common.dll" };

                foreach (string file in files)
                {
                    string fromFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
                    string toFile   = Path.Combine(this.Directory, string.Format("Bin\\{0}", file));
                    File.Copy(fromFile, toFile, true);
                }
            }
            catch (StackOverflowException) {
                throw;
            }
            catch (OutOfMemoryException) {
                throw;
            }
            catch (ThreadAbortException) {
                throw;
            }
            catch (Exception x) {
                PublisherException ae = new PublisherException("Catastrophic failure. Could not copy required host assemblies because one or more files was not found.", x);
                throw ae;
            }

            //
            // Fix Flow.config
            //
            try {
                string sourceFlowConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Flow.config");
                string outputFlowConfigFilename = Path.Combine(this.Directory, "Flow.config");
                if (File.Exists(outputFlowConfigFilename))
                {
                    //
                    // Modify existing Flow.config file.
                    //
                    XmlDocument xdSource = new XmlDocument( );
                    xdSource.Load(sourceFlowConfigFilename);

                    XmlDocument xdOutput = new XmlDocument( );
                    xdOutput.Load(outputFlowConfigFilename);

                    XmlDocument xdResult = FlowConfiguration.Merge(xdSource, xdOutput);
                    xdResult.Save(outputFlowConfigFilename);
                }
                else
                {
                    //
                    // Create new Flow.config file.
                    //
                    File.Copy(sourceFlowConfigFilename, outputFlowConfigFilename);
                }
            }
            catch (StackOverflowException) {
                throw;
            }
            catch (OutOfMemoryException) {
                throw;
            }
            catch (ThreadAbortException) {
                throw;
            }
            catch (Exception x) {
                PublisherException ae = new PublisherException("Catastrophic failure. Could not configure Flow.config.", x);
                throw ae;
            }

            //
            // Create app domain
            //
            try {
                AppDomainSetup ads = new AppDomainSetup( );
                ads.ApplicationBase     = this.Directory;
                ads.ConfigurationFile   = "Flow.config";
                ads.PrivateBinPath      = "Bin";
                ads.PrivateBinPathProbe = "*";
                this.AppDomain          = AppDomain.CreateDomain(this.Flow.FilenameFullPath, null, ads);
            }
            catch (StackOverflowException) {
                throw;
            }
            catch (OutOfMemoryException) {
                throw;
            }
            catch (ThreadAbortException) {
                throw;
            }
            catch (Exception x) {
                PublisherException ae = new PublisherException("Catastrophic failure. Could not create application domain.", x);
                throw ae;
            }

            //
            // Create type
            //
            try {
                this.RealFlow = (RealPublisher)this.AppDomain.CreateInstanceAndUnwrap("ItSoftware.CompuFlow.Publisher.HostRuntime", "ItSoftware.CompuFlow.Publisher.HostRuntime.RealPublisher");
            }
            catch (StackOverflowException) {
                throw;
            }
            catch (OutOfMemoryException) {
                throw;
            }
            catch (ThreadAbortException) {
                throw;
            }
            catch (Exception x) {
                AppDomain.Unload(this.AppDomain);
                this.AppDomain = null;
                PublisherException ae = new PublisherException("Could not create RealPublisher type in appdomain.", x);
                throw ae;
            }

            //
            // Mark initialization complete.
            //
            this.Initialized = true;
        }