Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中的非异步构造函数中调用异步函数,从而触发其他页面上的异步函数#_C#_Asp.net_.net_Xamarin_.net Core - Fatal编程技术网

C# 在C中的非异步构造函数中调用异步函数,从而触发其他页面上的异步函数#

C# 在C中的非异步构造函数中调用异步函数,从而触发其他页面上的异步函数#,c#,asp.net,.net,xamarin,.net-core,C#,Asp.net,.net,Xamarin,.net Core,在我的应用程序中,有一个异步函数ProcessOffer()。当我在构造函数中将其称为ProcessOffer时,它可以同步工作。我想在构造函数中异步调用这个函数 ProcessOffer()是在CredentialViewModel中实现的一个函数,但我希望,它应该在应用程序的任何地方异步触发(IndexViewModele.t.c) 如果我在扩展页面上,并且Web应用程序向移动应用程序发送请求,则应触发ProcessOffer()。。实际上,ProcessOffer所做的是,它要求用户输入P

在我的应用程序中,有一个异步函数
ProcessOffer()
。当我在构造函数中将其称为
ProcessOffer
时,它可以同步工作。我想在构造函数中异步调用这个函数

ProcessOffer()
是在
CredentialViewModel
中实现的一个函数,但我希望,它应该在应用程序的任何地方异步触发(
IndexViewModel
e.t.c)

如果我在
扩展页面上,并且Web应用程序向移动应用程序发送请求,则应触发
ProcessOffer()
。。实际上,
ProcessOffer
所做的是,它要求用户输入PIN,如果正确,它会将响应发送回Web应用程序

我尝试了其他帖子的答案,但他们返回了错误
Autofac.Core.DependencyResolutionException:“当我从Web应用程序向移动应用程序发送请求时,激活App.Name时引发了异常。”

我尝试过的解决方案

1-

2-
Task.Run(()=>ProcessOffer()).Wait()

3-
ProcessOffer().GetAwatier().GetResult()

CredentialViewModel.cs

namespace Osma.Mobile.App.ViewModels.Credentials
{
    public class CredentialViewModel : ABaseViewModel
    {
        private readonly CredentialRecord _credential;
        private readonly ICredentialService _credentialService;
        private readonly IAgentProvider _agentContextProvider;
        private readonly IConnectionService _connectionService;
        private readonly IMessageService _messageService;
        private readonly IPoolConfigurator _poolConfigurator;

        [Obsolete]
        public CredentialViewModel(
            IUserDialogs userDialogs,
            INavigationService navigationService,
            ICredentialService credentialService,
            IAgentProvider agentContextProvider,
            IConnectionService connectionService,
            IMessageService messageService,
            IPoolConfigurator poolConfigurator,
            CredentialRecord credential
        ) : base(
            nameof(CredentialViewModel),
            userDialogs,
            navigationService
        )
        {
            _credential = credential;
            _credentialService = credentialService;
            _agentContextProvider = agentContextProvider;
            _connectionService = connectionService;
            _messageService = messageService;
            _poolConfigurator = poolConfigurator;

            _credentialState = _credential.State.ToString();

            if (_credentialState == "Offered")
            {
                ProcessOffer();
            }
        }

