Exemple #1
0
        /// <summary>
        /// Handle the Print Task Setup Event
        /// Raised when the source app sets the Print Ticket. This event provides a callback method for the app to signal it is done handling this event
        /// and optionally specifying the need for UI, which will cause the UI part of this App to be launched in OnActivated() with ActivationKind.PrintWorkflowForegroundTask .
        /// </summary>
        /// <param name="sessionManager">Session manager</param>
        /// <param name="printTaskSetupArgs">Has the Configuration, which include the PrintTicket, and other information</param>
        private void OnSetupRequested(PrintWorkflowBackgroundSession sessionManager, PrintWorkflowBackgroundSetupRequestedEventArgs printTaskSetupArgs)
        {
            // Request a deferral if any of the calls here might result in an Async method being called
            Deferral setupRequestedDeferral = printTaskSetupArgs.GetDeferral();

            // Get information about the source application, print job title, and session ID
            string sourceApplicationName = printTaskSetupArgs.Configuration.SourceAppDisplayName;
            string jobTitle  = printTaskSetupArgs.Configuration.JobTitle;
            string sessionId = printTaskSetupArgs.Configuration.SessionId;

            // Check to see if user wanted to use the watermark already when the program was run "standalone" and saved in local storage
            // and not have UI every time. It can always be reset by running the app again and unchecking the check box
            localStorage = new LocalStorageUtilities();
            suppressUI   = localStorage.GetUseStandaloneSettings();
            if (!suppressUI)
            {
                // Indicate that we need to launch the UI, in this example, because we need to get watermarking text, and optionally an image
                printTaskSetupArgs.SetRequiresUI();
                // Set storage prefix so that foreground and background can pass properties
                string localStorageVariablePrefix = string.Format("{0}::", sessionId.Substring(0, 8));
                localStorage.SetStorageKeyPrefix(localStorageVariablePrefix);
            }
            else
            {
                // Use unprefixed default values set in "standalone" mode, without showing UI when activated in workflow mode
                localStorage.SetStorageKeyPrefix("");
            }

            // Complete the deferral taken out at the start of OnSetupRequested
            setupRequestedDeferral.Complete();
        }
        /// <summary>
        /// Handle the Print Task Setup Event
        /// Raised when the source app sets the Print Ticket. This event provides a callback method for the app to signal it is done handling this event
        /// and optionally specifying the need for UI, which will cause the UI part of this App to be launched in OnActivated() with ActivationKind.PrintWorkflowForegroundTask .
        /// </summary>
        /// <param name="sessionManager">Session manager</param>
        /// <param name="printTaskSetupArgs">Has the Configuration, which include the PrintTicket, and other information</param>
        private void OnSetupRequested(PrintWorkflowBackgroundSession sessionManager, PrintWorkflowBackgroundSetupRequestedEventArgs printTaskSetupArgs)
        {
            // Request a deferral if any of the calls here might result in an Async method being called
            Deferral setupRequestedDeferral = printTaskSetupArgs.GetDeferral();

            // Get information about the source application, print job title, and session ID
            string sourceApplicationName = printTaskSetupArgs.Configuration.SourceAppDisplayName;
            string jobTitle  = printTaskSetupArgs.Configuration.JobTitle;
            string sessionId = printTaskSetupArgs.Configuration.SessionId;

            // Check to see if user wanted to use the watermark already when the program was run "standalone" and saved in local storage
            // and not have UI every time. It can always be reset by running the app again and unchecking the check box
            localStorage = new LocalStorageUtilities();
            suppressUI   = localStorage.GetUseStandaloneSettings();
            if (!suppressUI)
            {
                // Indicate that we need to launch the UI, in this example, because we need to get watermarking text, and optionally an image
                printTaskSetupArgs.SetRequiresUI();
                // Set storage prefix so that foreground and background can pass properties
                string localStorageVariablePrefix = string.Format("{0}::{1}::", sourceApplicationName, sessionId.Substring(0, 8));
                localStorage.SetStorageKeyPrefix(localStorageVariablePrefix);
            }
            else
            {
                // Use unprefixed default values set in "standalone" mode, without showing UI when activated in workflow mode
                localStorage.SetStorageKeyPrefix("");
            }

            // Get the printer name
            try
            {
                // Get the PrinterExtensionContextNative from the activation arguments
                IntPtr ptr = GetPrintWorkflowConfigurationNativeAsIntPtr(printTaskSetupArgs);
                // Create the Print Helper
                PrintHelperClass printHelper = new PrintHelperClass(InitializationType.PrinterExtensionContextNativeType, (ulong)ptr);
                string           printerName = printHelper.GetPrinterName();
                // Save the name of the printer
                localStorage.SavePrinterNameToLocalStorage(printerName);
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                Debug.WriteLine(errorMessage);
            }
            finally
            {
                // Complete the deferral taken out at the start of OnSetupRequested
                setupRequestedDeferral.Complete();
            }
        }