示例#1
0
        public async Task <IEnumerable <Product> > GetAllProducts()
        {
            IReliableDictionary <Guid, Product> products = await _stateManager
                                                           .GetOrAddAsync <IReliableDictionary <Guid, Product> >("products");

            var results = new List <Product>();

            // Everything is done via transactions
            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                // Get all products from Service Fabric async. (Incurs a call cost)
                // Returns enumerable instead of list because there can be millions of products.
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <Guid, Product> > allProducts =
                    await products.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                // Get product enumerator from Service Fabric async. (Incurs a call cost)
                using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <Guid, Product> > enumerator =
                           allProducts.GetAsyncEnumerator())
                {
                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        KeyValuePair <Guid, Product> current = enumerator.Current;
                        results.Add(current.Value);
                    }
                }
            }

            return(results);
        }
示例#2
0
        public async Task <CheckoutSummary[]> GetOrderHistoryAsync(string userId)
        {
            var checkoutSummaryRecords = new List <CheckoutSummary>();

            IReliableDictionary <DateTime, CheckoutSummary> history =
                await StateManager.GetOrAddAsync <IReliableDictionary <DateTime, CheckoutSummary> >("history");

            using (ITransaction transaction = StateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <DateTime, CheckoutSummary> > allProducts =
                    await history.CreateEnumerableAsync(transaction, EnumerationMode.Unordered);

                using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <DateTime, CheckoutSummary> > enumerator = allProducts.GetAsyncEnumerator())
                {
                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        checkoutSummaryRecords.Add(enumerator.Current.Value);
                    }
                }
            }

            return(checkoutSummaryRecords.ToArray());
        }
示例#3
0
        public async Task <ActionResult <IEnumerable <string> > > Get()
        {
            CancellationToken ct = new CancellationToken();
            IReliableDictionary <string, long> playerDictionary = await this._stateManager.GetOrAddAsync <IReliableDictionary <string, long> >("rulesDictionary");


            using (ITransaction tx = this._stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, long> > playerList = await playerDictionary.CreateEnumerableAsync(tx);

                Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, long> > enumerator = playerList.GetAsyncEnumerator();

                List <KeyValuePair <string, long> > result = new List <KeyValuePair <string, long> >();

                while (await enumerator.MoveNextAsync(ct))
                {
                    result.Add(enumerator.Current);
                }

                return(new JsonResult(result));
            }
        }
        public async Task <IActionResult> Get()
        {
            try
            {
                List <KeyValuePair <string, string> > result = new List <KeyValuePair <string, string> >();

                ConditionalValue <IReliableDictionary <string, string> > tryGetResult =
                    await this.stateManager.TryGetAsync <IReliableDictionary <string, string> >(ValuesDictionaryName);

                if (tryGetResult.HasValue)
                {
                    IReliableDictionary <string, string> dictionary = tryGetResult.Value;

                    using (ITransaction tx = this.stateManager.CreateTransaction())
                    {
                        Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, string> > enumerable = await dictionary.CreateEnumerableAsync(tx);

                        Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, string> > enumerator = enumerable.GetAsyncEnumerator();

                        while (await enumerator.MoveNextAsync(CancellationToken.None))
                        {
                            result.Add(enumerator.Current);
                        }
                    }
                }
                return(this.Json(result));
            }
            catch (FabricException)
            {
                return(new ContentResult {
                    StatusCode = 503, Content = "The service was unable to process the request. Please try again."
                });
            }
        }
