Example #1
0
        public override async Task <FileInfo> GetFileInfo(string data)
        {
            var result = new FileInfo();

            var document = new BasicTableLayoutDocument(Container.Resolve <StyleSetup>(), new DocumentSettings(DocumentType.Pdf, Orientation.Landscape));

            document.SetDocumentTitle("This is a test PDF document");

            document.AddRowHeading("Name", "Name");
            document.AddRowHeading("Surname", "Surname");

            for (var i = 0; i < 50; i++)
            {
                document.AddRowUsingParams("Steve", "Brown");
                document.AddRowUsingParams("Jim", "Brown");
                document.AddRowUsingParams("Jack", "Black");
            }

            var userTask = BasicAuthentication.ControllerHelpers.Methods.GetLoggedInUserAsync(Container.Resolve <UserContext>());

            userTask.Wait();
            var user    = userTask.Result as User;
            var formats = DateTime.Now.GetDateTimeFormats();

            var footer = "Printed by " + user.UserName + " on " + System.DateTime.Now.ToString("yyyy-MM-dd");

            document.SetDocumentFooter(footer);

            document.SetSideMargin(Unit.FromCentimeter(1));

            using (var stream = document.GenerateDocument(false))
            {
                result.Data     = stream.ToArray();
                result.FileName = document.DocumentTitle;
                result.MimeType = "application/pdf";
            }

            return(result);
        }
Example #2
0
        public override async Task <FileInfo> GetFileInfo(string data)
        {
            var json = JsonHelper.Parse(data);

            var fromDate     = json.GetValue <DateTime>("FromDate");
            var toDate       = json.GetValue <DateTime>("ToDate");
            var userIdString = json.GetValue("UserIds");
            var userIds      = JArray.Parse(userIdString).Select(u => u.ToString()).ToArray();

            var document = new BasicTableLayoutDocument(StyleSetup, new DocumentSettings(DocumentType.Pdf, Orientation.Landscape));

            document.SetDocumentTitle("Audit Report: from " + fromDate.ToShortDateString() + " to " + toDate.ToShortDateString()); //TODO: need a subheading in report

            var user = await BasicAuthentication.ControllerHelpers.Methods.GetLoggedInUserAsync(UserContext);

            var footer = "Printed by " + user.UserName + " on " + System.DateTime.Now.ToString("yyyy-MM-dd");

            document.SetDocumentFooter(footer);
            document.SetSideMargin(Unit.FromCentimeter(1));

            document.AddRowHeading("User\t\tDate Time");
            document.AddRowHeading("Entity\t\tAction");

            using (var session = DataStore.OpenAuditSession())
            {
                var auditEvents = session.CreateCriteria <AuditEvent>()
                                  .Add(Restrictions.Gt("AuditEventDateTimeUTC", fromDate.AddDays(-1)))
                                  .Add(Restrictions.Lt("AuditEventDateTimeUTC", toDate.AddDays(1)))
                                  .Add(Restrictions.In("UserId", userIds))
                                  .AddOrder(Order.Asc("AuditEventDateTimeUTC"))
                                  .AddOrder(Order.Asc("EntityName"))
                                  .List <AuditEvent>()
                                  .ToList();

                var jdp = new JsonDiffPatch();

                foreach (var audit in auditEvents)
                {
                    if (audit.OriginalObject == null && audit.NewObject == null)
                    {
                        continue;
                    }
                    var origObj = audit.OriginalObject ?? String.Empty;
                    var newObj  = audit.NewObject.Replace(",\"", ", \"");

                    var diff = String.Empty;

                    if (String.IsNullOrWhiteSpace(audit.OriginalObject))
                    {
                        diff = audit.NewObject;
                    }
                    else if (String.IsNullOrWhiteSpace(audit.NewObject))
                    {
                        diff = audit.OriginalObject;
                    }
                    else
                    {
                        var left  = JToken.Parse(audit.OriginalObject);
                        var right = JToken.Parse(audit.NewObject);

                        var patch = jdp.Diff(left, right);
                        diff = jdp.Patch(left, patch)?.ToString();
                        //var diffItem = jdp.Diff(left, right);
                        //diff = diffItem.ToString();
                    }

                    //document.AddRowUsingParams(audit.User.UserName + "\t" + audit.AuditEventDateTimeUTC.ToString() + "\t" + audit.AuditAction.ToString() + "\t\t" + audit.EntityName + "\n" + origObj, "\n" + newObj + "\n\n" + diff);
                    document.AddRowUsingParams(audit.UserName + "\t\t" + audit.AuditEventDateTimeUTC.ToString(), audit.EntityName + "\t\t" + audit.AuditAction.ToString());
                    document.AddRowUsingParams("ORIGINAL ITEM", "MODIFICATION");
                    document.AddRowUsingParams(origObj, diff);
                    document.AddEmptyRow();
                }
            }

            var result = new FileInfo();

            using (var stream = document.GenerateDocument(false))
            {
                result.Data     = stream.ToArray();
                result.FileName = document.DocumentTitle;
                result.MimeType = "application/pdf";
            }

            return(result);
        }