コード例 #1
0
        private static void SetNewSensorHistoryChannelName(SensorHistoryRecord history, ChannelHistoryRecord record)
        {
            record.Name = record.Name.Replace(" ", "");

            string newName;

            if (TryGetNewSensorHistoryChannelName(record.Name, out newName))
            {
                if (history.ChannelRecords.Where(r => r != record).All(r =>
                {
                    //Is this new name unique amongst all the other channel names (after updating their names)?
                    string other;

                    if (!TryGetNewSensorHistoryChannelName(r.Name.Replace(" ", ""), out other))
                    {
                        other = r.Name;
                    }

                    return(other != newName);
                }))
                {
                    record.Name = newName;
                }
            }
        }
コード例 #2
0
        private PSObject CreateObject(SensorHistoryRecord date)
        {
            var obj = new PSObject();

            obj.Properties.Add(new PSNoteProperty("DateTime", date.DateTime));
            obj.Properties.Add(new PSNoteProperty("SensorId", date.SensorId));

            foreach (var channel in date.ChannelRecords)
            {
                if (!cmdlet.Raw && (channelUnitMap[channel.Name] != null || IsTimeSpan(channel)))
                {
                    //Implicitly not Raw if we have a channel unit
                    var value = GetChannelValue(channel);

                    obj.Properties.Add(new PSNoteProperty(channel.Name, value));
                }
                else
                {
                    obj.Properties.Add(new PSNoteProperty(channel.Name, cmdlet.Raw ? channel.Value?.ToString() : channel.DisplayValue));
                }
            }

            obj.Properties.Add(new PSNoteProperty("Coverage", date.Coverage));

            obj.TypeNames.Insert(0, typeNameRecord.TypeName);

            return(obj);
        }
コード例 #3
0
        private PSObject CreateObject(SensorHistoryRecord date)
        {
            var obj = new PSObject();

            obj.Properties.Add(new PSNoteProperty("DateTime", date.DateTime));
            obj.Properties.Add(new PSNoteProperty("SensorId", date.SensorId));

            foreach (var channel in date.ChannelRecords)
            {
                if (channelUnitMap[channel.Name] != null)
                {
                    var value = GetChannelValue(channel);

                    obj.Properties.Add(new PSNoteProperty(channel.Name, value));
                }
                else
                {
                    obj.Properties.Add(new PSNoteProperty(channel.Name, channel.DisplayValue));
                }
            }

            obj.Properties.Add(new PSNoteProperty("Coverage", date.Coverage));

            obj.TypeNames.Insert(0, typeNameRecord.TypeName);

            return(obj);
        }
コード例 #4
0
ファイル: ResponseParser.cs プロジェクト: vsbopi/PrtgAPI
        private static double?GetSensorHistoryChannelValue(SensorHistoryRecord history, ChannelHistoryRecord record)
        {
            //PRTG does not return a raw record if the sensor did not return a value
            //(such as because it was in an error state)
            var rawRecord = history.ChannelRecordsRaw.FirstOrDefault(r => r.ChannelId == record.ChannelId);

            return(rawRecord?.Value);
        }
コード例 #5
0
        private PSObject PrepareObject(SensorHistoryRecord data, bool isNew = false)
        {
            var ps = CreateObject(data);

            if (!xmlLoaded)
            {
                LoadFormat(ps, isNew);
                xmlLoaded = true;
            }

            return(ps);
        }
コード例 #6
0
        private static double?GetSensorHistoryChannelValue(SensorHistoryRecord history, ChannelHistoryRecord record)
        {
            //PRTG does not return a raw record if the sensor did not return a value
            //(such as because it was in an error state)
            var rawRecords = history.ChannelRecordsRaw.Where(r => r.ChannelId == record.ChannelId).ToArray();

            if (rawRecords.Length < 2)
            {
                return(rawRecords.FirstOrDefault()?.Value);
            }

            //We have a history record that contains multiple records for a specified channel ID (e.g. a Traffic Sensor)
            var displayRecords = history.ChannelRecords.Where(r => r.ChannelId == record.ChannelId).ToList();

            Debug.Assert(rawRecords.Length == displayRecords.Count, "Had different number of display and raw records!");

            var thisIndex = displayRecords.IndexOf(record);

            return(rawRecords[thisIndex].Value);
        }