/// <summary>
        /// Creates a new instance of the <see cref="RegisterIdentityModel"/> class.
        /// <param name="tagProfile">The tag profile to work with.</param>
        /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
        /// <param name="neuronService">The Neuron service for XMPP communication.</param>
        /// <param name="navigationService">The navigation service to use for app navigation</param>
        /// <param name="settingsService">The settings service for persisting UI state.</param>
        /// <param name="networkService">The network service for network access.</param>
        /// <param name="logService">The log service.</param>
        /// <param name="imageCacheService">The image cache to use.</param>
        /// </summary>
        public RegisterIdentityViewModel(
            ITagProfile tagProfile,
            IUiDispatcher uiDispatcher,
            INeuronService neuronService,
            INavigationService navigationService,
            ISettingsService settingsService,
            INetworkService networkService,
            ILogService logService,
            IImageCacheService imageCacheService)
            : base(RegistrationStep.RegisterIdentity, tagProfile, uiDispatcher, neuronService, navigationService, settingsService, logService)
        {
            this.networkService = networkService;
            IDeviceInformation deviceInfo = DependencyService.Get <IDeviceInformation>();

            this.DeviceId  = deviceInfo?.GetDeviceId();
            this.Countries = new ObservableCollection <string>();
            foreach (string country in ISO_3166_1.Countries)
            {
                this.Countries.Add(country);
            }
            this.SelectedCountry    = null;
            this.RegisterCommand    = new Command(async _ => await Register(), _ => CanRegister());
            this.TakePhotoCommand   = new Command(async _ => await TakePhoto(), _ => !IsBusy);
            this.PickPhotoCommand   = new Command(async _ => await PickPhoto(), _ => !IsBusy);
            this.RemovePhotoCommand = new Command(_ => RemovePhoto(true));
            this.Title = AppResources.PersonalLegalInformation;
            this.PersonalNumberPlaceholder = AppResources.PersonalNumber;
            this.localPhotoFileName        = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), ProfilePhotoFileName);
            imageCacheService = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
            this.photosLoader = new PhotosLoader(logService, networkService, neuronService, uiDispatcher, imageCacheService);
        }
예제 #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="RegistrationViewModel"/> class.
 /// For unit tests.
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="cryptoService">The service to use for cryptographic operations.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="networkService">The network and connectivity service.</param>
 /// <param name="logService">The log service.</param>
 /// <param name="imageCacheService">The image cache to use.</param>
 /// </summary>
 protected internal RegistrationViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     ISettingsService settingsService,
     INeuronService neuronService,
     ICryptoService cryptoService,
     INavigationService navigationService,
     INetworkService networkService,
     ILogService logService,
     IImageCacheService imageCacheService)
 {
     this.tagProfile        = tagProfile ?? DependencyService.Resolve <ITagProfile>();
     uiDispatcher           = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
     settingsService        = settingsService ?? DependencyService.Resolve <ISettingsService>();
     neuronService          = neuronService ?? DependencyService.Resolve <INeuronService>();
     cryptoService          = cryptoService ?? DependencyService.Resolve <ICryptoService>();
     this.navigationService = navigationService ?? DependencyService.Resolve <INavigationService>();
     networkService         = networkService ?? DependencyService.Resolve <INetworkService>();
     logService             = logService ?? DependencyService.Resolve <ILogService>();
     imageCacheService      = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
     GoToPrevCommand        = new Command(GoToPrev, () => (RegistrationStep)CurrentStep > RegistrationStep.Operator);
     RegistrationSteps      = new ObservableCollection <RegistrationStepViewModel>
     {
         this.AddChildViewModel(new ChooseOperatorViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, networkService, logService)),
         this.AddChildViewModel(new ChooseAccountViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, cryptoService, networkService, logService)),
         this.AddChildViewModel(new RegisterIdentityViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, networkService, logService, imageCacheService)),
         this.AddChildViewModel(new ValidateIdentityViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, networkService, logService, imageCacheService)),
         this.AddChildViewModel(new DefinePinViewModel(this.tagProfile, uiDispatcher, neuronService, this.navigationService, settingsService, logService))
     };
     SyncTagProfileStep();
     UpdateStepTitle();
 }
