using EVCB_OCPP.Domain; using EVCB_OCPP.Domain.Models.Database; using EVCB_OCPP.Packet.Features; using EVCB_OCPP.Packet.Messages; using EVCB_OCPP.Packet.Messages.Core; using Newtonsoft.Json; using OCPPPackage.Profiles; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace TestTool.RemoteTriggerAPP { /// /// MainWindow.xaml 的互動邏輯 /// public partial class MainWindow : Window { string action = ""; public MainWindow() { InitializeComponent(); } private void UxSubmitBtn_Click(object sender, RoutedEventArgs e) { switch (action) { case "ChangeAvailability_Inoperative": { SetChangeAvailability_Inoperative(); } break; case "ChangeAvailability_Operative": { SetChangeAvailability_Operative(); } break; case "ChangeConfiguration_MeterValueSampleInterval": { SetChangeConfiguration_MeterValueSampleInterval(); } break; case "ClearCache": { SetClearCache(); } break; case "RemoteStartTransaction": { SetRemoteStartTransaction(); } break; case "RemoteStopTransaction": { SetRemoteStopTransaction(); } break; case "HardReset": { SetHardReset(); } break; case "SoftReset": { SetSoftReset(); } break; case "UnlockConnector": { SetUnlockConnector(); } break; case "GetConfiguration_ALL": { SetGetConfiguration_ALL(); } break; case "GetConfiguration_SupportedFeatureProfiles": { SetGetConfiguration_SupportedFeatureProfiles(); } break; case "GetConfiguration_GetConfigurationMaxKeys": { SetGetConfiguration_GetConfigurationMaxKeys(); } break; case "GetConfiguration_MeterValueSampleInterval": { SetGetConfiguration_MeterValueSampleInterval(); } break; default: { } break; } } private void UxCmdCb_SelectionChanged(object sender, SelectionChangedEventArgs e) { var item = uxCmdCb.SelectedValue as ComboBoxItem; action = item.Content as string; } private void SetRemoteStartTransaction() { try { var uuid = Guid.NewGuid().ToString(); var request = new RemoteStartTransactionRequest() { connectorId = byte.Parse(uxConnectorIdTb.Text), idTag = uxIdTagTb.Text }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetUnlockConnector() { try { var uuid = Guid.NewGuid().ToString(); var request = new UnlockConnectorRequest() { connectorId = byte.Parse(uxConnectorIdTb.Text), }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetChangeAvailability_Inoperative() { try { var uuid = Guid.NewGuid().ToString(); var request = new ChangeAvailabilityRequest() { connectorId = byte.Parse(uxConnectorIdTb.Text), type = EVCB_OCPP.Packet.Messages.SubTypes.AvailabilityType.Inoperative }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetChangeAvailability_Operative() { try { var uuid = Guid.NewGuid().ToString(); var request = new ChangeAvailabilityRequest() { connectorId = byte.Parse(uxConnectorIdTb.Text), type = EVCB_OCPP.Packet.Messages.SubTypes.AvailabilityType.Operative }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetChangeConfiguration_UnSupport() { try { var uuid = Guid.NewGuid().ToString(); var request = new ChangeConfigurationRequest() { key = StandardConfiguration.MeterValueSampleInterval, value = "true", }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetChangeConfiguration_MeterValueSampleInterval() { try { var uuid = Guid.NewGuid().ToString(); var request = new ChangeConfigurationRequest() { key = StandardConfiguration.MeterValueSampleInterval, value = "true", }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetClearCache() { try { var uuid = Guid.NewGuid().ToString(); var request = new ClearCacheRequest() { }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetGetConfiguration_ALL() { try { var uuid = Guid.NewGuid().ToString(); var request = new GetConfigurationRequest() { key = new List() { } }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetGetConfiguration_MeterValueSampleInterval() { try { var uuid = Guid.NewGuid().ToString(); var request = new GetConfigurationRequest() { key = new List() { StandardConfiguration.MeterValueSampleInterval } }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetGetConfiguration_SupportedFeatureProfiles() { try { var uuid = Guid.NewGuid().ToString(); var request = new GetConfigurationRequest() { key = new List() { StandardConfiguration.SupportedFeatureProfiles } }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetGetConfiguration_GetConfigurationMaxKeys() { try { var uuid = Guid.NewGuid().ToString(); var request = new GetConfigurationRequest() { key = new List() { StandardConfiguration.GetConfigurationMaxKeys } }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetHardReset() { try { var uuid = Guid.NewGuid().ToString(); var request = new ResetRequest() { type = EVCB_OCPP.Packet.Messages.SubTypes.ResetType.Hard }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetSoftReset() { try { var uuid = Guid.NewGuid().ToString(); var request = new ResetRequest() { type = EVCB_OCPP.Packet.Messages.SubTypes.ResetType.Soft }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void SetRemoteStopTransaction() { try { var uuid = Guid.NewGuid().ToString(); var request = new RemoteStopTransactionRequest() { transactionId = int.Parse(uxTransactionIdTb.Text) }; WritetoDB(uuid, request); uxMsgTb.Text = string.Format("UUID:{0}", uuid); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void WritetoDB(string uuid, IRequest request) { using (var db = new MainDBContext()) { db.MachineOperateRecord.Add(new MachineOperateRecord() { CreatedOn = DateTime.Now, ChargeBoxId = uxChargeBoxIdTb.Text, SerialNo = uuid, RequestContent = JsonConvert.SerializeObject(request, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }), EVSE_Status = 0, Status = 0, RequestType = 1, }); db.ServerMessage.Add(new ServerMessage() { ChargeBoxId = uxChargeBoxIdTb.Text, CreatedBy = "TestTool", CreatedOn = DateTime.Now, OutAction = request.Action.ToString(), OutRequest = JsonConvert.SerializeObject(request, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }), SerialNo = uuid, InMessage = string.Empty }); db.SaveChanges(); } } } }