        [Obsolete]
        public async Task ProcessOffer()
        {

            foreach (var item in _credential.CredentialAttributesValues)
            {
                await SecureStorage.SetAsync(item.Name.ToString(), item.Value.ToString());
            }

            var RegisteredPIN = await SecureStorage.GetAsync("RegisteredPIN");
            string PIN = await App.Current.MainPage.DisplayPromptAsync("Enter PIN", null, "Ok", "Cancel", null, 6, Keyboard.Numeric);
            if (PIN == RegisteredPIN)
            {
                try
                {
                    //await _poolConfigurator.ConfigurePoolsAsync();
                    var agentContext = await _agentContextProvider.GetContextAsync();
                    var credentialRecord = await _credentialService.GetAsync(agentContext, _credential.Id);
                    var connectionId = credentialRecord.ConnectionId;
                    var connectionRecord = await _connectionService.GetAsync(agentContext, connectionId);
                    (var request, _) = await _credentialService.CreateRequestAsync(agentContext, _credential.Id);
                    await _messageService.SendAsync(agentContext.Wallet, request, connectionRecord);
                    await DialogService.AlertAsync("Request has been sent to the issuer.", "Success", "Ok");
                }
                catch (Exception e)
                {
                    await DialogService.AlertAsync(e.Message, "Error", "Ok");
                }
            }
            else if (PIN != RegisteredPIN && PIN != null)
            {
                DialogService.Alert("Provided PIN is not correct");
            }
        }

        #region Bindable Command
        [Obsolete]
        public ICommand ProcessOfferCommand => new Command(async () => await ProcessOffer());

        public ICommand NavigateBackCommand => new Command(async () =>
        {
            await NavigationService.PopModalAsync();
        });
        #endregion

        #region Bindable Properties
        private string _credentialState;
        public string CredentialState
        {
            get => _credentialState;
            set => this.RaiseAndSetIfChanged(ref _credentialState, value);
        }
        #endregion
    }
}
namespace Osma.Mobile.App.ViewModels.Index
{
    public class IndexViewModel : ABaseViewModel
    {
        private readonly IConnectionService _connectionService;
        private readonly IMessageService _messageService;
        private readonly IAgentProvider _agentContextProvider;
        private readonly IEventAggregator _eventAggregator;
        private readonly ILifetimeScope _scope;

        public IndexViewModel(
            IUserDialogs userDialogs,
            INavigationService navigationService,
            IConnectionService connectionService,
            IMessageService messageService,
            IAgentProvider agentContextProvider,
            IEventAggregator eventAggregator,
            ILifetimeScope scope
            ) : base(
                "Index",
                userDialogs,
                navigationService
           )
        {
            _connectionService = connectionService;
            _messageService = messageService;
            _agentContextProvider = agentContextProvider;
            _eventAggregator = eventAggregator;
            _scope = scope;
        }

        public override async Task InitializeAsync(object navigationData)
        {
            await base.InitializeAsync(navigationData);
        }

        public class Post
        {
            public string Success { get; set; }
            public string firstname { get; set; }
        }

        [Obsolete]
        public async Task ScanVerification(object sender, EventArgs e)
        {
            // Code
        }

        public async Task SettingsPage(SettingsViewModel settings) => await NavigationService.NavigateToAsync(settings, null, NavigationType.Modal);

        #region Bindable Command
        public ICommand SettingsPageCommand => new Command<SettingsViewModel>(async (settings) =>
        {
                await SettingsPage(settings);
        });

