예제 #1
0
        private static IContextStorageFactory CreateFactoryForTransactionContext(IContextStorage <IInternalTransaction> transactionContext)
        {
            var transactionContextFactory = Mock.Create <IContextStorageFactory>();

            Mock.Arrange(() => transactionContextFactory.CreateContext <IInternalTransaction>(Arg.AnyString)).Returns(transactionContext);
            return(transactionContextFactory);
        }
예제 #2
0
        public IContextStorage <T> Get()
        {
            IContextStorage <T> storage = null;
            string storageName          = this.platformSetting.ContextStorage;

            storage = func(storageName);
            return(storage as IContextStorage <T>);
        }
        public override bool AttachToAsync()
        {
            var currentValue = _currentContextStorage.GetData();

            _currentContextStorage = _asyncContextStorage;
            _currentContextStorage.SetData(currentValue);
            return(true);
        }
            protected override void Arrange()
            {
                Given <IContextStorage>(new HashtableContextStorage());

                Given <ISession>();
                contextstorage = new HashtableContextStorage();
                Supplied <IReadOnlyList <AuthorizationFilterDetails> >(CreateTestParameters());
                authProvider = new AuthorizationFilterContextProvider(contextstorage);
            }
예제 #5
0
        /// <summary>
        /// Sets up the context with the appropriate dependencies.
        /// </summary>
        /// <param name="contextStorage">The context storage for the dependencies.</param>
        /// <param name="logger">The logger for the system.</param>
        /// <param name="networkContext">The network context to be used through the application.</param>
        public static void Setup(IContextStorage contextStorage, ILogger logger, INetworkContext networkContext)
        {
            _contextStorage = contextStorage;

            _contextStorage.SetData(StorageKeyLogger, logger);
            _contextStorage.SetData(StorageKeyNetworkContext, networkContext);
            Keys.Clear();
            Keys.Add(StorageKeyLogger);
            Keys.Add(StorageKeyNetworkContext);
        }
예제 #6
0
        public ProductDeserializer(IFieldService fieldService, IServiceFactory serviceFactory, ICacheItemWatcher cacheItemWatcher, IContextStorage contextStorage, IConnectionProvider connectionProvider)
        {
            _fieldService = fieldService;

            _contentService = serviceFactory.GetContentService();

            _cacheItemWatcher = cacheItemWatcher;

            _contextStorage = contextStorage;

            _customer = connectionProvider.GetCustomer();
        }
        public ReadOnlyArticleServiceAdapter(ArticleService articleService, IConnectionProvider connectionProvider, IContextStorage contextStorage)
        {
            if (articleService == null)
            {
                throw new ArgumentNullException("articleService");
            }

            ArticleService = articleService;

            QpCustomer = connectionProvider.GetCustomer();

            ContextStorage = contextStorage;
        }
        private SessionsContainer GetSessionsContainer()
        {
            IContextStorage <SessionsContainer> storage = this.GetContextStorage();
            SessionsContainer container = storage.Get();

            if (container == null)
            {
                container = new SessionsContainer();
                storage.Store(container);
            }

            return(container);
        }
 public TransactionService(IEnumerable <IContextStorageFactory> factories, ITimerFactory timerFactory, ICallStackManagerFactory callStackManagerFactory, IDatabaseService databaseService, ITracePriorityManager tracePriorityManager, IDatabaseStatementParser databaseStatementParser,
                           IErrorService errorService, IDistributedTracePayloadHandler distributedTracePayloadHandler, IAttributeDefinitionService attribDefSvc)
 {
     _sortedPrimaryContexts          = GetPrimaryTransactionContexts(factories);
     _asyncContext                   = GetAsyncTransactionContext(factories);
     _timerFactory                   = timerFactory;
     _callStackManagerFactory        = callStackManagerFactory;
     _databaseService                = databaseService;
     _tracePriorityManager           = tracePriorityManager;
     _databaseStatementParser        = databaseStatementParser;
     _errorService                   = errorService;
     _distributedTracePayloadHandler = distributedTracePayloadHandler;
     _attribDefSvc                   = attribDefSvc;
 }
