コード例 #1
0
        private int MonthlyScheduler()
        {
            using (var session = this.databaseService.Database.CreateSession())
            {
                this.logger.LogInformation("Begin");

                var scheduler = new AutomatedAgents(session).System;
                session.SetUser(scheduler);

                WorkTasks.BaseMonthly(session);

                var validation = session.Derive(false);

                if (validation.HasErrors)
                {
                    foreach (var error in validation.Errors)
                    {
                        this.logger.LogError("Validation error: {error}", error);
                    }

                    session.Rollback();
                }
                else
                {
                    session.Commit();
                }

                session.Derive();
                session.Commit();

                this.logger.LogInformation("End");
            }

            return(ExitCode.Success);
        }
コード例 #2
0
        public void GivenAnAuthenticationPopulatonWhenCreatingAnAccessListForGuestThenPermissionIsDenied()
        {
            this.Session.Derive();
            this.Session.Commit();

            var sessions = new ISession[] { this.Session };

            foreach (var session in sessions)
            {
                session.Commit();

                var guest = new AutomatedAgents(this.Session).Guest;
                var acls  = new AccessControlLists(guest);
                foreach (Object aco in (IObject[])session.Extent(M.Organisation.ObjectType))
                {
                    // When
                    var accessList = acls[aco];

                    // Then
                    Assert.False(accessList.CanExecute(M.Organisation.JustDoIt));
                }

                session.Rollback();
            }
        }
コード例 #3
0
ファイル: Populate.cs プロジェクト: Zonsoft-be/ExcelShowcase
        public int OnExecute(CommandLineApplication app)
        {
            this.logger.LogInformation("Begin");

            this.databaseService.Database.Init();

            using (var session = this.databaseService.Database.CreateSession())
            {
                var config = new Config {
                    DataPath = this.dataPath
                };
                new Setup(session, config).Apply();

                session.Derive();
                session.Commit();

                var scheduler = new AutomatedAgents(session).System;
                session.SetUser(scheduler);

                new Allors.Upgrade(session, this.dataPath).Execute();

                session.Derive();
                session.Commit();
            }

            this.logger.LogInformation("End");

            return(ExitCode.Success);
        }
コード例 #4
0
        public int OnExecute(CommandLineApplication app)
        {
            var exitCode = ExitCode.Success;

            using (var session = this.databaseService.Database.CreateSession())
            {
                this.logger.LogInformation("Begin");

                var scheduler = new AutomatedAgents(session).System;
                session.SetUser(scheduler);

                var printDocuments = new PrintDocuments(session).Extent();
                printDocuments.Filter.AddNot().AddExists(M.PrintDocument.Media);

                foreach (PrintDocument printDocument in printDocuments)
                {
                    var printable = printDocument.PrintableWherePrintDocument;
                    if (printable == null)
                    {
                        this.logger.LogWarning($"PrintDocument with id {printDocument.Id} has no Printable object");
                        continue;
                    }

                    try
                    {
                        printable.Print();

                        if (printable.ExistPrintDocument)
                        {
                            this.logger.LogInformation($"Printed {printable.PrintDocument.Media.FileName}");
                        }

                        session.Derive();
                        session.Commit();
                    }
                    catch (Exception e)
                    {
                        session.Rollback();
                        exitCode = ExitCode.Error;

                        this.logger.LogError(e, $"Could not print {printable.ToString()}");
                    }
                }

                this.logger.LogInformation("End");
            }

            return(exitCode);
        }
コード例 #5
0
ファイル: Custom.cs プロジェクト: Zonsoft-be/ExcelShowcase
        public int OnExecute(CommandLineApplication app)
        {
            using (var session = this.databaseService.Database.CreateSession())
            {
                this.logger.LogInformation("Begin");

                var scheduler = new AutomatedAgents(session).System;
                session.SetUser(scheduler);

                // Custom code
                session.Derive();
                session.Commit();

                this.logger.LogInformation("End");
            }

            return(ExitCode.Success);
        }
コード例 #6
0
        private int PrintPurchaseInvoice()
        {
            using (var session = this.databaseService.Database.CreateSession())
            {
                this.logger.LogInformation("Begin");

                var scheduler = new AutomatedAgents(session).System;
                session.SetUser(scheduler);

                var templateFilePath = "domain/templates/PurchaseInvoice.odt";
                var templateFileInfo = new FileInfo(templateFilePath);
                var prefix           = string.Empty;
                while (!templateFileInfo.Exists)
                {
                    prefix          += "../";
                    templateFileInfo = new FileInfo(prefix + templateFilePath);
                }

                var invoice  = new PurchaseInvoices(session).Extent().Last();
                var template = invoice.BilledTo.PurchaseInvoiceTemplate;

                using (var memoryStream = new MemoryStream())
                    using (var fileStream = new FileStream(
                               templateFileInfo.FullName,
                               FileMode.Open,
                               FileAccess.Read,
                               FileShare.ReadWrite))
                    {
                        fileStream.CopyTo(memoryStream);
                        template.Media.InData = memoryStream.ToArray();
                    }

                session.Derive();

                var images = new Dictionary <string, byte[]> {
                    { "Logo", session.GetSingleton().LogoImage.MediaContent.Data },
                };

                if (invoice.ExistInvoiceNumber)
                {
                    var barcodeService = session.ServiceProvider.GetRequiredService <IBarcodeService>();
                    var barcode        = barcodeService.Generate(invoice.InvoiceNumber, BarcodeType.CODE_128, 320, 80);
                    images.Add("Barcode", barcode);
                }

                var printModel = new Allors.Domain.Print.PurchaseInvoiceModel.Model(invoice);
                invoice.RenderPrintDocument(template, printModel, images);

                session.Derive();

                var result = invoice.PrintDocument;

                var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                var outputFile = File.Create(Path.Combine(desktopDir, "purchaseInvoice.odt"));
                using (var stream = new MemoryStream(result.Media.MediaContent.Data))
                {
                    stream.CopyTo(outputFile);
                }

                this.logger.LogInformation("End");
            }

            return(ExitCode.Success);
        }