Skip to content

Commit

Permalink
Merge pull request Azure-Samples#1 from robinsh/robinsh-queues
Browse files Browse the repository at this point in the history
Update Queues samples.
  • Loading branch information
robinsh authored Aug 23, 2016
2 parents 7f77b3f + c67c521 commit 89d7ed4
Show file tree
Hide file tree
Showing 7 changed files with 651 additions and 239 deletions.
217 changes: 217 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

# NUNIT
*.VisualState.xml
TestResult.xml

# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c

# DNX
project.lock.json
artifacts/

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc

# Chutzpah Test files
_Chutzpah*

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap

# TFS 2012 Local Workspace
$tf/

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user

# JustCode is a .NET coding add-in
.JustCode

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*

# MightyMoose
*.mm.*
AutoTest.Net/

# Web workbench (sass)
.sass-cache/

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# Windows Azure Build Output
csx/
*.build.csdef

# Windows Store app package directory
AppPackages/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/

# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
*.mdf
*.ldf

# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings

# Microsoft Fakes
FakesAssemblies/

# Node.js Tools for Visual Studio
.ntvs_analysis.dat

# Visual Studio 6 build log
*.plg

# Visual Studio 6 workspace options file
*.opt

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
121 changes: 121 additions & 0 deletions QueueStorage/Advanced.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//----------------------------------------------------------------------------------
// Microsoft Azure Storage Team
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious. No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//----------------------------------------------------------------------------------

using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace QueueStorage
{
public class Advanced
{

/// <summary>
/// Test some of the queue storage operations.
/// </summary>
public async Task RunQueueStorageAdvancedOpsAsync()
{
try
{
//***** Setup *****//
Console.WriteLine("Getting reference to the storage account.");

// Retrieve storage account information from connection string
// How to create a storage connection string - http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx
CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));

Console.WriteLine("Instantiating queue client.");
Console.WriteLine(string.Empty);

// Create a queue client for interacting with the queue service.
CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();

// Create 3 queues.

// Create the queue name -- use a guid in the name so it's unique.
string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString();

// Keep a list of the queues so you can compare this list
// against the list of queues that we retrieve.
List<string> queueNames = new List<string>();

for (int i = 0; i < 3; i++)
{
// Set the name of the queue, then add it to the generic list.
string queueName = baseQueueName + "-0" + i;
queueNames.Add(queueName);

// Create the queue with this name.
Console.WriteLine("Creating queue with name {0}", queueName);
CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName);
try
{
await cloudQueue.CreateIfNotExistsAsync();
Console.WriteLine(" Queue created successfully.");
}
catch (StorageException exStorage)
{
Common.WriteException(exStorage);
Console.WriteLine("Please make sure your storage account is specified correctly in the app.config - then restart the sample.");
Console.WriteLine("Press any key to exit");
Console.ReadLine();
throw;
}
catch (Exception ex)
{
Console.WriteLine(" Exception thrown creating queue.");
Common.WriteException(ex);
throw;
}
}

Console.WriteLine(string.Empty);
Console.WriteLine("List of queues in the storage account:");

// List the queues for this storage account
IEnumerable<CloudQueue> cloudQueueList = cloudQueueClient.ListQueues();
try
{
foreach (CloudQueue cloudQ in cloudQueueList)
{
Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name);
}
}
catch (Exception ex)
{
Console.WriteLine(" Exception thrown listing queues.");
Common.WriteException(ex);
throw;
}

// Now clean up after yourself, using the list of queues that you created in case there were other queues in the account.
foreach (string oneQueueName in queueNames)
{
CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName);
cloudQueue.DeleteIfExists();
}
}
catch (Exception ex)
{
Console.WriteLine(" Exception thrown. Message = {0}{1} Strack Trace = {2}", ex.Message, Environment.NewLine, ex.StackTrace);
}

}
}
}
2 changes: 1 addition & 1 deletion QueueStorage/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- By default we are assuming you will use the Azure SDK Storage Emulator. If you have an Azure Subscription you can alternatively
create a Storage Account and run against the storage service by commenting out the connection string below and using the
second connection string - in which case you must also insert your storage account name and key in the line below. -->
<add key="StorageConnectionString" value = "UseDevelopmentStorage=true;"/>
<!-- <add key="StorageConnectionString" value = "UseDevelopmentStorage=true;"/> -->
<!--<add key="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=[AccountName];AccountKey=[AccountKey]" />-->
</appSettings>
</configuration>
44 changes: 44 additions & 0 deletions QueueStorage/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.WindowsAzure.Storage;
using System;

namespace QueueStorage
{
public class Common
{

/// <summary>
/// Validate the connection string information in app.config and throws an exception if it looks like
/// the user hasn't updated this to valid values.
/// </summary>
/// <param name="storageConnectionString">The storage connection string</param>
/// <returns>CloudStorageAccount object</returns>
public static CloudStorageAccount CreateStorageAccountFromConnectionString(string storageConnectionString)
{
CloudStorageAccount storageAccount;
try
{
storageAccount = CloudStorageAccount.Parse(storageConnectionString);
}
catch (FormatException)
{
Console.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
Console.ReadLine();
throw;
}
catch (ArgumentException)
{
Console.WriteLine("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app.config file - then restart the sample.");
Console.ReadLine();
throw;
}

return storageAccount;
}

public static void WriteException(Exception ex)
{
Console.WriteLine("Exception thrown. {0}, msg = {1}", ex.Source, ex.Message);
}

}
}
Loading

0 comments on commit 89d7ed4

Please sign in to comment.