        [Obsolete]
        public ICommand ScanVerificationCommand => new Command(async () => await ScanVerification(default, default));
        #endregion
    }
}
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Osma.Mobile.App
{
    public partial class App : Application
    {
        public new static App Current => Application.Current as App;
        public static IContainer Container { get; set; }

        // Timer to check new messages in the configured mediator agent every 10sec
        private readonly Timer timer;
        private static IHost Host { get; set; }

        public App()
        {
            InitializeComponent();

            timer = new Timer
            {
                Enabled = false,
                AutoReset = true,
                Interval = TimeSpan.FromSeconds(10).TotalMilliseconds
            };
            timer.Elapsed += Timer_Elapsed;
        }

        public App(IHost host) : this() => Host = host;

        public static IHostBuilder BuildHost(Assembly platformSpecific = null) =>
            XamarinHost.CreateDefaultBuilder<App>()
                .ConfigureServices((_, services) =>
                {
                    services.AddAriesFramework(builder => builder.RegisterEdgeAgent(
                        options: options =>
                        {
                            options.AgentName = "Mobile Holder";
                            options.EndpointUri = "http://11.222.333.44:5000";

                            options.WalletConfiguration.StorageConfiguration =
                                new WalletConfiguration.WalletStorageConfiguration
                                {
                                    Path = Path.Combine(
                                        path1: FileSystem.AppDataDirectory,
                                        path2: ".indy_client",
                                        path3: "wallets")
                                };
                            options.WalletConfiguration.Id = "MobileWallet";
                            options.WalletCredentials.Key = "SecretWalletKey";
                            options.RevocationRegistryDirectory = Path.Combine(
                                path1: FileSystem.AppDataDirectory,
                                path2: ".indy_client",
                                path3: "tails");

                            // Available network configurations (see PoolConfigurator.cs):
                            options.PoolName = "sovrin-test";
                        },
                        delayProvisioning: true));

                    services.AddSingleton<IPoolConfigurator, PoolConfigurator>();

                    var containerBuilder = new ContainerBuilder();
                    containerBuilder.RegisterAssemblyModules(typeof(CoreModule).Assembly);
                    if (platformSpecific != null)
                    {
                        containerBuilder.RegisterAssemblyModules(platformSpecific);
                    }

                    containerBuilder.Populate(services);
                    Container = containerBuilder.Build();
                });

        protected override async void OnStart()
        {
            await Host.StartAsync();

            // View models and pages mappings
            var _navigationService = Container.Resolve<INavigationService>();
            _navigationService.AddPageViewModelBinding<MainViewModel, MainPage>();
            _navigationService.AddPageViewModelBinding<RegisterViewModel, RegisterPage>();
            _navigationService.AddPageViewModelBinding<IndexViewModel, IndexPage>();
            _navigationService.AddPageViewModelBinding<SettingsViewModel, SettingsPage>();
            _navigationService.AddPageViewModelBinding<CredentialsViewModel, CredentialsPage>();
            _navigationService.AddPageViewModelBinding<CredentialViewModel, CredentialPage>();

            if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
            {
                await _navigationService.NavigateToAsync<MainViewModel>();
            }
            else
            {
                await _navigationService.NavigateToAsync<ProviderViewModel>();
            }

            timer.Enabled = true;
        }

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // Check for new messages with the mediator agent if successfully provisioned
            if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
            {
                Device.BeginInvokeOnMainThread(async () =>
                {
                    try
                    {
                        var context = await Container.Resolve<IAgentProvider>().GetContextAsync();
                        await Container.Resolve<IEdgeClientService>().FetchInboxAsync(context);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                });
            }
        }
        protected override void OnSleep() =>
            // Stop timer when application goes to background
            timer.Enabled = false;

        protected override void OnResume() =>
            // Resume timer when application comes in foreground
            timer.Enabled = true;
    }
}
IndexViewModel.cs

namespace Osma.Mobile.App.ViewModels.Credentials
{
    public class CredentialViewModel : ABaseViewModel
    {
        private readonly CredentialRecord _credential;
        private readonly ICredentialService _credentialService;
        private readonly IAgentProvider _agentContextProvider;
        private readonly IConnectionService _connectionService;
        private readonly IMessageService _messageService;
        private readonly IPoolConfigurator _poolConfigurator;

        [Obsolete]
        public CredentialViewModel(
            IUserDialogs userDialogs,
            INavigationService navigationService,
            ICredentialService credentialService,
            IAgentProvider agentContextProvider,
            IConnectionService connectionService,
            IMessageService messageService,
            IPoolConfigurator poolConfigurator,
            CredentialRecord credential
        ) : base(
            nameof(CredentialViewModel),
            userDialogs,
            navigationService
        )
        {
            _credential = credential;
            _credentialService = credentialService;
            _agentContextProvider = agentContextProvider;
            _connectionService = connectionService;
            _messageService = messageService;
            _poolConfigurator = poolConfigurator;

            _credentialState = _credential.State.ToString();

            if (_credentialState == "Offered")
            {
                ProcessOffer();
            }
        }

