コード例 #1
0
        public string AssignmentExpressionNameTest(string expression)
        {
            var context = factory.Create();
            var value   = context.Set(expression);

            return(value.Name);
        }
        public async Task ExecuteAsync(ICommand command, IExecutionContext executionContext)
        {
            var userContext = await _userContextService.GetCurrentContextByUserAreaAsync(_userArea.UserAreaCode);

            var newExecutionContext = _executionContextFactory.Create(userContext, executionContext);
            await _innerDomainRepositoryExecutor.ExecuteAsync(command, newExecutionContext);
        }
コード例 #3
0
        public object UseNullForMissingVariableTest(string target, IEnumerable <string> expressions)
        {
            factory.FailWhenMissingVariable = false;
            var context = factory.Create();

            foreach (var item in expressions)
            {
                context.Set(item);
            }
            return(context.GetValue(target, null));
        }
コード例 #4
0
        public async Task ExecuteAsync(Controller controller, PageActionRoutingState state)
        {
            // The ambient auth scheme might not be the cofoundry admin scheme
            // So we will attempt to find the cofoundry user to execute the contoller with
            // falling back to the user authenticated with the ambient scheme
            state.AmbientUserContext = await _userContextService.GetCurrentContextAsync();

            IUserContext cofoundryUserContext = null;

            if (state.AmbientUserContext.IsCofoundryUser())
            {
                cofoundryUserContext = state.AmbientUserContext;
            }
            else
            {
                cofoundryUserContext = await _userContextService.GetCurrentContextByUserAreaAsync(CofoundryAdminUserArea.Code);
            }

            if (cofoundryUserContext.IsCofoundryUser())
            {
                state.IsCofoundryAdminUser           = true;
                state.CofoundryAdminUserContext      = cofoundryUserContext;
                state.CofoundryAdminExecutionContext = _executionContextFactory.Create(state.CofoundryAdminUserContext);
            }
        }
コード例 #5
0
        /// <summary>
        /// Handles the execution of the specified command.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <param name="userContext">
        /// Optional user context which can be used to impersonate/elevate permissions.
        /// </param>
        public Task ExecuteAsync(ICommand command, IUserContext userContext)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException(nameof(userContext));
            }

            var executionContext = _executionContextFactory.Create(userContext);

            return(ExecuteAsync(command, executionContext));
        }
コード例 #6
0
        /// <summary>
        /// Handles the asynchronous execution the specified query.
        /// </summary>
        /// <param name="query">Query to execute.</param>
        /// <param name="userContext">
        /// Optional user context which can be used to impersonate/elevate permissions.
        /// </param>
        public Task <TResult> ExecuteAsync <TResult>(IQuery <TResult> query, IUserContext userContext)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException(nameof(userContext));
            }

            var executionContext = _executionContextFactory.Create(userContext);

            return(ExecuteAsync(query, executionContext));
        }
コード例 #7
0
        void ProcessStep(Step step, Criterion criterion, ScenarioContext scenarioContext,
            IExecutionContextFactory executionContextFactory)
        {
            dynamic executionContext = executionContextFactory.Create(scenarioContext.Scenario, step);

            _progressReporter.Report(new StepStartedReport(scenarioContext.Scenario.ScenarioId, criterion.CriterionId,
                step.StepId, executionContext.ExecutionContextId));

            StepExecutionResult result = executionContext.Execute(step as dynamic, scenarioContext);

            _progressReporter.Report(new StepStoppedReport(scenarioContext.Scenario.ScenarioId, criterion.CriterionId,
                step.StepId, executionContext.ExecutionContextId, result));
        }
コード例 #8
0
        public object NormalOperation(string target, IDictionary <string, object> input, IEnumerable <string> expressions)
        {
            factory.FailWhenMissingVariable = false;
            var context = factory.Create();

            if (expressions != null)
            {
                foreach (var item in expressions)
                {
                    context.Set(item);
                }
            }
            return(context.GetValue(target, input));
        }