예제 #3
0
        /// <summary>
        /// Creates an instance of the <see cref="ViewContractViewModel"/> class.
        /// For unit tests.
        /// <param name="tagProfile">The tag profile to work with.</param>
        /// <param name="neuronService">The Neuron service for XMPP communication.</param>
        /// <param name="logService">The log service.</param>
        /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
        /// <param name="navigationService">The navigation service to use for app navigation</param>
        /// <param name="networkService">The network and connectivity service.</param>
        /// <param name="imageCacheService">The image cache to use.</param>
        /// <param name="contractOrchestratorService">The service to use for contract orchestration.</param>
        /// </summary>
        protected internal ViewContractViewModel(
            ITagProfile tagProfile,
            INeuronService neuronService,
            ILogService logService,
            IUiDispatcher uiDispatcher,
            INavigationService navigationService,
            INetworkService networkService,
            IImageCacheService imageCacheService,
            IContractOrchestratorService contractOrchestratorService)
        {
            this.tagProfile                  = tagProfile ?? DependencyService.Resolve <ITagProfile>();
            this.neuronService               = neuronService ?? DependencyService.Resolve <INeuronService>();
            this.logService                  = logService ?? DependencyService.Resolve <ILogService>();
            this.uiDispatcher                = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
            this.navigationService           = navigationService ?? DependencyService.Resolve <INavigationService>();
            networkService                   = networkService ?? DependencyService.Resolve <INetworkService>();
            imageCacheService                = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
            this.contractOrchestratorService = contractOrchestratorService ?? DependencyService.Resolve <IContractOrchestratorService>();

            this.Photos                  = new ObservableCollection <ImageSource>();
            this.photosLoader            = new PhotosLoader(this.logService, networkService, this.neuronService, this.uiDispatcher, imageCacheService, this.Photos);
            this.ObsoleteContractCommand = new Command(async _ => await ObsoleteContract());
            this.DeleteContractCommand   = new Command(async _ => await DeleteContract());
            this.GeneralInformation      = new ObservableCollection <PartModel>();
        }
예제 #4
0
 /// <summary>
 /// Creates a new instance of the <see cref="MainViewModel"/> class.
 /// For unit tests.
 /// </summary>
 protected internal MainViewModel(
     ILogService logService,
     INeuronService neuronService,
     IUiDispatcher uiDispatcher,
     ITagProfile tagProfile,
     INavigationService navigationService,
     INetworkService networkService,
     IImageCacheService imageCacheService,
     IContractOrchestratorService contractOrchestratorService,
     IThingRegistryOrchestratorService thingThingRegistryOrchestratorService)
     : base(neuronService ?? DependencyService.Resolve <INeuronService>(), uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>())
 {
     this.logService                       = logService ?? DependencyService.Resolve <ILogService>();
     this.tagProfile                       = tagProfile ?? DependencyService.Resolve <ITagProfile>();
     this.navigationService                = navigationService ?? DependencyService.Resolve <INavigationService>();
     this.networkService                   = networkService ?? DependencyService.Resolve <INetworkService>();
     imageCacheService                     = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
     this.contractOrchestratorService      = contractOrchestratorService ?? DependencyService.Resolve <IContractOrchestratorService>();
     this.thingRegistryOrchestratorService = thingThingRegistryOrchestratorService ?? DependencyService.Resolve <IThingRegistryOrchestratorService>();
     this.photosLoader                     = new PhotosLoader(this.logService, this.networkService, this.NeuronService, this.UiDispatcher, imageCacheService);
     this.UpdateLoggedOutText(true);
     this.ViewMyContractsCommand = new Command(async() => await ViewMyContracts(), () => this.IsConnected);
     this.ScanQrCodeCommand      = new Command(async() => await ScanQrCode(), () => this.IsConnected);
     this.ViewWalletCommand      = new Command(async() => await ViewWallet(), () => this.IsConnected);
 }
        /// <summary>
        /// Creates an instance of the <see cref="MyContractsViewModel"/> class.
        /// For unit tests.
        /// </summary>
        /// <param name="ContractsListMode">What list of contracts to display.</param>
        /// <param name="neuronService">The Neuron service for XMPP communication.</param>
        /// <param name="networkService">The network service for network access.</param>
        /// <param name="navigationService">The navigation service.</param>
        /// <param name="uiDispatcher"> The dispatcher to use for alerts and accessing the main thread.</param>
        protected internal MyContractsViewModel(ContractsListMode ContractsListMode, INeuronService neuronService, INetworkService networkService, INavigationService navigationService, IUiDispatcher uiDispatcher)
        {
            this.neuronService     = neuronService ?? DependencyService.Resolve <INeuronService>();
            this.networkService    = networkService ?? DependencyService.Resolve <INetworkService>();
            this.navigationService = navigationService ?? DependencyService.Resolve <INavigationService>();
            this.uiDispatcher      = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
            this.contractsListMode = ContractsListMode;
            this.contractsMap      = new Dictionary <string, Contract>();
            this.Contracts         = new ObservableCollection <ContractModel>();

            switch (ContractsListMode)
            {
            case ContractsListMode.MyContracts:
                this.Title       = AppResources.MyContracts;
                this.Description = AppResources.MyContractsInfoText;
                break;

            case ContractsListMode.SignedContracts:
                this.Title       = AppResources.SignedContracts;
                this.Description = AppResources.SignedContractsInfoText;
                break;

            case ContractsListMode.ContractTemplates:
                this.Title       = AppResources.ContractTemplates;
                this.Description = AppResources.ContractTemplatesInfoText;
                break;
            }
        }
