示例#1
0
文件: AntiForgery.cs 项目: Nakro/Mvc
 public AntiForgery([NotNull] IClaimUidExtractor claimUidExtractor,
                    [NotNull] IDataProtectionProvider dataProtectionProvider,
                    [NotNull] IAntiForgeryAdditionalDataProvider additionalDataProvider,
                    [NotNull] IOptionsAccessor<MvcOptions> mvcOptions)
 {
     var config = mvcOptions.Options.AntiForgeryOptions;
     var serializer = new AntiForgeryTokenSerializer(dataProtectionProvider.CreateProtector(_purpose));
     var tokenStore = new AntiForgeryTokenStore(config, serializer);
     var tokenProvider = new TokenProvider(config, claimUidExtractor, additionalDataProvider);
     _worker = new AntiForgeryWorker(serializer, config, tokenStore, tokenProvider, tokenProvider);
 }
示例#2
0
        public AntiForgery([NotNull] IClaimUidExtractor claimUidExtractor,
                           [NotNull] IDataProtectionProvider dataProtectionProvider,
                           [NotNull] IAntiForgeryAdditionalDataProvider additionalDataProvider,
                           [NotNull] IOptions<MvcOptions> mvcOptions,
                           [NotNull] IHtmlEncoder htmlEncoder,
                           [NotNull] IOptions<DataProtectionOptions> dataProtectionOptions)
        {
            var config = mvcOptions.Options.AntiForgeryOptions;
            var applicationId = dataProtectionOptions.Options.ApplicationDiscriminator ?? string.Empty;
            config.CookieName = config.CookieName ?? ComputeCookieName(applicationId);

            var serializer = new AntiForgeryTokenSerializer(dataProtectionProvider.CreateProtector(_purpose));
            var tokenStore = new AntiForgeryTokenStore(config, serializer);
            var tokenProvider = new TokenProvider(config, claimUidExtractor, additionalDataProvider);
            _worker = new AntiForgeryWorker(serializer, config, tokenStore, tokenProvider, tokenProvider, htmlEncoder);
        }
        private QueueClient CreateQueueClientIfNotExist(string p_healthMonitorCommandQueueName, bool p_requiresSession, string p_serviceBusUri, TokenProvider p_tokenProvider, NamespaceManager p_namespaceManager)
        {
            if (!p_namespaceManager.QueueExists(p_healthMonitorCommandQueueName))
            {
                QueueDescription qDesc = new QueueDescription(p_healthMonitorCommandQueueName);
                qDesc.MaxSizeInMegabytes = 5120;
                qDesc.DefaultMessageTimeToLive = TimeSpan.FromDays(14); // on Free tier pricing, max 14 days are allowed
                qDesc.EnableDeadLetteringOnMessageExpiration = false;
                qDesc.LockDuration = TimeSpan.FromMinutes(5);  // default is 30seconds, I have changed it to 5minutes, which is the maximum
                qDesc.RequiresDuplicateDetection = false;
                // 'RequiresSession' cannot be set when creating a Queue IF the namespace 'sqhealthmonitorservicebusqueue-ns' is using free 'Basic' tier.
                qDesc.RequiresSession = p_requiresSession;      // if there is only one consumer of the command queue, no sessionID is required, for the commandResult there are more consumers
                qDesc.EnablePartitioning = true;
                // until this line is the properties that can be set in Azure portal

                qDesc.EnableBatchedOperations = false;      // for low latency, quick response, don't wait miliseconds to batch messages, but send them instantly
                var qDescCreated = p_namespaceManager.CreateQueue(qDesc);
            }
            MessagingFactorySettings mfs = new MessagingFactorySettings();
            mfs.TokenProvider = p_tokenProvider;
            //mfs.TransportType = TransportType.Amqp;       // 400msec latency
            mfs.TransportType = TransportType.NetMessaging;     // 50msec latency
            mfs.NetMessagingTransportSettings.BatchFlushInterval = TimeSpan.Zero;  // instead of 20msec, // latency is 37msec was the minimum I measured (instead of 43msec)
            MessagingFactory factory = MessagingFactory.Create(p_serviceBusUri, mfs);
            var queueClient = factory.CreateQueueClient(p_healthMonitorCommandQueueName, ReceiveMode.PeekLock);
            queueClient.PrefetchCount = 0;  // it is the default too, and it was 0 in the fast and in the slow cases too
            return queueClient;
        }