コード例 #1
0
        public DocumentInfo(BaseInboxMessage signatureRequest)
        {
            InitializeComponent();

            GetAuthors(signatureRequest.Documents.First()).ContinueWith(t =>
            {
                if (!t.IsFaulted)
                {
                    autores.ReplaceItems(t.Result);
                }
            });

            lstAutores.ItemsSource = autores;

            lblCreator.Text      = AppResources.CREATOR;
            lblCreatorValue.Text = signatureRequest.Author;

            lblTitle.Text       = signatureRequest.Title;
            lblDescription.Text = signatureRequest.Description;

            lblDateTime.Text      = AppResources.CREATION_TIME;
            lblDateTimeValue.Text = signatureRequest.Date.ToString("dd/MM/yyyy HH:mm");

            lblAuthors.Text = AppResources.AUTHORS;

            lstAutores.ItemTapped += LstAutores_ItemTapped;
        }
コード例 #2
0
        public PdfPage(BaseInboxMessage request, Document document, bool showSignButton, EventHandler OnAssinar)
        {
            this.Document         = document;
            this.SignatureRequest = request;

            this.Title = "PDF";

            if (Device.OS == TargetPlatform.iOS)
            {
                this.Icon = (FileImageSource)FileImageSource.FromFile("pdf.png");
            }

            pdfWebView = new CustomWebView
            {
                HorizontalOptions    = LayoutOptions.FillAndExpand,
                VerticalOptions      = LayoutOptions.FillAndExpand,
                MinimumHeightRequest = 300,
                OverviewMode         = true
            };

            if (showSignButton)
            {
                var relativeLayout = new RelativeLayout();

                relativeLayout.Children.Add(pdfWebView, Constraint.RelativeToParent((parent) => {
                    return(parent.X);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Y);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Width);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Height - 50);
                }));

                Button btnAssinar = new Button()
                {
                    Text = AppResources.SIGN_DOCUMENT,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };

                relativeLayout.Children.Add(btnAssinar, Constraint.RelativeToView(pdfWebView, (Parent, sibling) => {
                    return(0);
                }), Constraint.RelativeToView(pdfWebView, (parent, sibling) => {
                    return(sibling.Height);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Width);
                }), Constraint.Constant(50));

                this.Content = relativeLayout;

                btnAssinar.Clicked += OnAssinar;
            }
            else
            {
                this.Content = pdfWebView;
            }

            CreateShareToolbarItem(this);
        }
コード例 #3
0
        public string GetPDFDir(BaseInboxMessage req)
        {
            string cacheDir = fileSystem.GetFilesDir();
            string attPath  = fileSystem.JoinPaths(cacheDir, "reqs", req.Id.ToString(), "pdf");

            fileSystem.CreateFolder(attPath);
            return(attPath);
        }
コード例 #4
0
        public SignaturePage(string title, BaseInboxMessage request, Document document, bool showSignButton = true)
        {
            this.tcs = new TaskCompletionSource <bool>();
            this.SignatureRequest = request;
            this.Document         = document;

            this.Title = title;
            this.CurrentPageChanged += AssinarPage_CurrentPageChanged;

            this.Children.Add(new TextPage(request, document, showSignButton, Sign));
            this.Children.Add(new PdfPage(request, Document, showSignButton, Sign));
        }
コード例 #5
0
        public AttachmentsPage(BaseInboxMessage req)
        {
            InitializeComponent();
            this.Title        = AppResources.ATTACHMENTS;
            this.inboxMessage = req;

            GetAttachments(req.Documents.First()).ContinueWith(t =>
            {
                if (!t.IsFaulted)
                {
                    attachments.ReplaceItems(t.Result);
                }
            });
            lstAttachments.ItemsSource   = attachments;
            lstAttachments.ItemSelected += LstAttachments_ItemSelected;
        }