예제 #6
0
 /// <summary>
 /// Creates a new instance of the <see cref="PhotosLoader"/> class.
 /// Use this constructor for when you want to load a a <b>single photo</b>.
 /// </summary>
 /// <param name="logService">The log service to use if and when logging errors.</param>
 /// <param name="networkService">The network service to use for checking connectivity.</param>
 /// <param name="neuronService">The neuron service to know which XMPP server to connect to.</param>
 /// <param name="uiDispatcher">The UI dispatcher to use for alerts and context switching.</param>
 /// <param name="imageCacheService">The image cache service to use for optimizing requests.</param>
 public PhotosLoader(
     ILogService logService,
     INetworkService networkService,
     INeuronService neuronService,
     IUiDispatcher uiDispatcher,
     IImageCacheService imageCacheService)
     : this(logService, networkService, neuronService, uiDispatcher, imageCacheService, new ObservableCollection <ImageSource>())
 {
 }
예제 #7
0
 /// <summary>
 /// Creates a new instance of the <see cref="LoadingViewModel"/> class.
 /// For unit tests.
 /// </summary>
 protected internal LoadingViewModel(
     INeuronService neuronService,
     IUiDispatcher uiDispatcher,
     ITagProfile tagProfile,
     INavigationService navigationService)
     : base(neuronService ?? DependencyService.Resolve <INeuronService>(), uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>())
 {
     this.tagProfile        = tagProfile ?? DependencyService.Resolve <ITagProfile>();
     this.navigationService = navigationService ?? DependencyService.Resolve <INavigationService>();
 }
예제 #8
0
 /// <summary>
 /// Creates a new instance of the <see cref="AppShellViewModel"/> class.
 /// For unit tests.
 /// </summary>
 protected internal AppShellViewModel(ITagProfile tagProfile, INeuronService neuronService, INetworkService networkService, IUiDispatcher uiDispatcher)
 {
     this.tagProfile          = tagProfile ?? DependencyService.Resolve <ITagProfile>();
     this.neuronService       = neuronService ?? DependencyService.Resolve <INeuronService>();
     this.networkService      = networkService ?? DependencyService.Resolve <INetworkService>();
     this.uiDispatcher        = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
     this.ConnectionStateText = AppResources.XmppState_Offline;
     this.IsOnline            = this.networkService.IsOnline;
     this.neuronService.ConnectionStateChanged += NeuronService_ConnectionStateChanged;
     this.networkService.ConnectivityChanged   += NetworkService_ConnectivityChanged;
     this.UpdateLogInLogOutMenuItem();
 }
예제 #9
0
        /// <summary>
        /// Create a new instance of an <see cref="XmppCommunicationViewModel"/>.
        /// For unit tests.
        /// </summary>
        protected internal XmppCommunicationViewModel(INeuronService neuronService, ILogService logService)
        {
            this.neuronService = neuronService ?? DependencyService.Resolve <INeuronService>();
            this.logService    = logService ?? DependencyService.Resolve <ILogService>();

            ClearCommand         = new Command(_ => this.ClearHtmlContent());
            CopyCommand          = new Command(_ => this.CopyHtmlToClipboard());
            ShowHistoryCommand   = new Command(_ => this.ShowHtmlHistory());
            SendDebugInfoCommand = new Command(_ => this.SendDebugInfo());

            HistoryButtonText = "History";

            RunAutoUpdateTask();
        }
예제 #10
0
 /// <summary>
 /// Creates a new instance of the <see cref="DefinePinViewModel"/> class.
 /// </summary>
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="logService">The log service.</param>
 public DefinePinViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ISettingsService settingsService,
     ILogService logService)
     : base(RegistrationStep.Pin, tagProfile, uiDispatcher, neuronService, navigationService, settingsService, logService)
 {
     this.ContinueCommand      = new Command(_ => Continue(), _ => CanContinue());
     this.SkipCommand          = new Command(_ => Skip(), _ => CanSkip());
     this.Title                = AppResources.DefinePin;
     this.PinIsTooShortMessage = string.Format(AppResources.PinTooShort, Constants.Authentication.MinPinLength);
 }
