Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WorkerExecutionForm"/> class.
        /// </summary>
        /// <param name="controllerHostname">the client controller name</param>
        /// <param name="instanceId">A unique id for this instance</param>
        /// <param name="logPath">The path to the datalogger database</param>
        public WorkerExecutionForm(string controllerHostname, string instanceId, string logPath)
        {
            InitializeComponent();
            this.Text               = $"{instanceId} {this.Text}";
            userLabel.Text          = instanceId;
            profilePictureBox.Image = GetAvatarImage();

            // The args should split into two items.  The first item is the Key, the second
            // is the hostname for the Client Factory (no more is it assumed that the Client Factory
            // is running on the same host as this application).

            // Instantiate the engine controller, passing in a reference to the client controller hostname.
            _clientControllerHostName = controllerHostname;
            _instanceId = instanceId;
            _logPath    = logPath;

            // Attach unhandled exception handlers (make sure the default handler is detached first)
            AppDomain.CurrentDomain.UnhandledException -= UnhandledExceptionHandler.UnhandledExceptionMethod;
            AppDomain.CurrentDomain.UnhandledException += (s, e) => UnhandledException((Exception)e.ExceptionObject);
            Application.ThreadException += (s, e) => UnhandledException(e.Exception);

            // Attach the DAT logger adapter
            DatLoggerAdapter.Attach();

            // Subscribe to this event so that the controller will be started after the form is done loading
            Application.Idle += new EventHandler(OnLoaded);

            //Make sure we've got the registry keys MS Office uses to print.
            PrintRegistryUtil.CreateUserRegistryKeys();
        }
        /// <summary>
        /// Gets a detailed queue name with network port, as sometimes required by Office interop.
        /// (Results are cached to minimize registry access.)
        /// </summary>
        /// <param name="printQueue">The <see cref="PrintQueue" />.</param>
        /// <returns>The full name of the print queue with the port appended to the end.</returns>
        protected static string GetQueueNameWithPort(PrintQueue printQueue)
        {
            string queueName = printQueue.FullName;

            // Retrieving the port name for a queue requires digging into (and sometimes modifying) the registry.
            // Cache the values to minimize the number of times we do this.
            if (!_printQueueNamesWithPorts.ContainsKey(queueName))
            {
                string queueNameWithPort = PrintRegistryUtil.GetQueueNameWithPort(printQueue);
                _printQueueNamesWithPorts.Add(queueName, queueNameWithPort);
            }

            return(_printQueueNamesWithPorts[queueName]);
        }