예제 #1
0
        protected override void OnStart(string[] args)
        {
            StopStopping = false;

            // decode the list of printers to stop
            var stopUsString = StopPrintJobs.Properties.Settings.Default.PrintersToStop;
            var stopUs       = new List <string>();

            foreach (var printer in stopUsString.Split(';'))
            {
                var trimmedPrinter = printer.Trim();
                if (trimmedPrinter.Length != 0)
                {
                    stopUs.Add(trimmedPrinter);
                }
            }

            if (stopUs.Count == 0)
            {
                TheEventLog.WriteEntry("No printers to stop! Exiting.");
                this.Stop();
                return;
            }

            // prepare for stoppage
            Spool = new Spooler();

            // launch the thread
            StopperThread = new Thread(() => Proc(stopUs));
            StopperThread.Start();
        }
예제 #2
0
        public void LoadIntoDatabase(IList <string> strings)
        {
            Spooler.AddItem(strings);
            ActiveCount++;

            Console.WriteLine("Spooled");
        }
예제 #3
0
        public async Task CreateSpoolerWithTasks_GivesTasks()
        {
            Spooler <int, int, Tuple <int, string> > spooler = await Spooler <int, int, Tuple <int, string> > .StartNewAsync(_stateManager, _requests.ToArray(), Double, ResultConvertor, 5);

            var tasks = spooler.GetTasks();

            Assert.Equal(11, tasks.Count);
        }
예제 #4
0
        public async Task CreateSpoolerWithTasks_GivesValidBookMark()
        {
            Spooler <int, int, Tuple <int, string> > spooler = await Spooler <int, int, Tuple <int, string> > .StartNewAsync(_stateManager, _requests.ToArray(), Double, ResultConvertor);

            var bookmark = spooler.GetBookmark();

            Assert.NotNull(bookmark);
            Assert.Equal(11, bookmark.TotalCount);
        }
        /// <summary>
        /// Write a line of text to the file
        /// </summary>
        /// <param name="contentLine">the line of text</param>
        /// <param name="formatArgs">args for string.format</param>
        public void WriteLine(string contentLine, params object[] formatArgs)
        {
            string       cmdContent = formatArgs != null & formatArgs.Length > 0 ? string.Format(contentLine, formatArgs) : contentLine;
            WriteCommand cmd        = new WriteCommand()
            {
                WriteType = WriteTypes.Line,
                Content   = cmdContent
            };

            Spooler.AddItem(cmd);
        }
예제 #6
0
 public SpoolerParams(Task task, Spooler sp, bool orderJob, bool shellMode)
 {
     spoolerTask = task;
     spooler     = sp;
     isOrderJob  = orderJob;
     isShellMode = shellMode;
     if (isShellMode)
     {
         schedulerVariableNamePrefix = spooler.variables().value("scheduler.variable_name_prefix");
     }
 }
예제 #7
0
 public SpoolerParams(Task task, Spooler spooler, bool isOrderJob, bool isShellMode)
 {
     this.spoolerTask = task;
     this.spooler = spooler;
     this.isOrderJob = isOrderJob;
     this.isShellMode = isShellMode;
     if (this.isShellMode)
     {
         this.schedulerVariableNamePrefix = this.spooler.variables().value("scheduler.variable_name_prefix");
     }
 }
예제 #8
0
        protected ScriptAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, String scriptContent)
        {
            this.spooler_log = contextLog;
            this.spooler_task = contextTask;
            this.spooler_job = contextJob;
            this.spooler = contextSpooler;

            this.Script = scriptContent;
            this.IsOrderJob = this.spooler_job.order_queue() != null;
        }
예제 #9
0
            public override async Task <ActionResult> HandleAsync(Command request, CancellationToken cancellationToken)
            {
                var spooler = new Spooler(request.ZoneId, request.Body.Name);

                _db.Spoolers.Add(spooler);
                await _db.SaveChangesAsync();

                return(RedirectToEndpoint(new GetById.Query()
                {
                    Id = spooler.Id
                }));
            }
예제 #10
0
        protected ScriptAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, String contextStdErrLogLevel, String scriptContent)
        {
            spooler_log  = contextLog;
            spooler_task = contextTask;
            spooler_job  = contextJob;
            spooler      = contextSpooler;

            IsStdErrLogLevel = contextStdErrLogLevel.Equals("error");
            Script           = scriptContent;
            IsOrderJob       = spooler_job.order_queue() != null;
        }