コード例 #9
0
        public async Task ExecuteAsync(Controller controller, PageActionRoutingState state)
        {
            // The ambient auth schema might not be the cofoundry admin scheme
            // So we will attempt to find the cofoundry user to execute the contoller with
            // falling back to the user authenticated with the ambient scheme
            state.AmbientUserContext = await _userContextService.GetCurrentContextAsync();

            IUserContext cofoundryUserContext = null;

            if (state.AmbientUserContext.IsCofoundryUser())
            {
                cofoundryUserContext = state.AmbientUserContext;
            }
            else
            {
                cofoundryUserContext = await _userContextService.GetCurrentContextByUserAreaAsync(CofoundryAdminUserArea.AreaCode);
            }

            if (cofoundryUserContext.IsCofoundryUser())
            {
                state.IsCofoundryAdminUser           = true;
                state.CofoundryAdminUserContext      = cofoundryUserContext;
                state.CofoundryAdminExecutionContext = _executionContextFactory.Create(state.CofoundryAdminUserContext);
            }

            // Work out whether to view the page in live/draft/edit mode.
            // We use live by default (for logged out users) or for authenticated
            // users we can show draft too.
            var visualEditorMode = VisualEditorMode.Live;

            if (state.IsCofoundryAdminUser)
            {
                if (state.InputParameters.VersionId.HasValue)
                {
                    visualEditorMode = VisualEditorMode.SpecificVersion;
                }
                else if (!Enum.TryParse(state.InputParameters.VisualEditorMode, true, out visualEditorMode))
                {
                    visualEditorMode = VisualEditorMode.Any;
                }
            }
            else if (_contentSettings.AlwaysShowUnpublishedData)
            {
                // We can optionally set the visual editor mode to any - ie show draft and published pages
                // This is used in scenarios where devs are making modifications against a live db using a
                // local debug version of the site but aren't ready to publish the pages yet.
                visualEditorMode = VisualEditorMode.Any;
            }
            state.VisualEditorMode = visualEditorMode;
        }
コード例 #10
0
        public void CatchCircularReference(IDictionary <string, object> input, IEnumerable <string> expressions)
        {
            TestDelegate handle = new TestDelegate(() => {
                factory.FailWhenMissingVariable = false;
                var context = factory.Create();
                if (expressions != null)
                {
                    foreach (var item in expressions)
                    {
                        context.Set(item);
                    }
                }
                context.GetValue("a", input);
            });

            Assert.Catch <CircularReferenceException>(handle);
        }
コード例 #11
0
        private IExecutionContext CreateExecutionContext(IExecutionContext cx)
        {
            if (cx == null)
            {
                return(_executionContextFactory.Create());
            }

            if (cx.UserContext == null)
            {
                throw new ExecutionContextNotInitializedException("The UserContext property cannot be null");
            }

            if (cx.ExecutionDate == DateTime.MinValue)
            {
                throw new ExecutionContextNotInitializedException("The ExecutionDate property has not been set");
            }

            return(cx);
        }
コード例 #12
0
        /// <summary>
        /// Invokes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            var request = context.Request;

            //TO DO: Code here to get from header or token, whatever u want dear
            request.Query.TryGetValue(ContextKeys.TenantKey,
                                      out var tenantKey);
            request.Query.TryGetValue(ContextKeys.FacilityKey,
                                      out var facilityKey);
            request.Query.TryGetValue(ContextKeys.FacilityCode,
                                      out var facilityCode);
            request.Query.TryGetValue(ContextKeys.Locale,
                                      out var locale);

            //Hard Code first Tenant in system
            if (string.IsNullOrWhiteSpace(tenantKey))
            {
                tenantKey = "e767b738-3944-4896-93a0-6f074ba16616";
            }
            if (string.IsNullOrWhiteSpace(facilityKey))
            {
                if (request.HttpContext.GetRouteData()?.Values.ContainsKey(ContextKeys.FacilityKey) ??
                    false)
                {
                    facilityKey = request.HttpContext?.GetRouteData()?.Values[ContextKeys.FacilityKey].ToString();
                }
                else
                {
                    facilityKey = string.Empty;
                }
            }

            _executionContextFactory.Create(
                new TenantContext(tenantKey),
                new FacilityContext(facilityKey, facilityCode),
                locale);

            await _next(context);
        }
 public async Task ExecuteAsync(ICommand command, IExecutionContext executionContext)
 {
     var newExecutionContext = _executionContextFactory.Create(_userContext, executionContext);
     await _innerDomainRepositoryExecutor.ExecuteAsync(command, newExecutionContext);
 }
コード例 #14
0
        public object Run(string expression, Data data)
        {
            var context = factory.Create();

            return(context.Eval(expression, data, null));
        }