        [Obsolete]
        public async Task ProcessOffer()
        {

            foreach (var item in _credential.CredentialAttributesValues)
            {
                await SecureStorage.SetAsync(item.Name.ToString(), item.Value.ToString());
            }

            var RegisteredPIN = await SecureStorage.GetAsync("RegisteredPIN");
            string PIN = await App.Current.MainPage.DisplayPromptAsync("Enter PIN", null, "Ok", "Cancel", null, 6, Keyboard.Numeric);
            if (PIN == RegisteredPIN)
            {
                try
                {
                    //await _poolConfigurator.ConfigurePoolsAsync();
                    var agentContext = await _agentContextProvider.GetContextAsync();
                    var credentialRecord = await _credentialService.GetAsync(agentContext, _credential.Id);
                    var connectionId = credentialRecord.ConnectionId;
                    var connectionRecord = await _connectionService.GetAsync(agentContext, connectionId);
                    (var request, _) = await _credentialService.CreateRequestAsync(agentContext, _credential.Id);
                    await _messageService.SendAsync(agentContext.Wallet, request, connectionRecord);
                    await DialogService.AlertAsync("Request has been sent to the issuer.", "Success", "Ok");
                }
                catch (Exception e)
                {
                    await DialogService.AlertAsync(e.Message, "Error", "Ok");
                }
            }
            else if (PIN != RegisteredPIN && PIN != null)
            {
                DialogService.Alert("Provided PIN is not correct");
            }
        }

        #region Bindable Command
        [Obsolete]
        public ICommand ProcessOfferCommand => new Command(async () => await ProcessOffer());

        public ICommand NavigateBackCommand => new Command(async () =>
        {
            await NavigationService.PopModalAsync();
        });
        #endregion

        #region Bindable Properties
        private string _credentialState;
        public string CredentialState
        {
            get => _credentialState;
            set => this.RaiseAndSetIfChanged(ref _credentialState, value);
        }
        #endregion
    }
}
namespace Osma.Mobile.App.ViewModels.Index
{
    public class IndexViewModel : ABaseViewModel
    {
        private readonly IConnectionService _connectionService;
        private readonly IMessageService _messageService;
        private readonly IAgentProvider _agentContextProvider;
        private readonly IEventAggregator _eventAggregator;
        private readonly ILifetimeScope _scope;

        public IndexViewModel(
            IUserDialogs userDialogs,
            INavigationService navigationService,
            IConnectionService connectionService,
            IMessageService messageService,
            IAgentProvider agentContextProvider,
            IEventAggregator eventAggregator,
            ILifetimeScope scope
            ) : base(
                "Index",
                userDialogs,
                navigationService
           )
        {
            _connectionService = connectionService;
            _messageService = messageService;
            _agentContextProvider = agentContextProvider;
            _eventAggregator = eventAggregator;
            _scope = scope;
        }

        public override async Task InitializeAsync(object navigationData)
        {
            await base.InitializeAsync(navigationData);
        }

        public class Post
        {
            public string Success { get; set; }
            public string firstname { get; set; }
        }

        [Obsolete]
        public async Task ScanVerification(object sender, EventArgs e)
        {
            // Code
        }

        public async Task SettingsPage(SettingsViewModel settings) => await NavigationService.NavigateToAsync(settings, null, NavigationType.Modal);

        #region Bindable Command
        public ICommand SettingsPageCommand => new Command<SettingsViewModel>(async (settings) =>
        {
                await SettingsPage(settings);
        });

