Skip to content

Commit

Permalink
Merge branch 'master' into issue/838
Browse files Browse the repository at this point in the history
  • Loading branch information
einari committed Jul 2, 2017
2 parents a0c00f3 + 6425df2 commit b7864e7
Show file tree
Hide file tree
Showing 43 changed files with 977 additions and 168 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -5,6 +5,7 @@
*.gif binary
*.dll binary
*.exe binary
*.ttf binary

*.cs diff=csharp
*.sln text eol=crlf
65 changes: 65 additions & 0 deletions Documentation/Frontend/JavaScript/origins.md
@@ -0,0 +1,65 @@
---
title: About Origins
description: Learn how to configure origins
keywords: Frontend
author: einari
---

# Origins

Bifrost has a relationship with files and artifacts hosted on the server. Typically these are views, viewmodels and API calls
for instance for executing a command or a query.

By default everything will be relative to where the initial document is being loaded.


## Attributes

There are two `data-*` attributes that can be used:

```
data-files-origin
data-apis-origin
```

There are a couple of ways you can use these.
If you want the origin of these to be relative to where you're for instance getting the `/Bifrost/Application` bundle, you
can simply do as follows:

```html
<script src="/Bifrost/Application" data-files-origin data-apis-origin></script>
```

By not setting a specific value, Bifrost will look at the actual `src` of the script tag. This will only work for element types that
has the `src` attribute, typically a `script` tag.

You can be very specific about the origin by setting a value instead:

```html
<script src="/Bifrost/Application"
data-files-origin="http://someplace"
data-apis-origin="http://someotherplace"></script>
```

You can also add these to the body or any element within it:

```html
<body data-files-origin="http://someplace"
data-apis-origin="http://someotherplace">

</body>
```


## JavaScript

Another option is to programatically using JavaScript assign the values within a `script`.

```html
<script>
var configuration = Bifrost.configuration.create();
configuration.origins.files = "http://www.db.no";
configuration.origins.APIs = "http://www.vg.no";
</script>
```

