Exemplo n.º 1
0
        private void _notificationTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var visService  = new VisService();
            var spisService = new SpisService();
            List <Notification> notifications = new List <Notification>();

            var visNotifications = visService.GetNotifications();

            if (visNotifications != null)
            {
                notifications.AddRange(visNotifications);
            }

            var spisNotifications = spisService.GetNotifications();

            if (spisNotifications != null)
            {
                notifications.AddRange(spisNotifications);
            }

            if (notifications != null)
            {
                foreach (var notification in notifications)
                {
                    Instance_NewNotification(sender, notification);
                }
            }
        }
Exemplo n.º 2
0
        public async void ExecuteFindServicesCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Searching Service Registry";
            await Task.Factory.StartNew(() =>
            {
                var visService = new VisService();

                try
                {
                    List <string> ServiceProviderIdsList = null;
                    if (!string.IsNullOrEmpty(ServiceProviderIds))
                    {
                        string[] s             = ServiceProviderIds.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        ServiceProviderIdsList = s.ToList();
                    }

                    List <string> KeywordsList = null;
                    if (!string.IsNullOrEmpty(Keywords))
                    {
                        string[] s   = Keywords.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        KeywordsList = s.ToList();
                    }

                    Services = visService.FindServices("WKT", Area, UnloCode, ServiceProviderIdsList, ServiceDesignId, ServiceInstanceId,
                                                       Mmsi, Imo, ServiceType, ServiceStatus, KeywordsList, FreeText, 0, 1000);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            });

            Busy = false;
        }
        public async void LoadAcl(string id)
        {
            Busy        = true;
            BusyContent = "Loading ACL";
            Id          = id;

            List <Organization> orgs             = new List <Organization>();
            List <IdentityDescriptionObject> acl = new List <IdentityDescriptionObject>();

            AllIdentities = new ObservableCollection <Organization>();
            AclList       = new ObservableCollection <IdentityDescriptionObject>();

            await Task.Factory.StartNew(() =>
            {
                var visService = new VisService();
                acl            = visService.GetAcl(Id);
                orgs           = visService.FindIdentties();
            });

            foreach (var i in acl)
            {
                AclList.Add(i);
            }

            foreach (var org in orgs)
            {
                if (acl.FirstOrDefault(x => x.IdentityId == org.Mrn) == null)
                {
                    AllIdentities.Add(org);
                }
            }

            Busy = false;
        }
        public async void ExecuteAddAclCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Adding ACL";

            try
            {
                var identity = new IdentityDescriptionObject(SelectedIdentity.Mrn, SelectedIdentity.Name);

                await Task.Factory.StartNew(() =>
                {
                    var visService = new VisService();
                    visService.AuthorizeIdentities(Id, new List <IdentityDescriptionObject>
                    {
                        identity
                    });
                });

                AclList.Add(identity);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Busy = false;
            }
        }
        public async void ExecuteDeleteAclCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Deleting ACL";

            try
            {
                await Task.Factory.StartNew(() =>
                {
                    var visService = new VisService();
                    visService.RemoveAuthorization(Id, new List <IdentityDescriptionObject>
                    {
                        SelectedAcl
                    });
                });

                AclList.Remove(SelectedAcl);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Busy = false;
            }
        }
        public async void LoadSubscriptions(string id)
        {
            Busy        = true;
            BusyContent = "Loading subscriptions";
            Id          = id;

            List <VisSubscriptionObject>     subscriptions = new List <VisSubscriptionObject>();
            List <IdentityDescriptionObject> acl           = new List <IdentityDescriptionObject>();

            SubscriptionList = new ObservableCollection <VisSubscriptionObject>();
            AclList          = new ObservableCollection <IdentityDescriptionObject>();

            await Task.Factory.StartNew(() =>
            {
                var visService = new VisService();
                subscriptions  = visService.GetSubscriptions(Id);
                acl            = visService.GetAcl(Id);
            });


            foreach (var i in acl)
            {
                AclList.Add(i);
            }

            foreach (var i in subscriptions)
            {
                SubscriptionList.Add(i);
            }

            Busy = false;
        }
        public async void ExecuteDeleteSubscriptionCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Deleting subscription";

            try
            {
                await Task.Factory.StartNew(() =>
                {
                    var visService = new VisService();
                    visService.RemoveSubscription(Id, new List <VisSubscriptionObject>
                    {
                        SelectedSubscription
                    });
                });

                SubscriptionList.Remove(SelectedSubscription);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Busy = false;
            }
        }
        public async void ExecuteDeleteMessageCommand(object parameter)
        {
            if (MessageBox.Show("Are you sure that you want to delete message?", "Delete message", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                return;
            }

            Busy        = true;
            BusyContent = "Deleting voyageplan";
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    var visService = new VisService();
                    var result     = visService.DeleteMessage(SelectedMessage.MessageID);
                    MessageBox.Show(result);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    Busy = false;
                }
            });

            ExecuteLoadPublishedMessagesCommand(null);
        }
        public async void ExecuteAddSubscriptionCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Adding subscription";

            try
            {
                var subscription = new VisSubscriptionObject
                {
                    EndpointURL  = new Uri(Url),
                    IdentityId   = SelectedAcl.IdentityId,
                    IdentityName = SelectedAcl.IdentityName
                };

                await Task.Factory.StartNew(() =>
                {
                    var visService = new VisService();
                    visService.AddSubscription(Id, new List <VisSubscriptionObject>
                    {
                        subscription
                    });
                });

                SubscriptionList.Add(subscription);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Busy = false;
            }
        }
        public async void ExecutePublishMessageCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Publishing voyageplan";
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    var visService = new VisService();
                    var result     = visService.PublishMessage(SelectedMessage.MessageID, "RTZ", SelectedMessage.Message);
                    MessageBox.Show(result);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    Busy = false;
                }
            });


            Busy = false;
        }
