Exemplo n.º 1
0
        public void Process()
        {
            var dataSetApi = new DataSetApi(BaseUrlPath);

            var dataSetResponse = dataSetApi.DataSetGetDataSetId();
            var dataSetId       = dataSetResponse.DatasetId;

            var vehicles = FetchVehicles(dataSetId);

            var dealerIds = vehicles?.Where(x => x.DealerId.HasValue)?
                            .Select(x => x.DealerId.Value)
                            .Distinct();
            var dealers = FetchDealers(dataSetId, dealerIds);

            foreach (var dealer in dealers)
            {
                dealer.Vehicles = new List <VehicleAnswer>();

                var dealerVehicles = vehicles.Where(x => x.DealerId.HasValue && x.DealerId.Value == dealer.DealerId);

                foreach (var vehicle in dealerVehicles)
                {
                    dealer.Vehicles.Add(new VehicleAnswer(vehicle.VehicleId, vehicle.Year, vehicle.Make, vehicle.Model));
                }
            }

            Log("Posting Answer");

            var response = dataSetApi.DataSetPostAnswer(dataSetId, new Answer(dealers));

            OutputResults(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets companies data from monitor
        /// </summary>
        /// <param name="requestPath">Request path, used for API calls (URI)</param>
        /// <param name="accessToken">Access Token for API call (JWT OAuth)</param>
        /// <param name="accountId">Account id</param>
        /// <param name="filterStartDate">Start date for the filtering</param>
        /// <param name="filterEndDate">End date for the filtering</param>
        /// <returns>The json, containing companies data from monitor</returns>
        public virtual IEnumerable <object> Invoke(
            string accessToken,
            string requestPath,
            string accountId,
            string filterStartDate,
            string filterEndDate)
        {
            ApiClient apiClient = new ApiClient(ApiClient.Demo_REST_BasePath);

            //  Construct API headers
            // step 2 start
            apiClient.SetBasePath(ApiClient.Demo_REST_BasePath);
            apiClient.Configuration.DefaultHeader.Add("Authorization", String.Format("Bearer {0}", accessToken));
            apiClient.Configuration.DefaultHeader.Add("Content-Type", "application/json");
            // step 2 end

            // Declare variables
            // step 4 start
            DataSetApi dataSetApi = new DataSetApi(apiClient);
            WebQuery   options    = PrepareWebQuery(filterStartDate, filterEndDate, accountId);

            var cursoredResult = dataSetApi.PostWebQuery("2.0", "monitor", options);

            // step 4 end

            return(cursoredResult.Result);
        }
        /// <summary>
        /// Gets data from monitor
        /// </summary>
        /// <param name="requestPath">Request path, used for API calls (URI)</param>
        /// <param name="accessToken">Access Token for API call (JWT OAuth)</param>
        /// <returns>The list of JObjects, containing data from monitor</returns>
        public virtual IEnumerable <Object> Invoke(string accessToken, string requestPath)
        {
            ApiClient apiClient = new ApiClient(ApiClient.Demo_REST_BasePath);

            //  Construct API headers
            // step 2 start
            apiClient.SetBasePath(ApiClient.Demo_REST_BasePath);
            apiClient.Configuration.DefaultHeader.Add("Authorization", String.Format("Bearer {0}", accessToken));
            apiClient.Configuration.DefaultHeader.Add("Content-Type", "application/json");
            // step 2 end

            // Declare variables
            // step 3 start
            bool          complete       = false;
            string        cursorValue    = "";
            int           limit          = 2; // Amount of records you want to read in one request
            List <object> functionResult = new List <object>();

            DataSetApi       dataSetApi = new DataSetApi(apiClient);
            GetStreamOptions options    = new GetStreamOptions();

            options.limit = limit;

            // Get monitoring data
            do
            {
                if (!string.IsNullOrEmpty(cursorValue))
                {
                    options.cursor = cursorValue;
                }

                var cursoredResult = dataSetApi.GetStreamWithHttpInfo("2.0", "monitor", options);

                string endCursor = cursoredResult.Data.EndCursor;

                // If the endCursor from the response is the same as the one that you already have,
                // it means that you have reached the end of the records
                if (endCursor == cursorValue)
                {
                    complete = true;
                }
                else
                {
                    cursorValue = endCursor;
                    functionResult.Add(cursoredResult.Data);
                }
            }while (!complete);
            // step 3 end

            return(functionResult);
        }
Exemplo n.º 4
0
        public AnswerResponse VehiclePostAnswerTest()
        {
            dsInstance      = new DataSetApi();
            vehicleInstance = new VehiclesApi();
            dealerInstance  = new DealersApi();

            Answer answer = new Answer();

            // Get DataSet ID
            string            datasetId         = "";
            DatasetIdResponse responseDataSetId = dsInstance.DataSetGetDataSetId();

            datasetId = responseDataSetId.DatasetId;

            // Get the Dealers and Vehicles for the given DataSetID

            // Get VehicleIds
            VehicleIdsResponse responseVehicleIds = new VehicleIdsResponse();

            responseVehicleIds = vehicleInstance.VehiclesGetIds(datasetId);



            /////////////////////////  CHEAT /////////////////////////////////////////////////
            answer = dsInstance.DataSetGetCheat(datasetId);   //// CHEAT answer
            /////////////////////////////////////////////////////////////////////////////////


            // Post the response answer
            //var response = dsInstance.DataSetPostAnswer(datasetId, answer);
            AnswerResponse ansResponse = dsInstance.DataSetPostAnswer(datasetId, answer);

            Assert.IsInstanceOf <AnswerResponse>(ansResponse, "response is AnswerResponse");

            return(ansResponse);
        }
Exemplo n.º 5
0
 public void Init()
 {
     instance = new DataSetApi();
 }
Exemplo n.º 6
0
        private async void startButton_Click(object sender, RoutedEventArgs e)
        {
            resultsTextBox.Clear();
            vehicleList.Clear();
            dealerList.Clear();

            dsInstance      = new DataSetApi();
            vehicleInstance = new VehiclesApi();
            dealerInstance  = new DealersApi();

            Answer answer = new Answer();

            // Get DataSet ID
            string            datasetId         = "";
            DatasetIdResponse responseDataSetId = dsInstance.DataSetGetDataSetId();

            datasetId = responseDataSetId.DatasetId;

            // Get the Dealers and Vehicles for the given DataSetID

            // Get VehicleIds
            VehicleIdsResponse responseVehicleIds = new VehicleIdsResponse();

            responseVehicleIds = vehicleInstance.VehiclesGetIds(datasetId);

            //Get Vechicle details for each VehicleId
            VehicleResponse responseVehicle = new VehicleResponse();

            await CreateVehicleTasksAsync(datasetId, responseVehicleIds);

            // For the vehicles, get the dealers
            var        Ids       = vehicleList.Select(v => (int)v.DealerId).ToList().Distinct();
            List <int> dealerIds = Ids.ToList();

            await CreateDealerTasksAsync(datasetId, dealerIds);

            // Once Vehicle list and Dealer list are done, build the answer
            List <DealerAnswer> dealerAnswers = new List <DealerAnswer>();

            foreach (DealersResponse dealer in dealerList)
            {
                DealerAnswer dealerAnswer = new DealerAnswer();
                dealerAnswer.DealerId = dealer.DealerId;
                dealerAnswer.Name     = dealer.Name;

                List <VehicleAnswer>   dealerVehicles = new List <VehicleAnswer>();
                List <VehicleResponse> vehicles       = vehicleList.Where(v => v.DealerId == dealer.DealerId).ToList();

                foreach (VehicleResponse res in vehicles)
                {
                    VehicleAnswer vehicle = new VehicleAnswer();
                    vehicle.VehicleId = res.VehicleId;
                    vehicle.Make      = res.Make;
                    vehicle.Model     = res.Model;
                    vehicle.Year      = res.Year;
                    dealerVehicles.Add(vehicle);
                }

                dealerAnswer.Vehicles = dealerVehicles;
                dealerAnswers.Add(dealerAnswer);
            }

            answer.Dealers = dealerAnswers;

            // Post the response answer
            AnswerResponse ansResponse = dsInstance.DataSetPostAnswer(datasetId, answer);

            string results = ansResponse.Message + "\r\n\r\n" + ansResponse.Success + "\r\n\r\nTime(seconds): " + ansResponse.TotalMilliseconds / 1000.00;

            foreach (DealerAnswer d in answer.Dealers)
            {
                results += "\r\n\r\n----------------------------------------------------------------\r\n\r\n" + d.Name;
                results += "\r\n\r\n-------------------------";
                foreach (VehicleAnswer v in d.Vehicles)
                {
                    //results += "\r\n\r\n";
                    results += "\r\n\r\n" + v.Make + "  " + v.Model + " " + v.Year;
                }
            }
            resultsTextBox.Text = results;
        }