protected void AreEqual(PowerAction mp, PowerAction ddi, string name) { if (mp == null) { Assert.IsNull(ddi, "Action not null " + name); return; } Assert.IsNotNull(ddi, "Missing action for " + name); Assert.AreEqual(mp.Action, ddi.Action, "Invalid action Type for " + name); Assert.AreEqual(mp.Recharge, ddi.Recharge); Assert.AreEqual(mp.SustainAction, ddi.SustainAction); Assert.AreEqual(mp.Trigger, ddi.Trigger); Assert.AreEqual(mp.Use, ddi.Use, "Invalid use for action " + name); Assert.AreEqual(mp.ToString(), ddi.ToString()); }
protected void AreEqual(PowerAction mp, PowerAction ddi, string name) { if (mp == null) { Assert.IsNull(ddi, "Action not null " + name); return; } Assert.IsNotNull(ddi, "Missing action for " + name); Assert.AreEqual(mp.Action, ddi.Action, "Invalid action Type for " + name); Assert.AreEqual(mp.Recharge, ddi.Recharge); Assert.AreEqual(mp.SustainAction, ddi.SustainAction); Assert.AreEqual(mp.Trigger, ddi.Trigger); Assert.AreEqual(mp.Use, ddi.Use,"Invalid use for action " + name); Assert.AreEqual(mp.ToString(), ddi.ToString()); }
public async Task <AssetPowerStateDto> UpdatePowerStateAsync(Guid assetId, PowerAction state) { var asset = await _assetService.GetAssetAsync(assetId); if (asset.Model.MountType == "blade") { return(await SetBladePowerStatus(asset, state)); } var pduPorts = asset.PowerPorts .Where(o => o.PduPort != null) .GroupBy(o => o.PduPort.Pdu.ToString()) .ToDictionary(d => d.Key, d => d.Select(o => o.PduPort.Number) .ToList()); var powerStates = new List <AssetPowerPortStateDto>(); foreach (var kvp in pduPorts) { // data is pdu: (hpdu-rtp1-A01L) (rack address + pdunumber + (LorR) // port: number // v: on, off foreach (var port in kvp.Value) { var requestData = new Dictionary <String, String> { { "pdu", kvp.Key }, { "port", port.ToString() }, { "v", state.ToString().ToLower() } }; if (state.ToString().ToLower().Equals("cycle")) { requestData.Remove("v"); requestData.Add("v", "off"); var d = new FormUrlEncodedContent(requestData); var r = await Client.PostAsync("/power.php", d); await Task.Delay(2000); // Two seconds after sending the power off signal, send power on requestData.Remove("v"); requestData.Add("v", "on"); } var data = new FormUrlEncodedContent(requestData); var response = await Client.PostAsync("/power.php", data); Console.WriteLine(response); // Translate the action that was taken on the asset into a current power state var powerState = PowerState.Off; if (state == PowerAction.On || state == PowerAction.Cycle) { powerState = PowerState.On; } var powerPortState = new AssetPowerPortStateDto() { Port = kvp.Key.ToString(), Status = powerState }; powerStates.Add(powerPortState); } } var ret = new AssetPowerStateDto() { Id = assetId, PowerPorts = powerStates }; //GetChassisPower(); return(ret); }