Exemplo n.º 1
0
 public void Add(Printer printer, bool verbose = false)
 {
     try
     {
         switch (printer.Type)
         {
             case Printer.PrinterType.iPrint:
                 AddiPrint(printer, verbose);
                 break;
             case Printer.PrinterType.Local:
                 AddLocal(printer,verbose);
                 break;
             case Printer.PrinterType.Network:
                 AddNetwork(printer, verbose);
                 break;
             case Printer.PrinterType.CUPS:
                 AddCUPS(printer, verbose);
                 break;
         }
     }
     catch (Exception ex)
     {
         Log.Error(LogName, "Could not add");
         Log.Error(LogName, ex);
     }
 }
Exemplo n.º 2
0
        public void Add(Printer printer)
        {
            Log.Entry(LogName, "Attempting to add printer:");

            if (printer.Name != null)
                Log.Entry(LogName, $"--> Name = {printer.Name}");
            if (printer.IP != null)
                Log.Entry(LogName, $"--> IP = {printer.IP}");
            if (printer.Port != null)
                Log.Entry(LogName, $"--> Port = {printer.Port}");
            if (printer.File != null)
                Log.Entry(LogName, $"--> File = {printer.File}");
            if (printer.Model != null)
                Log.Entry(LogName, $"--> Model = {printer.Model}");

            try
            {
                if (printer is iPrintPrinter)
                    AddiPrint((iPrintPrinter) printer);
                else if (printer is LocalPrinter)
                    AddLocal((LocalPrinter) printer);
                else if (printer is NetworkPrinter)
                    AddNetwork((NetworkPrinter) printer);
            }
            catch (Exception ex)
            {
                Log.Error(LogName, "Could not add");
                Log.Error(LogName, ex);
            }
        }
Exemplo n.º 3
0
        protected override void AddCUPS(Printer printer, bool verbose = false)
        {
            string[] stdout;
            ProcessHandler.Run("echo", $"{printer.Name} | tr ' ' '_'", true, out stdout);
            var portName = stdout[0];

            var lpdAddress = $"lpd://{printer.IP}";
            ProcessHandler.Run("lpadmin",
                $"-p {portName} -E -v {lpdAddress} -P {printer.File} -D {printer.Name}");
        }
        public override void Configure(Printer printer, bool verbose = false)
        {
            if (printer.Type == Printer.PrinterType.Network)
            {
                Log.Entry(LogName, $"Invoking add {printer.Name} for all users");
                PrintUI($"/in /n \"{printer.Name}\"", verbose);
            }

            if (string.IsNullOrEmpty(printer.ConfigFile)) return;

            Log.Entry(LogName, "Configuring " + printer.Name);
            PrintUI($"/Sr /n \"{printer.Name}\" /a \"{printer.ConfigFile}\" m f g p", verbose);
        }
Exemplo n.º 5
0
        private void addButton_Click(object sender, EventArgs e)
        {
            aliasBox.Enabled = false;
            ipBox.Enabled = false;
            portBox.Enabled = false;
            modelBox.Enabled = false;
            driverBox.Enabled = false;
            typeCombo.Enabled = false;

            // Create the printer
            var printer = new Printer
            {
                Name = aliasBox.Text,
                File = driverBox.Text,
                IP = ipBox.Text,
                Port = portBox.Text,
                Model = modelBox.Text
            };

            if (typeCombo.SelectedItem.Equals("TCP/IP"))
            {
                printer.Type = Printer.PrinterType.Local;
            }
            else if (typeCombo.SelectedItem.Equals("Network"))
            {
                printer.Type = Printer.PrinterType.Network;

            }
            else if (typeCombo.SelectedItem.Equals("iPrint"))
            {
                printer.Type = Printer.PrinterType.iPrint;
            }

            printer.Add(_instance, true);

            aliasBox.Enabled = true;
            ipBox.Enabled = true;
            portBox.Enabled = true;
            modelBox.Enabled = true;
            driverBox.Enabled = true;
            typeCombo.Enabled = true;
        }
