Skip to content

Commit

Permalink
Merge pull request #5 from daenetCorporation/master
Browse files Browse the repository at this point in the history
.NET Sample migrated to .NET Core
  • Loading branch information
mhopkins-msft authored Jul 15, 2020
2 parents ad9713c + eab3a86 commit b0777a1
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 252 deletions.
2 changes: 1 addition & 1 deletion QueueStorage/Advanced.cs → Advanced.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task RunQueueStorageAdvancedOpsAsync()

// 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"));
CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(Common.ConnStr);

Console.WriteLine("Instantiating queue client.");
Console.WriteLine(string.Empty);
Expand Down
20 changes: 20 additions & 0 deletions QueueStorage/Common.cs → Common.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
using Microsoft.Azure.Storage;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Runtime.CompilerServices;

namespace QueueStorage
{
public class Common
{
internal static string ConnStr { get; private set; }

/// <summary>
/// Loads the connection string from the appsettings.
/// </summary>
static Common()
{
var builder = new ConfigurationBuilder()

.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

var cfgRoot = builder.Build();

ConnStr = cfgRoot["ConnectionString"];
}


/// <summary>
/// Validate the connection string information in app.config and throws an exception if it looks like
Expand Down
7 changes: 5 additions & 2 deletions QueueStorage/GettingStarted.cs → GettingStarted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
using Microsoft.Azure;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Queue;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Threading.Tasks;

namespace QueueStorage
Expand Down Expand Up @@ -55,14 +57,15 @@ public async Task RunQueueStorageOperationsAsync()

}


/// <summary>
/// Create a queue for the sample application to process messages in.
/// </summary>
/// <returns>A CloudQueue object</returns>
public async Task<CloudQueue> CreateQueueAsync(string queueName)
{
// Retrieve storage account information from connection string.
CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(Common.ConnStr);

// Create a queue client for interacting with the queue service
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
Expand Down Expand Up @@ -129,7 +132,7 @@ public async Task UpdateEnqueuedMessageAsync(CloudQueue queue)

Console.WriteLine("6. Change the contents of a queued message");
CloudQueueMessage message = await queue.GetMessageAsync();
message.SetMessageContent2("Updated contents.", false);
message.SetMessageContent2($"Updated contents {DateTime.Now.Ticks}.", false);
await queue.UpdateMessageAsync(
message,
TimeSpan.Zero, // For the purpose of the sample make the update visible immediately
Expand Down
156 changes: 78 additions & 78 deletions QueueStorage/Program.cs → Program.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
//----------------------------------------------------------------------------------
// 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 System;

namespace QueueStorage
{

/// <summary>
/// Azure Queue Service Sample - The Queue Service provides reliable messaging for workflow processing and for communication
/// between loosely coupled components of cloud services. This sample demonstrates how to perform common tasks including
/// inserting, peeking, getting and deleting queue messages, as well as creating and deleting queues.
///
/// Note: This sample uses the .NET 4.5 asynchronous programming model to demonstrate how to call the Storage Service using the
/// storage client libraries asynchronous API's. When used in real applications this approach enables you to improve the
/// responsiveness of your application. Calls to the storage service are prefixed by the await keyword.
///
/// Documentation References:
/// - What is a Storage Account - http://azure.microsoft.com/en-us/documentation/articles/storage-whatis-account/
/// - Getting Started with Queues - http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-queues/
/// - Queue Service Concepts - http://msdn.microsoft.com/en-us/library/dd179353.aspx
/// - Queue Service REST API - http://msdn.microsoft.com/en-us/library/dd179363.aspx
/// - Queue Service C# API - http://go.microsoft.com/fwlink/?LinkID=398944
/// - Storage Emulator - http://msdn.microsoft.com/en-us/library/azure/hh403989.aspx
/// - Asynchronous Programming with Async and Await - http://msdn.microsoft.com/en-us/library/hh191443.aspx
/// </summary>
public class Program
{
// *************************************************************************************************************************
// Instructions: This sample can be run using either the Azure Storage Emulator that installs as part of this SDK - or by
// updating the App.Config file with your AccountName and Key.
//
// To run the sample using the Storage Emulator (default option)
// 1. Start the Azure Storage Emulator (once only) by pressing the Start button or the Windows key and searching for it
// by typing "Azure Storage Emulator". Select it from the list of applications to start it.
// 2. Set breakpoints and run the project using F10.
//
// To run the sample using the Storage Service
// 1. Open the app.config file and comment out the connection string for the emulator (UseDevelopmentStorage=True) and
// uncomment the connection string for the storage service (AccountName=[]...)
// 2. Create a Storage Account through the Azure Portal and provide your [AccountName] and [AccountKey] in
// the App.Config file. See http://go.microsoft.com/fwlink/?LinkId=325277 for more information
// 3. Set breakpoints and run the project using F10.
//
// *************************************************************************************************************************
public static void Main()
{
Console.WriteLine("Azure Storage Queue Sample\n");

// Create queue, insert message, peek message, read message, change contents of queued message,
// queue 20 messages, get queue length, read 20 messages, delete queue.
GettingStarted getStarted = new GettingStarted();
getStarted.RunQueueStorageOperationsAsync().Wait();

// Get list of queues in storage account.
Advanced advMethods = new Advanced();
advMethods.RunQueueStorageAdvancedOpsAsync().Wait();

Console.WriteLine("Press any key to exit.");
Console.Read();
}


}
}
//----------------------------------------------------------------------------------
// 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 System;

namespace QueueStorage
{

/// <summary>
/// Azure Queue Service Sample - The Queue Service provides reliable messaging for workflow processing and for communication
/// between loosely coupled components of cloud services. This sample demonstrates how to perform common tasks including
/// inserting, peeking, getting and deleting queue messages, as well as creating and deleting queues.
///
/// Note: This sample uses the .NET 4.5 asynchronous programming model to demonstrate how to call the Storage Service using the
/// storage client libraries asynchronous API's. When used in real applications this approach enables you to improve the
/// responsiveness of your application. Calls to the storage service are prefixed by the await keyword.
///
/// Documentation References:
/// - What is a Storage Account - http://azure.microsoft.com/en-us/documentation/articles/storage-whatis-account/
/// - Getting Started with Queues - http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-queues/
/// - Queue Service Concepts - http://msdn.microsoft.com/en-us/library/dd179353.aspx
/// - Queue Service REST API - http://msdn.microsoft.com/en-us/library/dd179363.aspx
/// - Queue Service C# API - http://go.microsoft.com/fwlink/?LinkID=398944
/// - Storage Emulator - http://msdn.microsoft.com/en-us/library/azure/hh403989.aspx
/// - Asynchronous Programming with Async and Await - http://msdn.microsoft.com/en-us/library/hh191443.aspx
/// </summary>
public class Program
{
// *************************************************************************************************************************
// Instructions: This sample can be run using either the Azure Storage Emulator that installs as part of this SDK - or by
// updating the App.Config file with your AccountName and Key.
//
// To run the sample using the Storage Emulator (default option)
// 1. Start the Azure Storage Emulator (once only) by pressing the Start button or the Windows key and searching for it
// by typing "Azure Storage Emulator". Select it from the list of applications to start it.
// 2. Set breakpoints and run the project using F10.
//
// To run the sample using the Storage Service
// 1. Open the app.config file and comment out the connection string for the emulator (UseDevelopmentStorage=True) and
// uncomment the connection string for the storage service (AccountName=[]...)
// 2. Create a Storage Account through the Azure Portal and provide your [AccountName] and [AccountKey] in
// the App.Config file. See http://go.microsoft.com/fwlink/?LinkId=325277 for more information
// 3. Set breakpoints and run the project using F10.
//
// *************************************************************************************************************************
public static void Main()
{
Console.WriteLine("Azure Storage Queue Sample\n");

// Create queue, insert message, peek message, read message, change contents of queued message,
// queue 20 messages, get queue length, read 20 messages, delete queue.
GettingStarted getStarted = new GettingStarted();
getStarted.RunQueueStorageOperationsAsync().Wait();

// Get list of queues in storage account.
Advanced advMethods = new Advanced();
advMethods.RunQueueStorageAdvancedOpsAsync().Wait();

Console.WriteLine("Press any key to exit.");
Console.Read();
}


}
}
19 changes: 19 additions & 0 deletions QueueStorage.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Storage.Queue" Version="11.1.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0-preview.4.20251.6" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
17 changes: 10 additions & 7 deletions QueueStorage.sln
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29911.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QueueStorage", "QueueStorage\QueueStorage.csproj", "{2F53D824-D081-4281-81E5-38C7B35C965B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QueueStorage", "QueueStorage.csproj", "{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F53D824-D081-4281-81E5-38C7B35C965B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F53D824-D081-4281-81E5-38C7B35C965B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F53D824-D081-4281-81E5-38C7B35C965B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F53D824-D081-4281-81E5-38C7B35C965B}.Release|Any CPU.Build.0 = Release|Any CPU
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {69D79CDC-5479-4F3B-BA43-127BBEE4E0E7}
EndGlobalSection
EndGlobal
23 changes: 0 additions & 23 deletions QueueStorage/App.config

This file was deleted.

36 changes: 0 additions & 36 deletions QueueStorage/Properties/AssemblyInfo.cs

This file was deleted.

Loading

0 comments on commit b0777a1

Please sign in to comment.