Exemple #1
0
    static async Task <int> SynchronizeRepositoriesAsync(string fileName, Credentials credentials)
    {
        var context = ContextLoader.Load(fileName);

        var returnValue  = 0;
        var repositories = context.Repositories;

        for (var i = 0; i < repositories.Count; i++)
        {
            var targetRepository = repositories[i];

            var prefix = $"({i + 1} / {repositories.Count})]";

            Console.WriteLine($"{prefix} Setting up synchronization for '{targetRepository}'");
            var stopwatch = Stopwatch.StartNew();

            try
            {
                await SyncRepository(context, targetRepository, credentials);

                Console.WriteLine($"{prefix} Synchronized '{targetRepository}', took {stopwatch.Elapsed:hh\\:mm\\:ss}");
            }
            catch (Exception exception)
            {
                returnValue = 1;
                Console.WriteLine($"Failed to synchronize '{targetRepository}'. Exception: {exception}");

                Console.WriteLine("Press a key to continue...");
                Console.ReadKey();
            }
        }

        return(returnValue);
    }
Exemple #2
0
        public void IIIF003()
        {
            string[] files = new string[] { "2.IIIF003Policy.xml", "2.IIIF003Request.xml", "2.IIIF003Response.xml" };
            Assert.AreEqual(files.Length, 3); FileInfo policyFile = new FileInfo(Consts.Path + files[0]);
            FileInfo requestFile  = new FileInfo(Consts.Path + files[1]);
            FileInfo responseFile = new FileInfo(Consts.Path + files[2]);

            using (FileStream fs = new FileStream(policyFile.FullName, FileMode.Open, FileAccess.Read))
                using (FileStream fs1 = new FileStream(requestFile.FullName, FileMode.Open, FileAccess.Read))
                    using (FileStream fs2 = new FileStream(responseFile.FullName, FileMode.Open, FileAccess.Read))
                    {
                        // Load Policy
                        PolicyDocument policyDocument = (PolicyDocument)PolicyLoader.LoadPolicyDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadOnly);
                        // Load Request
                        ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);
                        // Load ResponseElement
                        ContextDocumentReadWrite responseDocument = ContextLoader.LoadContextDocument(fs2, XacmlVersion.Version20);
                        EvaluationEngine         engine           = new EvaluationEngine();

                        ResponseElement res = engine.Evaluate(policyDocument, (ContextDocument)requestDocument);
                        Assert.AreEqual(((ResultElement)res.Results[0]).Obligations.Count, ((ResultElement)responseDocument.Response.Results[0]).Obligations.Count);
                        Assert.AreEqual(responseDocument.Response.Results.Count, res.Results.Count);
                        Assert.IsTrue(((ResultElement)res.Results[0]).Decision.ToString() == ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), string.Format("Decission incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), ((ResultElement)res.Results[0]).Decision.ToString()));
                        Assert.IsTrue(((ResultElement)res.Results[0]).Status.StatusCode.Value == ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, String.Format("Status incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, ((ResultElement)res.Results[0]).Status.StatusCode.Value));
                    }
        }
Exemple #3
0
        public void IIA001()
        {
            string[]      files    = new string[] { "2.IIA001Request.xml" };
            string        tempFile = Path.GetTempFileName();
            XmlTextWriter tw       = new XmlTextWriter(tempFile, System.Text.Encoding.ASCII);

            tw.Namespaces = true;
            tw.Formatting = Formatting.Indented;

            FileInfo requestFile = new FileInfo(Consts.Path + files[0]);

            using (FileStream fs = new FileStream(requestFile.FullName, FileMode.Open, FileAccess.Read))
            {
                // Load Request
                ContextDocumentReadWrite contextDocument = ContextLoader.LoadContextDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadWrite);

                contextDocument.Request.Action.Attributes[0].AttributeId = "UnitTest!!!";

                contextDocument.WriteRequestDocument(tw);
                tw.Close();

                using (FileStream fs1 = new FileStream(tempFile, FileMode.Open, FileAccess.Read))
                {
                    ContextDocument newCon = (ContextDocument)ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);

                    Assert.AreEqual(newCon.Request.Action.Attributes[0].AttributeId, contextDocument.Request.Action.Attributes[0].AttributeId);
                }
            }
        }
