예제 #1
0
 public ThrottlingTest()
 {
     Throttling.Init();
     walletUtils = new WalletUtils();
     recipient   = new Recipient {
     };
 }
예제 #2
0
파일: App.xaml.cs 프로젝트: Daiwv/exmo-1
        protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
        {
            base.OnBackgroundActivated(args);

            var taskInstance = args.TaskInstance;
            var service      = new Throttling();

            service.Run(taskInstance);
        }
예제 #3
0
 public AsyncLogger(Layout loggingLayout, EnforcementConfig enforcementConfig, MessageBuilder messageBuilder, MessageTransmitterConfig messageTransmitterConfig)
 {
     layout             = loggingLayout;
     cts                = new CancellationTokenSource();
     token              = cts.Token;
     throttling         = Throttling.FromConfig(enforcementConfig.Throttling);
     queue              = NewBlockingCollection();
     buffer             = new ByteArray(enforcementConfig.TruncateMessageTo);
     messageTransmitter = MessageTransmitter.FromConfig(messageTransmitterConfig);
     Task.Run(() => ProcessQueueAsync(messageBuilder));
 }
예제 #4
0
        public object Clone()
        {
            WriteBehind writeBehind = new WriteBehind();

            writeBehind.Mode         = Mode != null ? (string)Mode.Clone() : null;
            writeBehind.Throttling   = Throttling != null ? (string)Throttling.Clone() : null;
            writeBehind.Eviction     = Eviction != null ? (string)Eviction.Clone() : null;
            writeBehind.RequeueLimit = RequeueLimit != null ? (string)RequeueLimit.Clone() : null;
            writeBehind.BatchConfig  = BatchConfig != null?BatchConfig.Clone() as BatchConfig : null;

            return(writeBehind);
        }
 public AsyncLogger(Layout loggingLayout, EnforcementConfig enforcementConfig, MessageBuilder messageBuilder, MessageTransmitterConfig messageTransmitterConfig)
 {
     layout                = loggingLayout;
     cts                   = new CancellationTokenSource();
     token                 = cts.Token;
     throttling            = Throttling.FromConfig(enforcementConfig.Throttling);
     queue                 = NewBlockingCollection();
     buffer                = new ByteArray(enforcementConfig.TruncateMessageTo);
     messageTransmitter    = MessageTransmitter.FromConfig(messageTransmitterConfig);
     flushCompletionMarker = new LogEventInfo(LogLevel.Off, string.Empty, nameof(flushCompletionMarker));
     Task.Run(() => ProcessQueueAsync(messageBuilder));
     processWithTimeoutAction = (asyncLogEventInfo, timeout) => Enqueue(asyncLogEventInfo, timeout);
     discardAction            = asyncLogEventInfo => asyncLogEventInfo.Continuation(new InvalidOperationException($"Enqueue skipped"));
 }
        public IActionResult SendCoin([FromBody] Recipient recipient)
        {
            try
            {
                recipient.ip_address = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
                if (Throttling.Transactions.Count > 100)
                {
                    throw new FaucetException("Too many faucet users");
                }

                Throttling.Transactions.GetOrAdd(recipient.address, recipient);
                return(new JsonResult(Throttling.WaitForTransaction(recipient.address)));
            }
            catch (FaucetException ex)
            {
                // TODO figure out the right way to do this for knockout::
                throw new ApplicationException(ex.Message);
            }
        }
예제 #7
0
        public async static void Execute(WalletUtils walletUtils)
        {
            //   Console.WriteLine("SendCoinJob.Execute");
            foreach (Recipient recp in Throttling.Transactions.Values)
            {
                // Console.WriteLine("Sending Transaction {0}  ",  recp.address);
                if (!recp.is_sent && !recp.is_error)
                {
                    try
                    {
                        await walletUtils.SendCoin(recp);
                    }
                    catch (FaucetException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }

            Throttling.Manage();
        }
예제 #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            Throttling.Init();
            JobExecutor.Init(new WalletUtils(Configuration));
        }
 protected virtual void OnThrottling(EventArgs e)
 {
     Throttling?.Invoke(this, e);
 }
 void DisableAllThermalWarnings()
 {
     NoWarning.SetActive(false);
     ThrottlingImminent.SetActive(false);
     Throttling.SetActive(false);
 }
예제 #11
0
 public ThrottlingMiddleware(RequestDelegate next, IOptions <Throttling> throttlingSettings, ThrottlingDemoService throttlingDemoService)
 {
     this.next = next;
     this.throttlingSettings    = throttlingSettings.Value;
     this.throttlingDemoService = throttlingDemoService;
 }