/// <summary>
        /// Parses a "device" node. A device node contains sensors of various types in its "nodes" child node.
        /// The aim here is to retrieve the netflow sensors and parse their channel definitions.
        /// </summary>
        /// <param name="nodes">The TreeNodeCollection the devices should be added to.</param>
        /// <param name="deviceXEl">The XElement containing the device node to be parsed</param>
        /// <returns></returns>
        private int ParseDeviceNode(TreeNode parentNode, XElement deviceXEl)
        {
            TreeNode deviceNode         = new DeviceTreeNode((string)deviceXEl.Attribute("id"), ((string)deviceXEl.Element("data").Element("name")).Trim());
            int      netFlowSensorCount = 0;

            foreach (XElement sensorXEl in deviceXEl.Element("nodes").Elements("sensor"))
            {
                if (((string)sensorXEl.Element("data").Element("sensorkind")).Trim().Equals("netflow9custom"))
                {
                    netFlowSensorCount++;
                    // Note: PRTG seems to use \r as a line separator in netflow channel defs.
                    // We convert them to CRLF in order for display to be handled correctly in the GUI.
                    string netflowChannelDef = ((string)sensorXEl.Element("data").Element("flowchannel")).Trim().Replace("\r", Environment.NewLine);
                    int    channelDefNum     = this.AddChannelDef(netflowChannelDef, parentNode);
                    deviceNode.Nodes.Add(new NetflowSensorTreeNode((string)sensorXEl.Attribute("id"), channelDefNum));
                }
            }

            if (netFlowSensorCount > 0)
            {
                parentNode.Nodes.Add(deviceNode);
            }

            return(netFlowSensorCount);
        }
Beispiel #2
0
        /// <summary>
        /// Загрузка данных из БД
        /// Создание нод для TreeView
        /// </summary>
        private async void LoadData()
        {
            //получаем коллекцию устройств из БД
            List <Device> devices = await _data.GetDevicesAsync();

            //создаем ноды и наполняем TreeView
            foreach (var device in devices)
            {
                var node = new DeviceTreeNode(device);
                node.ImageIndex         = 0;
                node.SelectedImageIndex = 1;
                _treeViewDevices.Nodes.Add(node);
            }
        }
Beispiel #3
0
        //private static String GetDeviceUrl(Device device)
        //{
        //    return "http://www.netping.ru/products/" + device.Url;
        //}

        private static void AddOffers(DeviceTreeNode offerNode, Shop shop, DeviceTreeNode childCategoryNode)
        {
            if (!(String.IsNullOrEmpty(offerNode.Device.Label.OwnNameFromPath) ||
                  offerNode.Device.Label.OwnNameFromPath.Equals("New", StringComparison.CurrentCultureIgnoreCase)))
            {
                return;
            }

            var shortDescription = offerNode.Device.Short_description;
            var descr            = String.Empty;

            if (!String.IsNullOrWhiteSpace(shortDescription))
            {
                var htmlDoc = new HtmlDocument();

                htmlDoc.LoadHtml(shortDescription);
                var ulNodes = htmlDoc.DocumentNode.SelectNodes("//ul");
                if (ulNodes != null)
                {
                    foreach (var ulNode in ulNodes)
                    {
                        ulNode.Remove();
                    }
                }
                descr = htmlDoc.DocumentNode.InnerText.Replace("&#160;", " ");
            }

            var deviceUrl = UrlBuilder.GetDeviceUrl(offerNode.Device.Url).ToString();

            bool stock = true;

            if (offerNode.Device.DeviceStock <= 0)
            {
                stock = false;
            }

            shop.Offers.Add(new Offer
            {
                Id          = offerNode.Id,
                Url         = deviceUrl,
                Price       = (Int32)(offerNode.Device.Price.HasValue ? offerNode.Device.Price.Value : 0),
                CategoryId  = childCategoryNode.Id,
                Picture     = offerNode.Device.GetCoverPhoto(true).Url,
                TypePrefix  = "",
                VendorCode  = offerNode.Name,
                Model       = offerNode.Name,
                Store       = stock,
                Description = descr
            });
        }
        private void AddDeviceTreeForChannel(int channelID, TreeNode parentNode)
        {
            if (!flowChannels.ContainsKey(channelID))
            {
                flowChannels[channelID] = new ChannelDefTreeNode(channelID, "ChannelDef_" + channelID);
            }

            TreeNode currentNode = flowChannels[channelID];

            PRTGTreeNode parNode = parentNode as PRTGTreeNode;
            PRTGTreeNode curNode = currentNode as PRTGTreeNode;

            if (parNode == null || curNode == null)
            {
                return;
            }

            Stack <PRTGTreeNode> nodeList = new Stack <PRTGTreeNode>();

            while (parNode != null)
            {
                PRTGTreeNode newNode = null;
                if (parNode is DeviceTreeNode)
                {
                    newNode = new DeviceTreeNode(parNode.Id, parNode.Text);
                }
                else if (parNode is GroupTreeNode)
                {
                    newNode = new GroupTreeNode(parNode.Id, parNode.Text);
                }
                else if (parNode is ProbeTreeNode)
                {
                    newNode = new ProbeTreeNode(parNode.Id, parNode.Text);
                }
                nodeList.Push(newNode);
                parNode = parNode.Parent as PRTGTreeNode;
            }

            while (nodeList.Count > 0)
            {
                PRTGTreeNode n     = nodeList.Pop();
                bool         found = false;
                PRTGTreeNode t     = null;

                foreach (PRTGTreeNode p in curNode.Nodes)
                {
                    if ((n is DeviceTreeNode && p is DeviceTreeNode && n.Id == p.Id) ||
                        (n is GroupTreeNode && p is GroupTreeNode && n.Id == p.Id) ||
                        (n is ProbeTreeNode && p is ProbeTreeNode && n.Id == p.Id))
                    {
                        found = true;
                        t     = p;
                        break;
                    }
                }

                if (found == true)
                {
                    curNode = t;
                    continue;
                }

                curNode.Nodes.Add(n);
                curNode = n;
            }
        }