Ejemplo n.º 1
0
            public override async ValueTask <bool> MoveNextAsync(ITrace trace)
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                if (!await this.inputStage.MoveNextAsync(trace))
                {
                    this.Current = default;
                    return(false);
                }

                TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;

                if (tryGetSourcePage.Failed)
                {
                    this.Current = tryGetSourcePage;
                    return(true);
                }

                QueryPage sourcePage = tryGetSourcePage.Result;

                // Skip the documents but keep all the other headers
                IReadOnlyList <CosmosElement> documentsAfterSkip = sourcePage.Documents.Skip(this.skipCount).ToList();

                int numberOfDocumentsSkipped = sourcePage.Documents.Count() - documentsAfterSkip.Count();

                this.skipCount -= numberOfDocumentsSkipped;

                QueryState state;

                if (sourcePage.State == null)
                {
                    state = default;
                }
                else
                {
                    OffsetContinuationToken offsetContinuationToken = new OffsetContinuationToken(
                        offset: this.skipCount,
                        sourceToken: sourcePage.State.Value);

                    state = new QueryState(OffsetContinuationToken.ToCosmosElement(offsetContinuationToken));
                }

                QueryPage queryPage = new QueryPage(
                    documents: documentsAfterSkip,
                    requestCharge: sourcePage.RequestCharge,
                    activityId: sourcePage.ActivityId,
                    responseLengthInBytes: sourcePage.ResponseLengthInBytes,
                    cosmosQueryExecutionInfo: sourcePage.CosmosQueryExecutionInfo,
                    disallowContinuationTokenMessage: sourcePage.DisallowContinuationTokenMessage,
                    state: state);

                this.Current = TryCatch <QueryPage> .FromResult(queryPage);

                return(true);
            }
            public override async Task <TryCatch <QueryPage> > MonadicQueryAsync(
                SqlQuerySpec sqlQuerySpec,
                FeedRangeState <QueryState> feedRangeState,
                QueryPaginationOptions queryPaginationOptions,
                ITrace trace,
                CancellationToken cancellationToken)
            {
                await this.semaphore.WaitAsync(this.cancellationToken);

                int count = ParseQueryState(feedRangeState.State);

                QueryState continuationToken = count < this.continuationCount ? CreateQueryState(++count) : default;
                QueryPage  page = new QueryPage(
                    documents: new List <CosmosElement> {
                },
                    requestCharge: 3.0,
                    activityId: "E7980B1F-436E-44DF-B7A5-655C56D38648",
                    responseLengthInBytes: 48,
                    cosmosQueryExecutionInfo: new Lazy <CosmosQueryExecutionInfo>(() => new CosmosQueryExecutionInfo(false, false)),
                    disallowContinuationTokenMessage: null,
                    additionalHeaders: null,
                    state: continuationToken);

                return(continuationToken != default ?
                       TryCatch <QueryPage> .FromResult(page) :
                       await base.MonadicQueryAsync(
                           sqlQuerySpec,
                           new FeedRangeState <QueryState>(feedRangeState.FeedRange, default),
                           queryPaginationOptions,
                           trace,
                           cancellationToken));
            }
Ejemplo n.º 3
0
        private void MainPage_Load(object sender, EventArgs e)
        {
            ///assign current logged user
            if (UserManager.instance != null)
            {
                currUser              = UserManager.instance.currentUser;
                IssueBtn.Enabled      = currUser.IssueDocument;
                officialTSBtn.Enabled = currUser.Username == "ninotech";
            }

            ///activate addnew log in button depending on user privileges
            //AddNewLoginBtn.Enabled = curr.canAddUser ? true : false;

            ///set the text to userwelcome text
            currUserBtn.Text = currUser.Username;

            Current = DashControl;
            //printingFiles.OpeningForm += (x, y) => { Enabled = !y; };
            try
            {
                DashControl.InitValues();
                QueryPage.setUser();
                complaintPage.LoadValues();
                complaintPage.InitButtons();
            }
            catch
            {
            }
        }
            protected override Task <TryCatch <OrderByQueryPage> > GetNextPageAsync(ITrace trace, CancellationToken cancellationToken)
            {
                // Unfortunately we need to keep both the epk range and partition key for queries
                // Since the continuation token format uses epk range even though we only need the partition key to route the request.
                FeedRangeInternal feedRange = this.PartitionKey.HasValue ? new FeedRangePartitionKey(this.PartitionKey.Value) : this.Range;

                return(this.queryDataSource
                       .MonadicQueryAsync(
                           sqlQuerySpec: this.SqlQuerySpec,
                           continuationToken: this.State == null ? null : ((CosmosString)this.State.Value).Value,
                           feedRange: feedRange,
                           pageSize: this.PageSize,
                           trace: trace,
                           cancellationToken)
                       .ContinueWith <TryCatch <OrderByQueryPage> >(antecedent =>
                {
                    TryCatch <QueryPage> monadicQueryPage = antecedent.Result;
                    if (monadicQueryPage.Failed)
                    {
                        return TryCatch <OrderByQueryPage> .FromException(monadicQueryPage.Exception);
                    }

                    QueryPage queryPage = monadicQueryPage.Result;
                    return TryCatch <OrderByQueryPage> .FromResult(new OrderByQueryPage(queryPage));
                }));
            }
