Exemplo n.º 1
0
        private static async Task <TryCatch <int> > FunctionThatTriesToDoWorkButBubblesUpException2()
        {
            TryCatch <int> tryResult = await FunctionThatTriesToDoWorkButBubblesUpException1();

            // Just try to do your work. If it fails just bubble it up.
            return(tryResult.Try((result) => { return result + 2; }));
        }
Exemplo n.º 2
0
        public async Task TestRetryExceptionBubblingUp()
        {
            // This test demos how exceptions will bubble up using the try pattern instead of throwing and catching.
            TryCatch <int> tryMonand = await FunctionThatTriesToDoWorkButBubblesUpException2();

            tryMonand
            .Try((result) =>
            {
                Console.WriteLine($"Got a result: {result}");
            })
            .Catch((requestRateTooLargeException) =>
            {
                Console.WriteLine($"Got a 429: {requestRateTooLargeException}");
            });
        }
        private bool TableExists(string tableName)
        {
            bool tableExists = false;

            TryCatch.Try(
                tryAction: () =>
            {
                DescribeTableResponse response = Client.DescribeTableAsync(tableName).Result;
                tableExists = true;
            },
                catchAction: caughtException =>
            {
                tableExists = false;
            },
                catchableExceptions: new List <Type> {
                typeof(ResourceNotFoundException)
            });
            return(tableExists);
        }
        /// <summary>
        /// Gets the filters for every partition.
        /// </summary>
        private static TryCatch <OrderByInitInfo> TryGetOrderByPartitionKeyRangesInitializationInfo(
            OrderByContinuationToken[] suppliedContinuationTokens,
            List <PartitionKeyRange> partitionKeyRanges,
            SortOrder[] sortOrders,
            string[] orderByExpressions)
        {
            TryCatch <InitInfo <OrderByContinuationToken> > tryFindRangeAndContinuationTokensMonad = CosmosCrossPartitionQueryExecutionContext.TryFindTargetRangeAndExtractContinuationTokens(
                partitionKeyRanges,
                suppliedContinuationTokens
                .Select(token => Tuple.Create(token, token.CompositeContinuationToken.Range)));

            return(tryFindRangeAndContinuationTokensMonad.Try <OrderByInitInfo>((indexAndContinuationTokens) =>
            {
                int minIndex = indexAndContinuationTokens.TargetIndex;
                IReadOnlyDictionary <string, OrderByContinuationToken> partitionKeyRangeToContinuationToken = indexAndContinuationTokens.ContinuationTokens;

                FormattedFilterInfo formattedFilterInfo = CosmosOrderByItemQueryExecutionContext.GetFormattedFilters(
                    orderByExpressions,
                    suppliedContinuationTokens,
                    sortOrders);

                RangeFilterInitializationInfo[] filters = new RangeFilterInitializationInfo[]
                {
                    new RangeFilterInitializationInfo(
                        filter: formattedFilterInfo.FilterForRangesLeftOfTargetRanges,
                        startIndex: 0,
                        endIndex: minIndex - 1),
                    new RangeFilterInitializationInfo(
                        filter: formattedFilterInfo.FiltersForTargetRange,
                        startIndex: minIndex,
                        endIndex: minIndex),
                    new RangeFilterInitializationInfo(
                        filter: formattedFilterInfo.FilterForRangesRightOfTargetRanges,
                        startIndex: minIndex + 1,
                        endIndex: partitionKeyRanges.Count - 1),
                };

                return new OrderByInitInfo(
                    filters,
                    partitionKeyRangeToContinuationToken);
            }));
        }