4 changes: 3 additions & 1 deletion Documentation/Frontend/JavaScript/toc.yml
@@ -1,5 +1,7 @@
- name: Getting started
- name: Getting started
href: getting_started.md
- name: Origins
href: origins.md
- name: Proxy Generation
href: proxy_generation.md
- name: Commands
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Tutorials/quickstart.md
Expand Up @@ -57,7 +57,7 @@ With the quickstart you get a Web based project that showcases Bifrost in an [en
* Manage the NuGet packages for the project:
![Manage NuGet Packages](quickstart_images/manage_nuget_packages.png)

* Browse / Search for Bifrost and find the QuickStart package and then click **Install**:
* Browse / Search for Bifrost and find the latest QuickStart package and then click **Install**:
![Find correct NuGet Package](quickstart_images/find_package.png)

* During installation it will ask you accept licenses, accept these:
Expand Down
@@ -0,0 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard1.6</TargetFrameworks>
<AssemblyName>Bifrost.Events.Azure.ServiceBus</AssemblyName>
<PackageId>Bifrost.Events.Azure.ServiceBus</PackageId>
<DocumentationFile>bin\Debug\net461\Bifrost.Events.Azure.ServiceBus.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup>
<Version>1.0.0</Version>
<Description>Bifrost is a platform designed to build Line of Business applications without sacrificing architectural quality, code quality or scalability.</Description>
<Copyright>Copyright 2008 - 2017 Dolittle</Copyright>
<Authors>all contributors</Authors>
<TargetFrameworks>net461;netstandard1.6</TargetFrameworks>
<DebugType>portable</DebugType>
<PackageTags>MVVM;SOLID;CQRS;LOB</PackageTags>
<PackageReleaseNotes>https://github.com/dolittle/Bifrost/blob/master/CHANGELOG.md</PackageReleaseNotes>
<PackageIconUrl>https://github.com/dolittle/Bifrost/raw/master/Media/Logo/logo_128x128.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/dolittle/Bifrost/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/dolittle/bifrost</RepositoryUrl>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net461|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TreatSpecificWarningsAsErrors />
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<None Update="**\*.cs">
<PackagePath>src/</PackagePath>
<Pack>true</Pack>
</None>
<None Update="bin\Release\netstandard1.6\*.pdb">
<PackagePath>lib/netstandard1.6/</PackagePath>
<Pack>true</Pack>
</None>
<None Update="bin\Release\net461\*.pdb">
<PackagePath>lib/net461/</PackagePath>
<Pack>true</Pack>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="0.0.5-preview" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bifrost\Bifrost.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Dynamic" />
</ItemGroup>

</Project>
110 changes: 110 additions & 0 deletions Source/Bifrost.Events.Azure.ServiceBus/CommittedEventStreamReceiver.cs
@@ -0,0 +1,110 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Bifrost.Applications;
using Bifrost.Lifecycle;
using Bifrost.Serialization;
using Microsoft.Azure.ServiceBus;

namespace Bifrost.Events.Azure.ServiceBus
{
/// <summary>
/// Represents an implementation of <see cref="ICanReceiveCommittedEventStream"/> for Azure ServiceBus
/// </summary>
public class CommittedEventStreamReceiver : ICanReceiveCommittedEventStream
{
readonly ISerializer _serializer;
readonly IApplicationResourceIdentifierConverter _applicationResourceIdentifierConverter;
readonly IApplicationResourceResolver _applicationResourceResolver;
readonly QueueClient _queueClient;

/// <inheritdoc/>
public event CommittedEventStreamReceived Received = (e) => { };

/// <summary>
/// Initializes a new instance of <see cref="CommittedEventStreamCoordinator"/>
/// </summary>
/// <param name="serializer"><see cref="ISerializer"/> to use for deserializing <see cref="IEvent">events</see></param>
/// <param name="applicationResourceIdentifierConverter"><see cref="IApplicationResourceIdentifierConverter"/> used for converting resource identifiers</param>
/// <param name="applicationResourceResolver"><see cref="IApplicationResourceResolver"/> used for resolving types from <see cref="IApplicationResourceIdentifier"/></param>
/// <param name="connectionStringProvider"><see cref="ICanProvideConnectionStringToReceiver">Provider</see> of connection string</param>
public CommittedEventStreamReceiver(
ISerializer serializer,
IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
IApplicationResourceResolver applicationResourceResolver,
ICanProvideConnectionStringToReceiver connectionStringProvider)
{
_serializer = serializer;
_applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
_applicationResourceResolver = applicationResourceResolver;

var connectionString = connectionStringProvider();
_queueClient = new QueueClient(connectionString, Constants.QueueName, ReceiveMode.PeekLock);
_queueClient.RegisterMessageHandler(Receive);
}



Task Receive(Message message, CancellationToken token)
{
var dynamicEventsAndEnvelopes = new List<dynamic>();
var json = System.Text.Encoding.UTF8.GetString(message.Body);

_serializer.FromJson(dynamicEventsAndEnvelopes, json);

var eventsAndEnvelopes = new List<EventAndEnvelope>();

foreach (var dynamicEventAndEnvelope in dynamicEventsAndEnvelopes)
{
var env = dynamicEventAndEnvelope.Envelope;

var correlationId = (TransactionCorrelationId)Guid.Parse(env.CorrelationId.ToString());
var eventId = (EventId)Guid.Parse(env.EventId.ToString());
var sequenceNumber = (EventSequenceNumber)long.Parse(env.SequenceNumber.ToString());
var sequenceNumberForEventType = (EventSequenceNumber)long.Parse(env.SequenceNumberForEventType.ToString());
var generation = (EventGeneration)long.Parse(env.Generation.ToString());
var @event = _applicationResourceIdentifierConverter.FromString(env.Event.ToString());
var eventSourceId = (EventSourceId)Guid.Parse(env.EventSourceId.ToString());
var eventSource = _applicationResourceIdentifierConverter.FromString(env.EventSource.ToString());
var version = (EventSourceVersion)EventSourceVersion.FromCombined(double.Parse(env.Version.ToString()));
var causedBy = (CausedBy)env.CausedBy.ToString();
var occurred = DateTimeOffset.Parse(env.Occurred.ToString());

var envelope = new EventEnvelope(
correlationId,
eventId,
sequenceNumber,
sequenceNumberForEventType,
generation,
@event,
eventSourceId,
eventSource,
version,
causedBy,
occurred
);

var eventType = _applicationResourceResolver.Resolve(@event);

var eventInstance = Activator.CreateInstance(eventType, new object[] { eventSourceId }) as IEvent;
var e = dynamicEventAndEnvelope.Event.ToString();

_serializer.FromJson(eventInstance, e);
eventsAndEnvelopes.Add(new EventAndEnvelope(envelope, eventInstance));
}

var stream = new CommittedEventStream(eventsAndEnvelopes.First().Envelope.EventSourceId, eventsAndEnvelopes);
Received(stream);

_queueClient.CompleteAsync(message.SystemProperties.LockToken);

return Task.CompletedTask;
}
}
}
@@ -0,0 +1,54 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
using Bifrost.Dynamic;
using Bifrost.Serialization;
using Microsoft.Azure.ServiceBus;

namespace Bifrost.Events.Azure.ServiceBus
{
/// <summary>
/// Represents an implementation of <see cref="ICanSendCommittedEventStream"/> for Azure ServiceBus
/// </summary>
public class CommittedEventStreamSender : ICanSendCommittedEventStream
{
readonly ISerializer _serializer;
readonly string _connectionString;
readonly IQueueClient _queueClient;

/// <summary>
/// Initializes a new instance of <see cref="CommittedEventStreamSender"/>
/// </summary>
/// <param name="serializer"><see cref="ISerializer"/> used for serializing messages</param>
/// <param name="connectionStringProvider"><see cref="ICanProvideConnectionStringToSender">Provider</see> for connectionstring</param>
public CommittedEventStreamSender(ICanProvideConnectionStringToSender connectionStringProvider, ISerializer serializer)
{
_serializer = serializer;
_connectionString = connectionStringProvider();

_queueClient = new QueueClient(_connectionString, Constants.QueueName, ReceiveMode.PeekLock, RetryPolicy.Default);
}

/// <inheritdoc/>
public void Send(CommittedEventStream committedEventStream)
{
var eventsToSend = new List<dynamic>();
foreach (var eventAndEnvelope in committedEventStream)
{
dynamic eventToSend = new ExpandoObject();
eventToSend.Envelope = eventAndEnvelope.Envelope;
eventToSend.Event = eventAndEnvelope.Event.AsExpandoObject();
eventsToSend.Add(eventToSend);
}

var eventsToSendAsJson = _serializer.ToJson(eventsToSend);
var messageBodyBytes = Encoding.UTF8.GetBytes(eventsToSendAsJson);
var message = new Message(messageBodyBytes);
_queueClient.SendAsync(message);
}
}
}
42 changes: 42 additions & 0 deletions Source/Bifrost.Events.Azure.ServiceBus/ConfigurationExtensions.cs
@@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
using Bifrost.Configuration;
using Bifrost.Events.Azure.ServiceBus;

namespace Bifrost.Events
{
/// <summary>
/// Extensions for configuring RabbitMQ related communication for <see cref="IEvent">events</see>
/// </summary>
public static class ConfigurationExtensions
{
/// <summary>
/// Configure <see cref="ICanSendCommittedEventStream"/> using RabbitMQ
/// </summary>
/// <param name="configuration"><see cref="CommittedEventStreamReceiverConfiguration"/> to configure</param>
/// <param name="connectionString">ConnectionString to connect with</param>
/// <returns>Chained <see cref="CommittedEventStreamReceiverConfiguration"/></returns>
public static CommittedEventStreamSenderConfiguration UsingServiceBus(this CommittedEventStreamSenderConfiguration configuration, string connectionString)
{
configuration.CommittedEventStreamSender = typeof(CommittedEventStreamSender);
Configure.Instance.Container.Bind<ICanProvideConnectionStringToSender>(() => connectionString);
return configuration;
}


/// <summary>
/// Configure <see cref="ICanReceiveCommittedEventStream"/> using RabbitMQ
/// </summary>
/// <param name="configuration"><see cref="CommittedEventStreamReceiverConfiguration"/> to configure</param>
/// <param name="connectionString">ConnectionString to connect with</param>
/// <returns>Chained <see cref="CommittedEventStreamReceiverConfiguration"/></returns>
public static CommittedEventStreamReceiverConfiguration UsingServiceBus(this CommittedEventStreamReceiverConfiguration configuration, string connectionString)
{
configuration.CommittedEventStreamReceiver = typeof(CommittedEventStreamReceiver);
Configure.Instance.Container.Bind<ICanProvideConnectionStringToReceiver>(() => connectionString);
return configuration;
}
}
}
17 changes: 17 additions & 0 deletions Source/Bifrost.Events.Azure.ServiceBus/Constants.cs
@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
namespace Bifrost.Events.Azure.ServiceBus
{
/// <summary>
/// Holds constants used
/// </summary>
public class Constants
{
/// <summary>
/// The name of the queue being used
/// </summary>
public const string QueueName = "BifrostQueue";
}
}
@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2008-2017 Dolittle. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
namespace Bifrost.Events.Azure.ServiceBus
{
/// <summary>
/// Defines something that can provide a connection string for Redis
/// </summary>
public delegate string ICanProvideConnectionStringToReceiver();
}

0 comments on commit b7864e7

Please sign in to comment.