        [Obsolete]
        public ICommand ScanVerificationCommand => new Command(async () => await ScanVerification(default, default));
        #endregion
    }
}
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Osma.Mobile.App
{
    public partial class App : Application
    {
        public new static App Current => Application.Current as App;
        public static IContainer Container { get; set; }

        // Timer to check new messages in the configured mediator agent every 10sec
        private readonly Timer timer;
        private static IHost Host { get; set; }

        public App()
        {
            InitializeComponent();

            timer = new Timer
            {
                Enabled = false,
                AutoReset = true,
                Interval = TimeSpan.FromSeconds(10).TotalMilliseconds
            };
            timer.Elapsed += Timer_Elapsed;
        }

        public App(IHost host) : this() => Host = host;

        public static IHostBuilder BuildHost(Assembly platformSpecific = null) =>
            XamarinHost.CreateDefaultBuilder<App>()
                .ConfigureServices((_, services) =>
                {
                    services.AddAriesFramework(builder => builder.RegisterEdgeAgent(
                        options: options =>
                        {
                            options.AgentName = "Mobile Holder";
                            options.EndpointUri = "http://11.222.333.44:5000";

                            options.WalletConfiguration.StorageConfiguration =
                                new WalletConfiguration.WalletStorageConfiguration
                                {
                                    Path = Path.Combine(
                                        path1: FileSystem.AppDataDirectory,
                                        path2: ".indy_client",
                                        path3: "wallets")
                                };
                            options.WalletConfiguration.Id = "MobileWallet";
                            options.WalletCredentials.Key = "SecretWalletKey";
                            options.RevocationRegistryDirectory = Path.Combine(
                                path1: FileSystem.AppDataDirectory,
                                path2: ".indy_client",
                                path3: "tails");

                            // Available network configurations (see PoolConfigurator.cs):
                            options.PoolName = "sovrin-test";
                        },
                        delayProvisioning: true));

                    services.AddSingleton<IPoolConfigurator, PoolConfigurator>();

                    var containerBuilder = new ContainerBuilder();
                    containerBuilder.RegisterAssemblyModules(typeof(CoreModule).Assembly);
                    if (platformSpecific != null)
                    {
                        containerBuilder.RegisterAssemblyModules(platformSpecific);
                    }

                    containerBuilder.Populate(services);
                    Container = containerBuilder.Build();
                });

        protected override async void OnStart()
        {
            await Host.StartAsync();

            // View models and pages mappings
            var _navigationService = Container.Resolve<INavigationService>();
            _navigationService.AddPageViewModelBinding<MainViewModel, MainPage>();
            _navigationService.AddPageViewModelBinding<RegisterViewModel, RegisterPage>();
            _navigationService.AddPageViewModelBinding<IndexViewModel, IndexPage>();
            _navigationService.AddPageViewModelBinding<SettingsViewModel, SettingsPage>();
            _navigationService.AddPageViewModelBinding<CredentialsViewModel, CredentialsPage>();
            _navigationService.AddPageViewModelBinding<CredentialViewModel, CredentialPage>();

            if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
            {
                await _navigationService.NavigateToAsync<MainViewModel>();
            }
            else
            {
                await _navigationService.NavigateToAsync<ProviderViewModel>();
            }

            timer.Enabled = true;
        }

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // Check for new messages with the mediator agent if successfully provisioned
            if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
            {
                Device.BeginInvokeOnMainThread(async () =>
                {
                    try
                    {
                        var context = await Container.Resolve<IAgentProvider>().GetContextAsync();
                        await Container.Resolve<IEdgeClientService>().FetchInboxAsync(context);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                });
            }
        }
        protected override void OnSleep() =>
            // Stop timer when application goes to background
            timer.Enabled = false;

        protected override void OnResume() =>
            // Resume timer when application comes in foreground
            timer.Enabled = true;
    }
}
名称空间Osma.Mobile.App.ViewModels.Index
{
公共类索引模型:ABaseViewModel
{
专用只读IConnectionService\u connectionService;
私有只读IMessageService(u messageService);
专用只读IAgentProvider\u代理外部提供商;
私有只读ieventagegrator\u事件聚合器;
私有只读ILifetimeScope\u范围;
公共索引模型(
IUserDialogs用户对话框,
在激活服务导航服务中,
i连接服务连接服务,
IMessageService消息服务,
IAgentProvider代理ContextProvider,
IEventagegrogator事件聚合器,
髂腓肠镜
):基本(
“索引”,
用户对话框,
导航服务
)
{
_connectionService=connectionService;
_messageService=messageService;
_agentContextProvider=agentContextProvider;
_eventAggregator=eventAggregator;
_范围=范围;
}
公共覆盖异步任务InitializeAsync(对象导航数据)
{
wait base.InitializeAsync(导航数据);
}
公营职位
{
公共字符串成功{get;set;}
公共字符串名{get;set;}
}
[过时]
公共异步任务扫描验证(对象发送方、事件参数)
{
//代码
}
公共异步任务SettingsPage(SettingsViewModel设置)=>Wait NavigationService.NavigateAsync(设置,null,NavigationType.Modal);
#区域绑定命令
公共ICommand设置SPAGECommand=>新命令(异步(设置)=>
{
等待设置页面(设置);
});
[过时]
公共ICommand ScanVerificationCommand=>新命令(异步()=>等待扫描验证(默认,默认));
#端区
}
}
App.xml.cs

