Exemplo n.º 1
0
        public void OnPerforming(PerformingContext filterContext)
        {
            var cultureName   = filterContext.GetJobParameter <string>("CurrentCulture");
            var uiCultureName = filterContext.GetJobParameter <string>("CurrentUICulture");

            try
            {
                if (cultureName != null)
                {
                    filterContext.Items["PreviousCulture"] = CultureInfo.CurrentCulture;
                    SetCurrentCulture(new CultureInfo(cultureName));
                }
            }
            catch (CultureNotFoundException ex)
            {
                // TODO: Make this overridable, and start with throwing an exception
                _logger.WarnException($"Unable to set CurrentCulture for job {filterContext.BackgroundJob.Id} due to an exception", ex);
            }

            try
            {
                if (uiCultureName != null)
                {
                    filterContext.Items["PreviousUICulture"] = CultureInfo.CurrentUICulture;
                    SetCurrentUICulture(new CultureInfo(uiCultureName));
                }
            }
            catch (CultureNotFoundException ex)
            {
                // TODO: Make this overridable, and start with throwing an exception
                _logger.WarnException($"Unable to set CurrentUICulture for job {filterContext.BackgroundJob.Id} due to an exception", ex);
            }
        }
Exemplo n.º 2
0
        public void OnPerforming(PerformingContext filterContext)
        {
            var cultureName   = filterContext.GetJobParameter <string>("CurrentCulture");
            var uiCultureName = filterContext.GetJobParameter <string>("CurrentUICulture");

            try
            {
                if (!String.IsNullOrEmpty(cultureName))
                {
                    filterContext.Items["PreviousCulture"] = CultureInfo.CurrentCulture;
                    SetCurrentCulture(new CultureInfo(cultureName));
                }
            }
            catch (CultureNotFoundException ex)
            {
                _logger.WarnException($"Unable to set CurrentCulture for job {filterContext.BackgroundJob.Id} due to an exception", ex);
            }

            try
            {
                if (!String.IsNullOrEmpty(uiCultureName))
                {
                    filterContext.Items["PreviousUICulture"] = CultureInfo.CurrentUICulture;
                    SetCurrentUICulture(new CultureInfo(uiCultureName));
                }
            }
            catch (CultureNotFoundException ex)
            {
                _logger.WarnException($"Unable to set CurrentUICulture for job {filterContext.BackgroundJob.Id} due to an exception", ex);
            }
        }
Exemplo n.º 3
0
        public void OnPerforming(PerformingContext filterContext)
        {
            var importId = filterContext.GetJobParameter <int>("ImportId");

            filterContext.Items["haha"] = importId;

            // set current import id...
        }
Exemplo n.º 4
0
        public void OnPerforming(PerformingContext filterContext)
        {
            var cultureName   = filterContext.GetJobParameter <string>("CurrentCulture");
            var uiCultureName = filterContext.GetJobParameter <string>("CurrentUICulture");

            if (!String.IsNullOrEmpty(cultureName))
            {
                filterContext.Items["PreviousCulture"] = CultureInfo.CurrentCulture;
                Thread.CurrentThread.CurrentCulture    = new CultureInfo(cultureName);
            }

            if (!String.IsNullOrEmpty(uiCultureName))
            {
                filterContext.Items["PreviousUICulture"] = CultureInfo.CurrentUICulture;
                Thread.CurrentThread.CurrentUICulture    = new CultureInfo(uiCultureName);
            }
        }
Exemplo n.º 5
0
        public void OnPerforming(PerformingContext filterContext)
        {
            var correlationId = Guid.NewGuid().ToString("N");

            MappedDiagnosticsLogicalContext.Set("CorrelationId", correlationId);

            var correlationBlob = filterContext.GetJobParameter <string>("CorrelationBlob");

            MappedDiagnosticsLogicalContext.Set("CorrelationBlob", $"{correlationBlob}:{correlationId}");
        }
    public void OnPerforming(PerformingContext filterContext)
    {
        if (filterContext == null)
        {
            throw new ArgumentNullException(nameof(filterContext));
        }

        var tenantId = filterContext.GetJobParameter <string>("TenantId");

        TenantCurrentService.TenantId = tenantId;
    }
        public void OnPerforming(PerformingContext filterContext)
        {
            string             correlationId      = filterContext.GetJobParameter <string>(CorrelationIdKey) ?? filterContext.BackgroundJob.Id;
            IActivity          activity           = _activityFactory.CreateActivity();
            CorrelationContext correlationContext = activity.Start(correlationId);

            if (correlationContext != null)
            {
                filterContext.Items[CorrelationIdKey]     = correlationContext.CorrelationId;
                filterContext.Items[CorrelateActivityKey] = activity;
            }
        }
