Skip to content

Commit

Permalink
Fix #1 Update Azure SDK, Add number of lines to scan
Browse files Browse the repository at this point in the history
Migrate from version 1.7 to 4.2 of Azure Storage SDK.
Add a setting to driver to define number of lines to scan to determine the schema of a table.
  • Loading branch information
Mauricio Diaz Orlich committed Aug 20, 2014
1 parent 76c1a6d commit e58cfe3
Show file tree
Hide file tree
Showing 11 changed files with 414 additions and 215 deletions.
47 changes: 12 additions & 35 deletions Madd0.AzureStorageDriver/AzureDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Madd0.AzureStorageDriver
using System.Reflection;
using LINQPad.Extensibility.DataContext;
using Madd0.AzureStorageDriver.Properties;
using Madd0.UserQuery;
using Microsoft.WindowsAzure.Storage.Table.DataServices;

/// <summary>
/// LINQPad dynamic driver that lets users connect to an Azure Table Storage account.
Expand Down Expand Up @@ -55,7 +57,9 @@ public override bool ShowConnectionDialog(IConnectionInfo connectionInfo, bool i
{
if (isNewConnection)
{
new StorageAccountProperties(connectionInfo).UseLocalStorage = true;
var prop = new StorageAccountProperties(connectionInfo);
prop.UseHttps = true;
prop.NumberOfRows = 100;
}

bool? result = new ConnectionDialog(connectionInfo).ShowDialog();
Expand Down Expand Up @@ -84,8 +88,8 @@ public override IEnumerable<string> GetAssembliesToAdd()
{
return new string[]
{
"System.Data.Services.Client.dll",
"Microsoft.WindowsAzure.StorageClient.dll"
"Microsoft.WindowsAzure.Storage.dll",
"Microsoft.Data.Services.Client.dll"
};
}

Expand All @@ -97,9 +101,9 @@ public override IEnumerable<string> GetNamespacesToAdd()
{
return new string[]
{
"System.Data.Services.Client",
"Microsoft.WindowsAzure",
"Microsoft.WindowsAzure.StorageClient"
"Microsoft.WindowsAzure.Storage",
"Microsoft.WindowsAzure.Storage.Table"
};
}

Expand Down Expand Up @@ -135,9 +139,7 @@ public override object[] GetContextConstructorArguments(IConnectionInfo connecti

return new object[]
{
storageAccount.TableEndpoint.ToString(),
storageAccount.Credentials,
storageAccount
storageAccount.CreateCloudTableClient()
};
}

Expand All @@ -150,34 +152,9 @@ public override object[] GetContextConstructorArguments(IConnectionInfo connecti
public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo connectionInfo)
{
return new[]
{
new ParameterDescriptor("baseAddress", "System.String"),
new ParameterDescriptor("credentials", "Microsoft.WindowsAzure.StorageCredentials"),
new ParameterDescriptor("account", "Microsoft.WindowsAzure.CloudStorageAccount")
{
new ParameterDescriptor("client", "Microsoft.WindowsAzure.Storage.Table.CloudTableClient ")
};
}

/// <summary>
/// Initializes the data context.
/// </summary>
/// <remarks>In this driver, initialization consists of listening to the
/// <see cref="DataServiceContext.SendingRequest"/> event in order to extract the requested
/// URI and display it in the SQL tab.</remarks>
/// <param name="connectionInfo">The connection info.</param>
/// <param name="context">The context.</param>
/// <param name="executionManager">The execution manager.</param>
public override void InitializeContext(IConnectionInfo connectionInfo, object context, QueryExecutionManager executionManager)
{
/* Write Azure HTTP reuests to SQL tab in LinqPAD
* Skip if SqlTranslationWriter is not available
*/

var dsContext = context as DataServiceContext;
if (dsContext == null) return;

if (executionManager.SqlTranslationWriter == null) return;

dsContext.SendingRequest += (sender, e) => executionManager.SqlTranslationWriter.WriteLine(e.Request.RequestUri);
}
}
}
95 changes: 76 additions & 19 deletions Madd0.AzureStorageDriver/ConnectionDialog.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<Window x:Class="Madd0.AzureStorageDriver.ConnectionDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Width="400"
Title="Azure Storage Account" ResizeMode="NoResize"
SizeToContent="Height" WindowStartupLocation="CenterScreen" Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}">
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="Azure Storage Account"
Width="400"
Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}"
ResizeMode="NoResize"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Window.Resources>
<Style TargetType="TextBox">
<Style.Triggers>
Expand All @@ -17,26 +21,69 @@
</Style>
</Window.Resources>
<StackPanel Margin="7">