예제 #11
0
 /// <summary>
 /// Create a new instance of the <see cref="AppShell"/> class.
 /// </summary>
 public AppShell()
 {
     this.ViewModel                        = new AppShellViewModel();
     this.neuronService                    = DependencyService.Resolve <INeuronService>();
     this.networkService                   = DependencyService.Resolve <INetworkService>();
     this.navigationService                = DependencyService.Resolve <INavigationService>();
     this.logService                       = DependencyService.Resolve <ILogService>();
     this.uiDispatcher                     = DependencyService.Resolve <IUiDispatcher>();
     this.contractOrchestratorService      = DependencyService.Resolve <IContractOrchestratorService>();
     this.thingRegistryOrchestratorService = DependencyService.Resolve <IThingRegistryOrchestratorService>();
     InitializeComponent();
     SetTabBarIsVisible(this, false);
     RegisterRoutes();
 }
예제 #12
0
 public ThingRegistryOrchestratorService(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ILogService logService,
     INetworkService networkService)
 {
     this.tagProfile        = tagProfile;
     this.uiDispatcher      = uiDispatcher;
     this.neuronService     = neuronService;
     this.navigationService = navigationService;
     this.logService        = logService;
     this.networkService    = networkService;
 }
예제 #13
0
 /// <summary>
 /// Creates a new instance of the <see cref="PhotosLoader"/> class.
 /// Use this constructor for when you want to load a <b>list of photos</b>.
 /// </summary>
 /// <param name="logService">The log service to use if and when logging errors.</param>
 /// <param name="networkService">The network service to use for checking connectivity.</param>
 /// <param name="neuronService">The neuron service to know which XMPP server to connect to.</param>
 /// <param name="uiDispatcher">The UI dispatcher to use for alerts and context switching.</param>
 /// <param name="imageCacheService">The image cache service to use for optimizing requests.</param>
 /// <param name="photos">The collection the photos should be added to when downloaded.</param>
 public PhotosLoader(
     ILogService logService,
     INetworkService networkService,
     INeuronService neuronService,
     IUiDispatcher uiDispatcher,
     IImageCacheService imageCacheService,
     ObservableCollection <ImageSource> photos)
 {
     this.logService        = logService;
     this.networkService    = networkService;
     this.neuronService     = neuronService;
     this.uiDispatcher      = uiDispatcher;
     this.imageCacheService = imageCacheService;
     this.photos            = photos;
     this.attachmentIds     = new List <string>();
 }
예제 #14
0
 /// <summary>
 /// Creates a new instance of the <see cref="ChooseOperatorViewModel"/> class.
 /// </summary>
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="networkService">The network service for network access.</param>
 /// <param name="logService">The log service.</param>
 public ChooseOperatorViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ISettingsService settingsService,
     INetworkService networkService,
     ILogService logService)
     : base(RegistrationStep.Operator, tagProfile, uiDispatcher, neuronService, navigationService, settingsService, logService)
 {
     this.networkService        = networkService;
     this.Operators             = new ObservableCollection <string>();
     this.ConnectCommand        = new Command(async() => await Connect(), ConnectCanExecute);
     this.ManualOperatorCommand = new Command <string>(async text => await ManualOperatorTextEdited(text));
     this.PopulateOperators();
     this.Title = AppResources.SelectOperator;
 }
 public ContractOrchestratorService(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ILogService logService,
     INetworkService networkService,
     ISettingsService settingsService)
 {
     this.tagProfile        = tagProfile;
     this.uiDispatcher      = uiDispatcher;
     this.neuronService     = neuronService;
     this.navigationService = navigationService;
     this.logService        = logService;
     this.networkService    = networkService;
     this.settingsService   = settingsService;
 }
예제 #16
0
 /// <summary>
 /// Creates a new instance of the <see cref="RegisterIdentityViewModel"/> class.
 /// </summary>
 /// <param name="step">The current step for this instance.</param>
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="logService">The log service.</param>
 public RegistrationStepViewModel(
     RegistrationStep step,
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ISettingsService settingsService,
     ILogService logService)
 {
     this.Step              = step;
     this.UiDispatcher      = uiDispatcher;
     this.TagProfile        = tagProfile;
     this.NeuronService     = neuronService;
     this.NavigationService = navigationService;
     this.SettingsService   = settingsService;
     this.LogService        = logService;
 }