Ejemplo n.º 5
0
            public override async ValueTask <bool> MoveNextAsync(ITrace trace)
            {
                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                if (!await this.inputStage.MoveNextAsync(trace))
                {
                    this.Current = default;
                    return(false);
                }

                TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;

                if (tryGetSourcePage.Failed)
                {
                    this.Current = tryGetSourcePage;
                    return(true);
                }

                QueryPage sourcePage = tryGetSourcePage.Result;

                List <CosmosElement> distinctResults = new List <CosmosElement>();

                foreach (CosmosElement document in sourcePage.Documents)
                {
                    if (this.distinctMap.Add(document, out UInt128 _))
                    {
                        distinctResults.Add(document);
                    }
                }

                QueryState queryState;

                if (sourcePage.State != null)
                {
                    DistinctContinuationToken distinctContinuationToken = new DistinctContinuationToken(
                        sourceToken: sourcePage.State.Value,
                        distinctMapToken: this.distinctMap.GetCosmosElementContinuationToken());
                    queryState = new QueryState(DistinctContinuationToken.ToCosmosElement(distinctContinuationToken));
                }
                else
                {
                    queryState = null;
                }

                QueryPage queryPage = new QueryPage(
                    documents: distinctResults,
                    requestCharge: sourcePage.RequestCharge,
                    activityId: sourcePage.ActivityId,
                    responseLengthInBytes: sourcePage.ResponseLengthInBytes,
                    cosmosQueryExecutionInfo: sourcePage.CosmosQueryExecutionInfo,
                    disallowContinuationTokenMessage: ComputeDistinctQueryPipelineStage.UseTryGetContinuationTokenMessage,
                    state: queryState);

                this.Current = TryCatch <QueryPage> .FromResult(queryPage);

                return(true);
            }
Ejemplo n.º 6
0
            public override async ValueTask <bool> MoveNextAsync()
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (!await this.inputStage.MoveNextAsync())
                {
                    this.Current = default;
                    return(false);
                }

                TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;

                if (tryGetSourcePage.Failed)
                {
                    this.Current = tryGetSourcePage;
                    return(true);
                }

                QueryPage sourcePage = tryGetSourcePage.Result;

                List <CosmosElement> takedDocuments = sourcePage.Documents.Take(this.takeCount).ToList();

                this.takeCount -= takedDocuments.Count;

                QueryState state;

                if ((sourcePage.State != null) && (sourcePage.DisallowContinuationTokenMessage == null))
                {
                    string updatedContinuationToken = this.takeEnum switch
                    {
                        TakeEnum.Limit => new LimitContinuationToken(
                            limit: this.takeCount,
                            sourceToken: sourcePage.State?.Value.ToString()).ToString(),
                        TakeEnum.Top => new TopContinuationToken(
                            top: this.takeCount,
                            sourceToken: sourcePage.State?.Value.ToString()).ToString(),
                        _ => throw new ArgumentOutOfRangeException($"Unknown {nameof(TakeEnum)}: {this.takeEnum}."),
                    };

                    state = new QueryState(CosmosElement.Parse(updatedContinuationToken));
                }
                else
                {
                    state = null;
                }

                QueryPage queryPage = new QueryPage(
                    documents: takedDocuments,
                    requestCharge: sourcePage.RequestCharge,
                    activityId: sourcePage.ActivityId,
                    responseLengthInBytes: sourcePage.ResponseLengthInBytes,
                    cosmosQueryExecutionInfo: sourcePage.CosmosQueryExecutionInfo,
                    disallowContinuationTokenMessage: sourcePage.DisallowContinuationTokenMessage,
                    state: state);

                this.Current = TryCatch <QueryPage> .FromResult(queryPage);

                return(true);
            }
Ejemplo n.º 7
0
        public App()
        {
            // The root page of your application
            var content = new QueryPage();


            MainPage = content;
        }