Exemplo n.º 11
0
        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;
            }
        }
Exemplo n.º 12
0
        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 ExecuteLoadPublishedMessagesCommand(object parameter)
        {
            Busy        = true;
            BusyContent = "Loading published voyageplans from VIS";
            await Task.Factory.StartNew(() =>
            {
                var service = new VisService();
                Messages    = new ObservableCollection <PublishedMessageContract>(service.GetPublishedMessages());
            });

            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;
        }
Exemplo n.º 15
0
        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;
        }
Exemplo n.º 16
0
        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;
        }
        public async void ExecuteGetMessagesCommand(object parameter)
        {
            DateTime?from = null;
            DateTime?to   = null;
            DateTime temp;

            if (!string.IsNullOrEmpty(FromTime))
            {
                if (DateTime.TryParse(FromTime, out temp))
                {
                    from = temp;
                }
                else
                {
                    MessageBox.Show("Invalid from time");
                    return;
                }
            }

            if (!string.IsNullOrEmpty(ToTime))
            {
                if (DateTime.TryParse(ToTime, out temp))
                {
                    to = temp;
                }
                else
                {
                    MessageBox.Show("Invalid to time");
                    return;
                }
            }

            if (from != null)
            {
                Messages = new ObservableCollection <Message>();
            }

            var             visService = new VisService();
            MessageEnvelope result     = null;

            Busy        = true;
            BusyContent = "Loading messages from VIS";
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    result = visService.GetMessages(Id, LimitQuery, from, to);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    Busy = false;
                }
            });

            if (result == null)
            {
                return;
            }

            RemainingMessages = result.RemainingNumberOfMessages ?? 0;

            if (result.Messages != null)
            {
                foreach (var message in result.Messages)
                {
                    if (message != null && message.StmMessage != null && message.StmMessage.Message != null)
                    {
                        message.StmMessage.Message = XmlUtil.FormatXml(message.StmMessage.Message);
                    }

                    Messages.Add(message);
                }

                Messages = new ObservableCollection <Message>(Messages.OrderBy(x => x.ReceivedAt));
            }
        }