namespace Osma.Mobile.App.ViewModels.Credentials
{
    public class CredentialViewModel : ABaseViewModel
    {
        private readonly CredentialRecord _credential;
        private readonly ICredentialService _credentialService;
        private readonly IAgentProvider _agentContextProvider;
        private readonly IConnectionService _connectionService;
        private readonly IMessageService _messageService;
        private readonly IPoolConfigurator _poolConfigurator;

        [Obsolete]
        public CredentialViewModel(
            IUserDialogs userDialogs,
            INavigationService navigationService,
            ICredentialService credentialService,
            IAgentProvider agentContextProvider,
            IConnectionService connectionService,
            IMessageService messageService,
            IPoolConfigurator poolConfigurator,
            CredentialRecord credential
        ) : base(
            nameof(CredentialViewModel),
            userDialogs,
            navigationService
        )
        {
            _credential = credential;
            _credentialService = credentialService;
            _agentContextProvider = agentContextProvider;
            _connectionService = connectionService;
            _messageService = messageService;
            _poolConfigurator = poolConfigurator;

            _credentialState = _credential.State.ToString();

            if (_credentialState == "Offered")
            {
                ProcessOffer();
            }
        }

        [Obsolete]
        public async Task ProcessOffer()
        {

            foreach (var item in _credential.CredentialAttributesValues)
            {
                await SecureStorage.SetAsync(item.Name.ToString(), item.Value.ToString());
            }

            var RegisteredPIN = await SecureStorage.GetAsync("RegisteredPIN");
            string PIN = await App.Current.MainPage.DisplayPromptAsync("Enter PIN", null, "Ok", "Cancel", null, 6, Keyboard.Numeric);
            if (PIN == RegisteredPIN)
            {
                try
                {
                    //await _poolConfigurator.ConfigurePoolsAsync();
                    var agentContext = await _agentContextProvider.GetContextAsync();
                    var credentialRecord = await _credentialService.GetAsync(agentContext, _credential.Id);
                    var connectionId = credentialRecord.ConnectionId;
                    var connectionRecord = await _connectionService.GetAsync(agentContext, connectionId);
                    (var request, _) = await _credentialService.CreateRequestAsync(agentContext, _credential.Id);
                    await _messageService.SendAsync(agentContext.Wallet, request, connectionRecord);
                    await DialogService.AlertAsync("Request has been sent to the issuer.", "Success", "Ok");
                }
                catch (Exception e)
                {
                    await DialogService.AlertAsync(e.Message, "Error", "Ok");
                }
            }
            else if (PIN != RegisteredPIN && PIN != null)
            {
                DialogService.Alert("Provided PIN is not correct");
            }
        }

