Skip to content

Commit 04ef961

Browse files
Made Device name optional
1 parent 089e720 commit 04ef961

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

EventHub.RestClientGenerator/EventHubLogic/RestUriAndSharedAccessSignatureGenerator.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class RestUriAndSharedAccessSignatureGenerator
99
private string _publisherName;
1010
private TimeSpan _tokenLifeTime;
1111

12-
public RestUriAndSharedAccessSignatureGenerator(ConnectionDetails connectionDetails,string publisherName,TimeSpan tokenLifeTime)
12+
public RestUriAndSharedAccessSignatureGenerator(ConnectionDetails connectionDetails, string publisherName, TimeSpan tokenLifeTime)
1313
{
1414
_connectionDetails = connectionDetails;
1515
_publisherName = publisherName;
@@ -18,9 +18,18 @@ public RestUriAndSharedAccessSignatureGenerator(ConnectionDetails connectionDeta
1818

1919
public string GetEventHubRestUri()
2020
{
21-
return ServiceBusEnvironment.CreateServiceUri("https", _connectionDetails.EventHubNamespace, $"{_connectionDetails.EventHubName}/publishers/{_publisherName}/messages")
22-
.ToString()
23-
.Trim('/');
21+
if (string.IsNullOrWhiteSpace(_publisherName))
22+
{
23+
return ServiceBusEnvironment.CreateServiceUri("https", _connectionDetails.EventHubNamespace, $"{_connectionDetails.EventHubName}/messages")
24+
.ToString()
25+
.Trim('/');
26+
}
27+
else
28+
{
29+
return ServiceBusEnvironment.CreateServiceUri("https", _connectionDetails.EventHubNamespace, $"{_connectionDetails.EventHubName}/publishers/{_publisherName}/messages")
30+
.ToString()
31+
.Trim('/');
32+
}
2433
}
2534

2635
public string GenerateSharedAccessSignature()

EventHub.RestClientGenerator/View/InputView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<Label Grid.Row="1" Content="Event Hub Connection String"/>
2525
<TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" Text="{Binding ConnectionString,UpdateSourceTrigger=PropertyChanged}" Height="50" TextWrapping="Wrap"/>
2626

27-
<Label Grid.Row="2" Content="Publisher / Device name"/>
27+
<Label Grid.Row="2" Content="Device name (optional)"/>
2828
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding PublisherName,UpdateSourceTrigger=PropertyChanged}" />
2929

3030
<Label Grid.Row="2" Grid.Column="2" Content="Token Lifetime"/>

EventHub.RestClientGenerator/View/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</Grid.RowDefinitions>
1717

1818
<TextBlock FontWeight="Bold" Foreground="#CCCCCC" Margin="5" TextWrapping="Wrap">This tool generates the Shared Access Signature and a smal UWP-client-class to access the Rest-API of an Azure Event Hub.
19-
Just enter the connection string, the publisher name and the token lifetime. Find more information by <Hyperlink NavigateUri="http://www.thomasclaudiushuber.com/blog/2016/05/13/calling-the-azure-event-hub-rest-api-from-uwp-wpf-and-any-other-net-core-client" RequestNavigate="Hyperlink_RequestNavigate">clicking here</Hyperlink>.</TextBlock>
19+
Just enter the connection string, the token lifetime and optionally a publisher name. Find more information by <Hyperlink NavigateUri="http://www.thomasclaudiushuber.com/blog/2016/05/13/calling-the-azure-event-hub-rest-api-from-uwp-wpf-and-any-other-net-core-client" RequestNavigate="Hyperlink_RequestNavigate">clicking here</Hyperlink>.</TextBlock>
2020

2121
<view:InputView Grid.Row="1" Margin="0 10 0 0"/>
2222

EventHub.RestClientGenerator/ViewModel/MainViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,11 @@ private void GenerateOutput()
170170
}
171171
}
172172

173-
// TODO: Put this in a try-catch to find out too big values
173+
// Note: Put this in a try-catch to find out too big values for TimeSpan
174174
TimeSpan tokenLifeTime = GetTokenLifeTime(tokenLifeTimeInt);
175175

176176
if (!_errorsByPropertyName.Any()
177-
&& !string.IsNullOrWhiteSpace(ConnectionString)
178-
&& !string.IsNullOrWhiteSpace(PublisherName))
177+
&& !string.IsNullOrWhiteSpace(ConnectionString))
179178
{
180179
var generator = new RestUriAndSharedAccessSignatureGenerator(details, PublisherName, tokenLifeTime);
181180
SharedAccessSignature = generator.GenerateSharedAccessSignature();

0 commit comments

Comments
 (0)