Пример #1
0
        private static Uri GetModelServiceUri(string uri)
        {
            if (string.IsNullOrEmpty(uri))
            {
                IDiscoveryService        discoveryService = DiscoveryServiceProvider.Instance.ServiceClient;
                ContentServiceCapability contentService   =
                    discoveryService.CreateQuery <ContentServiceCapability>().Take(1).FirstOrDefault();
                if (contentService == null)
                {
                    throw new ModelServiceException("Content Service Capability not found in Discovery Service.");
                }
                ContentKeyValuePair modelServiceExtensionProperty = contentService.ExtensionProperties
                                                                    .FirstOrDefault(
                    xp => xp.Key.Equals(ModelServiceExtensionPropertyName, StringComparison.OrdinalIgnoreCase));
                if (modelServiceExtensionProperty == null)
                {
                    throw new ModelServiceException(
                              $"{ModelServiceName} is not registered; no extension property called '{ModelServiceExtensionPropertyName}' found on Content Service Capability.");
                }
                uri = modelServiceExtensionProperty.Value ?? string.Empty;
            }
            uri = uri.TrimEnd('/') + '/';
            Uri baseUri;

            if (!Uri.TryCreate(uri, UriKind.Absolute, out baseUri))
            {
                throw new ModelServiceException($"{ModelServiceName} is using an invalid uri '{uri}'.");
            }
            Logger.Debug($"{ModelServiceName} found at URL '{baseUri}'.");
            return(baseUri);
        }
Пример #2
0
        public async Task RefreshTransactions()
        {
            RefreshingTransactions = true;

            var context = await _agentContextProvider.GetContextAsync();

            var message = _discoveryService.CreateQuery(context, "*");

            DiscoveryDiscloseMessage protocols = null;

            try
            {
                var response = await SendMessage(context.Wallet, message);

                protocols = response.GetMessage <DiscoveryDiscloseMessage>();
            }
            catch (Exception)
            {
                //Swallow exception
                //TODO more granular error protection
            }

            IList <TransactionItem> transactions = new List <TransactionItem>();

            Transactions.Clear();

            if (protocols == null)
            {
                HasTransactions        = false;
                RefreshingTransactions = false;
                return;
            }

            foreach (var protocol in protocols.Protocols)
            {
                switch (protocol.ProtocolId)
                {
                case MessageTypes.TrustPingMessageType:
                    transactions.Add(new TransactionItem()
                    {
                        Title                = "Trust Ping",
                        Subtitle             = "Version 1.0",
                        PrimaryActionTitle   = "Ping",
                        PrimaryActionCommand = new Command(async() =>
                        {
                            await PingConnectionAsync();
                        }, () => true),
                        Type = TransactionItemType.Action.ToString("G")
                    });
                    break;
                }
            }

            Transactions.InsertRange(transactions);
            HasTransactions = transactions.Any();

            RefreshingTransactions = false;
        }
Пример #3
0
        private static Uri GetModelServiceUri()
        {
            IDiscoveryService        discoveryService = DiscoveryServiceProvider.Instance.ServiceClient;
            ContentServiceCapability contentService   = discoveryService.CreateQuery <ContentServiceCapability>().Take(1).FirstOrDefault();

            if (contentService == null)
            {
                throw new DxaException("Content Service Capability not found in Discovery Service.");
            }
            ContentKeyValuePair modelServiceExtensionProperty = contentService.ExtensionProperties
                                                                .FirstOrDefault(xp => xp.Key.Equals(ModelServiceExtensionPropertyName, StringComparison.OrdinalIgnoreCase));

            if (modelServiceExtensionProperty == null)
            {
                throw new DxaException($"{ModelServiceName} is not registered; no extension property called '{ModelServiceExtensionPropertyName}' found on Content Service Capability.");
            }
            return(new Uri(modelServiceExtensionProperty.Value));
        }
Пример #4
0
 public void CreateDiscoveryQueryThrowsArguementNullException()
 {
     Assert.Throws <ArgumentNullException>(() => _discoveryService.CreateQuery(_holderContext, null));
     Assert.Throws <ArgumentNullException>(() => _discoveryService.CreateQuery(_holderContext, ""));
 }
        public async Task RefreshTransactions()
        {
            RefreshingTransactions = true;

            _agentContext = await _agentContextProvider.GetContextAsync();

            var message = _discoveryService.CreateQuery(_agentContext, "*");
            DiscoveryDiscloseMessage protocols = null;

            if (!CrossConnectivity.Current.IsConnected)
            {
                UserDialogs.Instance.Toast("Looks like you're missing internet connection!", new TimeSpan(3));
                HasTransactions        = false;
                RefreshingTransactions = false;
                return;
            }

            try
            {
                var response = await _messageService.SendReceiveAsync(_agentContext, message, _record) as UnpackedMessageContext;

                protocols = response.GetMessage <DiscoveryDiscloseMessage>();
            }
            catch (Exception e)
            {
                //Swallow exception
                //TODO more granular error protection
                Console.Error.WriteLine(e);
            }

            IList <TransactionItem> transactions = new List <TransactionItem>();

            Transactions.Clear();

            if (protocols == null)
            {
                HasTransactions        = false;
                RefreshingTransactions = false;
                return;
            }

            foreach (var protocol in protocols.Protocols)
            {
                if (MessageTypes.TrustPingMessageType.Contains(protocol.ProtocolId))
                {
                    transactions.Add(new TransactionItem()
                    {
                        Title                = "Trust Ping",
                        Subtitle             = "Version 1.0",
                        PrimaryActionTitle   = "Ping",
                        PrimaryActionCommand = new Command(async() =>
                        {
                            await PingConnectionAsync();
                        }, () => true),
                        Type = TransactionItemType.Action.ToString("G")
                    });
                }

                //switch (protocol.ProtocolId)
                //{
                //    case MessageTypes.TrustPingMessageType:
                //        transactions.Add(new TransactionItem()
                //        {
                //            Title = "Trust Ping",
                //            Subtitle = "Version 1.0",
                //            PrimaryActionTitle = "Ping",
                //            PrimaryActionCommand = new Command(async () =>
                //            {
                //                await PingConnectionAsync();
                //            }, () => true),
                //            Type = TransactionItemType.Action.ToString("G")
                //        });
                //        break;
                //}
            }

            Transactions.InsertRange(transactions);
            HasTransactions = transactions.Any();

            RefreshingTransactions = false;
        }