Ejemplo n.º 1
0
        private static void ThreadMessage(this AgentMessage messageToThread, AgentMessage messageToThreadFrom)
        {
            ThreadDecorator previousMessageThreadContext = null;

            try
            {
                previousMessageThreadContext = messageToThreadFrom.GetDecorator <ThreadDecorator>(DecoratorIdentifier);
            }
            catch (AriesFrameworkException) { }

            ThreadDecorator currentThreadContext;

            if (previousMessageThreadContext != null)
            {
                currentThreadContext = new ThreadDecorator
                {
                    ParentThreadId = previousMessageThreadContext.ParentThreadId,
                    ThreadId       = previousMessageThreadContext.ThreadId
                };
            }
            else
            {
                currentThreadContext = new ThreadDecorator
                {
                    ThreadId = messageToThreadFrom.Id
                };
            }


            messageToThread.AddDecorator(currentThreadContext, DecoratorIdentifier);
        }
Ejemplo n.º 2
0
        private async Task ScanInvite()
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;

            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List <ZXing.BarcodeFormat> {
                    expectedFormat
                }
            };

            var context = await _agentContextProvider.GetContextAsync();

            var scanner = new ZXing.Mobile.MobileBarcodeScanner();

            var result = await scanner.Scan(opts);

            if (result == null)
            {
                return;
            }

            AgentMessage message = await MessageDecoder.ParseMessageAsync(result.Text);

            switch (message)
            {
            case ConnectionInvitationMessage invitation:
                break;

            case RequestPresentationMessage presentation:
                RequestPresentationMessage proofRequest = (RequestPresentationMessage)presentation;
                var         service     = message.GetDecorator <ServiceDecorator>(DecoratorNames.ServiceDecorator);
                ProofRecord proofRecord = await _proofService.ProcessRequestAsync(context, proofRequest, null);

                proofRecord.SetTag("RecipientKey", service.RecipientKeys.ToList()[0]);
                proofRecord.SetTag("ServiceEndpoint", service.ServiceEndpoint);
                await _recordService.UpdateAsync(context.Wallet, proofRecord);

                _eventAggregator.Publish(new ApplicationEvent {
                    Type = ApplicationEventType.ProofRequestUpdated
                });
                break;

            default:
                DialogService.Alert("Invalid invitation!");
                return;
            }

            Device.BeginInvokeOnMainThread(async() =>
            {
                if (message is ConnectionInvitationMessage)
                {
                    await NavigationService.NavigateToAsync <AcceptInviteViewModel>(message as ConnectionInvitationMessage, NavigationType.Modal);
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Threads the current message from a previous message.
        /// </summary>
        /// <param name="message">The message to add threading to.</param>
        /// <param name="previousMessage">The message to thread from.</param>
        public static void ThreadFrom(this AgentMessage message, AgentMessage previousMessage)
        {
            bool hasThreadBlock = false;

            try
            {
                message.GetDecorator <ThreadDecorator>(DecoratorIdentifier);
                hasThreadBlock = true;
            }
            catch (AriesFrameworkException) { }

            if (hasThreadBlock)
            {
                throw new AriesFrameworkException(ErrorCode.InvalidMessage, "Cannot thread message when it already has a valid thread decorator");
            }

            message.ThreadMessage(previousMessage);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the current messages thread id.
        /// </summary>
        /// <param name="message">Message to extract the thread id from.</param>
        /// <returns>Thread id of the message.</returns>
        public static string GetThreadId(this AgentMessage message)
        {
            string threadId = null;

            try
            {
                var threadBlock = message.GetDecorator <ThreadDecorator>(DecoratorIdentifier);
                threadId = threadBlock.ThreadId;
            }
            catch (Exception)
            {
                // ignored
            }

            if (string.IsNullOrEmpty(threadId))
            {
                threadId = message.Id;
            }

            return(threadId);
        }