예제 #17
0
 /// <summary>
 /// Creates a new instance of the <see cref="ValidateIdentityViewModel"/> class.
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="networkService">The network service for network access.</param>
 /// <param name="logService">The log service.</param>
 /// <param name="imageCacheService">The image cache to use.</param>
 /// </summary>
 public ValidateIdentityViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ISettingsService settingsService,
     INetworkService networkService,
     ILogService logService,
     IImageCacheService imageCacheService)
     : base(RegistrationStep.ValidateIdentity, tagProfile, uiDispatcher, neuronService, navigationService, settingsService, logService)
 {
     this.networkService        = networkService;
     this.InviteReviewerCommand = new Command(async _ => await InviteReviewer(), _ => this.State == IdentityState.Created && this.NeuronService.IsOnline);
     this.ContinueCommand       = new Command(_ => Continue(), _ => IsApproved);
     this.Title        = AppResources.ValidatingInformation;
     this.Photos       = new ObservableCollection <ImageSource>();
     imageCacheService = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
     this.photosLoader = new PhotosLoader(logService, networkService, neuronService, uiDispatcher, imageCacheService, this.Photos);
 }
        /// <summary>
        /// Creates an instance of the <see cref="ViewClaimThingViewModel"/> class.
        /// </summary>
        public ViewClaimThingViewModel(
            ITagProfile tagProfile,
            IUiDispatcher uiDispatcher,
            INeuronService neuronService,
            INavigationService navigationService,
            INetworkService networkService,
            ILogService logService)
            : base(neuronService, uiDispatcher)
        {
            this.tagProfile        = tagProfile;
            this.logService        = logService;
            this.navigationService = navigationService;
            this.networkService    = networkService;

            this.ClaimThingCommand = new Command(async _ => await ClaimThing(), _ => IsConnected);
            this.Tags = new ObservableCollection <HumanReadableTag>();

            this.ClickCommand = new Command(async x => await this.LabelClicked(x));
        }
 /// <summary>
 /// Creates a new instance of the <see cref="PetitionIdentityViewModel"/> class.
 /// For unit tests.
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="logService">The log service.</param>
 /// <param name="networkService">The network and connectivity service.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="imageCacheService">The image cache to use.</param>
 /// </summary>
 protected internal PetitionIdentityViewModel(
     INeuronService neuronService,
     INavigationService navigationService,
     ILogService logService,
     INetworkService networkService,
     IUiDispatcher uiDispatcher,
     IImageCacheService imageCacheService)
 {
     this.neuronService     = neuronService ?? DependencyService.Resolve <INeuronService>();
     this.navigationService = navigationService ?? DependencyService.Resolve <INavigationService>();
     logService             = logService ?? DependencyService.Resolve <ILogService>();
     this.networkService    = networkService ?? DependencyService.Resolve <INetworkService>();
     uiDispatcher           = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
     imageCacheService      = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
     this.AcceptCommand     = new Command(async _ => await Accept());
     this.DeclineCommand    = new Command(async _ => await Decline());
     this.IgnoreCommand     = new Command(async _ => await Ignore());
     this.Photos            = new ObservableCollection <ImageSource>();
     this.photosLoader      = new PhotosLoader(logService, this.networkService, this.neuronService, uiDispatcher, imageCacheService, this.Photos);
 }
 /// <summary>
 /// Creates a new instance of the <see cref="ChooseAccountViewModel"/> class.
 /// </summary>
 /// <param name="tagProfile">The tag profile to work with.</param>
 /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
 /// <param name="neuronService">The Neuron service for XMPP communication.</param>
 /// <param name="navigationService">The navigation service to use for app navigation</param>
 /// <param name="settingsService">The settings service for persisting UI state.</param>
 /// <param name="cryptoService">The crypto service to use for password generation.</param>
 /// <param name="networkService">The network service for network access.</param>
 /// <param name="logService">The log service.</param>
 public ChooseAccountViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     ISettingsService settingsService,
     ICryptoService cryptoService,
     INetworkService networkService,
     ILogService logService)
     : base(RegistrationStep.Account, tagProfile, uiDispatcher, neuronService, navigationService, settingsService, logService)
 {
     this.cryptoService        = cryptoService;
     this.networkService       = networkService;
     this.PerformActionCommand = new Command(async _ => await PerformAction(), _ => CanPerformAction());
     this.ActionButtonText     = AppResources.CreateNew;
     this.CreateNew            = true;
     this.Mode = AccountMode.Create;
     this.CreateRandomPassword = true;
     this.SwitchModeCommand    = new Command(_ => CreateNew = !CreateNew, _ => !IsBusy);
     this.Title = AppResources.ChooseAccount;
 }