Ejemplo n.º 8
0
            public override async ValueTask <bool> MoveNextAsync(ITrace trace)
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                if (this.ReturnedFinalPage || !await this.inputStage.MoveNextAsync(trace))
                {
                    this.Current   = default;
                    this.takeCount = 0;
                    return(false);
                }

                TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;

                if (tryGetSourcePage.Failed)
                {
                    this.Current = tryGetSourcePage;
                    return(true);
                }

                QueryPage sourcePage = tryGetSourcePage.Result;

                List <CosmosElement> takedDocuments = sourcePage.Documents.Take(this.takeCount).ToList();

                this.takeCount -= takedDocuments.Count;

                QueryState queryState;

                if (sourcePage.State != null)
                {
                    TakeContinuationToken takeContinuationToken = new TakeContinuationToken(
                        takeCount: this.takeCount,
                        sourceToken: sourcePage.State.Value);
                    queryState = new QueryState(TakeContinuationToken.ToCosmosElement(takeContinuationToken));
                }
                else
                {
                    queryState = default;
                }

                QueryPage queryPage = new QueryPage(
                    documents: takedDocuments,
                    requestCharge: sourcePage.RequestCharge,
                    activityId: sourcePage.ActivityId,
                    responseLengthInBytes: sourcePage.ResponseLengthInBytes,
                    cosmosQueryExecutionInfo: sourcePage.CosmosQueryExecutionInfo,
                    disallowContinuationTokenMessage: sourcePage.DisallowContinuationTokenMessage,
                    additionalHeaders: sourcePage.AdditionalHeaders,
                    state: queryState);

                this.Current = TryCatch <QueryPage> .FromResult(queryPage);

                return(true);
            }
Ejemplo n.º 9
0
            public override async ValueTask <bool> MoveNextAsync(ITrace trace)
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                if (this.returnedFinalPage)
                {
                    return(false);
                }

                // Note-2016-10-25-felixfan: Given what we support now, we should expect to return only 1 document.
                // Note-2019-07-11-brchon: We can return empty pages until all the documents are drained,
                // but then we will have to design a continuation token.

                double requestCharge       = 0;
                long   responseLengthBytes = 0;

                while (await this.inputStage.MoveNextAsync(trace))
                {
                    TryCatch <QueryPage> tryGetPageFromSource = this.inputStage.Current;
                    if (tryGetPageFromSource.Failed)
                    {
                        this.Current = tryGetPageFromSource;
                        return(true);
                    }

                    QueryPage sourcePage = tryGetPageFromSource.Result;

                    requestCharge       += sourcePage.RequestCharge;
                    responseLengthBytes += sourcePage.ResponseLengthInBytes;

                    foreach (CosmosElement element in sourcePage.Documents)
                    {
                        this.cancellationToken.ThrowIfCancellationRequested();

                        RewrittenAggregateProjections rewrittenAggregateProjections = new RewrittenAggregateProjections(
                            this.isValueQuery,
                            element);
                        this.singleGroupAggregator.AddValues(rewrittenAggregateProjections.Payload);
                    }
                }

                List <CosmosElement> finalResult       = new List <CosmosElement>();
                CosmosElement        aggregationResult = this.singleGroupAggregator.GetResult();

                if (aggregationResult != null)
                {
                    finalResult.Add(aggregationResult);
                }

                QueryPage queryPage = new QueryPage(
                    documents: finalResult,
                    requestCharge: requestCharge,
                    activityId: default,
            public override async ValueTask <bool> MoveNextAsync()
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (this.returnedLastPage)
                {
                    this.Current = default;
                    return(false);
                }

                // Draining GROUP BY is broken down into two stages:

                double requestCharge         = 0.0;
                long   responseLengthInBytes = 0;

                while (await this.inputStage.MoveNextAsync())
                {
                    this.cancellationToken.ThrowIfCancellationRequested();

                    // Stage 1:
                    // Drain the groupings fully from all continuation and all partitions
                    TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;
                    if (tryGetSourcePage.Failed)
                    {
                        this.Current = tryGetSourcePage;
                        return(true);
                    }

                    QueryPage sourcePage = tryGetSourcePage.Result;

                    requestCharge         += sourcePage.RequestCharge;
                    responseLengthInBytes += sourcePage.ResponseLengthInBytes;
                    this.AggregateGroupings(sourcePage.Documents);
                }

                // Stage 2:
                // Emit the results from the grouping table page by page
                IReadOnlyList <CosmosElement> results = this.groupingTable.Drain(this.pageSize);

                if (this.groupingTable.Count == 0)
                {
                    this.returnedLastPage = true;
                }

                QueryPage queryPage = new QueryPage(
                    documents: results,
                    requestCharge: requestCharge,
                    activityId: null,
                    responseLengthInBytes: responseLengthInBytes,
                    cosmosQueryExecutionInfo: null,
                    disallowContinuationTokenMessage: ClientGroupByQueryPipelineStage.ContinuationTokenNotSupportedWithGroupBy,
                    state: null);

                this.Current = TryCatch <QueryPage> .FromResult(queryPage);

                return(true);
            }
