Example #1
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();
 }
Example #2
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>();
        }
Example #3
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);
 }
Example #4
0
        public CoinModelFactory(IDirtySerializableCacheService serializableCacheService,
                                IDialogService dialogService,
                                IImageReaderService imageReaderService,
                                IImageCacheService imageCacheService)
        {
            if (serializableCacheService == null)
            {
                throw new ArgumentNullException(nameof(serializableCacheService));
            }
            if (dialogService == null)
            {
                throw new ArgumentNullException(nameof(dialogService));
            }
            if (imageReaderService == null)
            {
                throw new ArgumentNullException(nameof(imageReaderService));
            }
            if (imageCacheService == null)
            {
                throw new ArgumentNullException(nameof(imageCacheService));
            }

            _serializableCacheService = serializableCacheService;
            _dialogService            = dialogService;
            _imageReaderService       = imageReaderService;
            _imageCacheService        = imageCacheService;
        }
        /// <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);
        }
Example #6
0
        public CoinModel(Coin coin,
                         IDirtySerializableCacheService serializableCacheService,
                         IDialogService dialogService,
                         IImageReaderService imageReaderService,
                         IImageCacheService imageCacheService)
            : base(serializableCacheService)
        {
            _dialogService      = dialogService;
            _imageReaderService = imageReaderService;
            _imageCacheService  = imageCacheService;

            _coin = coin;

            Images        = new ObservableCollection <Image>(coin.Images ?? new List <Image>());
            SelectedImage = Images.FirstOrDefault();

            AddCoinImageCommand    = new RelayCommand <WindowCommandContext>(AddCoinImage);
            RemoveCoinImageCommand = new RelayCommand <WindowCommandContext>(RemoveCoinImage);

            Validator.AddRule(() => Title, () => RuleResult.Assert(!string.IsNullOrWhiteSpace(Title), Resources.ErrorBlankField));
            Validator.AddRule(() => Country, () => RuleResult.Assert(Country != null, Resources.ErrorBlankField));
            Validator.AddRule(() => Currency, () => RuleResult.Assert(Currency != null, Resources.ErrorBlankField));

            Validator.ValidateAll();
        }
Example #7
0
        public ContactImage()
        {
            _imageCacheService = Locator.Current.GetService <IImageCacheService>();

            Children.Add(_canvasView);
            _canvasView.PaintSurface += CanvasViewOnPaintSurface;
        }
Example #8
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>())
 {
 }
Example #9
0
 /// <summary>
 /// The dependency injected constructor
 /// </summary>
 /// <param name="logger">The logger</param>
 /// <param name="meta">The meta data service</param>
 /// <param name="image">The image cache service</param>
 /// <param name="api">The siege cache service</param>
 public MetaDataController(
     ILogger <MetaDataController> logger,
     IMetaDataService meta,
     IImageCacheService image,
     ISiegeService api)
 {
     _logger = logger;
     _meta   = meta;
     _image  = image;
     _api    = api;
 }
Example #10
0
        public static ICachedImage GetOrCreateCachedImage(this byte[] imageBytes, IImageCacheService imageCacheService)
        {
            var image = imageCacheService.Get(imageBytes);

            if (image != null)
            {
                return(image);
            }

            image = new CachedImage(imageBytes);
            imageCacheService.Add(imageBytes, image);

            return(image);
        }
Example #11
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>();
 }
Example #12
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 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);
 }
Example #14
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());
 }
Example #15
0
 public ResourceService(IImageCacheService cacheService, IHandleService handleService, ILogService logService)
 {
     this.cacheService  = cacheService;
     this.logService    = logService;
     this.handleService = handleService;
 }
