Skip to content

Commit b0777a1

Browse files
Merge pull request #5 from daenetCorporation/master
.NET Sample migrated to .NET Core
2 parents ad9713c + eab3a86 commit b0777a1

File tree

12 files changed

+137
-252
lines changed

12 files changed

+137
-252
lines changed

QueueStorage/Advanced.cs renamed to Advanced.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task RunQueueStorageAdvancedOpsAsync()
4141

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

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

QueueStorage/Common.cs renamed to Common.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
using Microsoft.Azure.Storage;
2+
using Microsoft.Extensions.Configuration;
23
using System;
4+
using System.IO;
5+
using System.Runtime.CompilerServices;
36

47
namespace QueueStorage
58
{
69
public class Common
710
{
11+
internal static string ConnStr { get; private set; }
12+
13+
/// <summary>
14+
/// Loads the connection string from the appsettings.
15+
/// </summary>
16+
static Common()
17+
{
18+
var builder = new ConfigurationBuilder()
19+
20+
.SetBasePath(Directory.GetCurrentDirectory())
21+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
22+
23+
var cfgRoot = builder.Build();
24+
25+
ConnStr = cfgRoot["ConnectionString"];
26+
}
27+
828

929
/// <summary>
1030
/// Validate the connection string information in app.config and throws an exception if it looks like

QueueStorage/GettingStarted.cs renamed to GettingStarted.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
using Microsoft.Azure;
1818
using Microsoft.Azure.Storage;
1919
using Microsoft.Azure.Storage.Queue;
20+
using Microsoft.Extensions.Configuration;
2021
using System;
22+
using System.IO;
2123
using System.Threading.Tasks;
2224

2325
namespace QueueStorage
@@ -55,14 +57,15 @@ public async Task RunQueueStorageOperationsAsync()
5557

5658
}
5759

60+
5861
/// <summary>
5962
/// Create a queue for the sample application to process messages in.
6063
/// </summary>
6164
/// <returns>A CloudQueue object</returns>
6265
public async Task<CloudQueue> CreateQueueAsync(string queueName)
6366
{
6467
// Retrieve storage account information from connection string.
65-
CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));
68+
CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(Common.ConnStr);
6669

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