Ejemplo n.º 11
0
            public override async ValueTask <bool> MoveNextAsync(ITrace trace)
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                if (this.returnedLastPage)
                {
                    this.Current = default;
                    return(false);
                }

                // Draining GROUP BY is broken down into two stages:

                double requestCharge         = 0.0;
                long   responseLengthInBytes = 0;
                IReadOnlyDictionary <string, string> addtionalHeaders = null;

                while (await this.inputStage.MoveNextAsync(trace))
                {
                    this.cancellationToken.ThrowIfCancellationRequested();

                    // Stage 1:
                    // Drain the groupings fully from all continuation and all partitions
                    TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;
                    if (tryGetSourcePage.Failed)
                    {
                        this.Current = tryGetSourcePage;
                        return(true);
                    }

                    QueryPage sourcePage = tryGetSourcePage.Result;

                    requestCharge         += sourcePage.RequestCharge;
                    responseLengthInBytes += sourcePage.ResponseLengthInBytes;
                    addtionalHeaders       = sourcePage.AdditionalHeaders;
                    this.AggregateGroupings(sourcePage.Documents);
                }

                // Stage 2:
                // Emit the results from the grouping table page by page
                IReadOnlyList <CosmosElement> results = this.groupingTable.Drain(this.pageSize);

                if (this.groupingTable.Count == 0)
                {
                    this.returnedLastPage = true;
                }

                QueryPage queryPage = new QueryPage(
                    documents: results,
                    requestCharge: requestCharge,
                    activityId: default,
Ejemplo n.º 12
0
        public void ChromeSanity()
        {
            HomePage homePage = new HomePage(driver);

            homePage
            .SearchQuery("query")
            .Header.PickCountry("israel");
            QueryPage queryPage = new QueryPage(driver);

            QueryPageExtensions.InterstByLocation(queryPage, "Tel Aviv District");
            Assert.IsNotNull(QueryPageExtensions.FindRelatedLocation(queryPage), "this district have no realted queries");
        }
            public override async ValueTask <bool> MoveNextAsync(ITrace trace)
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (trace == null)
                {
                    throw new ArgumentNullException(nameof(trace));
                }

                if (this.returnedFinalPage)
                {
                    return(false);
                }

                double requestCharge       = 0;
                long   responseLengthBytes = 0;
                IReadOnlyDictionary <string, string> additionalHeaders = null;

                while (await this.inputStage.MoveNextAsync(trace))
                {
                    TryCatch <QueryPage> tryGetPageFromSource = this.inputStage.Current;
                    if (tryGetPageFromSource.Failed)
                    {
                        this.Current = tryGetPageFromSource;
                        return(true);
                    }

                    QueryPage sourcePage = tryGetPageFromSource.Result;

                    requestCharge       += sourcePage.RequestCharge;
                    responseLengthBytes += sourcePage.ResponseLengthInBytes;
                    additionalHeaders    = sourcePage.AdditionalHeaders;

                    this.cancellationToken.ThrowIfCancellationRequested();
                    this.count += sourcePage.Documents.Count;
                }

                List <CosmosElement> finalResult       = new List <CosmosElement>();
                CosmosElement        aggregationResult = this.GetFinalResult();

                if (aggregationResult != null)
                {
                    finalResult.Add(aggregationResult);
                }

                QueryPage queryPage = new QueryPage(
                    documents: finalResult,
                    requestCharge: requestCharge,
                    activityId: default,
Ejemplo n.º 14
0
        private async Task <GenericResultsList <CustomerLite> > Load(QueryPage query)
        {
            var serverCount        = 0;
            var customersQueryable = this.context.Customers.AsQueryable();

            // Opt in because it results in a extra database hit
            if (query.IncludeServerCount)
            {
                serverCount = await customersQueryable.CountAsync();
            }

            var itemsPaged = await customersQueryable.Skip((query.Page - 1) *query.PageSize).Take(query.PageSize).ToArrayAsync();

            return(new GenericResultsList <CustomerLite>(itemsPaged.Select(this.Convert).ToArray(), new QueryPagingInfo(query.Page, query.PageSize, serverCount)));
        }
Ejemplo n.º 15
0
        private DispatcherTimer timer;      //时间定时器
        public AdminWindow()
        {
            InitializeComponent();
            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            //创建所有页面的对象
            pages[0]            = new RouteMapPage();
            pages[1]            = new QueryPage();
            pages[2]            = new OpenAccountPage();
            pages[3]            = new RechargePage();
            pages[4]            = new DelAccountPage();
            admin_frame.Content = pages[0];

            //定时器
            timer          = new DispatcherTimer();
            timer.Tick    += timer_Tick;
            timer.Interval = TimeSpan.FromMilliseconds(100);
            timer.Start();
        }
Ejemplo n.º 16
0
        public static async Task MainAsync(string[] args)
        {
            var dispatcher = ServiceProvider.GetService <IDispatcher>();

            // Command - Exception
            var createFaultedCustomerCommand = new CreateCustomer();
            var faultedResult = await dispatcher.Command(createFaultedCustomerCommand);

            // Command Create
            var createCustomerCommand = new CreateCustomer();

            createCustomerCommand.FirstName = "Louis";
            createCustomerCommand.LastName  = "Lewis";
            createCustomerCommand.UserName  = "******";

            var createResult = await dispatcher.Command(createCustomerCommand);

            var createdCustomerId = Guid.Parse(((CommandResult)createResult).RecordId);

            // Query Paged
            var queryPage        = new QueryPage();
            var queryPagedResult = await dispatcher.Query <QueryPage, GenericResultsList <CustomerLite> >(queryPage);

            // Query Single Lite
            var getCustomerQuery = new GetCustomer(id: createdCustomerId);
            var customerLite     = await dispatcher.Query <GetCustomer, CustomerLite>(getCustomerQuery);

            // Query Single Detail
            var customerDetail = await dispatcher.Query <GetCustomer, CustomerDetail>(getCustomerQuery);

            // Command Delete
            var deleteCommand = new DeleteCustomer(id: createdCustomerId);
            var deleteResult  = await dispatcher.Command(deleteCommand);

            // Message
            var exception        = new NotImplementedException("Lets throw an exception");
            var exceptionMessage = new ExceptionMessage {
                Exception = exception
            };
            await dispatcher.Message(exceptionMessage);
        }
            protected override async Task <TryCatch <OrderByQueryPage> > GetNextPageAsync(ITrace trace, CancellationToken cancellationToken)
            {
                // Unfortunately we need to keep both the epk range and partition key for queries
                // Since the continuation token format uses epk range even though we only need the partition key to route the request.
                FeedRangeInternal feedRange = this.PartitionKey.HasValue ? new FeedRangePartitionKey(this.PartitionKey.Value) : this.FeedRangeState.FeedRange;

                TryCatch <QueryPage> monadicQueryPage = await this.queryDataSource
                                                        .MonadicQueryAsync(
                    sqlQuerySpec : this.SqlQuerySpec,
                    feedRangeState : new FeedRangeState <QueryState>(feedRange, this.FeedRangeState.State),
                    queryPaginationOptions : this.queryPaginationOptions,
                    trace : trace,
                    cancellationToken);

                if (monadicQueryPage.Failed)
                {
                    return(TryCatch <OrderByQueryPage> .FromException(monadicQueryPage.Exception));
                }
                QueryPage queryPage = monadicQueryPage.Result;

                return(TryCatch <OrderByQueryPage> .FromResult(new OrderByQueryPage(queryPage)));
            }
Ejemplo n.º 18
0
        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Border border = sender as Border;

            if (border != null)
            {
                switch (border.Name)
                {
                case "route":
                    pages[0]            = new RouteMapPage();
                    admin_frame.Content = pages[0];
                    break;

                case "query":
                    pages[1]            = new QueryPage();
                    admin_frame.Content = pages[1];
                    break;

                case "openAccount":
                    pages[2]            = new OpenAccountPage();
                    admin_frame.Content = pages[2];
                    break;

                case "recharge":
                    pages[3]            = new RechargePage();
                    admin_frame.Content = pages[3];
                    break;

                case "delAccount":
                    pages[4]            = new DelAccountPage();
                    admin_frame.Content = pages[4];
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 19
0
            public StudyQueryIn(QueryPage queryPage)
            {
                var dateMin = queryPage.StudyDateStartPicker.SelectedDate;
                var dateMax = queryPage.StudyDateEndPicker.SelectedDate;
                // read search fields
                DateTime start = DateTime.Today.AddYears(-100), end = DateTime.Today;

                if (dateMin != null)
                {
                    start = queryPage.StudyDateStartPicker.SelectedDate.Value;
                    end   = start.AddDays(1);
                }
                if (dateMax != null)
                {
                    end   = queryPage.StudyDateEndPicker.SelectedDate.Value;
                    start = end.AddDays(-1);
                }
                end = end.AddSeconds(86399);

                StudyDate         = new DicomDateRange(start, end);
                PatientName       = patientFullName(queryPage.PatientNameBox, queryPage.PatientSurnameBox);
                ModalitiesInStudy = queryPage.ModalityBox.Text.ToString();
                PatientID         = queryPage.PatientIDBox.Text.ToString();
            }
Ejemplo n.º 20
0
        private static TryCatch <QueryPage> GetCosmosElementResponse(
            Guid clientQueryCorrelationId,
            QueryRequestOptions requestOptions,
            ResourceType resourceType,
            ResponseMessage cosmosResponseMessage,
            PartitionKeyRangeIdentity partitionKeyRangeIdentity,
            Action <QueryPageDiagnostics> queryPageDiagnostics,
            ITrace trace)
        {
            using (ITrace getCosmosElementResponse = trace.StartChild("Get Cosmos Element Response", TraceComponent.Json, Tracing.TraceLevel.Info))
            {
                using (cosmosResponseMessage)
                {
                    QueryPageDiagnostics queryPage = new QueryPageDiagnostics(
                        clientQueryCorrelationId: clientQueryCorrelationId,
                        partitionKeyRangeId: partitionKeyRangeIdentity.PartitionKeyRangeId,
                        queryMetricText: cosmosResponseMessage.Headers.QueryMetricsText,
                        indexUtilizationText: cosmosResponseMessage.Headers[HttpConstants.HttpHeaders.IndexUtilization],
                        diagnosticsContext: cosmosResponseMessage.DiagnosticsContext);
                    queryPageDiagnostics(queryPage);

                    if (
                        cosmosResponseMessage.Headers.QueryMetricsText != null &&
                        BackendMetricsParser.TryParse(cosmosResponseMessage.Headers.QueryMetricsText, out BackendMetrics backendMetrics))
                    {
                        QueryMetricsTraceDatum datum = new QueryMetricsTraceDatum(
                            new QueryMetrics(backendMetrics, IndexUtilizationInfo.Empty, ClientSideMetrics.Empty));
                        trace.AddDatum("Query Metrics", datum);
                    }

                    if (!cosmosResponseMessage.IsSuccessStatusCode)
                    {
                        CosmosException exception;
                        if (cosmosResponseMessage.CosmosException != null)
                        {
                            exception = cosmosResponseMessage.CosmosException;
                        }
                        else
                        {
                            exception = new CosmosException(
                                cosmosResponseMessage.ErrorMessage,
                                cosmosResponseMessage.StatusCode,
                                (int)cosmosResponseMessage.Headers.SubStatusCode,
                                cosmosResponseMessage.Headers.ActivityId,
                                cosmosResponseMessage.Headers.RequestCharge);
                        }

                        return(TryCatch <QueryPage> .FromException(exception));
                    }

                    if (!(cosmosResponseMessage.Content is MemoryStream memoryStream))
                    {
                        memoryStream = new MemoryStream();
                        cosmosResponseMessage.Content.CopyTo(memoryStream);
                    }

                    long        responseLengthBytes = memoryStream.Length;
                    CosmosArray documents           = CosmosQueryClientCore.ParseElementsFromRestStream(
                        memoryStream,
                        resourceType,
                        requestOptions.CosmosSerializationFormatOptions);

                    CosmosQueryExecutionInfo cosmosQueryExecutionInfo;
                    if (cosmosResponseMessage.Headers.TryGetValue(QueryExecutionInfoHeader, out string queryExecutionInfoString))
                    {
                        cosmosQueryExecutionInfo = JsonConvert.DeserializeObject <CosmosQueryExecutionInfo>(queryExecutionInfoString);
                    }
                    else
                    {
                        cosmosQueryExecutionInfo = default;
                    }

                    QueryState queryState;
                    if (cosmosResponseMessage.Headers.ContinuationToken != null)
                    {
                        queryState = new QueryState(CosmosString.Create(cosmosResponseMessage.Headers.ContinuationToken));
                    }
                    else
                    {
                        queryState = default;
                    }

                    QueryPage response = new QueryPage(
                        documents,
                        cosmosResponseMessage.Headers.RequestCharge,
                        cosmosResponseMessage.Headers.ActivityId,
                        responseLengthBytes,
                        cosmosQueryExecutionInfo,
                        disallowContinuationTokenMessage: null,
                        queryState);

                    return(TryCatch <QueryPage> .FromResult(response));
                }
            }
        }
            public override async ValueTask <bool> MoveNextAsync()
            {
                this.cancellationToken.ThrowIfCancellationRequested();

                if (!await this.inputStage.MoveNextAsync())
                {
                    this.Current = default;
                    return(false);
                }

                TryCatch <QueryPage> tryGetSourcePage = this.inputStage.Current;

                if (tryGetSourcePage.Failed)
                {
                    this.Current = tryGetSourcePage;
                    return(true);
                }

                QueryPage sourcePage = tryGetSourcePage.Result;

                List <CosmosElement> distinctResults = new List <CosmosElement>();

                foreach (CosmosElement document in sourcePage.Documents)
                {
                    this.cancellationToken.ThrowIfCancellationRequested();

                    if (this.distinctMap.Add(document, out UInt128 _))
                    {
                        distinctResults.Add(document);
                    }
                }

                // For clients we write out the continuation token if it's a streaming query.
                QueryPage queryPage;

                if (this.distinctQueryType == DistinctQueryType.Ordered)
                {
                    QueryState state;
                    if (sourcePage.State != null)
                    {
                        string updatedContinuationToken = new DistinctContinuationToken(
                            sourceToken: sourcePage.State.Value.ToString(),
                            distinctMapToken: this.distinctMap.GetContinuationToken()).ToString();
                        state = new QueryState(CosmosElement.Parse(updatedContinuationToken));
                    }
                    else
                    {
                        state = null;
                    }

                    queryPage = new QueryPage(
                        documents: distinctResults,
                        requestCharge: sourcePage.RequestCharge,
                        activityId: sourcePage.ActivityId,
                        responseLengthInBytes: sourcePage.ResponseLengthInBytes,
                        cosmosQueryExecutionInfo: sourcePage.CosmosQueryExecutionInfo,
                        disallowContinuationTokenMessage: sourcePage.DisallowContinuationTokenMessage,
                        state: state);
                }
                else
                {
                    queryPage = new QueryPage(
                        documents: distinctResults,
                        requestCharge: sourcePage.RequestCharge,
                        activityId: sourcePage.ActivityId,
                        responseLengthInBytes: sourcePage.ResponseLengthInBytes,
                        cosmosQueryExecutionInfo: sourcePage.CosmosQueryExecutionInfo,
                        disallowContinuationTokenMessage: ClientDistinctQueryPipelineStage.DisallowContinuationTokenMessage,
                        state: null);
                }

                this.Current = TryCatch <QueryPage> .FromResult(queryPage);

                return(true);
            }
Ejemplo n.º 22
0
        public async ValueTask <bool> MoveNextAsync(ITrace trace)
        {
            this.cancellationToken.ThrowIfCancellationRequested();

            if (trace == null)
            {
                throw new ArgumentNullException(nameof(trace));
            }

            if (!await this.crossPartitionRangePageAsyncEnumerator.MoveNextAsync(trace))
            {
                this.Current = default;
                return(false);
            }

            TryCatch <CrossFeedRangePage <QueryPage, QueryState> > currentCrossPartitionPage = this.crossPartitionRangePageAsyncEnumerator.Current;

            if (currentCrossPartitionPage.Failed)
            {
                this.Current = TryCatch <QueryPage> .FromException(currentCrossPartitionPage.Exception);

                return(true);
            }

            CrossFeedRangePage <QueryPage, QueryState> crossPartitionPageResult = currentCrossPartitionPage.Result;
            QueryPage backendQueryPage = crossPartitionPageResult.Page;
            CrossFeedRangeState <QueryState> crossPartitionState = crossPartitionPageResult.State;

            QueryState queryState;

            if (crossPartitionState == null)
            {
                queryState = null;
            }
            else
            {
                // left most and any non null continuations
                IOrderedEnumerable <FeedRangeState <QueryState> > feedRangeStates = crossPartitionState
                                                                                    .Value
                                                                                    .ToArray()
                                                                                    .OrderBy(tuple => ((FeedRangeEpk)tuple.FeedRange).Range.Min);

                List <ParallelContinuationToken> activeParallelContinuationTokens = new List <ParallelContinuationToken>();
                {
                    FeedRangeState <QueryState> firstState = feedRangeStates.First();
                    ParallelContinuationToken   firstParallelContinuationToken = new ParallelContinuationToken(
                        token: firstState.State != null ? ((CosmosString)firstState.State.Value).Value : null,
                        range: ((FeedRangeEpk)firstState.FeedRange).Range);

                    activeParallelContinuationTokens.Add(firstParallelContinuationToken);
                }

                foreach (FeedRangeState <QueryState> feedRangeState in feedRangeStates.Skip(1))
                {
                    this.cancellationToken.ThrowIfCancellationRequested();

                    if (feedRangeState.State != null)
                    {
                        ParallelContinuationToken parallelContinuationToken = new ParallelContinuationToken(
                            token: feedRangeState.State != null ? ((CosmosString)feedRangeState.State.Value).Value : null,
                            range: ((FeedRangeEpk)feedRangeState.FeedRange).Range);

                        activeParallelContinuationTokens.Add(parallelContinuationToken);
                    }
                }

                IEnumerable <CosmosElement> cosmosElementContinuationTokens = activeParallelContinuationTokens
                                                                              .Select(token => ParallelContinuationToken.ToCosmosElement(token));
                CosmosArray cosmosElementParallelContinuationTokens = CosmosArray.Create(cosmosElementContinuationTokens);

                queryState = new QueryState(cosmosElementParallelContinuationTokens);
            }

            QueryPage crossPartitionQueryPage = new QueryPage(
                backendQueryPage.Documents,
                backendQueryPage.RequestCharge,
                backendQueryPage.ActivityId,
                backendQueryPage.ResponseLengthInBytes,
                backendQueryPage.CosmosQueryExecutionInfo,
                backendQueryPage.DisallowContinuationTokenMessage,
                queryState);

            this.Current = TryCatch <QueryPage> .FromResult(crossPartitionQueryPage);

            return(true);
        }
Ejemplo n.º 23
0
 public OrderByQueryPage(QueryPage queryPage)
     : base(queryPage.State)
 {
     this.Page       = queryPage ?? throw new ArgumentNullException(nameof(queryPage));
     this.Enumerator = queryPage.Documents.GetEnumerator();
 }
Ejemplo n.º 24
0
        //void InitCustomFont()
        //{
        //    //Create your private font collection object.
        //    PrivateFontCollection pfc = new PrivateFontCollection();

        //    //Select your font from the resources.
        //    //My font here is "Digireu.ttf"
        //    int fontLength = Properties.Resources.BebasNeue_Regular.Length;

        //    // create a buffer to read in to
        //    byte[] fontdata = Properties.Resources.BebasNeue_Regular;

        //    // create an unsafe memory block for the font data
        //    System.IntPtr data = Marshal.AllocCoTaskMem(fontLength);

        //    // copy the bytes to the unsafe memory block
        //    Marshal.Copy(fontdata, 0, data, fontLength);

        //    // pass the font to the font collection
        //    pfc.AddMemoryFont(data, fontLength);

        //    label1.Font = new Font(pfc.Families[0], label1.Font.Size);
        //    QueryBtn.Font = new Font(pfc.Families[0], QueryBtn.Font.Size);
        //    complaintsBtn.Font = new Font(pfc.Families[0], complaintsBtn.Font.Size);
        //    IssueBtn.Font = new Font(pfc.Families[0], IssueBtn.Font.Size);
        //}
        private void QueryBtn_Click(object sender, EventArgs e)
        {
            SetSelectionPanel(QueryBtn);
            SwitchPage(QueryPage);
            QueryPage.BringToFront();
        }
Ejemplo n.º 25
0
 void refresh()
 {
     DashControl.InitValues();
     QueryPage.showData();
 }
        private static TryCatch <QueryPage> GetCosmosElementResponse(
            QueryRequestOptions requestOptions,
            ResourceType resourceType,
            ResponseMessage cosmosResponseMessage,
            ITrace trace)
        {
            using (ITrace getCosmosElementResponse = trace.StartChild("Get Cosmos Element Response", TraceComponent.Json, Tracing.TraceLevel.Info))
            {
                using (cosmosResponseMessage)
                {
                    if (
                        cosmosResponseMessage.Headers.QueryMetricsText != null &&
                        BackendMetricsParser.TryParse(cosmosResponseMessage.Headers.QueryMetricsText, out BackendMetrics backendMetrics))
                    {
                        QueryMetricsTraceDatum datum = new QueryMetricsTraceDatum(
                            new QueryMetrics(backendMetrics, IndexUtilizationInfo.Empty, ClientSideMetrics.Empty));
                        trace.AddDatum("Query Metrics", datum);
                    }

                    if (!cosmosResponseMessage.IsSuccessStatusCode)
                    {
                        CosmosException exception = cosmosResponseMessage.CosmosException ?? new CosmosException(
                            cosmosResponseMessage.ErrorMessage,
                            cosmosResponseMessage.StatusCode,
                            (int)cosmosResponseMessage.Headers.SubStatusCode,
                            cosmosResponseMessage.Headers.ActivityId,
                            cosmosResponseMessage.Headers.RequestCharge);
                        return(TryCatch <QueryPage> .FromException(exception));
                    }

                    if (!(cosmosResponseMessage.Content is MemoryStream memoryStream))
                    {
                        memoryStream = new MemoryStream();
                        cosmosResponseMessage.Content.CopyTo(memoryStream);
                    }

                    long        responseLengthBytes = memoryStream.Length;
                    CosmosArray documents           = CosmosQueryClientCore.ParseElementsFromRestStream(
                        memoryStream,
                        resourceType,
                        requestOptions.CosmosSerializationFormatOptions);

                    CosmosQueryExecutionInfo cosmosQueryExecutionInfo;
                    if (cosmosResponseMessage.Headers.TryGetValue(QueryExecutionInfoHeader, out string queryExecutionInfoString))
                    {
                        cosmosQueryExecutionInfo = JsonConvert.DeserializeObject <CosmosQueryExecutionInfo>(queryExecutionInfoString);
                    }
                    else
                    {
                        cosmosQueryExecutionInfo = default;
                    }

                    QueryState queryState;
                    if (cosmosResponseMessage.Headers.ContinuationToken != null)
                    {
                        queryState = new QueryState(CosmosString.Create(cosmosResponseMessage.Headers.ContinuationToken));
                    }
                    else
                    {
                        queryState = default;
                    }

                    Dictionary <string, string> additionalHeaders = new Dictionary <string, string>();
                    foreach (string key in cosmosResponseMessage.Headers)
                    {
                        if (!QueryPage.BannedHeaders.Contains(key))
                        {
                            additionalHeaders[key] = cosmosResponseMessage.Headers[key];
                        }
                    }

                    QueryPage response = new QueryPage(
                        documents,
                        cosmosResponseMessage.Headers.RequestCharge,
                        cosmosResponseMessage.Headers.ActivityId,
                        responseLengthBytes,
                        cosmosQueryExecutionInfo,
                        disallowContinuationTokenMessage: null,
                        additionalHeaders,
                        queryState);

                    return(TryCatch <QueryPage> .FromResult(response));
                }
            }
        }
Ejemplo n.º 27
0
 public async Task <IActionResult> Index(QueryPage queryPage)
 {
     return(this.View(await this.GetDispatcher().Query <QueryPage, GenericResultsList <CustomerLite> >(queryPage)));
 }
 public static RelatedQueriesComponent FindRelatedLocation(this QueryPage page)
 {
     return(page.RelatedQueries.FindRelatedQueriesOverDistrict());
 }
 public static RegionComponenent InterstByLocation(this QueryPage page, string location)
 {
     return(page.Region.ByLocation(location));
 }
 public static QueryHeader SearchCountry(this QueryPage page, string country)
 {
     return(page
            .Header.PickCountry(country));
 }