コード例 #1
0
        public async Task <string> Get()
        {
            //We need to provide two sets of info to the service proxy. The name of the service as registered
            //wit SF and the partition key, which is set to 0 currently because we only have one partition.
            //partitioning info found here https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-concepts-partitioning
            ISnowProvider snow =
                ServiceProxy.Create <ISnowProvider>(new Uri("fabric:/GoodVibesSurfing/GetSnowConditions"),
                                                    new ServicePartitionKey(0));

            try
            {
                var taskResult = await RetryPattern.DoTaskWithRetry(snow.GetSnowConditionsAsync);

                //due to some nested task garbaggio we're going to wait for this again. The reason is that our delegate is running a task
                //which runs a task... so the await for some reason isn't sufficient
                taskResult.Wait();

                var conditions = taskResult.Result;
                //Dictionary<string, long> conditions = await snow.GetSnowConditionsAsync();
                return(JsonConvert.SerializeObject(conditions));
            }
            catch (AggregateException ex)
            {
                if (ex.InnerExceptions.Any(x => x is TimeoutException) || ex.GetBaseException() is TimeoutException)
                {
                    //need to tell the user that we timed out after retry
                }
            }
            catch (Exception ex)
            {
                if (ex is TimeoutException || ex.InnerException is TimeoutException)
                {
                    //implement retry pattern
                }
            }

            throw new ApplicationException();
        }