示例#1
0
        /// <summary>
        /// Runner for the AddData Methods
        /// </summary>
        /// <param name="requestBody"></param>
        /// <returns>True if successful</returns>
        private async Task <bool> PerformAddData(AddDataRequest requestBody)
        {
            HttpResponseMessage response = null;

            try
            {
                response = await Client.PostAsync(Endpoints.AddData, IndicoCustomRequest.StringContentFromObject(requestBody));

                HTTPMagic.CheckStatus(response);
                string responseBody = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <SimpleResponse>(responseBody).Results);
            }
            catch (HttpRequestException hre)
            {
                throw new IndicoAPIException(Resources.Application_API_Request_Failure, hre);
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
            }
        }
示例#2
0
        public async Task <IActionResult> AddNewData([FromBody] AddDataRequest reqBody)
        {
            try
            {
                var addTableName = reqBody.AddTableType;

                // Parse row's data from Json in request as an instance of Activity/Opportunities/Leads
                var(idColumn, newData) = dataverseService.ParseDataRowFromJson(reqBody.NewData, addTableName);

                // Set current UTC date in the RowCreationDate column
                dataverseService.SetRowCreationDate(newData);

                // Check if parsing was successful
                if (newData is null)
                {
                    return(BadRequest(Constant.InvalidReq));
                }

                // Insert the given data in Dataverse, baseId is null as it is not known at time of insert
                await dataverseService.AddNewRow(newData, addTableName, idColumn);

                return(Ok());
            }
            catch (JsonException ex)
            {
                logger.LogError(ex, ex.Message);
                return(StatusCode((int)HttpStatusCode.BadRequest, Constant.DataParsingFailed));
            }
            catch (DataverseException ex)
            {
                logger.LogError(ex, ex.Message);
                return(StatusCode((int)HttpStatusCode.BadRequest, ex.Message));
            }
            catch (MsalServiceException ex)
            {
                logger.LogError(ex, ex.Message);
                return(StatusCode(ex.StatusCode, ex.Message));
            }
            catch (MsalClientException ex)
            {
                logger.LogError(ex, ex.Message);
                if (Int32.TryParse(ex.ErrorCode, out int errorCode))
                {
                    return(StatusCode(errorCode, ex.Message));
                }
                else
                {
                    return(StatusCode(403, ex.Message));
                }
            }
            // Handling generic exception to prevent sending complete stack trace to client side
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
        /// <summary>
        ///  udostępniona metoda dodania danych gps do bazy
        /// </summary>
        /// <param name="addDataRequest"></param>
        /// <returns>zwracana odpowiedź czy udało się dodać dane do bazy</returns>
        public BaseResponse AddData(AddDataRequest addDataRequest)
        {
            var response = new BaseResponse();

            try
            {
                var addSession         = new SessionService.SessionService();
                AddSessionResponse res = addSession.AddSession(new AddSessionRequest
                {
                    IdBoat    = addDataRequest.IdBoat,
                    StartDate = addDataRequest.GpsDataList.Max(x => x.SecondsFromStart),
                    StopDate  = addDataRequest.GpsDataList.Min(x => x.SecondsFromStart)
                });

                _unitOfWork.BeginTransaction();
                if (res.IsSuccess)
                {
                    foreach (var item in addDataRequest.GpsDataList)
                    {
                        GPSData data = Mapper.Map <GPSData>(item);
                        data.BoatDirection = 4;
                        data.BoatSpeed     = 6;
                        data.WindDirection = 2;
                        data.WindSpeed     = 9;
                        data.IdSession     = new Guid("4ADAEDD9-DAB7-E511-82AF-ACB57D99B460");
                        data.IdGPSData     = Guid.NewGuid();
                        _repositoryGpsData.Add(data);
                    }

                    _unitOfWork.Commit();
                    response.IsSuccess = true;
                }
                else
                {
                    _unitOfWork.Commit();
                    response.IsSuccess    = false;
                    response.ErrorMessage = "Nie udalo sie utworzyc sesji.";
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        response.ErrorMessage += validationError.PropertyName + "\n";
                        response.ErrorMessage += validationError.ErrorMessage + "\n";
                    }
                }
                response.IsSuccess = false;
            }

            return(response);
        }
        /// <summary>
        ///  udostępniona metoda dodania danych gps do bazy
        /// </summary>
        /// <param name="addDataRequest"></param>
        /// <returns>zwracana odpowiedź czy udało się dodać dane do bazy</returns>
        public BaseResponse AddData(AddDataRequest addDataRequest)
        {
            var response = new BaseResponse();
            try
            {
                var addSession = new SessionService.SessionService();
                AddSessionResponse res = addSession.AddSession(new AddSessionRequest
                {
                    IdBoat = addDataRequest.IdBoat,
                    StartDate = addDataRequest.GpsDataList.Max(x => x.SecondsFromStart),
                    StopDate = addDataRequest.GpsDataList.Min(x => x.SecondsFromStart)
                });

                _unitOfWork.BeginTransaction();
                if (res.IsSuccess)
                {
                    foreach (var item in addDataRequest.GpsDataList)
                    {
                        GPSData data= Mapper.Map<GPSData>(item);
                        data.BoatDirection = 4;
                        data.BoatSpeed = 6;
                        data.WindDirection = 2;
                        data.WindSpeed = 9;
                        data.IdSession =new Guid("4ADAEDD9-DAB7-E511-82AF-ACB57D99B460");
                        data.IdGPSData = Guid.NewGuid();
                        _repositoryGpsData.Add(data);
                    }

                    _unitOfWork.Commit();
                    response.IsSuccess = true;
                }
                else
                {
                    _unitOfWork.Commit();
                    response.IsSuccess = false;
                    response.ErrorMessage = "Nie udalo sie utworzyc sesji.";
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        response.ErrorMessage += validationError.PropertyName + "\n";
                        response.ErrorMessage += validationError.ErrorMessage + "\n";
                    }
                }
                response.IsSuccess = false;
            }

            return response;
        }
        /// <summary>
        /// przykładowa metoda dodania danych gps. Wywoluje metody wcf dla sprawdzenia poprawnosci ich działania
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnAddData_Click(object sender, RoutedEventArgs e)
        {
            var            client  = new GpsServiceClient();
            AddDataRequest request = new AddDataRequest();

            request.IdBoat = new Guid("5608fc44-abb7-e511-82af-acb57d99b460");

            string[] dataGridPagerStyle = File.ReadAllLines(@"C:\Users\hpereverzieva\Desktop\11.txt");
            request.GpsDataList = new GpsData[60];
            try
            {
                for (int i = 0; i < dataGridPagerStyle.Count(); i++)
                {
                    string entry = dataGridPagerStyle[i];
                    string item  = entry.Substring(0, entry.IndexOf(";", StringComparison.Ordinal));
                    request.GpsDataList[i] = new GpsData();
                    request.GpsDataList[i].SecondsFromStart = Convert.ToDateTime(item);


                    entry = entry.Remove(0, entry.IndexOf(";", StringComparison.Ordinal) + 1);
                    item  = entry.Substring(0, entry.IndexOf(";", StringComparison.Ordinal));
                    request.GpsDataList[i].GeoWidth = item;

                    entry = entry.Remove(0, entry.IndexOf(";", StringComparison.Ordinal) + 1);
                    item  = entry.Substring(0, entry.IndexOf(";", StringComparison.Ordinal));
                    request.GpsDataList[i].GeoHeight = item;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            var response = client.AddData(request);

            Txb.Text += "koniec!!!!!!!";
            Txb.Text += response.ErrorMessage;
            Txb.Text += response.IsSuccess.ToString();

            client.Close();
        }
        /// <summary>
        /// przykładowa metoda dodania danych gps. Wywoluje metody wcf dla sprawdzenia poprawnosci ich działania
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddData_Click(object sender, RoutedEventArgs e)
        {
            var client=new GpsServiceClient();
            AddDataRequest request=new AddDataRequest();
            request.IdBoat = new Guid("5608fc44-abb7-e511-82af-acb57d99b460");

            string[] dataGridPagerStyle = File.ReadAllLines(@"C:\Users\hpereverzieva\Desktop\11.txt");
            request.GpsDataList= new GpsData[60];
            try
            {
                for (int i = 0; i < dataGridPagerStyle.Count(); i++)
                {
                    string entry = dataGridPagerStyle[i];
                    string item = entry.Substring(0, entry.IndexOf(";", StringComparison.Ordinal));
                    request.GpsDataList[i]=new GpsData();
                    request.GpsDataList[i].SecondsFromStart = Convert.ToDateTime(item);

                    entry = entry.Remove(0, entry.IndexOf(";", StringComparison.Ordinal) + 1);
                    item = entry.Substring(0, entry.IndexOf(";", StringComparison.Ordinal));
                    request.GpsDataList[i].GeoWidth =item;

                    entry = entry.Remove(0, entry.IndexOf(";", StringComparison.Ordinal) + 1);
                    item = entry.Substring(0, entry.IndexOf(";", StringComparison.Ordinal));
                    request.GpsDataList[i].GeoHeight = item;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            var response =client.AddData(request);
            Txb.Text += "koniec!!!!!!!";
            Txb.Text += response.ErrorMessage;
            Txb.Text += response.IsSuccess.ToString();

            client.Close();
        }
示例#7
0
        /// <summary>
        /// Adds Data to a collection
        /// </summary>
        /// <param name="collectionName">Name of the collection to add data too</param>
        /// <param name="labeledData">list of labeled data points</param>
        /// <returns>True if successful</returns>
        public async Task <bool> AddData(string collectionName, List <CollectionData> labeledData)
        {
            AddDataRequest requestBody = new AddDataRequest(APIKey, collectionName, labeledData);

            return(await PerformAddData(requestBody));
        }