Exemple #1
0
        public static string GetMonitoringStatusImageUrl(MonitoringStatus status)
        {
            var url = new UrlHelper(HttpContext.Current.Request.RequestContext);

            if (status == MonitoringStatus.Alarm)
            {
                return(url.Content("~/Content/Icons/Circle-Red.png"));
            }

            if (status == MonitoringStatus.Warning)
            {
                return(url.Content("~/Content/Icons/Circle-Yellow.png"));
            }

            if (status == MonitoringStatus.Success)
            {
                return(url.Content("~/Content/Icons/Circle-Green.png"));
            }

            if (status == MonitoringStatus.Disabled)
            {
                return(url.Content("~/Content/Icons/Circle-Disabled.png"));
            }

            return(url.Content("~/Content/Icons/Circle-Gray.png"));
        }
        public static MonitoringStatus MonitoringStatus()
        {
            var monitoringXml = WebClient.XmlGet("api/monitoring/status");
            MonitoringStatus basicInformation = XmlSerialization.Deserialize <MonitoringStatus>(monitoringXml);

            return(basicInformation);
        }
Exemple #3
0
        public static MvcHtmlString MonitoringStatusIcon(this HtmlHelper htmlHelper, MonitoringStatus status)
        {
            var img = new TagBuilder("img");

            img.Attributes.Add("src", GetMonitoringStatusImageUrl(status));
            img.Attributes.Add("title", EnumHelper.EnumToString(status));
            img.AddCssClass("img-status-icon");
            return(new MvcHtmlString(img.ToString()));
        }