예제 #21
0
        /// <summary>
        /// Creates an instance of the <see cref="NewContractViewModel"/> class.
        /// For unit tests.
        /// <param name="tagProfile">The tag profile to work with.</param>
        /// <param name="logService">The log service.</param>
        /// <param name="neuronService">The Neuron service for XMPP communication.</param>
        /// <param name="uiDispatcher">The UI dispatcher for alerts.</param>
        /// <param name="navigationService">The navigation service to use for app navigation</param>
        /// <param name="settingsService">The settings service for persisting UI state.</param>
        /// <param name="contractOrchestratorService">The service to use for contract orchestration.</param>
        /// </summary>
        protected internal NewContractViewModel(
            ITagProfile tagProfile,
            ILogService logService,
            INeuronService neuronService,
            IUiDispatcher uiDispatcher,
            INavigationService navigationService,
            ISettingsService settingsService,
            IContractOrchestratorService contractOrchestratorService)
        {
            this.tagProfile                  = tagProfile ?? DependencyService.Resolve <ITagProfile>();
            this.logService                  = logService ?? DependencyService.Resolve <ILogService>();
            this.neuronService               = neuronService ?? DependencyService.Resolve <INeuronService>();
            this.uiDispatcher                = uiDispatcher ?? DependencyService.Resolve <IUiDispatcher>();
            this.navigationService           = navigationService ?? DependencyService.Resolve <INavigationService>();
            this.settingsService             = settingsService ?? DependencyService.Resolve <ISettingsService>();
            this.contractOrchestratorService = contractOrchestratorService ?? DependencyService.Resolve <IContractOrchestratorService>();

            this.ContractVisibilityItems = new ObservableCollection <ContractVisibilityModel>();
            this.AvailableRoles          = new ObservableCollection <string>();
            this.ProposeCommand          = new Command(async _ => await this.Propose(), _ => this.CanPropose());
            this.partsToAdd = new Dictionary <string, string>();
        }
예제 #22
0
 /// <summary>
 /// Creates an instance of the <see cref="ViewIdentityViewModel"/> class.
 /// </summary>
 public ViewIdentityViewModel(
     ITagProfile tagProfile,
     IUiDispatcher uiDispatcher,
     INeuronService neuronService,
     INavigationService navigationService,
     INetworkService networkService,
     ILogService logService,
     IImageCacheService imageCacheService)
     : base(neuronService, uiDispatcher)
 {
     this.tagProfile        = tagProfile;
     this.logService        = logService;
     this.navigationService = navigationService;
     this.networkService    = networkService;
     imageCacheService      = imageCacheService ?? DependencyService.Resolve <IImageCacheService>();
     this.ApproveCommand    = new Command(async _ => await Approve(), _ => IsConnected);
     this.RejectCommand     = new Command(async _ => await Reject(), _ => IsConnected);
     this.RevokeCommand     = new Command(async _ => await Revoke(), _ => IsConnected);
     this.CompromiseCommand = new Command(async _ => await Compromise(), _ => IsConnected);
     this.Photos            = new ObservableCollection <ImageSource>();
     this.photosLoader      = new PhotosLoader(this.logService, this.networkService, this.NeuronService, this.UiDispatcher, imageCacheService, this.Photos);
     this.CopyCommand       = new Command(_ => this.CopyHtmlToClipboard());
 }
예제 #23
0
        public NeuronGraphPaneViewModel(INeuronService neuronService = null)
        {
            this.neuronService = neuronService ?? Locator.Current.GetService <INeuronService>();

            bool DefaultPredicate(Node <NeuronDto, int> node) => node.IsRoot;

            var cache = new SourceCache <NeuronDto, int>(x => x.Id);

            this.AddCommand = ReactiveCommand.Create(() =>
                                                     this.neuronService.Add(cache, NeuronService.CreateNeuron("Root Neuron", ChildType.NotSet)));
            this.ReloadCommand = ReactiveCommand.Create(() => {
                cache.Clear();
                this.neuronService.Reload(cache);
            });
            this.cleanUp = cache.AsObservableCache().Connect()
                           .TransformToTree(child => child.ParentId, Observable.Return((Func <Node <NeuronDto, int>, bool>)DefaultPredicate))
                           .Transform(e =>
                                      e.Item.Type == ChildType.Postsynaptic ?
                                      (NeuronViewModelBase)(new PostsynapticViewModel(e.Item.Data, e, cache)) :
                                      (NeuronViewModelBase)(new PresynapticViewModel(e.Item.Data, e, cache)))
                           .Bind(out this.children)
                           .DisposeMany()
                           .Subscribe();
        }