        #region Bindable Command
        [Obsolete]
        public ICommand ProcessOfferCommand => new Command(async () => await ProcessOffer());

        public ICommand NavigateBackCommand => new Command(async () =>
        {
            await NavigationService.PopModalAsync();
        });
        #endregion

        #region Bindable Properties
        private string _credentialState;
        public string CredentialState
        {
            get => _credentialState;
            set => this.RaiseAndSetIfChanged(ref _credentialState, value);
        }
        #endregion
    }
}
namespace Osma.Mobile.App.ViewModels.Index
{
    public class IndexViewModel : ABaseViewModel
    {
        private readonly IConnectionService _connectionService;
        private readonly IMessageService _messageService;
        private readonly IAgentProvider _agentContextProvider;
        private readonly IEventAggregator _eventAggregator;
        private readonly ILifetimeScope _scope;

        public IndexViewModel(
            IUserDialogs userDialogs,
            INavigationService navigationService,
            IConnectionService connectionService,
            IMessageService messageService,
            IAgentProvider agentContextProvider,
            IEventAggregator eventAggregator,
            ILifetimeScope scope
            ) : base(
                "Index",
                userDialogs,
                navigationService
           )
        {
            _connectionService = connectionService;
            _messageService = messageService;
            _agentContextProvider = agentContextProvider;
            _eventAggregator = eventAggregator;
            _scope = scope;
        }

        public override async Task InitializeAsync(object navigationData)
        {
            await base.InitializeAsync(navigationData);
        }

        public class Post
        {
            public string Success { get; set; }
            public string firstname { get; set; }
        }

        [Obsolete]
        public async Task ScanVerification(object sender, EventArgs e)
        {
            // Code
        }

        public async Task SettingsPage(SettingsViewModel settings) => await NavigationService.NavigateToAsync(settings, null, NavigationType.Modal);

        #region Bindable Command
        public ICommand SettingsPageCommand => new Command<SettingsViewModel>(async (settings) =>
        {
                await SettingsPage(settings);
        });

