Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ac43a2a
Merge pull request #1 from KBS-ASD/develop
BramblePie Nov 29, 2018
9ac9ea7
Merge pull request #2 from BramblePie/develop
BramblePie Nov 29, 2018
ac7da65
Test commit to fork Bram
BramblePie Nov 29, 2018
153bb3d
Test commit to fork Bram
BramblePie Nov 29, 2018
e7ec184
Merge branch 'develop' of https://github.com/BramblePie/message-bus-p…
BramblePie Nov 29, 2018
64b8d4d
Merge pull request #3 from BramblePie/develop
BramblePie Nov 29, 2018
ac8faf6
Added singleton bus control, publish byte array and publish a like to…
BramblePie Nov 29, 2018
2f0063a
Merge pull request #4 from BramblePie/develop
BramblePie Nov 29, 2018
9e4190a
BusControl needs to be stopped
BramblePie Nov 29, 2018
6201d92
Merge pull request #5 from BramblePie/develop
BramblePie Nov 29, 2018
1b61761
Update src/KBS.FauxApplication/SingleBusControl.cs
Dec 3, 2018
3c20ebd
Update src/KBS.FauxApplication/FauxApp.cs
Dec 3, 2018
8ac4239
Update src/KBS.FauxApplication/FauxApp.cs
Dec 3, 2018
d1742e3
Update src/KBS.Messages/IFauxMessage.cs
Dec 3, 2018
d445c29
Added TODO
BramblePie Dec 3, 2018
5f0ce6a
Clarification of temporality of the like counter
BramblePie Dec 3, 2018
566e61e
No RabbitMQ
BramblePie Dec 3, 2018
f908fd3
Run CodeMaid and rename variables
BramblePie Dec 3, 2018
127cdce
Added randomizer with noise generator
BramblePie Dec 3, 2018
ba5d1f6
CodeMaid cleanup
BramblePie Dec 3, 2018
faf4d95
#33 Set up CI with Azure Pipelines
Nov 28, 2018
200681b
#21 start api controller, connected infrastructure to controller.
GerwinvBeek Nov 29, 2018
0cbd248
renaming IManager in infrastructure
GerwinvBeek Dec 3, 2018
e91c77f
renamed and moved files, also added some xml documentation
GerwinvBeek Dec 3, 2018
15d6c9c
Add web.config
Dec 3, 2018
d2468b0
Update src/KBS.FauxApplication/Configuration.cs
Dec 3, 2018
a34939b
Added randomizer with noise generator
BramblePie Dec 3, 2018
a3925b5
Merge branch 'develop' into feature/faux-application-setup-#24
Dec 3, 2018
5b082a2
Merge branch 'develop' into feature/faux-application-setup-#24
BramblePie Dec 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/KBS.Controller/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using KBS.Infrastructure;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -17,13 +17,13 @@ namespace KBS.Controller
{
public class Startup
{
private IConfiguration Configuration { get; }

public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
Expand Down
2 changes: 0 additions & 2 deletions src/KBS.ControllerTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Xunit;

namespace KBS.ControllerTests
Expand All @@ -8,7 +7,6 @@ public class UnitTest1
[Fact]
public void Test1()
{

}
}
}
24 changes: 24 additions & 0 deletions src/KBS.FauxApplication/FauxApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Threading.Tasks;
using KBS.Messages;

namespace KBS.FauxApplication
{
public class FauxApp : SingleBusControl
{
private readonly Random random = new Random();

/// <summary>
/// Publish an array of random bytes
/// </summary>
/// <param name="arraySize">Size of the array to publish</param>
public Task PublishRandomBytes(uint arraySize)
{
byte[] bytes = new byte[arraySize];
random.NextBytes(bytes);
return BusControl.Publish<IFauxMessage>(new { ByteArray = bytes });
}

public Task PublishLike() => BusControl.Publish<ILiked>(new { });
}
}
8 changes: 8 additions & 0 deletions src/KBS.FauxApplication/KBS.FauxApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MassTransit" Version="5.1.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KBS.Messages\KBS.Messages.csproj" />
</ItemGroup>

</Project>
21 changes: 17 additions & 4 deletions src/KBS.FauxApplication/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
using System;
using System;
using System.Threading;

namespace KBS.FauxApplication
{
class Program
internal static class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
Console.WriteLine("Hello World!");
// TODO: Configurable setup
var fauxApplication = new FauxApp();
var randomizer = new Randomizer(1, 40, 4, 66);

for (var i = 0; i < 10; i++)
{
//fauxApplication.PublishRandomBytes(1048576);
fauxApplication.PublishLike();
Thread.Sleep(randomizer.GetNextNoiseInt());
}

Console.Read();
fauxApplication.StopBusControl();
}
}
}
79 changes: 79 additions & 0 deletions src/KBS.FauxApplication/Randomizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;