예제 #24
0
 public TestNeuronViewModel(INeuronService neuronService, IUiDispatcher uiDispatcher)
     : base(neuronService, uiDispatcher)
 {
 }
        /// <summary>
        /// Converts the <see cref="RegisterIdentityModel"/> to an array of <inheritdoc cref="Property"/>.
        /// </summary>
        /// <param name="neuronService">The Neuron service to use for accessing the Bare Jid.</param>
        /// <returns>The <see cref="RegisterIdentityModel"/> as a list of properties.</returns>
        public Property[] ToProperties(INeuronService neuronService)
        {
            List <Property> properties = new List <Property>();
            string          s;

            if (!string.IsNullOrWhiteSpace(s = this.FirstName?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.FirstName, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.MiddleNames?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.MiddleName, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.LastNames?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.LastName, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.PersonalNumber?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.PersonalNumber, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Address?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Address, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Address2?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Address2, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.ZipCode?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.ZipCode, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Area?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Area, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.City?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.City, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Region?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Region, s));
            }

            if (!string.IsNullOrWhiteSpace(s = this.Country?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.Country, ISO_3166_1.ToCode(s)));
            }

            if (!string.IsNullOrWhiteSpace(s = this.DeviceId?.Trim()))
            {
                properties.Add(new Property(Constants.XmppProperties.DeviceId, s));
            }

            properties.Add(new Property(Constants.XmppProperties.JId, neuronService.BareJId));

            return(properties.ToArray());
        }