<Label Padding="0 0 0 3">Storage account name:</Label>

<DockPanel>
<CheckBox TabIndex="2" Content="Use _development storage" VerticalAlignment="Center"
Margin="30 0 0 0" DockPanel.Dock="Right"
<CheckBox x:Name="UseDevelopmentStorage"
Margin="30 0 0 0"
VerticalAlignment="Center"
Content="Use _development storage"
DockPanel.Dock="Right"
IsChecked="{Binding UseLocalStorage}"
x:Name="UseDevelopmentStorage" />
TabIndex="2" />
<TextBox TabIndex="1" Text="{Binding AccountName}" />
</DockPanel>

<Label Padding="0 0 0 3">Storage account key:</Label>
<TextBox TabIndex="3" Text="{Binding AccountKey}" />

<CheckBox TabIndex="4" Content="_Use HTTPS" Margin="0 10 0 0"
IsChecked="{Binding UseHttps}" />
<CheckBox TabIndex="5" Content="_Remember this connection" Margin="0 5 0 0"
IsChecked="{Binding Persist}" />

<DockPanel LastChildFill="False" Margin="0 10 0 0">
<CheckBox Margin="0 10"
Content="_Remember this connection"
IsChecked="{Binding Persist}"
TabIndex="5" />

<Expander Header="_Advanced">
<Expander.Style>
<Style TargetType="Expander">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=UseDevelopmentStorage}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Expander.Style>
<StackPanel Margin="23 5 0 0">
<CheckBox Margin="0"
Content="_Use HTTPS"
IsChecked="{Binding UseHttps}"
TabIndex="4" />
<StackPanel Margin="0 10" Orientation="Horizontal">
<TextBlock>Number of lines to sample:</TextBlock>
<TextBox Width="50"
Margin="5 0"
Text="{Binding NumberOfRows}"
TextAlignment="Right" />
<Grid>
<Grid.ToolTip>
<ToolTip>
<TextBlock>The number of lines that will be read in order to determine the schema of an Azure Table.</TextBlock>
</ToolTip>
</Grid.ToolTip>
<Ellipse Width="15"
Height="15"
Fill="#3CA1C8" />
<TextBlock Margin="0 1 0 0"
HorizontalAlignment="Center"
FontWeight="Bold"
Foreground="White"
Text="?" />
</Grid>
</StackPanel>
</StackPanel>
</Expander>

<DockPanel Margin="0 10 0 0" LastChildFill="False">
<DockPanel.Resources>
<Style TargetType="Button">
<Setter Property="DockPanel.Dock" Value="Right" />
Expand All @@ -46,9 +93,19 @@
</Style>
</DockPanel.Resources>

<Button TabIndex="7" Grid.Row="5" Grid.Column="1" IsCancel="True">_Cancel</Button>
<Button TabIndex="6" Grid.Row="5" IsDefault="True" Click="OnOkClick">_OK</Button>
<Button Grid.Row="5"
Grid.Column="1"
IsCancel="True"
TabIndex="7">
_Cancel
</Button>
<Button Grid.Row="5"
Click="OnOkClick"
IsDefault="True"
TabIndex="6">
_OK
</Button>
</DockPanel>

</StackPanel>
</Window>
Loading

0 comments on commit e58cfe3

Please sign in to comment.