예제 #10
0
        public void SetUp()
        {
            _lowPriorityTransactionContext = Mock.Create <IContextStorage <IInternalTransaction> >();
            Mock.Arrange(() => _lowPriorityTransactionContext.Priority).Returns(1);
            DictionaryTransactionContext(_lowPriorityTransactionContext);

            _highPriorityTransactionContext = Mock.Create <IContextStorage <IInternalTransaction> >();
            Mock.Arrange(() => _highPriorityTransactionContext.Priority).Returns(2);
            DictionaryTransactionContext(_highPriorityTransactionContext);

            var factory1 = CreateFactoryForTransactionContext(_highPriorityTransactionContext);
            var factory2 = CreateFactoryForTransactionContext(_lowPriorityTransactionContext);

            IAttributeDefinitionService _attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f));

            _transactionService = new TransactionService(new[] { factory1, factory2 }, Mock.Create <ITimerFactory>(), Mock.Create <ICallStackManagerFactory>(), Mock.Create <IDatabaseService>(), Mock.Create <ITracePriorityManager>(), Mock.Create <IDatabaseStatementParser>(), Mock.Create <IErrorService>(), Mock.Create <IDistributedTracePayloadHandler>(), _attribDefSvc);
        }
        private IInternalTransaction TryGetInternalTransaction(IContextStorage <IInternalTransaction> transactionContext)
        {
            try
            {
                if (transactionContext == null)
                {
                    return(null);
                }

                return(transactionContext.GetData());
            }
            catch (Exception exception)
            {
                Log.Error($"ITransactionContext threw an exception when calling GetData with {TransactionContextKey}: {exception}");
                return(null);
            }
        }
예제 #12
0
        private static void DictionaryTransactionContext(IContextStorage <IInternalTransaction> transactionContext)
        {
            const string key        = "TEST";
            var          dictionary = new Dictionary <string, object>();

            Mock.Arrange(() => transactionContext.CanProvide).Returns(true);
            Mock.Arrange(() => transactionContext.SetData((IInternalTransaction)Arg.AnyObject)).DoInstead((object value) =>
            {
                dictionary[key] = value;
            });
            Mock.Arrange(() => transactionContext.GetData()).Returns(() =>
            {
                if (!dictionary.ContainsKey(key))
                {
                    return(null);
                }

                object value;
                dictionary.TryGetValue(key, out value);
                return(value as IInternalTransaction);
            });
        }
예제 #13
0
 public SnapshotContextProvider(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthorizationFilterContextProvider" /> class using the specified context storage.
 /// </summary>
 /// <param name="contextStorage">The component to be used to store the contextual data.</param>
 public AuthorizationFilterContextProvider(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
 public CachedReadOnlyArticleServiceAdapter(ArticleService articleService, IConnectionProvider connectionProvider, IContextStorage contextStorage, ILogger logger)
     : base(articleService, connectionProvider, contextStorage)
 {
     _logger = logger;
 }
예제 #16
0
 public FeaturesDataAccessor(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
 public SyncToAsyncCallStackManager(IContextStorage <int?> asyncContextStorage)
 {
     _asyncContextStorage   = asyncContextStorage;
     _currentContextStorage = new SynchronousContextStorage();
 }
예제 #18
0
 public SchoolYearContextProvider(IContextStorage contextStorage)
 {
     this.contextStorage = contextStorage;
 }
예제 #19
0
 public InstanceIdContextProvider(IContextStorage contextStorage)
 {
     this.contextStorage = contextStorage;
 }
예제 #20
0
 public TaskDataAccessor(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
예제 #21
0
 public ApiKeyContextProvider(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
예제 #22
0
 /// <summary>
 /// Sets the context storage to use for this type of context.
 /// </summary>
 /// <param name="contextStorage">The context storage implementation.</param>
 public static void SetContextStorage(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
예제 #23
0
 private static void ThrowingTransactionContext(IContextStorage <IInternalTransaction> transactionContext)
 {
     Mock.Arrange(() => transactionContext.CanProvide).Returns(true);
     Mock.Arrange(() => transactionContext.SetData((IInternalTransaction)Arg.AnyObject)).Throws <Exception>();
     Mock.Arrange(() => transactionContext.GetData()).Throws <Exception>();
 }
예제 #24
0
 public ArticleServiceAdapter(ArticleService articleService, IConnectionProvider connectionProvider, IContextStorage contextStorage, IIdentityProvider provider)
     : base(articleService, connectionProvider, contextStorage)
 {
     _provider = provider;
 }
예제 #25
0
 public PermissionsDataAccessor(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
예제 #26
0
 static ContextStorage()
 {
     ContextStorageImplementation = new InternalContextStorage();
 }
예제 #27
0
 public UsersDataAccessor(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
 public AsyncCallStackManagerFactory(IContextStorageFactory factory)
 {
     this._storageContext = factory.CreateContext <int?>("NewRelic.ParentObject");
 }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpContextStorage"/> class with a secondary
 /// <see cref="IContextStorage"/> implementation to use in scenarios where <see cref="HttpContext.Current"/>
 /// is null (such as in background Tasks).
 /// </summary>
 /// <param name="next">The secondary context storage to use when <see cref="HttpContext.Current"/> is null.</param>
 public HttpContextStorage(IContextStorage next)
 {
     _next = next;
 }
예제 #30
0
 public EmployeeModelBinder(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }
예제 #31
0
 public ProjectsDataAccessor(IContextStorage contextStorage)
 {
     _contextStorage = contextStorage;
 }