Skip to content

Instantly share code, notes, and snippets.

@NineMvp
NineMvp / IPAddressThrottlingHandlers.cs
Last active August 29, 2015 14:19
IPAddressThrottlingHandlers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Http;
using WebApiContrib.Caching;
using WebApiContrib.MessageHandlers;
public class IPAddressThrottlingHandlers : ThrottlingHandler
{
public IPAddressThrottlingHandlers(IThrottleStore store, Func<string, long> maxRequestsForIpAddress, TimeSpan period, string message)
@NineMvp
NineMvp / BalanceController.cs
Created April 24, 2015 21:01
BalanceController
public class BalanceController : ApiController
{
[HttpGet]
public HttpResponseMessage Get()
{
return Request.CreateResponse(HttpStatusCode.OK,
new List<Balance>
{
new Balance{ Date = new DateTime(2014,02,01), Amount = 500m },
new Balance{ Date = new DateTime(2014,02,05), Amount = 400m },
@NineMvp
NineMvp / ThrottlingHandler.cs
Last active August 29, 2015 14:19
ThrottlingHandler
var throttlingHandler = new ThrottlingHandler(
new InMemoryThrottleStore(),
quota => 10,
TimeSpan.FromMinutes(1),
"Exceed the limit 10 requests per minute!");
config.MessageHandlers.Add(throttlingHandler);
@NineMvp
NineMvp / MyConfig.cs
Last active August 29, 2015 14:22
DemoConfig
using FX.Configuration;
public class MyConfig : JsonConfiguration
{
public MyConfig() : base("MyConfig.json") { }
public string Name { get; set; }
public int Count { get; set; }
public int[] Ports { get; set; }
public DateTime StartDate { get; set; }
@NineMvp
NineMvp / myconfig.json
Last active August 29, 2015 14:22
MyConfig.json
{
"Name": "Config",
"Count": 30,
"Ports": [ 9001, 9002, 9003 ],
"StartDate": "2015-06-01",
"RecycleTime" : "0.0:1:00",
"Server": {
"Name": "Server 1",
"IP": "10.10.10.10"
@NineMvp
NineMvp / Program.cs
Created June 3, 2015 17:35
Program.cs
class Program
{
static void Main(string[] args)
{
var config = new MyConfig();
Console.WriteLine(config.ToString());
Console.Read();
}
PM> Install-Package AKKA <Enter>
Attempting to gather dependencies information for package 'akka.1.0.5' with respect to project 'ConsoleApplication1', targeting '.NETFramework,Version=v4.6.1'
.....................
Successfully installed 'Akka 1.0.5' to ConsoleApplication1
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Akka" version="1.0.5" targetFramework="net461" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net461" />
</packages>
using System;
using Akka.Actor;
namespace ConsoleApplication1
{
public class SmsSenderActor : ReceiveActor
{
public SmsSenderActor()
{
Receive<string>(message => Console.WriteLine(message));
using System;
using Akka.Actor;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var smsActorSystem = ActorSystem.Create("SmsActorSystem");
Console.WriteLine("Actor System Created");