示例#5
0
        private async Task <List <InstallerPkg> > GetInstallerPackagesAsync()
        {
            CancellationToken ct = new CancellationToken();

            IReliableDictionary <string, InstallerPkg> packagesDictionary = await this._statemanager.GetOrAddAsync <IReliableDictionary <string, InstallerPkg> >("packages");

            using (ITransaction tx = this._statemanager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, InstallerPkg> > list = await packagesDictionary.CreateEnumerableAsync(tx);

                Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, InstallerPkg> > enumerator = list.GetAsyncEnumerator();

                List <InstallerPkg> result = new List <InstallerPkg>();

                while (await enumerator.MoveNextAsync(ct))
                {
                    result.Add(enumerator.Current.Value);
                }

                return(result);
            }
        }
        public async Task <ActionResult <IEnumerable <string> > > Get()
        {
            CancellationToken ct = new CancellationToken();
            IReliableDictionary <int, int> playerDictionary = await this._stateManager.GetOrAddAsync <IReliableDictionary <int, int> >("PlayerMatchStatisticsDictionary");


            using (ITransaction tx = this._stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <int, int> > playerList = await playerDictionary.CreateEnumerableAsync(tx);

                Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <int, int> > enumerator = playerList.GetAsyncEnumerator();


                var stats = new List <UserTeamPlayers>();

                while (await enumerator.MoveNextAsync(ct))
                {
                    stats.Add(new UserTeamPlayers {
                        PlayerId = enumerator.Current.Key, Point = enumerator.Current.Value
                    });
                }

                return(new JsonResult(stats));
            }
        }
示例#7
0
        public async Task <IActionResult> Get()
        {
            CancellationToken ct = new CancellationToken();

            IReliableDictionary <string, int> votesDictionary = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, int> >("counts");

            using (ITransaction tx = this.stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, int> > list = await votesDictionary.CreateEnumerableAsync(tx);

                Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, int> > enumerator = list.GetAsyncEnumerator();

                List <KeyValuePair <string, int> > result = new List <KeyValuePair <string, int> >();

                while (await enumerator.MoveNextAsync(ct))
                {
                    logger.Debug("Voting Category {VoteCategoryName} and {Count}", enumerator.Current.Key, enumerator.Current.Value);
                    result.Add(enumerator.Current);
                }

                logger.Information("Retrieved list of voting options {@VoteOptions}", result);
                return(Json(result));
            }
        }
示例#8
0
        public async Task <List <VehicleModel> > GetVehicles(CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                IReliableDictionary <Guid, VehicleModel> vehicleDictionary = await GetVehicleModelsFromReliableStateAsync();

                List <VehicleModel> vehicleModels = new List <VehicleModel>();

                using (ITransaction tx = _stateManager.CreateTransaction())
                {
                    Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <Guid, VehicleModel> > allVehicles =
                        await vehicleDictionary.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                    using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <Guid, VehicleModel> > enumertor =
                               allVehicles.GetAsyncEnumerator())
                    {
                        while (await enumertor.MoveNextAsync(CancellationToken.None))
                        {
                            KeyValuePair <Guid, VehicleModel> current = enumertor.Current;
                            vehicleModels.Add(current.Value);
                        }
                    }
                }

                return(vehicleModels);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#9
0
        public static async Task <List <ExternalResource> > GetExternalResourcesAsync(IReliableStateManager _stateManager)
        {
            var dict = await StateManagerHelper.GetExternalResourceDictAsync(_stateManager);

            List <ExternalResource> listResources = new List <ExternalResource>();

            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, ExternalResource> > list = await dict.CreateEnumerableAsync(tx, EnumerationMode.Ordered)
                                                                                                                .ConfigureAwait(false);

                var asyncEnumerator = list.GetAsyncEnumerator();
                while (await asyncEnumerator.MoveNextAsync(CancellationToken.None).ConfigureAwait(false))
                {
                    listResources.Add(asyncEnumerator.Current.Value);
                }
            }
            return(listResources);
        }
示例#10
0
        public async Task <ActionResult <List <Employee> > > GetAll()
        {
            CancellationToken ct = new CancellationToken();

            IReliableDictionary <string, Employee> employees = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, Employee> >("employees");

            List <Employee> employeesList = new List <Employee>();

            using (ITransaction tx = this.stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, Employee> > list = await employees.CreateEnumerableAsync(tx);

                Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, Employee> > enumerator = list.GetAsyncEnumerator();

                while (await enumerator.MoveNextAsync(ct))
                {
                    employeesList.Add(enumerator.Current.Value);
                }
            }

            return(new ObjectResult(employeesList));
        }
