Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
madd0 committed Jan 8, 2012
1 parent 1eb6be2 commit 512dbae
Show file tree
Hide file tree
Showing 15 changed files with 1,268 additions and 189 deletions.
78 changes: 71 additions & 7 deletions Madd0.AzureStorageDriver/AzureDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

namespace Madd0.AzureStorageDriver
{
using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Reflection;
using LINQPad.Extensibility.DataContext;
using Madd0.AzureStorageDriver.Properties;

Expand All @@ -18,6 +19,9 @@ namespace Madd0.AzureStorageDriver
/// </summary>
public class AzureDriver : DynamicDataContextDriver
{
/// <summary>
/// Gets the name of the driver author.
/// </summary>
public override string Author
{
get { return Resources.AuthorName; }
Expand All @@ -39,6 +43,12 @@ public override string GetConnectionDescription(IConnectionInfo connectionInfo)
return new StorageAccountProperties(connectionInfo).DisplayName;
}

/// <summary>
/// Shows the connection dialog.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
/// <param name="isNewConnection">if set to <c>true</c> [is new connection].</param>
/// <returns></returns>
public override bool ShowConnectionDialog(IConnectionInfo connectionInfo, bool isNewConnection)
{
if (isNewConnection)
Expand All @@ -50,6 +60,12 @@ public override bool ShowConnectionDialog(IConnectionInfo connectionInfo, bool i
return result == true;
}

/// <summary>
/// Determines whether two repositories are equivalent.
/// </summary>
/// <param name="connection1">The connection information of the first repository.</param>
/// <param name="connection2">The connection information of the second repository.</param>
/// <returns><c>true</c> if both repositories use the same account name; <c>false</c> otherwise.</returns>
public override bool AreRepositoriesEquivalent(IConnectionInfo connection1, IConnectionInfo connection2)
{
var account1 = (string)connection1.DriverData.Element("AccountName") ?? string.Empty;
Expand All @@ -58,6 +74,10 @@ public override bool AreRepositoriesEquivalent(IConnectionInfo connection1, ICon
return account1.Equals(account2);
}

/// <summary>
/// Gets the assemblies to add.
/// </summary>
/// <returns>A list of assembly names to add in order to execute the current driver.</returns>
public override IEnumerable<string> GetAssembliesToAdd()
{
return new string[]
Expand All @@ -67,6 +87,10 @@ public override IEnumerable<string> GetAssembliesToAdd()
};
}

/// <summary>
/// Gets the namespaces to add.
/// </summary>
/// <returns>A list of namespaces to add in order to execute this driver.</returns>
public override IEnumerable<string> GetNamespacesToAdd()
{
return new string[]
Expand All @@ -77,34 +101,74 @@ public override IEnumerable<string> GetNamespacesToAdd()
};
}

public override List<ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo connectionInfo, System.Reflection.AssemblyName assemblyToBuild, ref string nameSpace, ref string typeName)
/// <summary>
/// Gets the schema and builds the assembly that contains the typed data context.
/// </summary>
/// <param name="connectionInfo">The connection information.</param>
/// <param name="assemblyToBuild">The assembly to build.</param>
/// <param name="namepace">The namespace to be used in the generated code.</param>
/// <param name="typeName">Name of the type of the typed data context.</param>
/// <returns>A list of <see cref="ExplorerItem"/> instaces that describes the current schema.</returns>
public override List<ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo connectionInfo, AssemblyName assemblyToBuild, ref string @namespace, ref string typeName)
{
// The helper class SchemaBuilder will do the heavy lifting
return SchemaBuilder.GetSchemaAndBuildAssembly(
new StorageAccountProperties(connectionInfo),
this.GetDriverFolder(),
assemblyToBuild,
ref nameSpace,
ref typeName);
@namespace,
typeName);
}

/// <summary>
/// Gets the context constructor arguments.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
/// <returns>An ordered collection of objects to pass to the data context as arguments.</returns>
public override object[] GetContextConstructorArguments(IConnectionInfo connectionInfo)
{
var properties = new StorageAccountProperties(connectionInfo);

var storageAccount = properties.GetStorageAccount();

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

/// <summary>
/// Gets the context constructor parameters.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
/// <returns>A list of <see cref="ParameterDescriptor"/> objects that describe the parameters
/// of the typed data context's constructor.</returns>
public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo connectionInfo)
{
return new[]
{
new ParameterDescriptor("baseAddress", "System.String"),
new ParameterDescriptor("credentials", "Microsoft.WindowsAzure.StorageCredentials")
new ParameterDescriptor("credentials", "Microsoft.WindowsAzure.StorageCredentials"),
new ParameterDescriptor("account", "Microsoft.WindowsAzure.CloudStorageAccount")
};
}

/// <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)
{
var dsContext = (DataServiceContext)context;

dsContext.SendingRequest += (sender, e) => executionManager.SqlTranslationWriter.WriteLine(e.Request.RequestUri);
}
}
}
42 changes: 31 additions & 11 deletions Madd0.AzureStorageDriver/ConnectionDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,61 @@ namespace Madd0.AzureStorageDriver
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using LINQPad.Extensibility.DataContext;

/// <summary>
/// Interaction logic for ConnectionDialog.xaml
/// </summary>
public partial class ConnectionDialog : Window
{
/// <summary>
/// Initializes a new instance of the <see cref="ConnectionDialog"/> class.
/// </summary>
/// <param name="connectionInfo">The connection info.</param>
public ConnectionDialog(IConnectionInfo connectionInfo)
{
InitializeComponent();

DataContext = new StorageAccountProperties(connectionInfo);
}

[DllImport("user32.dll")]
static extern uint GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

private const int GWL_STYLE = -16;

private const uint WS_SYSMENU = 0x80000;

/// <summary>
/// Raises the <see cref="E:System.Windows.Window.SourceInitialized"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
protected override void OnSourceInitialized(EventArgs e)
{
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
IntPtr hwnd = new WindowInteropHelper(this).Handle;

// Change the window style to remove icon and buttons
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & (0xFFFFFFFF ^ WS_SYSMENU));

base.OnSourceInitialized(e);
}

/// <summary>
/// Called when the OK button is clicked.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
private void OnOkClick(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}

#region p/invoke

[DllImport("user32.dll")]
private static extern uint GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

private const int GWL_STYLE = -16;

private const uint WS_SYSMENU = 0x80000;

#endregion
}
}

0 comments on commit 512dbae

Please sign in to comment.