<commit_before>﻿using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ServiceFabric.Data;
using Microsoft.ServiceFabric.Data.Collections;

namespace Back_Stateful.Controllers
{
    [Route("api/[controller]")]
    public class OrdersController : Controller
    {
        public OrdersController(IReliableStateManager stateManager)
        {
            this.stateManager = stateManager;
        }

        [HttpGet]
        public async Task<IEnumerable<Order>> Orders()
        {
            var orders = new List<Order>();

            var result = await stateManager.TryGetAsync<IReliableDictionary<int, Order>>(Order.OrdersDictionaryName).ConfigureAwait(false);

            if (!result.HasValue)
            {
                return orders;
            }

            var dictionary = result.Value;

            using (var transaction = stateManager.CreateTransaction())
            {
                var enumerable = await dictionary.CreateEnumerableAsync(transaction);
                var enumerator = enumerable.GetAsyncEnumerator();

                while (await enumerator.MoveNextAsync(CancellationToken.None))
                {
                    orders.Add(enumerator.Current.Value);
                }
            }

            return orders;
        }

        readonly IReliableStateManager stateManager;
    }
}<commit_msg>Add scope token<commit_after>﻿using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ServiceFabric.Data;
using Microsoft.ServiceFabric.Data.Collections;

namespace Back_Stateful.Controllers
{
    [Route("api/[controller]")]
    public class OrdersController : Controller
    {
        public OrdersController(IReliableStateManager stateManager, IApplicationLifetime applicationLifetime)
        {
            this.stateManager = stateManager;
            this.applicationLifetime = applicationLifetime;
        }

        [HttpGet]
        public async Task<IEnumerable<Order>> Orders()
        {
            var orders = new List<Order>();

            var result = await stateManager.TryGetAsync<IReliableDictionary<int, Order>>(Order.OrdersDictionaryName).ConfigureAwait(false);

            if (!result.HasValue)
            {
                return orders;
            }

            var dictionary = result.Value;

            using (var transaction = stateManager.CreateTransaction())
            {
                var enumerable = await dictionary.CreateEnumerableAsync(transaction);
                var enumerator = enumerable.GetAsyncEnumerator();

                while (await enumerator.MoveNextAsync(applicationLifetime.ApplicationStopping))
                {
                    orders.Add(enumerator.Current.Value);
                }
            }

            return orders;
        }

        readonly IReliableStateManager stateManager;
        readonly IApplicationLifetime applicationLifetime;
    }
}
{'fraction_non_alphanumeric': 0.07973856209150326, 'fraction_numerical': 0.0, 'mean_word_length': 2.263326226012793, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1563220', 'n_tokens_mistral': 748, 'n_tokens_neox': 724, 'n_words': 141}