示例#11
0
        public async Task <IEnumerable <Equipment> > GetAllEquipment()
        {
            // GetorAdd will return empty referene is it's not exist
            IReliableDictionary <Guid, Equipment> equipements = await _stateManager
                                                                .GetOrAddAsync <IReliableDictionary <Guid, Equipment> >("equipements");

            var result = new List <Equipment>();

            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                // Service fabric store all data in replica
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <Guid, Equipment> > allEquipments = await equipements.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <Guid, Equipment> > enumerator =
                           allEquipments.GetAsyncEnumerator())
                {
                    // Get all records
                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        KeyValuePair <Guid, Equipment> current = enumerator.Current;
                        result.Add(current.Value);
                    }
                }
            }
            return(result);
        }
示例#12
0
        private async Task <List <KeyValuePair <string, Order> > > ExecuteGetOrdersAsync()
        {
            List <KeyValuePair <string, Order> > result = new List <KeyValuePair <string, Order> >();

            ConditionalValue <IReliableDictionary <string, Order> > conditionResult =
                await this.stateManager.TryGetAsync <IReliableDictionary <string, Order> >(this.setName);

            if (conditionResult.HasValue)
            {
                IReliableDictionary <string, Order> orders = conditionResult.Value;

                using (var tx = this.stateManager.CreateTransaction())
                {
                    Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, Order> > enumerable = await orders.CreateEnumerableAsync(tx);

                    Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, Order> > enumerator = enumerable.GetAsyncEnumerator();

                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        result.Add(enumerator.Current);
                    }
                    await tx.CommitAsync();
                }
            }
            return(result);
        }
示例#13
0
        /// <summary>
        /// Gets a filtered set of MetricCheck items.
        /// </summary>
        /// <param name="application">Optional application filter.</param>
        /// <param name="service">Optional service filter.</param>
        /// <param name="partition">Optional partition filter.</param>
        /// <returns>List containing the set of matching HealthCheck items.</returns>
        /// <remarks>If application is null or empty, the values passed in service and partition will be ignored.
        /// If service is null or empty, the values passed in partition will be ignored.
        /// </remarks>
        public async Task <IList <MetricCheck> > GetMetricsAsync(string application = null, string service = null, Guid?partition = null)
        {
            string             filter = string.Empty;
            List <MetricCheck> items  = new List <MetricCheck>();

            // Get the required dictionaries.
            IReliableDictionary <string, MetricCheck> hcDict = await this.GetMetricCheckDictionaryAsync().ConfigureAwait(false);

            if ((false == string.IsNullOrWhiteSpace(application)) && (false == string.IsNullOrWhiteSpace(service)) && (partition.HasValue))
            {
                filter = $"fabric:/{application}/{service}/{partition}";
            }
            else if ((false == string.IsNullOrWhiteSpace(application)) && (false == string.IsNullOrWhiteSpace(service)))
            {
                filter = $"fabric:/{application}/{service}";
            }
            else if (false == string.IsNullOrWhiteSpace(application))
            {
                filter = $"fabric:/{application}";
            }

            try
            {
                using (ITransaction tx = this._service.StateManager.CreateTransaction())
                {
                    // Query the dictionary for an order list filtered by however much the user specified.
                    Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, MetricCheck> > list = null;
                    if (string.IsNullOrWhiteSpace(filter))
                    {
                        list = await hcDict.CreateEnumerableAsync(tx, EnumerationMode.Ordered).ConfigureAwait(false);
                    }
                    else
                    {
                        list = await hcDict.CreateEnumerableAsync(tx, (s) => { return(s.StartsWith(filter)); }, EnumerationMode.Ordered).ConfigureAwait(false);
                    }

                    Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, MetricCheck> > asyncEnumerator = list.GetAsyncEnumerator();
                    while (await asyncEnumerator.MoveNextAsync(this._token).ConfigureAwait(false))
                    {
                        if (this._token.IsCancellationRequested)
                        {
                            break;
                        }

                        items.Add(asyncEnumerator.Current.Value);
                    }
                }

                // Update the metric count
                Interlocked.CompareExchange(ref this._metricCount, items.Count, this._metricCount);
            }
            catch (FabricObjectClosedException)
            {
                this._service.RefreshFabricClient();
            }
            catch (TimeoutException ex)
            {
                ServiceEventSource.Current.Exception(ex.Message, ex.GetType().Name, nameof(this.GetMetricsAsync));
            }
            catch (FabricTransientException ex)
            {
                ServiceEventSource.Current.Exception(ex.Message, ex.GetType().Name, nameof(this.GetMetricsAsync));
            }

            // Return the list of HealthCheck items.
            return(items);
        }