namespace KBS.FauxApplication
{
internal class Randomizer
{
/// <summary>
/// Random number generator
/// </summary>
private readonly Random random;

/// <summary>
/// Previously generated noise value, needed to generate next value
/// </summary>
private double noiseValue;

/// <summary>
/// The randomizer for generating noise or other random values for simulation
/// </summary>
/// <param name="lowerLimt">Inclusive lower limit of random value</param>
/// <param name="upperLimit">Exclusive upper limit of random value</param>
/// <param name="smoothness">Rate of change in generated noise, higher smoothness means lower rate of change</param>
public Randomizer(int lowerLimit, int upperLimit, double smoothness)
{
LowerLimit = lowerLimit;
UpperLimit = upperLimit;
Smoothness = smoothness;
random = new Random();
noiseValue = NextDouble;
}

/// <summary>
/// The randomizer for generating noise or other random values for simulation
/// </summary>
/// <param name="lowerLimt">Inclusive lower limit of random value</param>
/// <param name="upperLimit">Exclusive upper limit of random value</param>
/// <param name="smoothness">Rate of change in generated noise, higher smoothness means lower rate of change</param>
/// <param name="seed">Seed for random generator</param>
public Randomizer(int lowerLimt, int upperLimit, double smoothness, int seed) : this(lowerLimt, upperLimit, smoothness)
{
random = new Random(seed);
noiseValue = NextDouble;
}

/// <summary>
/// Get next noise value within the limits given in the contructor
/// </summary>
/// <returns>Next noise value rounded to an integer</returns>
public int GetNextNoiseInt()
{
double next = random.NextDouble() / Smoothness - (0.5 / Smoothness);
if (noiseValue + next > UpperLimit || noiseValue + next < LowerLimit)
noiseValue -= next;
else
noiseValue += next;
return (int)noiseValue;
}

/// <summary>
/// Inclusive lower limit of random value
/// </summary>
public int LowerLimit { get; }

/// <summary>
/// Exclusive upper limit of random value
/// </summary>
public int UpperLimit { get; }

/// <summary>
/// Rate of change in generated noise, higher smoothness means lower rate of change
/// </summary>
public double Smoothness { get; }

/// <summary>
/// Random double within the limits given in the contructor, this is NO noise!
/// </summary>
private double NextDouble { get => random.NextDouble() * (UpperLimit - LowerLimit) + LowerLimit; }
}
}
55 changes: 55 additions & 0 deletions src/KBS.FauxApplication/SingleBusControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using KBS.Messages;
using MassTransit;

namespace KBS.FauxApplication
{
/// <summary>
/// Holds the bus control singleton
/// </summary>
public abstract class SingleBusControl
{
private static readonly object busLock = new object();
private static volatile IBusControl busControl;

/// <summary>
/// Get the bus control singleton, it's already started
/// </summary>
protected IBusControl BusControl
{
get
{
if (busControl == null)
{
lock (busLock)
{
if (busControl == null)
{
busControl = CreateBusControl();
BusControl.Start();
}
}
}
return busControl;
}
}

public void StopBusControl() => BusControl.Stop();

/// <summary>
/// Creates a new bus with respective queues
/// </summary>
/// <returns>Returns a new bus control</returns>
private static IBusControl CreateBusControl()
{
return Bus.Factory.CreateUsingInMemory(cfg =>
{
cfg.ReceiveEndpoint("queue_name", ep =>
{
ep.Handler<ILiked>(_ => Console.Out.WriteLineAsync(ILikeCounter.Likes.ToString()));
ep.Handler<IFauxMessage>(_ => Console.Out.WriteLineAsync("Bytes received"));
});
});
}
}
}
2 changes: 0 additions & 2 deletions src/KBS.FauxApplicationTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Xunit;

namespace KBS.FauxApplicationTests
Expand All @@ -8,7 +7,6 @@ public class UnitTest1
[Fact]
public void Test1()
{

}
}
}
2 changes: 0 additions & 2 deletions src/KBS.InfrastructureTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Xunit;

namespace KBS.InfrastructureTests
Expand All @@ -8,7 +7,6 @@ public class UnitTest1
[Fact]
public void Test1()
{

}
}
}
2 changes: 0 additions & 2 deletions src/KBS.MessageBus/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace KBS.MessageBus
{
public class Class1
Expand Down
2 changes: 0 additions & 2 deletions src/KBS.MessageBusTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Xunit;

namespace KBS.MessageBusTests
Expand All @@ -8,7 +7,6 @@ public class UnitTest1
[Fact]
public void Test1()
{

}
}
}
2 changes: 0 additions & 2 deletions src/KBS.Messages/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace KBS.Messages
{
public class Class1
Expand Down
13 changes: 13 additions & 0 deletions src/KBS.Messages/IFauxMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KBS.Messages
{
/// <summary>
/// A messages interface of a meaningless message, filled with a byte array
/// </summary>
public interface IFauxMessage
{
/// <summary>
/// A byte array used to bloat the message
/// </summary>
byte[] ByteArray { get; }
}
}
13 changes: 13 additions & 0 deletions src/KBS.Messages/LikeCounter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace KBS.Messages
{
/// <summary>
/// Very temporary example of a simple like counter
/// </summary>
public static class ILikeCounter
{
private static volatile int likes;
public static int Likes { get => ++likes; }
}

public interface ILiked { }
}