コード例 #1
0
        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, TransparentRetrival, RealRetrival, HostRuntimeSettings> controller = new Controller <Settings, TransparentRetrival, RealRetrival, HostRuntimeSettings>(settings, false);

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

                //
                // 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)
                                {
                                    RetrivalException ge = new RetrivalException("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)
            {
                RetrivalException ge = new RetrivalException("Retrival could not continue execution.", se);
                ExceptionManager.PublishException(ge, "Error");

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

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

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

                System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(base.ServiceName);
                sc.Stop();
            }
        }
コード例 #2
0
        //
        // Initialize the generator.
        //
        protected override void Initialize( )
        {
            this.GUID      = Guid.NewGuid( ).ToString( );
            this.Directory = Path.Combine(Settings.TemporaryRetrivalFilesDirectory, 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 RetrivalException(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 RetrivalException(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 GeneratorException( 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 RetrivalException( 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 RetrivalException(msg);
                }
            }
            catch (StackOverflowException) {
                throw;
            }
            catch (OutOfMemoryException) {
                throw;
            }
            catch (ThreadAbortException) {
                throw;
            }
            catch (Exception x) {
                RetrivalException ge = new RetrivalException("Catastophics failure. Error while unpacking flow.", x);
                throw ge;
            }

            //
            // Copy needed assemblies.
            //
            try {
                string[] files = new string[] { "ItSoftware.CompuFlow.Retrival.HostRuntime.dll",
                                                "ItSoftware.ExceptionHandler.dll",
                                                "ItSoftware.CompuFlow.Manifest.dll",
                                                "ItSoftware.CompuFlow.Retrival.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) {
                RetrivalException ae = new RetrivalException("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) {
                RetrivalException ae = new RetrivalException("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) {
                RetrivalException ae = new RetrivalException("Catastrophic failure. Could not create application domain.", x);
                throw ae;
            }

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

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