        [Obsolete]
        public ICommand ScanVerificationCommand => new Command(async () => await ScanVerification(default, default));
        #endregion
    }
}
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace Osma.Mobile.App
{
    public partial class App : Application
    {
        public new static App Current => Application.Current as App;
        public static IContainer Container { get; set; }

        // Timer to check new messages in the configured mediator agent every 10sec
        private readonly Timer timer;
        private static IHost Host { get; set; }

        public App()
        {
            InitializeComponent();

            timer = new Timer
            {
                Enabled = false,
                AutoReset = true,
                Interval = TimeSpan.FromSeconds(10).TotalMilliseconds
            };
            timer.Elapsed += Timer_Elapsed;
        }

        public App(IHost host) : this() => Host = host;

        public static IHostBuilder BuildHost(Assembly platformSpecific = null) =>
            XamarinHost.CreateDefaultBuilder<App>()
                .ConfigureServices((_, services) =>
                {
                    services.AddAriesFramework(builder => builder.RegisterEdgeAgent(
                        options: options =>
                        {
                            options.AgentName = "Mobile Holder";
                            options.EndpointUri = "http://11.222.333.44:5000";

                            options.WalletConfiguration.StorageConfiguration =
                                new WalletConfiguration.WalletStorageConfiguration
                                {
                                    Path = Path.Combine(
                                        path1: FileSystem.AppDataDirectory,
                                        path2: ".indy_client",
                                        path3: "wallets")
                                };
                            options.WalletConfiguration.Id = "MobileWallet";
                            options.WalletCredentials.Key = "SecretWalletKey";
                            options.RevocationRegistryDirectory = Path.Combine(
                                path1: FileSystem.AppDataDirectory,
                                path2: ".indy_client",
                                path3: "tails");

                            // Available network configurations (see PoolConfigurator.cs):
                            options.PoolName = "sovrin-test";
                        },
                        delayProvisioning: true));

                    services.AddSingleton<IPoolConfigurator, PoolConfigurator>();

                    var containerBuilder = new ContainerBuilder();
                    containerBuilder.RegisterAssemblyModules(typeof(CoreModule).Assembly);
                    if (platformSpecific != null)
                    {
                        containerBuilder.RegisterAssemblyModules(platformSpecific);
                    }

                    containerBuilder.Populate(services);
                    Container = containerBuilder.Build();
                });

        protected override async void OnStart()
        {
            await Host.StartAsync();

            // View models and pages mappings
            var _navigationService = Container.Resolve<INavigationService>();
            _navigationService.AddPageViewModelBinding<MainViewModel, MainPage>();
            _navigationService.AddPageViewModelBinding<RegisterViewModel, RegisterPage>();
            _navigationService.AddPageViewModelBinding<IndexViewModel, IndexPage>();
            _navigationService.AddPageViewModelBinding<SettingsViewModel, SettingsPage>();
            _navigationService.AddPageViewModelBinding<CredentialsViewModel, CredentialsPage>();
            _navigationService.AddPageViewModelBinding<CredentialViewModel, CredentialPage>();

            if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
            {
                await _navigationService.NavigateToAsync<MainViewModel>();
            }
            else
            {
                await _navigationService.NavigateToAsync<ProviderViewModel>();
            }

            timer.Enabled = true;
        }

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            // Check for new messages with the mediator agent if successfully provisioned
            if (Preferences.Get(AppConstant.LocalWalletProvisioned, false))
            {
                Device.BeginInvokeOnMainThread(async () =>
                {
                    try
                    {
                        var context = await Container.Resolve<IAgentProvider>().GetContextAsync();
                        await Container.Resolve<IEdgeClientService>().FetchInboxAsync(context);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                });
            }
        }
        protected override void OnSleep() =>
            // Stop timer when application goes to background
            timer.Enabled = false;

        protected override void OnResume() =>
            // Resume timer when application comes in foreground
            timer.Enabled = true;
    }
}
[程序集:XamlCompilation(XamlCompilationOptions.Compile)]
命名空间Osma.Mobile.App
{
公共部分类应用程序:应用程序
{
public new static App Current=>Application.Current as App;
公共静态IContainer容器{get;set;}
//计时器,用于每隔10秒检查配置的中介代理中的新消息
专用只读定时器;
私有静态IHost主机{get;set;}
公共应用程序()
{
初始化组件();
定时器=新定时器
{
启用=错误,
自动重置=真,
间隔=时间跨度。从秒(10)。总毫秒
};
timer.appeated+=timer\u appeated;
}
公共应用程序(IHost主机):this()=>host=host;
公共静态IHostBuilder构建主机(程序集平台特定=null)=>
XamarinHost.CreateDefaultBuilder()
.ConfigureServices((u,services)=>
{
services.AddAriesFramework(builder=>builder.RegisterEdgeAgent(
选项:选项=>
{
options.AgentName=“移动支架”;
options.EndpointUri=”http://11.222.333.44:5000";
options.WalletConfiguration.StorageConfiguration=
新WalletConfiguration.WalletStorageConfiguration
{
Path=Path.Combine(
路径1:FileSystem.AppDataDirectory,
路径2:“.indy_客户端”,
路径3:“钱包”)
};
options.WalletConfiguration.Id=“移动钱包”;
options.WalletCredentials.Key=“SecretWalletKey”;
options.RevocationRegistryDirectory=Path.Combine(
路径1:FileSystem.AppDataDirectory,
路径2:“.indy_客户端”,
路径3:“尾巴”);
//可用的网络配置(请参阅PoolConfigurator.cs):
options.PoolName=“sovrin测试”;
},
延迟设置:true);
services.AddSingleton();
var containerBuilder=新的containerBuilder();
containerBuilder.RegisterAssembly