From 5691b7c8ecd441818d8566300b7510fcacf3e11d Mon Sep 17 00:00:00 2001 From: tsushi Date: Fri, 12 Aug 2016 15:07:13 +0900 Subject: [PATCH] Adding DataPackage --- .../ConsoleRedirect/ConsoleRedirect.cs | 14 ++++----- .../ConsoleRedirect/ConsoleRedirect.csproj | 31 +++++++++++++++++++ .../PackageRoot/ServiceManifest.xml | 11 ++++--- .../PackageRoot/TestData/data.txt | 2 ++ .../ApplicationManifest.xml | 4 +-- .../PublishProfiles/Cloud.xml | 3 ++ .../PublishProfiles/Local.xml | 2 +- 7 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/PackageRoot/TestData/data.txt diff --git a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.cs b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.cs index 5a25d5e..d1d98f3 100644 --- a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.cs +++ b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Fabric; using System.Linq; +using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.ServiceFabric.Services.Communication.Runtime; @@ -36,15 +37,12 @@ protected override async Task RunAsync(CancellationToken cancellationToken) // TODO: Replace the following sample code with your own logic // or remove this RunAsync override if it's not needed in your service. - long iterations = 0; - - while (true) + while (!cancellationToken.IsCancellationRequested) { - cancellationToken.ThrowIfCancellationRequested(); - - ServiceEventSource.Current.ServiceMessage(this, "Working-{0}", ++iterations); - - await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); + var dataPackage = this.Context.CodePackageActivationContext.GetDataPackageObject("TestData"); + var text = File.ReadAllText(Path.Combine(dataPackage.Path, "data.txt")); + ServiceEventSource.Current.ServiceMessage(this, text); + await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); } } } diff --git a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.csproj b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.csproj index 739a622..2538d41 100644 --- a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.csproj +++ b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirect/ConsoleRedirect.csproj @@ -12,6 +12,21 @@ v4.5.2 512 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true true @@ -81,6 +96,22 @@ + + + + False + Microsoft .NET Framework 4.5.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + - + - + scripts\test.cmd @@ -27,8 +27,11 @@ - + + + + - + diff --git a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Cloud.xml b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Cloud.xml index 1301dd8..67d9b96 100644 --- a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Cloud.xml +++ b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Cloud.xml @@ -22,4 +22,7 @@ --> + + + \ No newline at end of file diff --git a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Local.xml b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Local.xml index 55fc650..90f905b 100644 --- a/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Local.xml +++ b/Chapter05/ConsoleRedirectTestApplication/ConsoleRedirectTestApplication/PublishProfiles/Local.xml @@ -8,7 +8,7 @@ --> - + \ No newline at end of file