示例#1
0
        protected virtual Task <GenerateResponse> GenerateAsync(GenerateRequest request)
        {
            string result = null;

            try
            {
                var pdfData = Locator.Current.GetService <IBusinessCardService>()
                              .GeneratePDF(new GenerateParameter()
                {
                    Name         = request.Name,
                    Organization = request.Organization
                })
                              .Result;
                var creationTime = DateTime.Now;
                var filePath     = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                    $"{creationTime:yyyyMMdd_HHmmss}_{request.Name}.pdf");
                File.WriteAllBytes(filePath, pdfData);
                result = filePath;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                Locator.Current.GetService <IMessageDialog>()
                .ShowAlertMessage("Generation error", ex.Message, () =>
                {
                    result = ex.Message;
                });
            }

            return(Task.FromResult(new GenerateResponse()
            {
                Result = result
            }));
        }
示例#2
0
 public IObservable <GenerateResponse> Generate(GenerateRequest request)
 {
     return(Observable
            .FromAsync(() => GenerateAsync(request))
            .SubscribeOn(ThreadPoolScheduler.Instance));
 }