示例#1
0
        //public static bool IsPlug(string printerName)
        //{
        //    if (printerName.IsNullOrEmptyOrSpaces()) return false;

        //    var scope = new ManagementScope(@"\root\cimv2");
        //    scope.Connect();

        //    var allPrinters = new ManagementObjectSearcher("SELECT * FROM Win32_Printer");
        //    return (from ManagementBaseObject printer in allPrinters.Get()
        //            let name = printer.GetPropertyValue("Name").ToString()
        //            where String.Equals(printerName, name, StringComparison.InvariantCultureIgnoreCase)
        //            select (bool) printer.GetPropertyValue("WorkOffline")).FirstOrDefault();
        //}

        public static bool IsPrinterBusy(string printerName)
        {
            var          printJobCollection = new StringCollection();
            const string searchQuery        = "SELECT * FROM Win32_PrintJob";

            /*searchQuery can also be mentioned with where Attribute,
             *  but this is not working in Windows 2000 / ME / 98 machines
             *  and throws Invalid query error*/
            var searchPrintJobs   = new ManagementObjectSearcher(searchQuery);
            var prntJobCollection = searchPrintJobs.Get();

            foreach (var prntJob in prntJobCollection)
            {
                var jobName = prntJob.Properties["Name"].Value.ToString();

                //Job name would be of the format [Printer name], [Job ID]
                var splitArr = new char[1];
                splitArr[0] = Convert.ToChar(",");
                var prnterName   = jobName.Split(splitArr)[0];
                var documentName = prntJob.Properties["Document"].Value.ToString();
                if (String.Compare(prnterName, printerName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    printJobCollection.Add(documentName);
                }
            }

            return(!printJobCollection.IsNullOrEmpty());
        }
        public void IsNullOrEmpty_ShouldReturnFalseForNonEmptyCollection()
        {
            var collection = new StringCollection {
                "foo"
            };

            Assert.That(collection.IsNullOrEmpty(), Is.False);
        }
        public void IsNullOrEmpty_ShouldHandleNull()
        {
            StringCollection testCollection = null;

            Assert.That(testCollection.IsNullOrEmpty(), Is.True);
        }