示例#14
0
        public async Task <IActionResult> Get()
        {
            CancellationToken ct = new CancellationToken();

            IReliableDictionary <string, int> StaffDictionary = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, int> >("counts");

            using (ITransaction tx = this.stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <string, int> > list = await StaffDictionary.CreateEnumerableAsync(tx);

                Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <string, int> > enumerator = list.GetAsyncEnumerator();

                List <KeyValuePair <string, int> > result = new List <KeyValuePair <string, int> >();

                while (await enumerator.MoveNextAsync(ct))
                {
                    result.Add(enumerator.Current);
                }

                return(this.Json(result));
            }
        }
        /// <summary>
        /// Add CheckoutSummary to the history
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <CheckoutSummary[]> GetOrderHitoryAsync(string userId)
        {
            //get reference to history transaction
            var result = new List <CheckoutSummary>();
            IReliableDictionary <DateTime, CheckoutSummary> history =
                await StateManager.GetOrAddAsync <IReliableDictionary <DateTime, CheckoutSummary> >("history");

            //go through all items in history collection - return as list of history summary
            using (ITransaction tx = StateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <DateTime, CheckoutSummary> > allProducts =
                    await history.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <DateTime, CheckoutSummary> > enumerator = allProducts.GetAsyncEnumerator())
                {
                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        KeyValuePair <DateTime, CheckoutSummary> current = enumerator.Current;

                        result.Add(current.Value);
                    }
                }
            }

            return(result.ToArray());
        }
        public async Task <IEnumerable <Product> > GetAllProducts()
        {
            IReliableDictionary <Guid, Product> products =
                await _stateManager.GetOrAddAsync <IReliableDictionary <Guid, Product> >("products");

            var result = new List <Product>();

            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <Guid, Product> > allProducts =
                    await products.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <Guid, Product> > enumerator =
                           allProducts.GetAsyncEnumerator())
                {
                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        KeyValuePair <Guid, Product> current = enumerator.Current;
                        result.Add(current.Value);
                    }
                }
            }

            return(result);
        }
示例#17
0
        public async Task <IEnumerable <perStoryData> > GetAllStoryPointData()
        {
            IReliableDictionary <Guid, perStoryData> storypointdata =
                await _stateManager.GetOrAddAsync <IReliableDictionary <Guid, perStoryData> >("storypointdata");

            var result = new List <perStoryData>();

            using (ITransaction tx = _stateManager.CreateTransaction())
            {
                Microsoft.ServiceFabric.Data.IAsyncEnumerable <KeyValuePair <Guid, perStoryData> > allstorypointdata =
                    await storypointdata.CreateEnumerableAsync(tx, EnumerationMode.Unordered);

                using (Microsoft.ServiceFabric.Data.IAsyncEnumerator <KeyValuePair <Guid, perStoryData> > enumerator =
                           allstorypointdata.GetAsyncEnumerator())
                {
                    while (await enumerator.MoveNextAsync(CancellationToken.None))
                    {
                        KeyValuePair <Guid, perStoryData> current = enumerator.Current;
                        result.Add(current.Value);
                    }
                }
            }

            return(result);
        }