コード例 #6
0
        public static async Task Sign(BaseInboxMessage request)
        {
            try
            {
                var certificate = new MemoryStream();
                if (await Pkcs12FileHelper.LoadFileTo(certificate))
                {
                    var password = await DialogHelper.AskForPassword(AppResources.INPUT_PKCS12_PASSWORD, AppResources.SIGN_DOCUMENT);

                    PfxEntry pfxEntry = null;

                    try
                    {
                        pfxEntry = Pkcs12FileHelper.Load(certificate, password);
                    }
                    catch (IOException e)
                    {
                        throw new DigitalSignatureError(AppResources.UNABLE_TO_OPEN_PRIVATE_KEY, e);
                    }

                    if (pfxEntry != null)
                    {
                        if (!pfxEntry.Certificate.IsValidNow)
                        {
                            throw new CertificateExpiredError();
                        }

                        var xadesSigner = XAdESCrossPlatformSigner.Current;
                        using (DialogHelper.ShowProgress(AppResources.SIGNING))
                        {
                            List <Signature> signatures = new List <Signature>();
                            foreach (Document doc in request.Documents)
                            {
                                var signed = new MemoryStream();
                                var toSign = new MemoryStream(doc.Content);
                                xadesSigner.Sign(toSign, signed, "#documento", pfxEntry.Certificate, pfxEntry.Key, policy);

                                Signature signature = new Signature();
                                signature.Id = doc.Id;
                                byte[] baSigned = StreamHelper.StreamToByteArray(signed);
                                signature.SignatureData = Encoding.UTF8.GetString(baSigned, 0, baSigned.Length);
                                signatures.Add(signature);
                            }

                            var response = await HttpRequest.Post(EndPointHelper.GetSendSignature(),
                                                                  JsonHelper.ToJson <List <Signature> >(signatures),
                                                                  Encoding.UTF8,
                                                                  "application/json");

                            if (!response.IsSuccessStatusCode)
                            {
                                throw new DigitalSignatureError(AppResources.UNABLE_TO_SEND_DIGITAL_SIGNATURE);
                            }
                        }
                    }
                    else
                    {
                        throw new DigitalSignatureError(AppResources.UNABLE_TO_OPEN_PRIVATE_KEY);
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
                throw new DigitalSignatureError(AppResources.SIGNATURE_CANCELLED, ex);
            }
            catch (HttpException ex)
            {
                throw new DigitalSignatureError(AppResources.DIGITAL_SIGNATURE_FAILED, ex);
            }
            catch (DigitalSignatureError ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                //TODO: logar esse erro no servidor
                //UserDialogs.Instance.Alert(e.Message, AppResources.APP_TITLE, AppResources.OK);
                throw new DigitalSignatureError(AppResources.DIGITAL_SIGNATURE_FAILED_UNKNOW_REASON, ex);;
            }
        }
コード例 #7
0
        public TextPage(BaseInboxMessage request, Document document, bool showSignButton, EventHandler OnAssinar)
        {
            this.request = request;
            this.Title   = "Texto";
            if (Device.OS == TargetPlatform.iOS)
            {
                this.Icon = (FileImageSource)FileImageSource.FromFile("text.png");
            }

            var html = new HtmlWebViewSource();

            var browser = new CustomWebView
            {
                HorizontalOptions    = LayoutOptions.FillAndExpand,
                VerticalOptions      = LayoutOptions.FillAndExpand,
                Source               = html,
                MinimumHeightRequest = 300
            };

            if (showSignButton)
            {
                Button btnAssinar = new Button()
                {
                    Text = AppResources.SIGN_DOCUMENT,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };

                var relativeLayout = new RelativeLayout();

                relativeLayout.Children.Add(browser, Constraint.RelativeToParent((parent) => {
                    return(parent.X);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Y);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Width);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Height - 50);
                }));

                relativeLayout.Children.Add(btnAssinar, Constraint.RelativeToView(browser, (Parent, sibling) => {
                    return(0);
                }), Constraint.RelativeToView(browser, (parent, sibling) => {
                    return(sibling.Height);
                }), Constraint.RelativeToParent((parent) => {
                    return(parent.Width);
                }), Constraint.Constant(50));

                this.Content = relativeLayout;

                btnAssinar.Clicked += OnAssinar;
            }
            else
            {
                this.Content = browser;
            }

            GetXSLT().ContinueWith(action =>
            {
                if (action.IsCompleted && !action.IsFaulted)
                {
                    LoadHTML(html, document, action.Result);
                }
            });

            CreateInfoToolbarItem(this);
        }