Exemple #4
0
        public Aplus(Scope dlrglobals, LexerMode parsemode)
        {
            this.sysvars         = new SystemVariables();
            this.dependencies    = new DependencyManager();
            this.callbackManager = new CallbackManager();

            this.dlrglobals = dlrglobals;
            this.globals    = new DYN.ExpandoObject();

            this.sysvars["mode"] = ASymbol.Create(parsemode.ToString().ToLower());

            this.mmfmanager = new MemoryMappedFileManager();

            this.systemFunctions = Function.SystemFunction.DiscoverSystemFunctions();

            if (String.IsNullOrEmpty(Environment.GetEnvironmentVariable("APATH", EnvironmentVariableTarget.User)))
            {
                string paths = String.Join(";", ".", "./Runtime/Context/");
                Environment.SetEnvironmentVariable("APATH", paths, EnvironmentVariableTarget.User);
            }

            // TODO: Move this to app.config?
            this.autoloadContexts = new string[] { "sys" };
            this.contextLoader    = new ContextLoader(this);
        }
 public SchemaFormsHandler(
     ContextLoader contextLoader,
     IFormFieldsBuilder formFieldsBuilder,
     ModelLoader modelLoader)
 {
     _formFieldsBuilder = formFieldsBuilder;
     _modelLoader       = modelLoader;
     _contextLoader     = contextLoader;
 }
Exemple #6
0
 public virtual void BaseOneTimeSetUp()
 {
     Config     = TestConfigBuilder.BuildTestConfig();
     Context    = ContextLoader.GetDbContext(Config, EnableRetryOnFailure);
     TestConfig = new TestConfigReader(Config);
     Context.Database.EnsureDeleted();
     Context.Database.EnsureCreated();
     MockClock = new Mock <IClock>();
     MockClock.SetupGet(c => c.UtcNow).Returns(() => MockTime);
     OneTimeSetup();
 }
Exemple #7
0
        public void TestGetInstitutionEnrichmentWithDifferentUserFromSavedUser()
        {
            Context = ContextLoader.GetDbContext(Config);//refresh the context

            var enrichmentService = new EnrichmentService(Context);
            //test get the enrichment using user2
            var result = enrichmentService.GetProviderEnrichment(ProviderInstCode, Email2);

            result.Should().NotBeNull();
            result.EnrichmentModel.Should().NotBeNull();
            result.EnrichmentModel.TrainWithDisability.Should().BeEquivalentTo(TrainWithDisabilityText);
            result.EnrichmentModel.TrainWithUs.Should().BeEquivalentTo(TrainWithUsText);
            result.LastPublishedTimestampUtc.Should().BeNull();
            result.Status.Should().BeEquivalentTo(EnumStatus.Draft);
        }
Exemple #8
0
        public static void Test()
        {
            var context    = ContextLoader.CreateContextLoader <TestConfig>().LoadContext();
            var testString = context.Get <string>("testString");

            Console.WriteLine(testString);
            var testString2 = context.Get <string>("testString2");

            Console.WriteLine(testString2);
            var testItem = context.Get <TestItem>("testItem");

            testItem.Print();
            Console.WriteLine(testItem.Foo);
            Console.WriteLine(testItem.Bar);
            Console.WriteLine(testItem.FooBar);
            Console.WriteLine(context.Get <string>("testString3"));
        }
        private void SetupSmokeTestData()
        {
            // don't use the retrying context because the migrator hasn't been updated to use the retry strategy
            var migratorContext = ContextLoader.GetDbContext(Config, false);

            // Not using CurrentRecruitmentCycle from base class because it doesn't share this context
            var currentRecruitmentCycle = migratorContext
                                          .RecruitmentCycles
                                          .Single(rc => rc.Year == RecruitmentCycle.CurrentYear);

            migratorContext.AddTestReferenceData(TestConfig.SignInUsername, currentRecruitmentCycle);
            migratorContext.Save();

            var ucasDataMigrator = new UcasDataMigrator(migratorContext,
                                                        new Mock <Serilog.ILogger>().Object,
                                                        TestPayloadBuilder.MakeSimpleUcasPayload(),
                                                        null,
                                                        currentRecruitmentCycle);

            ucasDataMigrator.UpdateUcasData();
        }