Exemple #4
0
        internal static string ToSerializedValue(this MonitoringStatus value)
        {
            switch (value)
            {
            case MonitoringStatus.Enabled:
                return("Enabled");

            case MonitoringStatus.Disabled:
                return("Disabled");
            }
            return(null);
        }
 /// <summary>
 /// Initializes a new instance of the Volume class.
 /// </summary>
 /// <param name="sizeInBytes">The size of the volume in bytes.</param>
 /// <param name="volumeType">The type of the volume. Possible values
 /// include: 'Tiered', 'Archival', 'LocallyPinned'</param>
 /// <param name="accessControlRecordIds">The IDs of the access control
 /// records, associated with the volume.</param>
 /// <param name="volumeStatus">The volume status. Possible values
 /// include: 'Online', 'Offline'</param>
 /// <param name="monitoringStatus">The monitoring status of the volume.
 /// Possible values include: 'Enabled', 'Disabled'</param>
 /// <param name="id">The path ID that uniquely identifies the
 /// object.</param>
 /// <param name="name">The name of the object.</param>
 /// <param name="type">The hierarchical type of the object.</param>
 /// <param name="kind">The Kind of the object. Currently only
 /// Series8000 is supported. Possible values include:
 /// 'Series8000'</param>
 /// <param name="volumeContainerId">The ID of the volume container, in
 /// which this volume is created.</param>
 /// <param name="operationStatus">The operation status on the volume.
 /// Possible values include: 'None', 'Updating', 'Deleting',
 /// 'Restoring'</param>
 /// <param name="backupStatus">The backup status of the volume.
 /// Possible values include: 'Enabled', 'Disabled'</param>
 /// <param name="backupPolicyIds">The IDs of the backup policies, in
 /// which this volume is part of.</param>
 public Volume(long sizeInBytes, VolumeType volumeType, IList <string> accessControlRecordIds, VolumeStatus volumeStatus, MonitoringStatus monitoringStatus, string id = default(string), string name = default(string), string type = default(string), Kind?kind = default(Kind?), string volumeContainerId = default(string), OperationStatus?operationStatus = default(OperationStatus?), BackupStatus?backupStatus = default(BackupStatus?), IList <string> backupPolicyIds = default(IList <string>))
     : base(id, name, type, kind)
 {
     SizeInBytes            = sizeInBytes;
     VolumeType             = volumeType;
     VolumeContainerId      = volumeContainerId;
     AccessControlRecordIds = accessControlRecordIds;
     VolumeStatus           = volumeStatus;
     OperationStatus        = operationStatus;
     BackupStatus           = backupStatus;
     MonitoringStatus       = monitoringStatus;
     BackupPolicyIds        = backupPolicyIds;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the ISCSIDisk class.
 /// </summary>
 /// <param name="diskStatus">The disk status. Possible values include:
 /// 'Online', 'Offline'</param>
 /// <param name="accessControlRecords">The access control
 /// records.</param>
 /// <param name="dataPolicy">The data policy. Possible values include:
 /// 'Invalid', 'Local', 'Tiered', 'Cloud'</param>
 /// <param name="provisionedCapacityInBytes">The provisioned capacity
 /// in bytes.</param>
 /// <param name="monitoringStatus">The monitoring. Possible values
 /// include: 'Enabled', 'Disabled'</param>
 /// <param name="id">The identifier.</param>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 /// <param name="description">The description.</param>
 /// <param name="usedCapacityInBytes">The used capacity in
 /// bytes.</param>
 /// <param name="localUsedCapacityInBytes">The local used capacity in
 /// bytes.</param>
 public ISCSIDisk(DiskStatus diskStatus, IList <string> accessControlRecords, DataPolicy dataPolicy, long provisionedCapacityInBytes, MonitoringStatus monitoringStatus, string id = default(string), string name = default(string), string type = default(string), string description = default(string), long?usedCapacityInBytes = default(long?), long?localUsedCapacityInBytes = default(long?))
     : base(id, name, type)
 {
     Description                = description;
     DiskStatus                 = diskStatus;
     AccessControlRecords       = accessControlRecords;
     DataPolicy                 = dataPolicy;
     ProvisionedCapacityInBytes = provisionedCapacityInBytes;
     UsedCapacityInBytes        = usedCapacityInBytes;
     LocalUsedCapacityInBytes   = localUsedCapacityInBytes;
     MonitoringStatus           = monitoringStatus;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the FileShare class.
 /// </summary>
 /// <param name="shareStatus">The Share Status. Possible values
 /// include: 'Online', 'Offline'</param>
 /// <param name="dataPolicy">The data policy. Possible values include:
 /// 'Invalid', 'Local', 'Tiered', 'Cloud'</param>
 /// <param name="adminUser">The user/group who will have full
 /// permission in this share. Active directory email address. Example:
 /// [email protected] or Contoso\xyz.</param>
 /// <param name="provisionedCapacityInBytes">The total provisioned
 /// capacity in Bytes</param>
 /// <param name="monitoringStatus">The monitoring status. Possible
 /// values include: 'Enabled', 'Disabled'</param>
 /// <param name="id">The identifier.</param>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 /// <param name="description">Description for file share</param>
 /// <param name="usedCapacityInBytes">The used capacity in
 /// Bytes.</param>
 /// <param name="localUsedCapacityInBytes">The local used capacity in
 /// Bytes.</param>
 public FileShare(ShareStatus shareStatus, DataPolicy dataPolicy, string adminUser, long provisionedCapacityInBytes, MonitoringStatus monitoringStatus, string id = default(string), string name = default(string), string type = default(string), string description = default(string), long?usedCapacityInBytes = default(long?), long?localUsedCapacityInBytes = default(long?))
     : base(id, name, type)
 {
     Description = description;
     ShareStatus = shareStatus;
     DataPolicy  = dataPolicy;
     AdminUser   = adminUser;
     ProvisionedCapacityInBytes = provisionedCapacityInBytes;
     UsedCapacityInBytes        = usedCapacityInBytes;
     LocalUsedCapacityInBytes   = localUsedCapacityInBytes;
     MonitoringStatus           = monitoringStatus;
     CustomInit();
 }
Exemple #8
0
        private void CheckStatus(
            TestAccountInfo account,
            IComponentControl control,
            MonitoringStatus internalStatus,
            MonitoringStatus externalStatus)
        {
            var client        = account.GetClient();
            var internalState = client.ApiService.GetComponentInternalState(control.Info.Id, false).Data;

            Assert.Equal(internalStatus, internalState.Status);
            var totalState = client.ApiService.GetComponentTotalState(control.Info.Id, false).Data;

            Assert.Equal(externalStatus, totalState.Status);
        }
 public static EventImportance Get(MonitoringStatus status)
 {
     if (status == MonitoringStatus.Alarm)
     {
         return(EventImportance.Alarm);
     }
     if (status == MonitoringStatus.Warning)
     {
         return(EventImportance.Warning);
     }
     if (status == MonitoringStatus.Success)
     {
         return(EventImportance.Success);
     }
     if (status == MonitoringStatus.Unknown)
     {
         return(EventImportance.Unknown);
     }
     if (status == MonitoringStatus.Disabled)
     {
         return(EventImportance.Unknown);
     }
     throw new Exception("Неизвестное значение ComponentStatus: " + status);
 }
Exemple #10
0
 public static ObjectColor Get(MonitoringStatus status)
 {
     if (status == MonitoringStatus.Alarm)
     {
         return(ObjectColor.Red);
     }
     if (status == MonitoringStatus.Warning)
     {
         return(ObjectColor.Yellow);
     }
     if (status == MonitoringStatus.Success)
     {
         return(ObjectColor.Green);
     }
     if (status == MonitoringStatus.Unknown)
     {
         return(ObjectColor.Gray);
     }
     if (status == MonitoringStatus.Disabled)
     {
         return(ObjectColor.Gray);
     }
     throw new Exception("Неизвестный MonitoringStatus " + status);
 }
        public override void Update()
        {
            UpdateInputs();

            if (IsTrainControlEnabled())
            {
                if (VigilanceMonitor != null)
                {
                    UpdateVigilance();
                }
                if (OverspeedMonitor != null)
                {
                    UpdateSpeedControl();
                }

                bool EmergencyBrake = false;
                bool FullBrake      = false;
                bool PowerCut       = false;

                if (VigilanceMonitor != null)
                {
                    if (VigilanceMonitor.AppliesEmergencyBrake)
                    {
                        EmergencyBrake |= (VigilanceMonitorState == MonitorState.Emergency);
                    }
                    else if (VigilanceMonitor.AppliesFullBrake)
                    {
                        FullBrake |= (VigilanceMonitorState == MonitorState.Emergency);
                    }

                    if (VigilanceMonitor.EmergencyCutsPower)
                    {
                        PowerCut |= (VigilanceMonitorState == MonitorState.Emergency);
                    }
                }

                if (OverspeedMonitor != null)
                {
                    if (OverspeedMonitor.AppliesEmergencyBrake)
                    {
                        EmergencyBrake |= (OverspeedMonitorState == MonitorState.Emergency);
                    }
                    else if (OverspeedMonitor.AppliesFullBrake)
                    {
                        FullBrake |= (OverspeedMonitorState == MonitorState.Emergency);
                    }

                    if (OverspeedMonitor.EmergencyCutsPower)
                    {
                        PowerCut |= (OverspeedMonitorState == MonitorState.Emergency);
                    }
                }

                if (EmergencyStopMonitor != null)
                {
                    if (EmergencyStopMonitor.AppliesEmergencyBrake)
                    {
                        EmergencyBrake |= ExternalEmergency;
                    }
                    else if (EmergencyStopMonitor.AppliesFullBrake)
                    {
                        FullBrake |= ExternalEmergency;
                    }

                    if (EmergencyStopMonitor.EmergencyCutsPower)
                    {
                        PowerCut |= ExternalEmergency;
                    }
                }

                SetTractionAuthorization(!DoesBrakeCutPower() || LocomotiveBrakeCylinderPressureBar() < BrakeCutsPowerAtBrakeCylinderPressureBar());

                SetEmergencyBrake(EmergencyBrake);
                SetFullBrake(FullBrake);
                SetPowerAuthorization(!PowerCut);

                if (EmergencyCausesThrottleDown && (IsBrakeEmergency() || IsBrakeFullService()))
                {
                    SetThrottleController(0f);
                }

                if (EmergencyEngagesHorn)
                {
                    SetHorn(IsBrakeEmergency() || IsBrakeFullService());
                }

                SetPenaltyApplicationDisplay(IsBrakeEmergency() || IsBrakeFullService());

                // Update monitoring status
                if (SpeedMpS() > CurrentSpeedLimitMpS)
                {
                    if (OverspeedMonitor != null && (OverspeedMonitor.AppliesEmergencyBrake || OverspeedMonitor.AppliesFullBrake))
                    {
                        Status = MonitoringStatus.Intervention;
                    }
                    else
                    {
                        Status = MonitoringStatus.Warning;
                    }
                }
                else if (NextSpeedLimitMpS < CurrentSpeedLimitMpS && SpeedMpS() > NextSpeedLimitMpS)
                {
                    if (Deceleration(SpeedMpS(),NextSpeedLimitMpS,NextSignalDistanceM(0)) > 0.7f)
                    {
                        Status = MonitoringStatus.Overspeed;
                    }
                    else
                    {
                        Status = MonitoringStatus.Indication;
                    }
                }
                else
                {
                    Status = MonitoringStatus.Normal;
                }
                SetMonitoringStatus(Status);
            }
        }
Exemple #12
0
        protected IBulbCacheReadObject SetMetricValue(
            IMetricTypeCacheReadObject metricType,
            MetricCacheWriteObject metric,
            double?value,
            DateTime processDate,
            DateTime actualDate,
            MonitoringStatus status,
            string message,
            bool hasSignal)
        {
            // Обновим текущие значения
            var equal = (value == null && metric.Value == null) || (value == metric.Value);

            if (!equal)
            {
                metric.BeginDate = processDate;
            }
            metric.ActualDate = actualDate;
            metric.Value      = value;

            // Обновим статус метрики
            var statusService      = Context.BulbService;
            var noSignalColor      = metric.NoSignalColor ?? metricType.NoSignalColor ?? ObjectColor.Red;
            var noSignalImportance = EventImportanceHelper.Get(noSignalColor);
            var signal             = new BulbSignal()
            {
                AccountId          = metric.AccountId,
                ActualDate         = metric.ActualDate,
                StartDate          = metric.BeginDate,
                IsSpace            = !hasSignal,
                EventId            = Guid.Empty,
                Message            = message,
                NoSignalImportance = noSignalImportance,
                ProcessDate        = processDate,
                Status             = status
            };

            var statusData = statusService.SetSignal(metric.StatusDataId, signal);

            // сохраним историю
            var color   = ObjectColorHelper.Get(status);
            var history = new MetricHistory()
            {
                ComponentId   = metric.ComponentId,
                MetricTypeId  = metric.MetricTypeId,
                Value         = value,
                BeginDate     = processDate,
                ActualDate    = actualDate,
                Color         = color,
                StatusEventId = statusData.StatusEventId,
                HasSignal     = hasSignal
            };

            var accountDbContext  = Context.GetAccountDbContext(metric.AccountId);
            var historyRepository = accountDbContext.GetMetricHistoryRepository();

            historyRepository.Add(history);

            Context.SaveChanges();
            return(statusData);
        }
        private void SetData(float currentSpeed, int permittedSpeed, int targetSpeed, int releaseSpeed, float interventionSpeed, MonitoringStatus status)
        {
            if (interventionSpeed < permittedSpeed)
            {
                interventionSpeed = permittedSpeed;
            }
            if (currentSpeed > permittedSpeed && currentSpeed > interventionSpeed)
            {
                interventionSpeed = currentSpeed - 1;
            }

            switch (status)
            {
            case MonitoringStatus.Normal:
                GaugeColor  = targetSpeed < permittedSpeed ? Color.White : ColorDarkGrey;
                NeedleColor = ColorMediumGrey; SpeedColor = Color.Black; releaseSpeed = 0; interventionSpeed = permittedSpeed; break;

            case MonitoringStatus.Indication: GaugeColor = NeedleColor = Color.White; SpeedColor = Color.Black; interventionSpeed = permittedSpeed; break;

            case MonitoringStatus.Overspeed: GaugeColor = NeedleColor = ColorYellow; SpeedColor = Color.Black; interventionSpeed = permittedSpeed; break;

            case MonitoringStatus.Warning: GaugeColor = ColorYellow; NeedleColor = ColorOrange; SpeedColor = Color.Black; break;

            case MonitoringStatus.Intervention: GaugeColor = ColorYellow; NeedleColor = ColorRed; SpeedColor = Color.White; break;
            }

            CurrentSpeedAngle = Speed2Angle(currentSpeed);

            var shaderAngles = new Vector4(Speed2Angle(targetSpeed), Speed2Angle(permittedSpeed), Speed2Angle(interventionSpeed), Speed2Angle(releaseSpeed));

            Shader.SetData(shaderAngles, GaugeColor, NeedleColor);

            SpeedText = (int)(currentSpeed + (currentSpeed < 1f || currentSpeed < (float)SpeedText ? 0.99999f : 0.49999f));

            for (int i = 0, d = 1; i < CurrentSpeed.Length; i++, d *= 10)
            {
                CurrentSpeed[i].Color = SpeedColor;
                CurrentSpeed[i].Text  = (SpeedText >= d || SpeedText == 0 && d == 1) ? (SpeedText / d % 10).ToString() : String.Empty;
            }

            ReleaseSpeed.Text = releaseSpeed > 0 ? releaseSpeed.ToString() : String.Empty;
        }
        protected void CheckMetricColor(IClient client, Guid componentId, string metricName, MonitoringStatus status)
        {
            // Проверим цвет в истории
            var historyResponse = client.ApiService.GetMetricsHistory(componentId, new GetMetricsHistoryFilter()
            {
                MaxCount = 100
            });

            Assert.True(historyResponse.Success);
            var history = historyResponse.Data.Where(t => t.Name == metricName).OrderByDescending(t => t.BeginDate).FirstOrDefault();

            Assert.NotNull(history);
            Assert.Equal(status, history.Status);

            // Проверим цвет текущего значения
            var getMetricResponse = client.ApiService.GetMetric(componentId, metricName);

            Assert.True(getMetricResponse.Success);
            Assert.NotNull(getMetricResponse.Data);
            Assert.Equal(status, getMetricResponse.Data.Status);

            var getComponentResponse = client.ApiService.GetComponentInternalState(componentId, false);

            Assert.True(getComponentResponse.Success);
            Assert.Equal(status, getComponentResponse.Data.Status);
        }
Exemple #15
0
        internal static MonitorResourceData DeserializeMonitorResourceData(JsonElement element)
        {
            Optional <IdentityProperties> identity       = default;
            IDictionary <string, string>  tags           = default;
            AzureLocation               location         = default;
            ResourceIdentifier          id               = default;
            string                      name             = default;
            ResourceType                type             = default;
            SystemData                  systemData       = default;
            Optional <MonitoringStatus> monitoringStatus = default;
            Optional <MarketplaceSubscriptionStatus>  marketplaceSubscriptionStatus  = default;
            Optional <DynatraceEnvironmentProperties> dynatraceEnvironmentProperties = default;
            Optional <UserInfo> userInfo = default;
            Optional <PlanData> planData = default;
            Optional <LiftrResourceCategories> liftrResourceCategory = default;
            Optional <int> liftrResourcePreference         = default;
            Optional <ProvisioningState> provisioningState = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    identity = IdentityProperties.DeserializeIdentityProperties(property.Value);
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = new AzureLocation(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("monitoringStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            monitoringStatus = new MonitoringStatus(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("marketplaceSubscriptionStatus"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            marketplaceSubscriptionStatus = new MarketplaceSubscriptionStatus(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("dynatraceEnvironmentProperties"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            dynatraceEnvironmentProperties = DynatraceEnvironmentProperties.DeserializeDynatraceEnvironmentProperties(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("userInfo"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            userInfo = UserInfo.DeserializeUserInfo(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("planData"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            planData = PlanData.DeserializePlanData(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("liftrResourceCategory"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            liftrResourceCategory = new LiftrResourceCategories(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("liftrResourcePreference"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            liftrResourcePreference = property0.Value.GetInt32();
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new ProvisioningState(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new MonitorResourceData(id, name, type, systemData, tags, location, identity.Value, Optional.ToNullable(monitoringStatus), Optional.ToNullable(marketplaceSubscriptionStatus), dynatraceEnvironmentProperties.Value, userInfo.Value, planData.Value, Optional.ToNullable(liftrResourceCategory), Optional.ToNullable(liftrResourcePreference), Optional.ToNullable(provisioningState)));
        }
Exemple #16
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="MonitoringStatus" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => MonitoringStatus.CreateFrom(sourceValue);
        // Public method for sending changes to the monitoring status
        public async Task <Scrobble> SendMonitoringStatusChanged(MediaItem mediaItem, MonitoringStatus newMonitoringStatus)
        {
            string updateMethod = string.Empty;

            // Create an empty list of parameters
            var baseParameters = new Dictionary <string, string>();

            PlayStatusResponse response = null;

            // If monitoring has started
            if (newMonitoringStatus == MonitoringStatus.StartedMonitoring)
            {
                // Use the updateNowPlaying API method
                updateMethod = "track.updateNowPlaying";

                // Add details of the track to the parameter list
                baseParameters.Add("track", mediaItem.TrackName);
                baseParameters.Add("artist", mediaItem.ArtistName);

                if (!string.IsNullOrEmpty(mediaItem.AlbumName))
                {
                    baseParameters.Add("album", mediaItem.AlbumName);
                }

                if (mediaItem.TrackLength > 0)
                {
                    baseParameters.Add("duration", mediaItem.TrackLength.ToString());
                }
            }
            // Or the monitoring status is stopped
            else if (newMonitoringStatus == MonitoringStatus.StoppedMonitoring)
            {
                // Use the removeNowPlaying API method
                updateMethod = "track.removeNowPlaying";
            }

            // If a method has been specified (ie. someone hasn't tried to send a monitoring state > 1
            if (!string.IsNullOrEmpty(updateMethod))
            {
                // Add the required parameters (including the session token etc)
                AddRequiredRequestParams(baseParameters, updateMethod, _sessionToken.Key);

                // Convert the paremeters into body content
                FormUrlEncodedContent postContent = new FormUrlEncodedContent(baseParameters);

                // Send the request and get the response
                response = await Post <PlayStatusResponse>(updateMethod, postContent, baseParameters.ToArray()).ConfigureAwait(false);

#if DebugAPICalls
                Console.WriteLine($"Sent Playing Status request ({updateMethod}), response:\r\n {response}");
#endif
            }

            return(response?.NowPlaying);
        }