Exemplo n.º 6
0
 protected override void AddCUPS(Printer printer, bool verbose = false)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 protected override void AddNetwork(Printer printer, bool verbose = false)
 {
     PrintUI($"/ga /n \"{printer.Name}\"", verbose);
 }
Exemplo n.º 8
0
 public override void Configure(Printer printer, bool verbose = false)
 {
     throw new NotImplementedException();
 }
        protected override void AddLocal(Printer printer, bool verbose = false)
        {
            if (printer.IP != null)
                AddIPPort(printer, "9100");

            PrintUI($"/if /b \"{printer.Name}\" /f \"{printer.File}\" /r \"{printer.Port}\" /m \"{printer.Model}\"", verbose);
        }
Exemplo n.º 10
0
 public abstract void Configure(Printer printer, bool verbose = false);
Exemplo n.º 11
0
 public abstract void Configure(Printer printer, bool verbose     = false);
Exemplo n.º 12
0
 protected abstract void AddCUPS(Printer printer, bool verbose    = false);
Exemplo n.º 13
0
 protected abstract void AddNetwork(Printer printer, bool verbose = false);
Exemplo n.º 14
0
 protected abstract void AddLocal(Printer printer, bool verbose   = false);
Exemplo n.º 15
0
 protected override void AddCUPS(Printer printer, bool verbose = false)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 protected override void AddiPrint(Printer printer, bool verbose = false)
 {
     var proc = new Process
     {
         StartInfo =
         {
             FileName = @"c:\windows\system32\iprntcmd.exe",
             Arguments = " -a no-gui \"" + printer.Port + "\"",
             CreateNoWindow = true,
             WindowStyle = ProcessWindowStyle.Hidden
         }
     };
     proc.Start();
     proc.WaitForExit(120000);
     Log.Entry(LogName, "Return code " + proc.ExitCode);
 }
Exemplo n.º 17
0
 protected abstract void AddCUPS(Printer printer, bool verbose = false);
Exemplo n.º 18
0
 protected override void AddNetwork(Printer printer, bool verbose = false)
 {
     PrintUI($"/ga /n \"{printer.Name}\"", verbose);
 }
Exemplo n.º 19
0
 protected abstract void AddLocal(Printer printer, bool verbose = false);
        private void AddIPPort(Printer printer, string remotePort)
        {
            var conn = new ConnectionOptions
            {
                EnablePrivileges = true,
                Impersonation = ImpersonationLevel.Impersonate
            };

            var mPath = new ManagementPath("Win32_TCPIPPrinterPort");

            var mScope = new ManagementScope(@"\\.\root\cimv2", conn)
            {
                Options =
                {
                    EnablePrivileges = true,
                    Impersonation = ImpersonationLevel.Impersonate
                }
            };

            var mPort = new ManagementClass(mScope, mPath, null).CreateInstance();

            try
            {
                if (printer.IP != null && printer.IP.Contains(":"))
                {
                    var arIP = printer.IP.Split(':');
                    if (arIP.Length == 2)
                        remotePort = int.Parse(arIP[1]).ToString();
                }
            }
            catch (Exception ex)
            {
                Log.Error(LogName, "Could not parse port from IP");
                Log.Error(LogName, ex);
            }

            mPort.SetPropertyValue("Name", printer.Port);
            mPort.SetPropertyValue("Protocol", 1);
            mPort.SetPropertyValue("HostAddress", printer.IP);
            mPort.SetPropertyValue("PortNumber", remotePort);
            mPort.SetPropertyValue("SNMPEnabled", false);

            var put = new PutOptions
            {
                UseAmendedQualifiers = true,
                Type = PutType.UpdateOrCreate
            };
            mPort.Put(put);
        }
Exemplo n.º 21
0
 protected abstract void AddNetwork(Printer printer, bool verbose = false);