コード例 #8
0
        public ChildDocumentPage(BaseInboxMessage request, bool toSign)
        {
            this.tcs     = new TaskCompletionSource <bool>();
            this.request = request;
            this.Title   = request.Title;
            //this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5);

            var listView = new CustomListView
            {
                ItemsSource            = request.Documents,
                RowHeight              = 60,
                IsPullToRefreshEnabled = false,
                ItemTemplate           = new DataTemplate(() =>
                {
                    Grid gridTitle = new Grid
                    {
                        VerticalOptions = LayoutOptions.FillAndExpand,
                        RowDefinitions  =
                        {
                            new RowDefinition {
                                Height = GridLength.Auto
                            }
                        },
                        ColumnDefinitions =
                        {
                            new ColumnDefinition {
                                Width = new GridLength(1, GridUnitType.Star)
                            },
                            new ColumnDefinition {
                                Width = 70
                            }
                        }
                    };

                    gridTitle.HorizontalOptions = LayoutOptions.FillAndExpand;

                    Label labelTitle = new Label();
                    labelTitle.SetBinding(Label.TextProperty, "Title");
                    labelTitle.HorizontalOptions = LayoutOptions.FillAndExpand;
                    labelTitle.FontSize          = 18;

                    Label labelDescription = new Label();
                    labelDescription.SetBinding(Label.TextProperty, "Description");
                    labelDescription.FontSize          = 12;
                    labelDescription.Margin            = new Thickness(0, 5, 0, 0);
                    labelDescription.HorizontalOptions = LayoutOptions.FillAndExpand;
                    labelDescription.LineBreakMode     = LineBreakMode.TailTruncation;

                    gridTitle.Children.Add(labelTitle, 0, 0);

                    return(new ViewCell
                    {
                        View = new StackLayout
                        {
                            VerticalOptions = LayoutOptions.CenterAndExpand,
                            Padding = new Thickness(Device.OnPlatform(10, 0, 0), 5),
                            Orientation = StackOrientation.Horizontal,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            Children =
                            {
                                new StackLayout
                                {
                                    VerticalOptions = LayoutOptions.Center,
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    Spacing = 0,
                                    Children =
                                    {
                                        gridTitle,
                                        labelDescription
                                    }
                                }
                            }
                        }
                    });
                })
            };

            listView.Margin        = new Thickness(Device.OnPlatform(0, 10, 10), Device.OnPlatform(20, 0, 0), 10, 5);
            listView.ItemSelected += async delegate(object sender, SelectedItemChangedEventArgs e)
            {
                Document doc = (Document)e.SelectedItem;
                ((ListView)sender).SelectedItem = null;

                if (doc == null)
                {
                    return;
                }

                await LoadXMLs();

                await Navigation.PushAsync(new SignaturePage((toSign?AppResources.SIGN_DOCUMENT:doc.Title), request, doc, false));
            };

            Button btnAssinar = new Button()
            {
                Text = AppResources.SIGN_DOCUMENTS,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            if (toSign)
            {
                var relativeLayout = new RelativeLayout();

                relativeLayout.Children.Add(listView, Constraint.RelativeToParent((parent) =>
                {
                    return(parent.X);
                }), Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Y);
                }), Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Width);
                }), Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Height - 50);
                }));

                relativeLayout.Children.Add(btnAssinar, Constraint.RelativeToView(listView, (Parent, sibling) =>
                {
                    return(0);
                }), Constraint.RelativeToView(listView, (parent, sibling) =>
                {
                    return(sibling.Height);
                }), Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Width);
                }), Constraint.Constant(50));

                this.Content = relativeLayout;
            }
            else
            {
                this.Content = listView;
            }

            btnAssinar.Clicked += async delegate(object sender, EventArgs e)
            {
                await LoadXMLs();
                await Sign();
            };
        }