예제 #26
0
        /// <summary>
        /// Scans a QR Code, and depending on the actual result, takes different actions. This typically means navigating to an appropriate page.
        /// </summary>
        /// <param name="logService">The log service to use for logging.</param>
        /// <param name="neuronService">The Neuron service for XMPP access</param>
        /// <param name="navigationService">The navigation service for page navigation.</param>
        /// <param name="uiDispatcher">The ui dispatcher for main thread access.</param>
        /// <param name="contractOrchestratorService">The contract orchestrator service.</param>
        /// <param name="thingRegistryOrchestratorService">The thing registry orchestrator service.</param>
        /// <param name="commandName">The command name to display on the button when scanning.</param>
        /// <param name="action">An optional callback that will be called after scan, but before page navigation.</param>
        /// <returns></returns>
        public static async Task ScanQrCodeAndHandleResult(
            ILogService logService,
            INeuronService neuronService,
            INavigationService navigationService,
            IUiDispatcher uiDispatcher,
            IContractOrchestratorService contractOrchestratorService,
            IThingRegistryOrchestratorService thingRegistryOrchestratorService,
            string commandName,
            Func <string, Task> action = null)
        {
            string decodedText = await IdApp.QrCode.ScanQrCode(navigationService, AppResources.Open);

            if (string.IsNullOrWhiteSpace(decodedText))
            {
                return;
            }

            try
            {
                if (!Uri.TryCreate(decodedText, UriKind.Absolute, out Uri uri))
                {
                    await uiDispatcher.DisplayAlert(AppResources.ErrorTitle, AppResources.CodeNotRecognized);

                    return;
                }

                switch (uri.Scheme.ToLower())
                {
                case Constants.UriSchemes.UriSchemeIotId:
                    string legalId = Constants.UriSchemes.GetCode(decodedText);
                    await contractOrchestratorService.OpenLegalIdentity(legalId, AppResources.ScannedQrCode);

                    break;

                case Constants.UriSchemes.UriSchemeIotSc:
                    string contractId = Constants.UriSchemes.GetCode(decodedText);
                    await contractOrchestratorService.OpenContract(contractId, AppResources.ScannedQrCode);

                    break;

                case Constants.UriSchemes.UriSchemeIotDisco:
                    if (neuronService.ThingRegistry.IsIoTDiscoClaimURI(decodedText))
                    {
                        await thingRegistryOrchestratorService.OpenClaimDevice(decodedText);
                    }
                    else if (neuronService.ThingRegistry.IsIoTDiscoSearchURI(decodedText))
                    {
                        await thingRegistryOrchestratorService.OpenSearchDevices(decodedText);
                    }
                    else
                    {
                        await uiDispatcher.DisplayAlert(AppResources.ErrorTitle, $"{AppResources.InvalidIoTDiscoveryCode}{Environment.NewLine}{Environment.NewLine}{decodedText}");
                    }
                    break;

                case Constants.UriSchemes.UriSchemeTagSign:
                    string request = Constants.UriSchemes.GetCode(decodedText);
                    await contractOrchestratorService.TagSignature(request);

                    break;

                default:
                    if (!await Launcher.TryOpenAsync(uri))
                    {
                        await uiDispatcher.DisplayAlert(AppResources.ErrorTitle, $"{AppResources.QrCodeNotUnderstood}{Environment.NewLine}{Environment.NewLine}{decodedText}");
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                logService.LogException(ex);
                await uiDispatcher.DisplayAlert(ex);
            }
        }
 public TestContractOrchestratorService(ITagProfile tagProfile, IUiDispatcher uiDispatcher, INeuronService neuronService, INavigationService navigationService, ILogService logService, INetworkService networkService, ISettingsService settingsService)
     : base(tagProfile, uiDispatcher, neuronService, navigationService, logService, networkService, settingsService)
 {
 }
예제 #28
0
 /// <summary>
 /// Creates a new instance of the <see cref="MainPage"/> class.
 /// </summary>
 public MainPage()
 {
     InitializeComponent();
     ViewModel          = new MainViewModel();
     this.neuronService = DependencyService.Resolve <INeuronService>();
 }
예제 #29
0
        protected NeuronViewModelBase(Node <NeuronDto, int> node, SourceCache <NeuronDto, int> cache, NeuronViewModelBase parent = null, IExtendedSelectionService selectionService = null)
        {
            this.Id       = node.Key;
            this.NeuronId = node.Item.NeuronId;
            this.Data     = node.Item.Data;
            this.Parent   = parent;
            this.Dto      = node.Item;

            this.ReloadCommand          = ReactiveCommand.Create(() => this.neuronService.Reload(cache, this.Dto));
            this.AddPostsynapticCommand = ReactiveCommand.Create(() => this.neuronService.AddPostsynaptic(cache, this.Dto));
            this.AddPresynapticCommand  = ReactiveCommand.Create(() => this.neuronService.AddPresynaptic(cache, this.Dto));
            this.DeleteCommand          = ReactiveCommand.Create(() => this.neuronService.Delete(cache, this.Dto));

            this.neuronService    = neuronService ?? Locator.Current.GetService <INeuronService>();
            this.selectionService = selectionService ?? Locator.Current.GetService <IExtendedSelectionService>();

            var childrenLoader = new Lazy <IDisposable>(() => node.Children.Connect()
                                                        .Transform(e =>
                                                                   e.Item.Type == ChildType.Postsynaptic ?
                                                                   (NeuronViewModelBase)(new PostsynapticViewModel(e.Item.Data, e, cache, this)) :
                                                                   (NeuronViewModelBase)(new PresynapticViewModel(e.Item.Data, e, cache, this)))
                                                        .Bind(out this.children)
                                                        .DisposeMany()
                                                        .Subscribe()
                                                        );

            var shouldExpand = node.IsRoot ?
                               Observable.Return(true) :
                               Parent.Value.WhenValueChanged(t => t.IsExpanded);

            var expander = shouldExpand
                           .Where(isExpanded => isExpanded)
                           .Take(1)
                           .Subscribe(_ =>
            {
                var x = childrenLoader.Value;
            });

            var childrenCount = node.Children.CountChanged
                                .Select(count =>
            {
                if (count == 0)
                {
                    return("0 Synapses");
                }
                else
                {
                    return($"{node.Children.Items.Count(n => n.Item.Type == ChildType.Postsynaptic)} Postsynaptic; " +
                           $"{node.Children.Items.Count(n => n.Item.Type == ChildType.Presynaptic)} Presynaptic");
                }
            })
                                .Subscribe(text => this.ChildrenCountText = text);

            var changeData = this.WhenPropertyChanged(p => p.Data, false)
                             .Subscribe(x => this.neuronService.ChangeData(cache, this.Dto, x.Value));

            var selector = this.WhenPropertyChanged(p => p.IsSelected)
                           .Where(p => p.Value)
                           .Subscribe(x => this.selectionService.SetSelectedComponents(new object[] { x.Sender }));

            this.cleanUp = Disposable.Create(() =>
            {
                expander.Dispose();
                childrenCount.Dispose();
                if (childrenLoader.IsValueCreated)
                {
                    childrenLoader.Value.Dispose();
                }
                selector.Dispose();
            });
        }
예제 #30
0
 /// <summary>
 /// Creates an instance of a <see cref="NeuronViewModel"/>.
 /// </summary>
 /// <param name="neuronService"></param>
 /// <param name="uiDispatcher"></param>
 protected NeuronViewModel(INeuronService neuronService, IUiDispatcher uiDispatcher)
 {
     this.NeuronService       = neuronService;
     this.UiDispatcher        = uiDispatcher;
     this.ConnectionStateText = AppResources.XmppState_Offline;
 }