<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using StackExchange.Opserver.Data.Dashboard.Providers;

namespace StackExchange.Opserver.Data.Dashboard
{
    public partial class Node : IMonitorStatus, ISearchableNode
    {   
        string ISearchableNode.DisplayName => PrettyName;
        string ISearchableNode.Name => PrettyName;
        string ISearchableNode.CategoryName => Category?.Name.Replace(" Servers", "") ?? "Unknown";
        
        public DashboardDataProvider DataProvider { get; set; }
        public bool IsRealTimePollable => MachineType?.Contains("Windows") == true;
        public List<Issue<Node>> Issues { get; set; }

        public string Id { get; internal set; }
        public string Name { get; internal set; }
        public DateTime? LastSync { get; internal set; }
        public string MachineType { get; internal set; }
        public string MachineOSVersion { get; internal set; }
        private string _machineTypePretty;
        public string MachineTypePretty => _machineTypePretty ?? (_machineTypePretty = GetPrettyMachineType());
        public string Ip { get; internal set; }
        public short? PollIntervalSeconds { get; internal set; }

        public DateTime? LastBoot { get; internal set; }
        public NodeStatus Status { get; internal set; }
        public NodeStatus? ChildStatus { get; internal set; }
        public string StatusDescription { get; internal set; }
        private HardwareType? _hardwareType;
        public HardwareType HardwareType => _hardwareType ?? (_hardwareType = GetHardwareType()).Value;

        public short? CPULoad { get; internal set; }
        public float? TotalMemory { get; internal set; }
        public float? MemoryUsed { get; internal set; }
        public string VMHostID { get; internal set; }
        public bool IsVMHost { get; internal set; }
        public bool IsUnwatched { get; internal set; }

        public string Manufacturer { get; internal set; }
        public string Model { get; internal set; }
        public string ServiceTag { get; internal set; }
        public Version KernelVersion { get; internal set; }
        
        public string PrettyName => (Name ?? "").ToUpper();
        public TimeSpan? UpTime => DateTime.UtcNow - LastBoot;
        public MonitorStatus MonitorStatus => Status.ToMonitorStatus();

        // TODO: Implement
        public string MonitorStatusReason => null;

        public bool IsVM => VMHostID.HasValue();
        public bool HasValidMemoryReading => MemoryUsed.HasValue && MemoryUsed >= 0;

        public Node VMHost { get; internal set; }

        public List<Node> VMs { get; internal set; }

        private DashboardCategory _category;
        public DashboardCategory Category
        {
            get { return _category ?? (_category = DashboardCategory.AllCategories.FirstOrDefault(c => c.PatternRegex.IsMatch(Name)) ?? DashboardCategory.Unknown); }
        }

        private string GetPrettyMachineType()
        {
            if (MachineType.StartsWith("Linux")) return MachineOSVersion.IsNullOrEmptyReturn("Linux");
            return MachineType?.Replace("Microsoft Windows ", "");
        }

        private HardwareType GetHardwareType()
        {
            if (IsVM) return HardwareType.VirtualMachine;<commit_msg>Null ref fix<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using StackExchange.Opserver.Data.Dashboard.Providers;

namespace StackExchange.Opserver.Data.Dashboard
{
    public partial class Node : IMonitorStatus, ISearchableNode
    {   
        string ISearchableNode.DisplayName => PrettyName;
        string ISearchableNode.Name => PrettyName;
        string ISearchableNode.CategoryName => Category?.Name.Replace(" Servers", "") ?? "Unknown";
        
        public DashboardDataProvider DataProvider { get; set; }
        public bool IsRealTimePollable => MachineType?.Contains("Windows") == true;
        public List<Issue<Node>> Issues { get; set; }

        public string Id { get; internal set; }
        public string Name { get; internal set; }
        public DateTime? LastSync { get; internal set; }
        public string MachineType { get; internal set; }
        public string MachineOSVersion { get; internal set; }
        private string _machineTypePretty;
        public string MachineTypePretty => _machineTypePretty ?? (_machineTypePretty = GetPrettyMachineType());
        public string Ip { get; internal set; }
        public short? PollIntervalSeconds { get; internal set; }

        public DateTime? LastBoot { get; internal set; }
        public NodeStatus Status { get; internal set; }
        public NodeStatus? ChildStatus { get; internal set; }
        public string StatusDescription { get; internal set; }
        private HardwareType? _hardwareType;
        public HardwareType HardwareType => _hardwareType ?? (_hardwareType = GetHardwareType()).Value;

        public short? CPULoad { get; internal set; }
        public float? TotalMemory { get; internal set; }
        public float? MemoryUsed { get; internal set; }
        public string VMHostID { get; internal set; }
        public bool IsVMHost { get; internal set; }
        public bool IsUnwatched { get; internal set; }

        public string Manufacturer { get; internal set; }
        public string Model { get; internal set; }
        public string ServiceTag { get; internal set; }
        public Version KernelVersion { get; internal set; }
        
        public string PrettyName => (Name ?? "").ToUpper();
        public TimeSpan? UpTime => DateTime.UtcNow - LastBoot;
        public MonitorStatus MonitorStatus => Status.ToMonitorStatus();

        // TODO: Implement
        public string MonitorStatusReason => null;

        public bool IsVM => VMHostID.HasValue();
        public bool HasValidMemoryReading => MemoryUsed.HasValue && MemoryUsed >= 0;

        public Node VMHost { get; internal set; }

        public List<Node> VMs { get; internal set; }

        private DashboardCategory _category;
        public DashboardCategory Category
        {
            get { return _category ?? (_category = DashboardCategory.AllCategories.FirstOrDefault(c => c.PatternRegex.IsMatch(Name)) ?? DashboardCategory.Unknown); }
        }

        private string GetPrettyMachineType()
        {
            if (MachineType?.StartsWith("Linux") ?? false) return MachineOSVersion.IsNullOrEmptyReturn("Linux");
            return MachineType?.Replace("Microsoft Windows ", "");
        }

        private HardwareType GetHardwareType()
        {
            if (IsVM) return HardwareType.VirtualMachine;
{'fraction_non_alphanumeric': 0.08987246811702926, 'fraction_numerical': 0.0003000750187546887, 'mean_word_length': 2.8554077501445922, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7302687', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1640, 'n_words': 518}