예제 #11
0
        static void Main(string[] args)
        {
            var allPrinters = Spooler.EnumLocalPrinters(false);

            foreach (var printer in allPrinters)
            {
                Console.WriteLine(printer);
            }
            using (var spooler = new Spooler())
            {
                spooler.PauseNewJobsProc(allPrinters);
            }
        }
        public PowershellAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, String scriptContent)
            : base(contextLog, contextTask, contextJob, contextSpooler, scriptContent)
        {
            this.ParseScript();
            this.spoolerParams = new PowershellSpoolerParams(
                this.spooler_task, this.spooler, this.IsOrderJob, this.isShellMode);

            this.host = new PowershellAdapterPSHost(this.spooler_log);
            this.runspace = RunspaceFactory.CreateRunspace(this.host);
            this.runspace.Open();
            this.runspace.SessionStateProxy.SetVariable("spooler_log", this.spooler_log);
            this.runspace.SessionStateProxy.SetVariable("spooler_task", this.spooler_task);
            this.runspace.SessionStateProxy.SetVariable("spooler_job", this.spooler_job);
            this.runspace.SessionStateProxy.SetVariable("spooler", this.spooler);
            this.runspace.SessionStateProxy.SetVariable("spooler_params", this.spoolerParams);
        }
        public ScriptControlAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, string scriptContent,
            string language)
            : base(contextLog, contextTask, contextJob, contextSpooler, scriptContent)
        {
            this.spoolerParams = new SpoolerParams(this.spooler_task, this.spooler, this.IsOrderJob, false);

            var scriptType = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));
            this.scriptControl = Activator.CreateInstance(scriptType, false);
            this.scriptControl.Language = language;

            this.scriptControl.AddObject("spooler_log", this.spooler_log, false);
            this.scriptControl.AddObject("spooler_task", this.spooler_task, false);
            this.scriptControl.AddObject("spooler_job", this.spooler_job, false);
            this.scriptControl.AddObject("spooler", this.spooler, false);
            this.scriptControl.AddObject("spooler_params", this.spoolerParams, false);
        }
예제 #14
0
        public ScriptControlAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, string contextStdErrLogLevel, string scriptContent,
            string language)
            : base(contextLog, contextTask, contextJob, contextSpooler, contextStdErrLogLevel, scriptContent)
        {
            spoolerParams = new SpoolerParams(spooler_task, spooler, IsOrderJob, false);

            var scriptType = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));

            this.scriptControl          = Activator.CreateInstance(scriptType, false);
            this.scriptControl.Language = language;

            this.scriptControl.AddObject("spooler_log", spooler_log, false);
            this.scriptControl.AddObject("spooler_task", spooler_task, false);
            this.scriptControl.AddObject("spooler_job", spooler_job, false);
            this.scriptControl.AddObject("spooler", spooler, false);
            this.scriptControl.AddObject("spooler_params", spoolerParams, false);
        }
        public PowershellAdapter(
            Log contextLog, Task contextTask, Job contextJob, Spooler contextSpooler, String contextStdErrLogLevel, String scriptContent)
            : base(contextLog, contextTask, contextJob, contextSpooler, contextStdErrLogLevel, scriptContent)
        {
            ParseScript();
            spoolerParams = new PowershellSpoolerParams(spooler_task, spooler, IsOrderJob, isShellMode);

            host     = new PowershellAdapterPSHost(spooler_task, spooler_log);
            runspace = RunspaceFactory.CreateRunspace(host);
            runspace.Open();
            runspace.SessionStateProxy.SetVariable("spooler_log", spooler_log);
            runspace.SessionStateProxy.SetVariable("spooler_task", spooler_task);
            runspace.SessionStateProxy.SetVariable("spooler_job", spooler_job);
            runspace.SessionStateProxy.SetVariable("spooler", spooler);
            runspace.SessionStateProxy.SetVariable("spooler_params", spoolerParams);

            InvokeDollarProfile();
        }
예제 #16
0
 protected override void OnStop()
 {
     StopStopping = true;
     if (Spool != null)
     {
         Spool.StopPausingNewJobs();
     }
     if (StopperThread != null)
     {
         StopperThread.Join();
     }
     if (Spool != null)
     {
         Spool.Dispose();
     }
     Spool         = null;
     StopperThread = null;
 }
예제 #17
0
        public async Task CreateSpoolerFromBookmark_GivesResults()
        {
            Spooler <int, int, Tuple <int, string> > spooler = await Spooler <int, int, Tuple <int, string> > .StartNewAsync(_stateManager, _requests.ToArray(), Double, ResultConvertor);

            var bookmark = spooler.GetBookmark();

            var newSpooler = bookmark.CreateSpooler <int, int, Tuple <int, string> >(_stateManager, 2);

            var results = new List <string>();
            SpoolerResults <Tuple <int, string> > result;

            do
            {
                result = await newSpooler.GetResultsAsync(bookmark);

                bookmark = result.Bookmark;
                results.AddRange(result.Results.Select(x => x.Item2));
            } while (result.MoreResultsAvailable);

            Assert.Equal(11, results.Count);
        }