Exemplo n.º 8
0
        public void OnPerforming(PerformingContext filterContext)
        {
            //for recurring jobs
            var uniqueOpId = filterContext.GetJobParameter <string>("RecurringJobId");

            if (!string.IsNullOrWhiteSpace(uniqueOpId))
            {
                filterContext.Connection
                .GetAllEntriesFromHash($"{HangfireJobScheduler.RecurrentJobKeyPrefix}::{uniqueOpId}")
                .Where(_kvp => _kvp.Key == HangfireJobScheduler.CustomJobProperty_UserContext)
                .Select(_kvp => _kvp.Value)
                .FirstOrDefault()
                .Do(_v => CallContext.LogicalSetData(CallContextParameters_UserContext, JsonConvert.DeserializeObject <SerializableUserContext>(_v)));
            }

            //create a new resolution scope for use while invoking the job function
            CallContext.LogicalSetData(DependencyResolverScope, _scopeGenerator.Invoke());
        }
        public void OnPerforming(PerformingContext filterContext)
        {
            if (filterContext.Connection is not JobStorageConnection connection || connection == null)
            {
                return;
            }

            string?recurringJobId = filterContext.GetJobParameter <string?>("RecurringJobId");

            if (recurringJobId == null || !recurringJobId.EndsWith("start-movie"))
            {
                return;
            }

            if (connection.GetValueFromHash($"recurring-job:{recurringJobId}", "skip") != "true")
            {
                filterContext.Canceled = true;
            }
        }
        public void OnPerforming(PerformingContext filterContext)
        {
            var isPauseState = filterContext.GetJobParameter <bool>("PauseState");

            if (isPauseState)
            {
                filterContext.Items["PauseState"] = isPauseState;
                filterContext.Canceled            = true;
            }
            //var uiCultureName = filterContext.GetJobParameter<string>("CurrentUICulture");

            //if (!String.IsNullOrEmpty(cultureName))
            //{
            //    filterContext.Items["PreviousCulture"] = CultureInfo.CurrentCulture;
            //    SetCurrentCulture(new CultureInfo(cultureName));
            //}

            //if (!String.IsNullOrEmpty(uiCultureName))
            //{
            //    filterContext.Items["PreviousUICulture"] = CultureInfo.CurrentUICulture;
            //    SetCurrentUICulture(new CultureInfo(uiCultureName));
            //}
        }
        public void OnPerforming(PerformingContext filterContext)
        {
            var contextoTransiente = filterContext.GetJobParameter <WorkerContext>("contextoAplicacao");

            WorkerServiceScope.TransientContexts.TryAdd(WorkerContext.ContextIdentifier, contextoTransiente);
        }
        public void OnPerforming(PerformingContext filterContext)
        {
            var userName = filterContext.GetJobParameter <string>(USER_NAME);

            Thread.SetData(Thread.GetNamedDataSlot(USER_NAME), userName);
        }
Exemplo n.º 13
0
        public void OnPerforming(PerformingContext filterContext)
        {
            Assert.NotNull(filterContext);

            if (_cancelsTheCreation)
            {
                filterContext.Canceled = true;
            }

            _results.Add(String.Format("{0}::{1}", _name, "OnPerforming"));

            if (_setOnPreMethodParameters != null)
            {
                foreach (var parameter in _setOnPreMethodParameters)
                {
                    filterContext.SetJobParameter(parameter.Key, parameter.Value);
                }
            }

            if (_readParameters != null)
            {
                foreach (var parameter in _readParameters)
                {
                    Assert.Equal(
                        parameter.Value,
                        filterContext.GetJobParameter<string>(parameter.Key));
                }
            }
            
            if (_throwException)
            {
                throw new Exception();
            } 
        }
Exemplo n.º 14
0
        public void OnPerforming(PerformingContext filterContext)
        {
            var userName = filterContext.GetJobParameter <string>(USER_NAME);

            _userNameResolver.SetCurrentUserName(userName);
        }
Exemplo n.º 15
0
 public void OnPerforming(PerformingContext filterContext)
 {
     _context.Push(filterContext.GetJobParameter <string>("contextSnapshot"));
 }