Esempio n. 1
0
        /// <summary>
        /// Retrieves the data of all MPS Systems marked for gathereing information
        /// </summary>
        /// <returns></returns>
        public List <OidData> GainData()
        {
            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "RetrieveDeviceInformation", "GainData");
            var dt = Config.GetInstance().Query("select * from Devices where active='1' or active='True'");
            // DataTable resultTable = null;
            var data = new List <OidData>();

            for (var i = 0; i < dt.Rows.Count; i++)
            {
                if (DeviceTools.IdentDevice(dt.Rows[i].Field <string>("Ip")).Length > 0)
                {
                    if (FnPing.PingAndCheckSuccess(IPAddress.Parse(dt.Rows[i].Field <string>("Ip"))))
                    {
                        if (SnmpClient.ReadDeviceOiDs(dt.Rows[i].Field <string>("Ip"),
                                                      DeviceTools.IdentDevice(dt.Rows[i].Field <string>("Ip")), out OidData oidData))
                        {
                            if (oidData != null)
                            {
                                data.Add(oidData);
                            }
                        }
                    }
                }
            }

            return(data);
        }
Esempio n. 2
0
        /// <summary>
        /// Searches for printer.
        /// </summary>
        /// <param name="state">The state.</param>
        private void SearchForPrinter(object state)
        {
            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "SearchForDevices", "SearchForPrinter");

            var fp = new FnPing(StartIpAddress, EndIpAddress);

            var pingResultsIps = fp.RangePing();

            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "SearchForDevices",
                                             "SearchForPrinter - pingResultsIps Success Count:" + pingResultsIps.SuccessIpAddresses.Count);

            foreach (var ipAddress in pingResultsIps.SuccessIpAddresses)
            {
                try
                {
                    var ident  = DeviceTools.IdentDevice(ipAddress.ToString());
                    var modell = "";
                    var serial = "";
                    var asset  = "";
                    if (ident.Length > 0)
                    {
                        if (Config.GetInstance().Query(
                                "Select * from Devices where IP='" + ipAddress.ToString() + "';").Rows.Count >
                            0)
                        {
                            var dts = Config.GetInstance().GetOidRowByPrivateId(ident);
                            modell = SnmpClient.GetOidValue(ipAddress.ToString(), dts.Rows[0].Field <string>("Model"));
                            serial = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                            dts.Rows[0].Field <string>("SerialNumber"));
                            asset = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                           dts.Rows[0].Field <string>("AssetNumber"));
                            Config.GetInstance().UpdateDeviceTable(
                                "1",
                                ipAddress.GetAddressBytes(),
                                modell,
                                serial,
                                asset,
                                ipAddress.GetAddressBytes()
                                );
                            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "SearchForDevices",
                                                             "SearchForPrinter Found: " + ipAddress.ToString() + " Type: " + ident);
                        }
                        else
                        {
                            var dts = Config.GetInstance().GetOidRowByPrivateId(ident);

                            if (dts.Rows.Count > 0)
                            {
                                modell = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                                dts.Rows[0].Field <string>("Model"));
                                serial = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                                dts.Rows[0].Field <string>("SerialNumber"));
                                asset = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                               dts.Rows[0].Field <string>("AssetNumber"));
                                Config.GetInstance().Query("Delete from Devices where IP = '" +
                                                           ipAddress.ToString() + "'; ");
                                Config.GetInstance().InsertInDeviceTable(
                                    "1",
                                    ipAddress.GetAddressBytes(),
                                    modell,
                                    serial,
                                    asset
                                    );
                            }
                        }
                    }
                }
                catch (SnmpIdentNotFoundException)
                {
                }
            }
            DataGridDevices.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(LoadGridData));
            ButtonSearch.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(ShowStartButton));
        }