From 91a144209b543c6f53b6ffafbcc56dfd96eeac76 Mon Sep 17 00:00:00 2001 From: Wayne Foley Date: Tue, 25 Mar 2014 15:06:18 -0700 Subject: [PATCH] Adding Simple storage example project and solution Implements: blueprint initial-docs Change-Id: I0d31849aba7c3ae14dafbdc03a1a19b0b401d186 --- .gitattributes | 63 +++++++++++++++++ Openstack/Examples/Examples.sln | 22 ++++++ .../Examples/SimpleStorageExample/App.config | 6 ++ .../Examples/SimpleStorageExample/Program.cs | 65 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ .../SimpleStorageExample.csproj | 67 +++++++++++++++++++ 6 files changed, 259 insertions(+) create mode 100644 .gitattributes create mode 100644 Openstack/Examples/Examples.sln create mode 100644 Openstack/Examples/SimpleStorageExample/App.config create mode 100644 Openstack/Examples/SimpleStorageExample/Program.cs create mode 100644 Openstack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs create mode 100644 Openstack/Examples/SimpleStorageExample/SimpleStorageExample.csproj diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/Openstack/Examples/Examples.sln b/Openstack/Examples/Examples.sln new file mode 100644 index 0000000..45ea187 --- /dev/null +++ b/Openstack/Examples/Examples.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleStorageExample", "SimpleStorageExample\SimpleStorageExample.csproj", "{A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Openstack/Examples/SimpleStorageExample/App.config b/Openstack/Examples/SimpleStorageExample/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/Openstack/Examples/SimpleStorageExample/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Openstack/Examples/SimpleStorageExample/Program.cs b/Openstack/Examples/SimpleStorageExample/Program.cs new file mode 100644 index 0000000..d499898 --- /dev/null +++ b/Openstack/Examples/SimpleStorageExample/Program.cs @@ -0,0 +1,65 @@ +using System; +using System.Linq; +using System.Security; +using System.Threading; +using Openstack; +using Openstack.Identity; +using Openstack.Storage; + +namespace SimpleStorageExample +{ + class Program + { + static void Main(string[] args) + { + //enter your user name, password, tenant Id, and the authorization endpoint + //for the instance of openstack that you want to connect to. + var authUri = new Uri("https://region.identity.host.com:12345/v2.0/tokens"); + var userName = "user name"; + var password = "password"; + var tenantId = "tenant Id"; // e.g. XXXXXXXXXXXXX-Project + + //Convert the plain text password into a SecureString. + //Ideally you should never store your passwords in plain text, but for this example we will. + var securePassword = new SecureString(); + password.ToCharArray().ToList().ForEach(securePassword.AppendChar); + + //Construct an OpenstackCredential object that will be used to authenticate. + //The credential will also be useful later as it contains a reference to the service catalog, and access token. + var credential = new OpenstackCredential(authUri, userName, securePassword, tenantId); + + //Create a new OpenStackClient object using the credentials you just created. + //A cancellation token can also be supplied, this will allow you to cancel any long running tasks + //that the client may make. + var client = new OpenstackClient(credential, CancellationToken.None); + + //Connect the client to Openstack. This will authenticate you, as well as construct the service catalog, + //and retrieve the access token that will be used in future calls to Openstack services. + var connectTask = client.Connect(); + + //Console applications can't do async, so we need to wait on the task, + //in other contexts you can use the wait keyword. + connectTask.Wait(); + + //Once the OpenstackClient has been connected, you can request a service client from it. + //The service client will be created with the credentials that you have already specified, + //and do not need any additional information for you to interact with them. + var storageClient = client.CreateServiceClient(); + + //Once we have the storage service client, we can ask it for the details of the current storage account. + var getAccountTask = storageClient.GetStorageAccount(); + getAccountTask.Wait(); + var account = getAccountTask.Result; + + //Here we will write out the name of the account, and print out the names of each storage container in the account. + Console.WriteLine("Connected to storage account '{0}'", account.Name); + Console.WriteLine("Storage account '{0}' has the following containers:", account.Name); + foreach (var container in account.Containers) + { + Console.WriteLine("\t{0}",container.Name); + } + Console.WriteLine(string.Empty); + Console.ReadLine(); + } + } +} diff --git a/Openstack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs b/Openstack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6f198e8 --- /dev/null +++ b/Openstack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SimpleStorageExample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("SimpleStorageExample")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("095db9ea-9103-4a27-b7ec-e91bd1e0817c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Openstack/Examples/SimpleStorageExample/SimpleStorageExample.csproj b/Openstack/Examples/SimpleStorageExample/SimpleStorageExample.csproj new file mode 100644 index 0000000..ec95096 --- /dev/null +++ b/Openstack/Examples/SimpleStorageExample/SimpleStorageExample.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC} + Exe + Properties + SimpleStorageExample + SimpleStorageExample + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\Bin\Debug\Newtonsoft.Json.dll + + + ..\..\Bin\Debug\Openstack.dll + + + ..\..\Bin\Debug\Openstack.Common.dll + + + + + + + + + + + + + + + + + + + \ No newline at end of file