Exemple #10
0
        public void BaseSetup()
        {
            // get a fresh context every time to avoid stale in-memory data contaminating subsequent tests
            Context = ContextLoader.GetDbContext(Config, EnableRetryOnFailure);
            // Truncate (delete all data from) all tables, following FK constraints by virtue of CASCADE
            // https://stackoverflow.com/questions/2829158/truncating-all-tables-in-a-postgres-database/12082038#12082038
            Context.Database.ExecuteSqlCommandAsync(@"
                DO
                $func$
                BEGIN
                   EXECUTE
                   (SELECT 'TRUNCATE TABLE ' || string_agg(oid::regclass::text, ', ') || ' CASCADE'
                    FROM   pg_class
                    WHERE  relkind = 'r'  -- only tables
                    AND    relnamespace = 'public'::regnamespace
                   );
                END
                $func$;").Wait();

            // reset clock
            MockTime = new DateTime(1977, 1, 2, 3, 4, 5, 7);

            Context.RecruitmentCycles.AddRange(
                new List <RecruitmentCycle>
            {
                new RecruitmentCycle {
                    Year = RecruitmentCycle.CurrentYear
                },
                new RecruitmentCycle {
                    Year = "2020"
                },
            });
            Context.SaveChanges();

            // allow derived tests to do their own setup
            Setup();
        }
Exemple #11
0
    public Task Parsing()
    {
        var context = ContextLoader.Load(@".\ConfigImport.yaml");

        return(Verify(context));
    }
Exemple #12
0
 public ReportRepository()
 {
     _db = ContextLoader.LoadContext();
 }
Exemple #13
0
        /// <summary>
        /// Main method for the tool it receives command line arguments and performs the evaluation.
        /// </summary>
        /// <param name="args">The parsed command line arguments.</param>
        static void Main(string[] args)
        {
            var t = ConfigurationManager.OpenExeConfiguration(@"C:\Git\Xacml.Net\Xacml.Console\bin\Debug\Xacml.Console.exe.config");

            string policy = String.Empty, request = String.Empty;
            bool   verbose = false;

            //foreach (string arg in args)
            //{
            //    if ((arg[0] == '/' || arg[0] == '-'))
            //    {
            //        if (arg[1] == 'p' || arg[1] == 'P')
            //        {
            //            policy = arg.Substring(3);
            //        }

            //        if (arg[1] == 'r' || arg[1] == 'R')
            //        {
            //            request = arg.Substring(3);
            //        }

            //        if (arg[1] == 'v' || arg[1] == 'V')
            //        {
            //            verbose = true;
            //        }
            //    }
            //}

            try
            {
                request = @"C:\Git\Xacml.Net\Samples\requests\IIA001Request.xml";
                //request = @"C:\Git\Xacml.Net\Samples\Request.xml";
                policy = @"C:\Git\Xacml.Net\Samples\Policy.xml";
                if (request.Length != 0 && policy.Length != 0)
                {
                    using (FileStream fs1 = new FileStream(request, FileMode.Open, FileAccess.Read))

                    {
                        // Load Request
                        ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20);

                        var           res = new EvaluationEngine(verbose).Evaluate((ContextDocument)requestDocument);
                        XmlTextWriter tw  = new XmlTextWriter(System.Console.Out)
                        {
                            Formatting = Formatting.Indented
                        };
                        res.WriteDocument(tw);
                    }
                }
                else
                {
                    throw new Exception("Request or policy file not specified.");
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                System.Console.WriteLine();
                System.Console.WriteLine("Usage:");
                System.Console.WriteLine("\t-p:[policyFilePath]  - The path to the policy file");
                System.Console.WriteLine("\t-r:[requestFilePath] - The path to the request file");
                System.Console.WriteLine("\t-v                   - Makes the execution verbose");
            }

            System.Console.WriteLine("Press Enter to close...");
            System.Console.ReadLine();
        }