private async void ExecuteUploadVPCommand(object obj) { string vpbody = null; bool sendAck = false; string callbackEndpoint = string.Empty; var dlg = new NewSTMMessageDialog(); dlg.ViewModel.ShowAcknowledgement = true; dlg.ViewModel.ShowCallbackEndpoint = true; if (dlg.ShowDialog() == true) { var newMsg = new PublishedMessageContract { Message = dlg.ViewModel.StmMsg, //MessageID = dlg.ViewModel.Id }; sendAck = dlg.ViewModel.Acknowledgement; vpbody = newMsg.Message; callbackEndpoint = Uri.EscapeDataString(dlg.ViewModel.CallbackEndpoint ?? string.Empty); } if (!string.IsNullOrEmpty(vpbody)) { Busy = true; BusyContent = "Uploading voyageplan"; await Task.Factory.StartNew(() => { var visService = new VisService(); if (sendAck) { string myAck = ConfigurationManager.AppSettings.Get("VisPublicUrl").Replace("{database}", VisService.DbName); string endpointUri = SelectedService.EndpointUri; if (!string.IsNullOrEmpty(callbackEndpoint)) { endpointUri = WebRequestHelper.CombineUrl(endpointUri, string.Format("/voyagePlans?callbackEndpoint={0}", Uri.EscapeDataString(callbackEndpoint)) + string.Format("&deliveryAckEndPoint={0}", Uri.EscapeDataString(myAck))); } else { endpointUri = WebRequestHelper.CombineUrl(endpointUri, string.Format("/voyagePlans?deliveryAckEndPoint={0}", Uri.EscapeDataString(myAck ?? string.Empty))); } var result = visService.CallService(vpbody, endpointUri, "POST", "text/xml; charset=utf-8"); MessageBox.Show(result); } else { string endpointUri = WebRequestHelper.CombineUrl(SelectedService.EndpointUri, "/voyagePlans"); if (!string.IsNullOrEmpty(callbackEndpoint)) { endpointUri += string.Format("?callbackEndpoint={0}", Uri.EscapeDataString(callbackEndpoint)); } var result = visService.CallService(vpbody, endpointUri, "POST", "text/xml; charset=utf-8"); MessageBox.Show(result); } }); Busy = false; } }
private async void ExecuteGetVPCommand(object obj) { string endpoint = SelectedService.EndpointUri + "/voyagePlans"; string uvid; string routeStatus; var dlg = new GetVPDialog(); dlg.ShowDialog(); uvid = dlg.ViewModel.Uvid; routeStatus = dlg.ViewModel.RouteStatus; Busy = true; BusyContent = "Get voyageplan"; await Task.Factory.StartNew(() => { try { if (!string.IsNullOrEmpty(uvid) && string.IsNullOrEmpty(routeStatus)) { endpoint += "?uvid=" + Uri.EscapeDataString(uvid ?? string.Empty); } if (string.IsNullOrEmpty(uvid) && !string.IsNullOrEmpty(routeStatus)) { endpoint += "?routeStatus=" + routeStatus; } if (!string.IsNullOrEmpty(uvid) && !string.IsNullOrEmpty(routeStatus)) { endpoint += "?uvid=" + Uri.EscapeDataString(uvid ?? string.Empty); endpoint += "&routeStatus=" + routeStatus; } var visService = new VisService(); var result = visService.CallService(null, endpoint, "GET", "application/json; charset=utf-8"); if (!string.IsNullOrEmpty(result)) { var msg = new Message(); msg.FromServiceId = SelectedService.InstanceId; msg.MessageType = "RTZ"; msg.ReceivedAt = DateTime.UtcNow; msg.Id = "123"; msg.StmMessage = new StmMessage(result); ResultMessage = msg; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); Busy = false; }
public async void ExecuteCallServiceCommand(object parameter) { Busy = true; BusyContent = "Executing call service"; await Task.Factory.StartNew(() => { var visService = new VisService(); Response = visService.CallService(PostData, Url, RequestType, ContentType); }); Busy = false; }
private async void ExecuteDeleteSubscriberCommand(object obj) { string endpoint = SelectedService.EndpointUri + "/voyagePlans/subscription"; string uvid; string callbackEndpoint; //Dialog to get uvid parameter var dlg = new DeleteSubscriptionDialog(); dlg.ShowDialog(); uvid = dlg.ViewModel.Uvid; callbackEndpoint = dlg.ViewModel.CallbackEndpoint; Busy = true; BusyContent = "Delete subscription"; await Task.Factory.StartNew(() => { try { var visService = new VisService(); if (!string.IsNullOrEmpty(uvid) && !string.IsNullOrEmpty(callbackEndpoint)) { var endpAddress = string.Format(endpoint + "?uvid={0}&callbackEndpoint={1}", Uri.EscapeDataString(uvid ?? string.Empty), callbackEndpoint); var result = visService.CallService(null, endpAddress, "DELETE", "application/json; charset=utf-8"); MessageBox.Show(result); } else { MessageBox.Show("Mandatory parameters uvid and callbackEndpoint are missing or empty!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); Busy = false; }
private async void ExecuteSubscribeCommand(object obj) { //http://localhost/STM.VIS.Services.Public/VIS/V2/voyagePlans/subscription?callbackEndpoint=hello.com string endpoint = SelectedService.EndpointUri + "/voyagePlans/subscription?callbackEndpoint="; endpoint += ConfigurationManager.AppSettings["VisPublicUrl"].Replace("{database}", VisService.DbName); string uvid; //Dialog to get uvid parameter var dlg = new SubscriptionDialog(); dlg.ShowDialog(); uvid = dlg.ViewModel.Uvid; Busy = true; BusyContent = "Post subscription"; await Task.Factory.StartNew(() => { try { var visService = new VisService(); if (!string.IsNullOrEmpty(uvid)) { endpoint += "&uvid=" + Uri.EscapeDataString(uvid ?? string.Empty); } var result = visService.CallService(null, endpoint, "POST", "application/json; charset=utf-8"); MessageBox.Show(result); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }); Busy = false; }