예제 #18
0
        public static bool AddPrinter(string name)
        {
            bool             resultCode;
            clawPDFInstaller installer = new clawPDFInstaller();

            try
            {
                if (installer.AddCustomclawPDFPrinter(name))
                {
                    resultCode = true;
                    Spooler.stop();
                    Spooler.start();
                }
                else
                {
                    resultCode = false;
                }
            }
            finally
            { }
            return(resultCode);
        }
예제 #19
0
        public static async Task GetPrintersAsync(Spooler spooler, IDatabase db)
        {
            var batch = db.CreateBatch();

            var isOnlineTask = batch.HashExistsAsync(RedisConstants.ConnectedClients, spooler.Id);
            var detailsTask  = batch.HashGetAllAsync(RedisConstants.SpoolerDetails(spooler.Id));
            var printersTask = batch.SetMembersAsync(RedisConstants.InstalledPrinters(spooler.Id));

            batch.Execute();

            var isOnline = await isOnlineTask;
            var details  = (await detailsTask).ToStringDictionary();
            var printers = await printersTask;

            spooler.IsOnline               = isOnline;
            spooler.LastConnected          = GetDateTimeOrNull(details.GetValueOrDefault("last-connected"));
            spooler.LastDisconnected       = GetDateTimeOrNull(details.GetValueOrDefault("last-disconnected"));
            spooler.LastHelloReceived      = GetDateTimeOrNull(details.GetValueOrDefault("last-hello-received"));
            spooler.LastHeartbeatReceived  = GetDateTimeOrNull(details.GetValueOrDefault("last-heartbeat-received"));
            spooler.LastJobSpooled         = GetDateTimeOrNull(details.GetValueOrDefault("last-job-spooled"));
            spooler.PrintSpoolerAppVersion = details.GetValueOrDefault("print-spooler-app-version");

            spooler.Printers = printers.Select(x => (string)x).ToArray();
        }
예제 #20
0
        /// <summary>
        /// Adds the clawPDF port monitor
        /// </summary>
        /// <param name="monitorFilePath">Directory where the uninstalled monitor dll is located</param>
        /// <returns>true if the monitor is installed, false if install failed</returns>
        public bool AddclawPDFPortMonitor(String monitorFilePath)
        {
            bool monitorAdded = false;

            IntPtr oldRedirectValue = IntPtr.Zero;

            try
            {
                oldRedirectValue = DisableWow64Redirection();
                //if (!DoesMonitorExist(PORTMONITOR))
                //{
                // Copy the monitor DLL to
                // the system directory
                String monitorfileSourcePath        = Path.Combine(monitorFilePath, MONITORDLL);
                String monitorfileDestinationPath   = Path.Combine(Environment.SystemDirectory, MONITORDLL);
                String monitoruifileSourcePath      = Path.Combine(monitorFilePath, MONITORUIDLL);
                String monitoruifileDestinationPath = Path.Combine(Environment.SystemDirectory, MONITORUIDLL);

                Spooler.stop();

                try
                {
                    File.Copy(monitoruifileSourcePath, monitoruifileDestinationPath, true);
                }
                catch { }

                try
                {
                    File.Copy(monitorfileSourcePath, monitorfileDestinationPath, true);
                }
                catch { }

                Spooler.start();

                MONITOR_INFO_2 newMonitor = new MONITOR_INFO_2();
                newMonitor.pName        = PORTMONITOR;
                newMonitor.pEnvironment = ENVIRONMENT;
                newMonitor.pDLLName     = MONITORDLL;
                if (!AddPortMonitor(newMonitor))
                {
                    Console.WriteLine(String.Format("Could not add port monitor {0}", PORTMONITOR) + Environment.NewLine +
                                      String.Format(WIN32ERROR, Marshal.GetLastWin32Error().ToString()));
                }
                else
                {
                    monitorAdded = true;
                }
                //}
                //else
                //{
                // Monitor already installed -
                // log it, and keep going
                //    Console.WriteLine(String.Format("Port monitor {0} already installed.", PORTMONITOR));
                //    monitorAdded = true;
                // }
            }
            finally
            {
                if (oldRedirectValue != IntPtr.Zero)
                {
                    RevertWow64Redirection(oldRedirectValue);
                }
            }

            return(monitorAdded);
        }
 public PowershellSpoolerParams(Task task, Spooler spooler, bool isOrderJob, bool isShellMode)
     : base(task, spooler, isOrderJob, isShellMode)
 {
 }
 public PowershellSpoolerParams(Task task, Spooler spooler, bool isOrderJob, bool isShellMode)
     : base(task, spooler, isOrderJob, isShellMode)
 {
 }