130133
Console.WriteLine("6. Change the contents of a queued message");
131134
CloudQueueMessage message = await queue.GetMessageAsync();
132-
message.SetMessageContent2("Updated contents.", false);
135+
message.SetMessageContent2($"Updated contents {DateTime.Now.Ticks}.", false);
133136
await queue.UpdateMessageAsync(
134137
message,
135138
TimeSpan.Zero, // For the purpose of the sample make the update visible immediately
Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
//----------------------------------------------------------------------------------
2-
// Microsoft Azure Storage Team
3-
//
4-
// Copyright (c) Microsoft Corporation. All rights reserved.
5-
//
6-
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
7-
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
8-
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
9-
//----------------------------------------------------------------------------------
10-
// The example companies, organizations, products, domain names,
11-
// e-mail addresses, logos, people, places, and events depicted
12-
// herein are fictitious. No association with any real company,
13-
// organization, product, domain name, email address, logo, person,
14-
// places, or events is intended or should be inferred.
15-
//----------------------------------------------------------------------------------
16-
17-
using System;
18-
19-
namespace QueueStorage
20-
{
21-
22-
/// <summary>
23-
/// Azure Queue Service Sample - The Queue Service provides reliable messaging for workflow processing and for communication
24-
/// between loosely coupled components of cloud services. This sample demonstrates how to perform common tasks including
25-
/// inserting, peeking, getting and deleting queue messages, as well as creating and deleting queues.
26-
///
27-
/// Note: This sample uses the .NET 4.5 asynchronous programming model to demonstrate how to call the Storage Service using the
28-
/// storage client libraries asynchronous API's. When used in real applications this approach enables you to improve the
29-
/// responsiveness of your application. Calls to the storage service are prefixed by the await keyword.
30-
///
31-
/// Documentation References:
32-
/// - What is a Storage Account - http://azure.microsoft.com/en-us/documentation/articles/storage-whatis-account/
33-
/// - Getting Started with Queues - http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-queues/
34-
/// - Queue Service Concepts - http://msdn.microsoft.com/en-us/library/dd179353.aspx
35-
/// - Queue Service REST API - http://msdn.microsoft.com/en-us/library/dd179363.aspx
36-
/// - Queue Service C# API - http://go.microsoft.com/fwlink/?LinkID=398944
37-
/// - Storage Emulator - http://msdn.microsoft.com/en-us/library/azure/hh403989.aspx
38-
/// - Asynchronous Programming with Async and Await - http://msdn.microsoft.com/en-us/library/hh191443.aspx
39-
/// </summary>
40-
public class Program
41-
{
42-
// *************************************************************************************************************************
43-
// Instructions: This sample can be run using either the Azure Storage Emulator that installs as part of this SDK - or by
44-
// updating the App.Config file with your AccountName and Key.
45-
//
46-
// To run the sample using the Storage Emulator (default option)
47-
// 1. Start the Azure Storage Emulator (once only) by pressing the Start button or the Windows key and searching for it
48-
// by typing "Azure Storage Emulator". Select it from the list of applications to start it.
49-
// 2. Set breakpoints and run the project using F10.
50-
//
51-
// To run the sample using the Storage Service
52-
// 1. Open the app.config file and comment out the connection string for the emulator (UseDevelopmentStorage=True) and
53-
// uncomment the connection string for the storage service (AccountName=[]...)
54-
// 2. Create a Storage Account through the Azure Portal and provide your [AccountName] and [AccountKey] in
55-
// the App.Config file. See http://go.microsoft.com/fwlink/?LinkId=325277 for more information
56-
// 3. Set breakpoints and run the project using F10.
57-
//
58-
// *************************************************************************************************************************
59-
public static void Main()
60-
{
61-
Console.WriteLine("Azure Storage Queue Sample\n");
62-
63-
// Create queue, insert message, peek message, read message, change contents of queued message,
64-
// queue 20 messages, get queue length, read 20 messages, delete queue.
65-
GettingStarted getStarted = new GettingStarted();
66-
getStarted.RunQueueStorageOperationsAsync().Wait();
67-
68-
// Get list of queues in storage account.
69-
Advanced advMethods = new Advanced();
70-
advMethods.RunQueueStorageAdvancedOpsAsync().Wait();
71-
72-
Console.WriteLine("Press any key to exit.");
73-
Console.Read();
74-
}
75-
76-
77-
}
78-
}
1+
//----------------------------------------------------------------------------------
2+
// Microsoft Azure Storage Team
3+
//
4+
// Copyright (c) Microsoft Corporation. All rights reserved.
5+
//
6+
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
7+
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
8+
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
9+
//----------------------------------------------------------------------------------
10+
// The example companies, organizations, products, domain names,
11+
// e-mail addresses, logos, people, places, and events depicted
12+
// herein are fictitious. No association with any real company,
13+
// organization, product, domain name, email address, logo, person,
14+
// places, or events is intended or should be inferred.
15+
//----------------------------------------------------------------------------------
16+
17+
using System;
18+
19+
namespace QueueStorage
20+
{
21+
22+
/// <summary>
23+
/// Azure Queue Service Sample - The Queue Service provides reliable messaging for workflow processing and for communication
24+
/// between loosely coupled components of cloud services. This sample demonstrates how to perform common tasks including
25+
/// inserting, peeking, getting and deleting queue messages, as well as creating and deleting queues.
26+
///
27+
/// Note: This sample uses the .NET 4.5 asynchronous programming model to demonstrate how to call the Storage Service using the
28+
/// storage client libraries asynchronous API's. When used in real applications this approach enables you to improve the
29+
/// responsiveness of your application. Calls to the storage service are prefixed by the await keyword.
30+
///
31+
/// Documentation References:
32+
/// - What is a Storage Account - http://azure.microsoft.com/en-us/documentation/articles/storage-whatis-account/
33+
/// - Getting Started with Queues - http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-queues/
34+
/// - Queue Service Concepts - http://msdn.microsoft.com/en-us/library/dd179353.aspx
35+
/// - Queue Service REST API - http://msdn.microsoft.com/en-us/library/dd179363.aspx
36+
/// - Queue Service C# API - http://go.microsoft.com/fwlink/?LinkID=398944
37+
/// - Storage Emulator - http://msdn.microsoft.com/en-us/library/azure/hh403989.aspx
38+
/// - Asynchronous Programming with Async and Await - http://msdn.microsoft.com/en-us/library/hh191443.aspx
39+
/// </summary>
40+
public class Program
41+
{
42+
// *************************************************************************************************************************
43+
// Instructions: This sample can be run using either the Azure Storage Emulator that installs as part of this SDK - or by
44+
// updating the App.Config file with your AccountName and Key.
45+
//
46+
// To run the sample using the Storage Emulator (default option)
47+
// 1. Start the Azure Storage Emulator (once only) by pressing the Start button or the Windows key and searching for it
48+
// by typing "Azure Storage Emulator". Select it from the list of applications to start it.
49+
// 2. Set breakpoints and run the project using F10.
50+
//
51+
// To run the sample using the Storage Service
52+
// 1. Open the app.config file and comment out the connection string for the emulator (UseDevelopmentStorage=True) and
53+
// uncomment the connection string for the storage service (AccountName=[]...)
54+
// 2. Create a Storage Account through the Azure Portal and provide your [AccountName] and [AccountKey] in
55+
// the App.Config file. See http://go.microsoft.com/fwlink/?LinkId=325277 for more information
56+
// 3. Set breakpoints and run the project using F10.
57+
//
58+
// *************************************************************************************************************************
59+
public static void Main()
60+
{
61+
Console.WriteLine("Azure Storage Queue Sample\n");
62+
63+
// Create queue, insert message, peek message, read message, change contents of queued message,
64+
// queue 20 messages, get queue length, read 20 messages, delete queue.
65+
GettingStarted getStarted = new GettingStarted();
66+
getStarted.RunQueueStorageOperationsAsync().Wait();
67+
68+
// Get list of queues in storage account.
69+
Advanced advMethods = new Advanced();
70+
advMethods.RunQueueStorageAdvancedOpsAsync().Wait();
71+
72+
Console.WriteLine("Press any key to exit.");
73+
Console.Read();
74+
}
75+
76+
77+
}
78+
}

QueueStorage.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Azure.Storage.Queue" Version="11.1.7" />
10+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0-preview.4.20251.6" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="appsettings.json">
15+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
16+
</None>
17+
</ItemGroup>
18+
19+
</Project>

QueueStorage.sln

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.23107.0
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29911.84
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QueueStorage", "QueueStorage\QueueStorage.csproj", "{2F53D824-D081-4281-81E5-38C7B35C965B}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QueueStorage", "QueueStorage.csproj", "{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{2F53D824-D081-4281-81E5-38C7B35C965B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{2F53D824-D081-4281-81E5-38C7B35C965B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{2F53D824-D081-4281-81E5-38C7B35C965B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{2F53D824-D081-4281-81E5-38C7B35C965B}.Release|Any CPU.Build.0 = Release|Any CPU
14+
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{30EC1C93-9BEC-477E-9E24-C2AD1016DFD3}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection
1919
GlobalSection(SolutionProperties) = preSolution
2020
HideSolutionNode = FALSE
2121
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {69D79CDC-5479-4F3B-BA43-127BBEE4E0E7}
24+
EndGlobalSection
2225
EndGlobal

QueueStorage/App.config

Lines changed: 0 additions & 23 deletions
This file was deleted.

QueueStorage/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)