Example #16
0
        ///<inheritdoc/>
        public App()
        {
            this.startupProfiler = new Profiler("Startup", ProfilerThreadType.Sequential);  // Comment out to remove startup profiling.
            this.startupProfiler?.Start();
            this.startupProfiler?.NewState("Init");

            AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
            AppDomain.CurrentDomain.UnhandledException   += CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException        += TaskScheduler_UnobservedTaskException;

            InitializeComponent();

            try
            {
                this.startupProfiler?.NewState("Types");

                Assembly appAssembly = this.GetType().Assembly;

                if (!Types.IsInitialized)
                {
                    // Define the scope and reach of Runtime.Inventory (Script, Serialization, Persistence, IoC, etc.):
                    Types.Initialize(
                        appAssembly,                                // Allows for objects defined in this assembly, to be instantiated and persisted.
                        typeof(Database).Assembly,                  // Indexes default attributes
                        typeof(ObjectSerializer).Assembly,          // Indexes general serializers
                        typeof(FilesProvider).Assembly,             // Indexes special serializers
                        typeof(RuntimeSettings).Assembly,           // Allows for persistence of settings in the object database
                        typeof(InternetContent).Assembly,           // Common Content-Types
                        typeof(XML).Assembly,                       // XML Content-Type
                        typeof(MarkdownDocument).Assembly,          // Markdown support
                        typeof(XmppClient).Assembly,                // Serialization of general XMPP objects
                        typeof(ContractsClient).Assembly,           // Serialization of XMPP objects related to digital identities and smart contracts
                        typeof(ProvisioningClient).Assembly,        // Serialization of XMPP objects related to thing registries, provisioning and decision support.
                        typeof(SensorClient).Assembly,              // Serialization of XMPP objects related to sensors
                        typeof(ControlClient).Assembly,             // Serialization of XMPP objects related to actuators
                        typeof(ConcentratorClient).Assembly,        // Serialization of XMPP objects related to concentrators
                        typeof(Expression).Assembly,                // Indexes basic script functions
                        typeof(XmppServerlessMessaging).Assembly,   // Indexes End-to-End encryption mechanisms
                        typeof(TagConfiguration).Assembly,          // Indexes persistable objects
                        typeof(RegistrationStep).Assembly);         // Indexes persistable objects
                }

                this.startupProfiler?.NewState("SDK");
                // Create Services
                this.sdk = TagIdSdk.Create(appAssembly, this.startupProfiler, new XmppConfiguration().ToArray());
                this.imageCacheService = new ImageCacheService(this.sdk.SettingsService, this.sdk.LogService);
                this.sdk.RegisterSingleton <IImageCacheService, ImageCacheService>(this.imageCacheService);
                this.contractOrchestratorService = new ContractOrchestratorService(this.sdk.TagProfile, this.sdk.UiDispatcher, this.sdk.NeuronService, this.sdk.NavigationService, this.sdk.LogService, this.sdk.NetworkService, this.sdk.SettingsService);
                this.sdk.RegisterSingleton <IContractOrchestratorService, ContractOrchestratorService>(this.contractOrchestratorService);
                this.thingRegistryOrchestratorService = new ThingRegistryOrchestratorService(this.sdk.TagProfile, this.sdk.UiDispatcher, this.sdk.NeuronService, this.sdk.NavigationService, this.sdk.LogService, this.sdk.NetworkService);
                this.sdk.RegisterSingleton <IThingRegistryOrchestratorService, ThingRegistryOrchestratorService>(this.thingRegistryOrchestratorService);

                // Set resolver
                DependencyResolver.ResolveUsing(type =>
                {
                    object obj = this.sdk.Resolve(type);
                    if (!(obj is null))
                    {
                        return(obj);
                    }

                    if (Types.GetType(type.FullName) is null)
                    {
                        return(null);    // Type not managed by Runtime.Inventory. Xamarin.Forms resolves this using its default mechanism.
                    }
                    return(Types.Instantiate(true, type));
                });

                // Get the db started right away to save startup time.
                this.sdk.StorageService.Init(this.startupProfiler?.CreateThread("Database", ProfilerThreadType.Sequential));

                // Register log listener (optional)
                this.sdk.LogService.AddListener(new AppCenterEventSink(this.sdk.LogService));
            }
            catch (Exception e)
            {
                e = Waher.Events.Log.UnnestException(e);
                this.startupProfiler?.Exception(e);
                DisplayBootstrapErrorPage(e.Message, e.StackTrace);
                return;
            }

            // Start page
            try
            {
                this.startupProfiler?.NewState("MainPage");

                this.MainPage = new AppShell();
            }
            catch (Exception e)
            {
                e = Waher.Events.Log.UnnestException(e);
                this.startupProfiler?.Exception(e);
                this.sdk.LogService.SaveExceptionDump("StartPage", e.ToString());
            }

            this.startupProfiler?.MainThread.Idle();
        }