private async Task InitQRCode() { // this is vaild for 10 minutes _uuid = Guid.NewGuid().ToString(); _gotQRCode = await QrCodeGenerator.RequestNew_QR_Code(_uuid, ApplicationStateManager.RigID()); if (_gotQRCode) { // create qr code var(image, ok) = QrCodeImageGenerator.GetQRCodeImage(_uuid); if (ok) { rect_qrCode.Fill = image; ScanLabel.Content = "Scan with official NiceHash mobile application"; ScanConfirmButton.Content = "Confirm scan"; } else { ScanLabel.Content = "QR Code image generation failed"; ScanConfirmButton.Visibility = Visibility.Collapsed; } } else { ScanConfirmButton.Visibility = Visibility.Collapsed; ScanLabel.Content = "Unable to retreive QR Code"; //ScanConfirmButton.Content = "Retry QR code"; } }
private void SetTheme(bool isLight) { var displayTheme = isLight ? "Light" : "Dark"; GUISettings.Instance.DisplayTheme = displayTheme; ThemeSetterManager.SetTheme(isLight); if (_gotQRCode) { var(image, ok) = QrCodeImageGenerator.GetQRCodeImage(_uuid, isLight); if (ok) { rect_qrCode.Fill = image; } } }
private async Task ProcessQRCode() { stopWatch = new Stopwatch(); stopWatch.Start(); var rigID = ApplicationStateManager.RigID(); var res = await QrCodeGenerator.RequestNew_QR_Code(_uuid, rigID); if (!res) { lbl_qr_status.Visibility = Visibility.Visible; lbl_qr_status.Content = "Unable to retreive QR Code"; return; } var(image, ok) = QrCodeImageGenerator.GetQRCodeImage(_uuid, GUISettings.Instance.DisplayTheme == "Light"); if (!ok) { lbl_qr_status.Visibility = Visibility.Visible; lbl_qr_status.Content = "QR Code image generation failed"; return; } rect_qrCode.Fill = image; while (true) { await Task.Delay(5000); if (stopWatch.ElapsedMilliseconds >= (1000 * 60 * 10)) { lbl_qr_status.Visibility = Visibility.Visible; btn_gen_qr.Visibility = Visibility.Visible; lbl_qr_status.Content = Translations.Tr("QR Code timeout. Please generate new one."); return; } } }
private async Task LoadContract() { try { bool hasSigned = false; bool acceptsSignatures = (Contract.State == ContractState.Approved || Contract.State == ContractState.BeingSigned) && (!Contract.SignAfter.HasValue || Contract.SignAfter.Value < DateTime.Now) && (!Contract.SignBefore.HasValue || Contract.SignBefore.Value > DateTime.Now); Dictionary <string, int> nrSignatures = new Dictionary <string, int>(); if (!(Contract.ClientSignatures is null)) { foreach (ClientSignature signature in Contract.ClientSignatures) { if (signature.LegalId == this.tagProfile.LegalIdentity.Id) { hasSigned = true; } if (!nrSignatures.TryGetValue(signature.Role, out int count)) { count = 0; } nrSignatures[signature.Role] = count + 1; } } // General Information this.GeneralInformation.Add(new PartModel(AppResources.Created, Contract.Created.ToString(CultureInfo.CurrentUICulture))); if (this.Contract.Updated > DateTime.MinValue) { this.GeneralInformation.Add(new PartModel(AppResources.Created, Contract.Updated.ToString(CultureInfo.CurrentUICulture))); } this.GeneralInformation.Add(new PartModel(AppResources.State, Contract.State.ToString())); this.GeneralInformation.Add(new PartModel(AppResources.Visibility, Contract.Visibility.ToString())); this.GeneralInformation.Add(new PartModel(AppResources.Duration, Contract.Duration.ToString())); this.GeneralInformation.Add(new PartModel(AppResources.From, Contract.From.ToString(CultureInfo.CurrentUICulture))); this.GeneralInformation.Add(new PartModel(AppResources.To, Contract.To.ToString(CultureInfo.CurrentUICulture))); this.GeneralInformation.Add(new PartModel(AppResources.Archiving_Optional, Contract.ArchiveOptional.ToString())); this.GeneralInformation.Add(new PartModel(AppResources.Archiving_Required, Contract.ArchiveRequired.ToString())); this.GeneralInformation.Add(new PartModel(AppResources.CanActAsTemplate, Contract.CanActAsTemplate.ToYesNo())); // QR _ = Task.Run(() => { byte[] bytes = QrCodeImageGenerator.GeneratePng(Constants.UriSchemes.CreateSmartContractUri(this.Contract.ContractId), this.QrCodeWidth, this.QrCodeHeight); this.uiDispatcher.BeginInvokeOnMainThread(() => { if (this.IsBound) { this.QrCode = ImageSource.FromStream(() => new MemoryStream(bytes)); } else { this.QrCode = null; } }); }); // Roles if (!(Contract.Roles is null)) { StackLayout rolesLayout = new StackLayout(); foreach (Role role in Contract.Roles) { string html = role.ToHTML(Contract.DefaultLanguage, Contract); html = Waher.Content.Html.HtmlDocument.GetBody(html); AddKeyValueLabelPair(rolesLayout, role.Name, html + GenerateMinMaxCountString(role.MinCount, role.MaxCount), true, string.Empty, null); if (!this.isReadOnly && acceptsSignatures && !hasSigned && this.Contract.PartsMode == ContractParts.Open && (!nrSignatures.TryGetValue(role.Name, out int count) || count < role.MaxCount)) { Button button = new Button { Text = string.Format(AppResources.SignAsRole, role.Name), StyleId = role.Name }; button.Clicked += SignButton_Clicked; rolesLayout.Children.Add(button); } } this.Roles = rolesLayout; } // Parts StackLayout partsLayout = new StackLayout(); if (Contract.SignAfter.HasValue) { AddKeyValueLabelPair(partsLayout, AppResources.SignAfter, Contract.SignAfter.Value.ToString(CultureInfo.CurrentUICulture)); } if (Contract.SignBefore.HasValue) { AddKeyValueLabelPair(partsLayout, AppResources.SignBefore, Contract.SignBefore.Value.ToString(CultureInfo.CurrentUICulture)); } AddKeyValueLabelPair(partsLayout, AppResources.Mode, Contract.PartsMode.ToString()); if (!(Contract.Parts is null)) { TapGestureRecognizer openLegalId = new TapGestureRecognizer(); openLegalId.Tapped += this.Part_Tapped; foreach (Part part in Contract.Parts) { AddKeyValueLabelPair(partsLayout, part.Role, part.LegalId, false, part.LegalId, openLegalId); if (!this.isReadOnly && acceptsSignatures && !hasSigned && part.LegalId == this.tagProfile.LegalIdentity.Id) { Button button = new Button { Text = string.Format(AppResources.SignAsRole, part.Role), StyleId = part.Role }; button.Clicked += SignButton_Clicked; partsLayout.Children.Add(button); } } } this.Parts = partsLayout; // Parameters if (!(Contract.Parameters is null)) { StackLayout parametersLayout = new StackLayout(); foreach (Parameter parameter in Contract.Parameters) { AddKeyValueLabelPair(parametersLayout, parameter.Name, parameter.ObjectValue?.ToString()); } this.Parameters = parametersLayout; } // Human readable text StackLayout humanReadableTextLayout = new StackLayout(); string xaml = Contract.ToXamarinForms(Contract.DefaultLanguage); StackLayout humanReadableXaml = new StackLayout().LoadFromXaml(xaml); List <View> children = new List <View>(); children.AddRange(humanReadableXaml.Children); foreach (View view in children) { humanReadableTextLayout.Children.Add(view); } this.HumanReadableText = humanReadableTextLayout; // Machine readable text StackLayout machineReadableTextLayout = new StackLayout(); AddKeyValueLabelPair(machineReadableTextLayout, AppResources.ContractId, Contract.ContractId); if (!string.IsNullOrEmpty(Contract.TemplateId)) { AddKeyValueLabelPair(machineReadableTextLayout, AppResources.TemplateId, Contract.TemplateId); } AddKeyValueLabelPair(machineReadableTextLayout, AppResources.Digest, Convert.ToBase64String(Contract.ContentSchemaDigest)); AddKeyValueLabelPair(machineReadableTextLayout, AppResources.HashFunction, Contract.ContentSchemaHashFunction.ToString()); AddKeyValueLabelPair(machineReadableTextLayout, AppResources.LocalName, Contract.ForMachinesLocalName); AddKeyValueLabelPair(machineReadableTextLayout, AppResources.Namespace, Contract.ForMachinesNamespace); this.MachineReadableText = machineReadableTextLayout; // Client signatures if (!(Contract.ClientSignatures is null)) { StackLayout clientSignaturesLayout = new StackLayout(); TapGestureRecognizer openClientSignature = new TapGestureRecognizer(); openClientSignature.Tapped += this.ClientSignature_Tapped; foreach (ClientSignature signature in Contract.ClientSignatures) { string sign = Convert.ToBase64String(signature.DigitalSignature); AddKeyValueLabelPair(clientSignaturesLayout, signature.Role, signature.LegalId + ", " + signature.BareJid + ", " + signature.Timestamp.ToString(CultureInfo.CurrentUICulture) + ", " + sign, false, sign, openClientSignature); } this.ClientSignatures = clientSignaturesLayout; } // Server signature if (!(Contract.ServerSignature is null)) { StackLayout serverSignaturesLayout = new StackLayout(); TapGestureRecognizer openServerSignature = new TapGestureRecognizer(); openServerSignature.Tapped += this.ServerSignature_Tapped; AddKeyValueLabelPair(serverSignaturesLayout, Contract.Provider, Contract.ServerSignature.Timestamp.ToString(CultureInfo.CurrentUICulture) + ", " + Convert.ToBase64String(Contract.ServerSignature.DigitalSignature), false, Contract.ContractId, openServerSignature); this.ServerSignatures = serverSignaturesLayout; } this.CanDeleteOrObsoleteContract = !this.isReadOnly && !Contract.IsLegallyBinding(true); this.HasRoles = this.Roles?.Children.Count > 0; this.HasParts = this.Parts?.Children.Count > 0; this.HasParameters = this.Parameters?.Children.Count > 0; this.HasHumanReadableText = this.HumanReadableText?.Children.Count > 0; this.HasMachineReadableText = this.MachineReadableText?.Children.Count > 0; this.HasClientSignatures = this.ClientSignatures?.Children.Count > 0; this.HasServerSignatures = this.ServerSignatures?.Children.Count > 0; if (!(this.Contract.Attachments is null) && this.Contract.Attachments.Length > 0) { _ = this.photosLoader.LoadPhotos(this.Contract.Attachments, SignWith.LatestApprovedId, () => { this.uiDispatcher.BeginInvokeOnMainThread(() => HasPhotos = this.Photos.Count > 0); }); } else { this.HasPhotos = false; } }