コード例 #1
0
ファイル: SNMPLib.cs プロジェクト: Marat-b/PrinterOps
        /// <summary>
        /// Установка CMY цветов
        /// </summary>
        /// <param name="snmpPrinterColorStateModel"></param>
        void saveToDBforColor(SNMPPrinterColorStateModel snmpPrinterColorStateModel)
        {
            if (snmpPrinterColorStateModel != null)
            {
#if DEBUG
                Console.WriteLine("MaxLevelCyan=" + snmpPrinterColorStateModel.MaxLevelCyan);
                Console.WriteLine("TonerRemainingCyan=" + snmpPrinterColorStateModel.TonerRemainingCyan);
                Console.WriteLine("TonerRemainingCyan=" + snmpPrinterColorStateModel.TonerRemainingCyan);
#endif
                POServiceClient proxy = new POServiceClient("NetTCPBinding_IPOService");
                POServiceRef.SNMPPrinterColorStateModel snmpPrinterColorState = new POServiceRef.SNMPPrinterColorStateModel();
                Mapper.CreateMap <SNMPPrinterColorStateModel, POServiceRef.SNMPPrinterColorStateModel>();
                Mapper.Map(snmpPrinterColorStateModel, snmpPrinterColorState);
                proxy.Open();
#if DEBUG
                if (proxy.SetColor(snmpPrinterColorState))
                {
                    Console.WriteLine("Success Color");
                }
                else
                {
                    Console.WriteLine("Failed Color");
                }
#else
                proxy.SetColor(snmpPrinterColorState);
#endif
                proxy.Close();
            }
        }
コード例 #2
0
ファイル: SNMPLib.cs プロジェクト: Marat-b/PrinterOps
        /// <summary>
        /// Установка состояния принтера
        /// </summary>
        /// <param name="ipAddress"></param>
        public void SetStates(VersionCode version, string ipAddress, OctetString community, int timeout)
        {
            IPEndPoint            IpEndPoint       = new IPEndPoint(IPAddress.Parse(ipAddress), 161);
            SNMPPrinterStateModel snmpPrinterState = SNMPGet(version, IpEndPoint, community, timeout);

            if (snmpPrinterState != null)
            {
                snmpPrinterState.IPAddress    = ipAddress;
                snmpPrinterState.AlertMessage = SNMPAlertMessage(version, IpEndPoint, community, timeout);
                // Record date to DB
                saveToDB(snmpPrinterState);
            }

            SNMPPrinterColorStateModel snmpPrinterColorState = SNMPGetColor(version, IpEndPoint, community, timeout);

            if (snmpPrinterColorState != null)
            {
                snmpPrinterColorState.SerialNumber = snmpPrinterState.SerialNumber ?? "";
                saveToDBforColor(snmpPrinterColorState);
            }
        }
コード例 #3
0
ファイル: SNMPLib.cs プロジェクト: Marat-b/PrinterOps
        SNMPPrinterColorStateModel SNMPGetColor(VersionCode version, IPEndPoint ipEndPoint, OctetString community, int timeout)
        {
            /*
             *     [string]$ColorName=Invoke-SNMPget $IPAddress ".1.3.6.1.2.1.43.12.1.1.4.1.1"
             *      [int]$TonerRemaining=Invoke-SNMPget $IPAddress ".1.3.6.1.2.1.43.11.1.1.9.1.1"
             *      [int]$TonerMaxLevel=Invoke-SNMPget $IPAddress ".1.3.6.1.2.1.43.11.1.1.8.1.1"
             *
             */

            SNMPPrinterColorStateModel snmpPrinterColorState = new SNMPPrinterColorStateModel();

            List <Variable> variable = new List <Variable>();

            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.12.1.1.4.1.1"))); // Color Name - Black
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.9.1.1"))); //is the maximum of black toner remaining
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.8.1.1"))); //is the maximum black toner level
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.12.1.1.4.1.2"))); //Color Name - Cyan
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.9.1.2"))); //is the maximum of cyan toner remaining
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.8.1.2"))); //is the maximum cyan toner level
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.12.1.1.4.1.3"))); //Color Name - Magenta
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.9.1.3"))); //is the maximum of magenta toner remaining
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.8.1.3"))); // is the maximum magenta toner level
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.12.1.1.4.1.4"))); //Color Name - Yellow
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.9.1.4"))); //is the maximum of yellow toner remaining
            variable.Add(new Variable(new ObjectIdentifier(".1.3.6.1.2.1.43.11.1.1.8.1.4"))); // is the maximum yellow toner level

            try
            {
                var result = Messenger.Get(version,
                                           ipEndPoint,
                                           community,
                                           variable,
                                           timeout);

                if (result != null)
                {
#if DEBUG
                    foreach (Variable res in result)
                    {
                        Console.WriteLine(res);
                    }
#endif

                    snmpPrinterColorState.ColorNameBlack      = result[0].Data.ToString();
                    snmpPrinterColorState.TonerRemainingBlack = CheckVariableDataForInt(result[1].Data);
                    snmpPrinterColorState.MaxLevelBlack       = CheckVariableDataForInt(result[2].Data);

                    snmpPrinterColorState.ColorNameCyan      = result[3].Data.ToString();
                    snmpPrinterColorState.TonerRemainingCyan = CheckVariableDataForInt(result[4].Data);
                    snmpPrinterColorState.MaxLevelCyan       = CheckVariableDataForInt(result[5].Data);

                    snmpPrinterColorState.ColorNameMagenta      = result[6].Data.ToString();
                    snmpPrinterColorState.TonerRemainingMagenta = CheckVariableDataForInt(result[7].Data);
                    snmpPrinterColorState.MaxLevelMagenta       = CheckVariableDataForInt(result[8].Data);

                    snmpPrinterColorState.ColorNameYellow      = result[9].Data.ToString();
                    snmpPrinterColorState.TonerRemainingYellow = CheckVariableDataForInt(result[10].Data);
                    snmpPrinterColorState.MaxLevelYellow       = CheckVariableDataForInt(result[11].Data);
                }
            }
            catch
            {
#if DEBUG
                Console.WriteLine("Error result Color");
#endif
            }

            return(snmpPrinterColorState);
        }