/// <summary>
        /// Construct for a lower layer and a cache data set (from which we return the non-volatile data).
        /// </summary>
        public VolatileFetchingInterfaceDetails(IInterfaceDetails interfaceDetails, ISnmpLowerLayer lowerLayer)
        {
            this.lowerLayer = lowerLayer ?? throw new System.ArgumentNullException(nameof(lowerLayer), "lower layer is null");
            this.underlyingInterfaceDetails = interfaceDetails ?? throw new System.ArgumentNullException(nameof(interfaceDetails), "underlying interface details is null");

            this.Details = interfaceDetails.Details.Select(underlyingInterfaceDetail => new VolatileFetchingInterfaceDetail(underlyingInterfaceDetail, this.lowerLayer)).ToList();
        }
        /// <summary>
        /// Formats as block-formatted string of an <see cref="IInterfaceDetails" />.
        /// </summary>
        /// <param name="interfaceDetails">The data to format.</param>
        /// <returns>The formatted string.</returns>
        public string Format(IInterfaceDetails interfaceDetails)
        {
            if (interfaceDetails == null)
            {
                return("<null>");
            }

            StringBuilder returnBuilder = new StringBuilder(256);

            returnBuilder.Append("Interface Details: ");

            if (interfaceDetails.Details == null)
            {
                returnBuilder.Append(NotAvailableString);
            }
            else
            {
                foreach (var item in interfaceDetails.Details)
                {
                    returnBuilder.AppendLine().AppendLine(SnmpAbstraction.IndentLines(this.Format(item)));
                }
            }

            return(returnBuilder.ToString());
        }
        /// <summary>
        /// Construct from IWirelessPeerInfos.
        /// </summary>
        public SerializableInterfaceDetails(IInterfaceDetails inputInfos)
        {
            if (inputInfos is null)
            {
                throw new ArgumentNullException(nameof(inputInfos), "The IInterfaceDetails to make serializable is null");
            }

            this.interfaceDetailsBacking = inputInfos.Details.Select(p => new SerializableInterfaceDetail(p) as IInterfaceDetail).ToList();
            this.DeviceModel             = inputInfos.DeviceModel;
            this.DeviceAddress           = inputInfos.DeviceAddress;
        }
示例#4
0
        /// <summary>
        /// Fetches network interface data.
        /// </summary>
        private void FetchNetworkInterfaceData()
        {
            if (this.networkInterfaceDetailsBacking != null)
            {
                return;
            }

            Stopwatch stopper = Stopwatch.StartNew();

            this.EnsureOpenConnection();

            var interfaceData = this.TikConnection.LoadList <Interface>();

            stopper.Stop();

            this.networkInterfaceDetailsBacking = new SerializableInterfaceDetails
            {
                DeviceAddress = this.Address,
                DeviceModel   = this.SystemData.DeviceModel,
                Details       = interfaceData.Select(d => this.MakeInterfaceDetail(d)).ToList(),
                QueryDuration = stopper.Elapsed
            };
        }
示例#5
0
        /// <summary>
        /// Fetches the interface details from lower querier and saves it to the database.
        /// </summary>
        private void LowerQuerierFetchInterfaceDetails()
        {
            lock (this.SyncRoot)
            {
                if (this.volatileFetchingInterfaceDetails != null)
                {
                    return;
                }

                if (this.cacheEntry.InterfaceDetails == null)
                {
                    this.InitializeLowerQuerier();

                    var lowerLayerInterfaceDetails = this.lowerQuerier.NetworkInterfaceDetails;

                    // we force immediate evaluation in order to ensure that really all cachable OIDs have been set.
                    lowerLayerInterfaceDetails.ForceEvaluateAll();

                    this.cacheEntry.InterfaceDetails = new SerializableInterfaceDetails(lowerLayerInterfaceDetails);
                    this.cacheEntry.LastModification = DateTime.UtcNow;

                    this.cacheDatabaseContext.CacheData.Update(this.cacheEntry);
                    this.cacheDatabaseContext.SaveChanges();
                }

                if (this.cacheEntry.ApiUsed.HasFlag(QueryApis.VendorSpecific))
                {
                    log.Info($"Forcing non-cached operation for FetchInterfaceDetails of device {this.Address} due to vendor specific API usage");
                    this.InitializeLowerQuerier();
                    this.volatileFetchingInterfaceDetails = this.lowerQuerier.NetworkInterfaceDetails;
                }
                else
                {
                    this.volatileFetchingInterfaceDetails = new VolatileFetchingInterfaceDetails(this.cacheEntry.InterfaceDetails, this.lowerLayer);
                }
            }
        }
        /// <summary>
        /// Formats a generic object if it's of one of the supported types.
        /// </summary>
        /// <param name="someObject">The object to format.</param>
        /// <returns>The formatted text.</returns>
        public string Format(object someObject)
        {
            if (someObject == null)
            {
                return("<null>");
            }

            IDeviceSystemData asDevSysData = someObject as IDeviceSystemData;

            if (asDevSysData != null)
            {
                return(this.Format(asDevSysData));
            }

            IInterfaceDetails asIfDetails = someObject as IInterfaceDetails;

            if (asIfDetails != null)
            {
                return(this.Format(asIfDetails));
            }

            IInterfaceDetail asIfDetail = someObject as IInterfaceDetail;

            if (asIfDetail != null)
            {
                return(this.Format(asIfDetail));
            }

            IWirelessPeerInfos asWiPeerInfos = someObject as IWirelessPeerInfos;

            if (asWiPeerInfos != null)
            {
                return(this.Format(asWiPeerInfos));
            }

            IWirelessPeerInfo asWiPeerInfo = someObject as IWirelessPeerInfo;

            if (asWiPeerInfo != null)
            {
                return(this.Format(asWiPeerInfo));
            }

            ILinkDetails asLinkDetails = someObject as ILinkDetails;

            if (asLinkDetails != null)
            {
                return(this.Format(asLinkDetails));
            }

            IBgpPeers asBgpPeers = someObject as IBgpPeers;

            if (asBgpPeers != null)
            {
                return(this.Format(asBgpPeers));
            }

            IBgpPeer asBgpPeer = someObject as IBgpPeer;

            if (asBgpPeer != null)
            {
                return(this.Format(asBgpPeer));
            }

            ITracerouteResult asTracerouteResult = someObject as ITracerouteResult;

            if (asTracerouteResult != null)
            {
                return(this.Format(asTracerouteResult));
            }

            ITracerouteHop asTracerouteHop = someObject as ITracerouteHop;

            if (asTracerouteHop != null)
            {
                return(this.Format(asTracerouteHop));
            }

            // fallback: call the object's ToString
            return(someObject.ToString());
        }