public void OnException(ExceptionContext context) { try { HttpStatusCode status = HttpStatusCode.InternalServerError; String message = String.Empty; var exceptionType = context.Exception.GetType(); if (exceptionType == typeof(UnauthorizedAccessException)) { message = "Unauthorized Access"; status = HttpStatusCode.Unauthorized; } else if (exceptionType == typeof(NotImplementedException)) { message = "A server error occurred."; status = HttpStatusCode.NotImplemented; } else { message = context.Exception.Message; status = HttpStatusCode.NotFound; } HttpResponse response = context.HttpContext.Response; response.StatusCode = (int)status; response.ContentType = "application/json"; var err = message + " " + context.Exception.StackTrace; SLogger.LogError(err); //todo recolocar EResponse eResponse = new EResponse(); //response.WriteAsync(JsonConvert.SerializeObject(eResponse.SetErrorResponse((int)ErrorCode.ServerException))); response.WriteAsync("erro interno"); context.ExceptionHandled = true; // mark exception as handled } catch (Exception e) { Debug.WriteLine(e.StackTrace); } }
static public bool ConfirmOrder(EDeliveryConfirmOrder eDeliveryConfirmOrder) { try { using var context = new SMySQLContext(); EDeliveryOrder e = new EDeliveryOrder(); e.companyID = eDeliveryConfirmOrder.companyID; e.visualID = GetNextVisualID(e.companyID); e.entityID = eDeliveryConfirmOrder.userID; e.paymentMethodType = eDeliveryConfirmOrder.paymentMethodType; e.total = eDeliveryConfirmOrder.total; e.creationDateUTC = e.modificationDateUTC = DateTime.UtcNow; if (eDeliveryConfirmOrder.creationDateLocal == null) { e.creationDateLocal = DateTime.UtcNow; } else { e.creationDateLocal = eDeliveryConfirmOrder.creationDateLocal; } e.notes = eDeliveryConfirmOrder.comments; e.status = DeliveryStatus.PendingApproval; e.content = JsonConvert.SerializeObject(eDeliveryConfirmOrder.productList); e.changeFor = eDeliveryConfirmOrder.changeFor; var result = context.DeliveryOrders.Add(e); context.SaveChanges(); return(true); } catch (Exception e) { SLogger.LogError(e); } return(false); }
static public async Task <bool> ExecuteRecurringJob() { try { //SLogger.LogDebug("executando hangfire " + DateTime.Now.ToString(DateTimeHelper.IsoDateTime)); //var sTrips = SDefines.ApplicationContainer.Resolve<STrips>(); //var tableTrips = new STable(SDefines.TableTrips); //var sConfig = SDefines.ApplicationContainer.Resolve<SConfig>(); //sConfig.IncrementHangFireToday(); //DateTime utcNow = DateTime.UtcNow; //string filter = "date(requestedDateUTC) = '" + utcNow.ToString(DateTimeHelper.IsoDateFormat) + "' and status in (" + (int)TripStatus.Unassigned + "," + (int)TripStatus.PendingApprovalByDriver + ")"; //string[] columnsToSelect = { "id", "latestRequestedDateUTC", "requestedDateUTC" }; //List<ETrip> nonAssignedTripList = tableTrips.SelectWhere<ETrip>(filter, 0, -1, "id asc", columnsToSelect).ToList(); //foreach (ETrip eTrip in nonAssignedTripList) { // //vamos ver se o usuário requisitou a mais de 12 minutos // TimeSpan userWaitSpan = utcNow.Subtract(eTrip.requestedDateUTC); // if (userWaitSpan.Minutes > SDefines.maxMinutesUserCanWaitForConfirmation) continue;//usuario requisitou a mais de 12 minutos. nao enviamos para mais ninguem // TimeSpan span = utcNow.Subtract(eTrip.latestRequestedDateUTC); // if (span.TotalSeconds > 130) {//vamos convidar outro motorista // sTrips.UpdateLatestRequestedDateUTC(eTrip.id);//para nao alterar o status novamente enquanto o novo motorista ainda está dentro dos 120 segundos // STripLogs.Insert("Alterando trip status e driver status via hangfire..", eTrip.id, null, eTrip.driverID); // STrips.ChangeTripStatus(eTrip.id, TripStatus.Unassigned); // if (eTrip.driverID.HasValue) sTrips.RejectTrip(eTrip.driverID.Value, eTrip.id); // bool pushSent = await sTrips.InviteNearestAvailableDriverForTrip(eTrip.id); // } //} return(true); } catch (Exception e) { SLogger.LogError(e); } return(false); }
static public async Task <EUserAuth> CreateUserFromMobile(EBaseEntity eNewUser) { try { EUserAuth eUserAuth = new EUserAuth { }; using (var context = new SMySQLContext()) { if (context.BaseUsers.Any(x => x.email == eNewUser.email)) { eUserAuth.respCreateUser = (int)RespCreateUser.EmailExists; return(eUserAuth); } eNewUser.id = Guid.NewGuid().ToString(); eNewUser.creationDateUTC = DateTime.UtcNow; eNewUser.modificationDateUTC = DateTime.UtcNow; eNewUser.lastAccessUTC = DateTime.UtcNow; eNewUser.status = (int)UserStatus.Enabled; EBaseEntity result = context.BaseUsers.AddAsync(eNewUser).Result.Entity; await context.SaveChangesAsync(); eUserAuth.id = result.id; eUserAuth.cpf = result.cpf; eUserAuth.name = result.name; eUserAuth.token = STokens.GenerateToken(eNewUser.email); eUserAuth.authenticated = true; eUserAuth.respCreateUser = (int)RespCreateUser.Ok; } return(eUserAuth); } catch (Exception e) { SLogger.LogError(e); } return(null); }
public EBaseEntity GetTheNearestDriverAvailable(Int64 tripID, Int64 vehicleSubcategoryID, out List <EBaseEntity> driverRejectedList) { driverRejectedList = new List <EBaseEntity>(); try { //STripLogs.Insert("Procurando o motorista mais próximo", tripID); /*using (MySqlConnection con = new MySqlConnection(ServerBaseDefines.ConnectionString)) { * con.Open(); * var eTrip = table.SelectByID<ETrip>(tripID); * string[] driversRejected = { }; * if (!string.IsNullOrEmpty(eTrip.driversRejected)) driversRejected = eTrip.driversRejected.Split(','); * SGIS.GetCoordinates(eTrip.startCoordinates, out decimal latitude, out decimal longitude); * string latWithDot = latitude.ToString(CultureInfo.InvariantCulture); * string longWithDot = longitude.ToString(CultureInfo.InvariantCulture);//nao sei pq, mas era colocado virgula ao invéz de ponto * using (MySqlCommand cmd = new MySqlCommand()) { * cmd.Connection = con; * cmd.CommandText = $@"SELECT * drivers.id AS driverID, * drivers.name AS driverName, * vehicles.name AS vehicleName, * firebasetoken, * latitude, * longitude, * SQRT(POW(111.2 * (latitude - {latWithDot}), 2) + POW(111.2 * ({longWithDot} - longitude) * COS(latitude), 2)) AS distance * FROM * drivers * INNER JOIN * vehicles ON drivers.vehicleid = vehicles.id * WHERE * driverstatus = {((int)DriverStatus.Available).ToString()} * AND vehicles.subcategoryid = {vehicleSubcategoryID} * ORDER BY distance;";//todo mudar para driverstatus=1 HAVING distance < 25 ORDER BY distance; * using (MySqlDataReader reader = cmd.ExecuteReader()) { * while (reader.Read()) { * //vamos ler somente o primeiro que nao esteja na lista de rejected * ELogisticsDriver eDriver = new ELogisticsDriver(); * eDriver.id = Convert.ToString(reader["driverID"]); * eDriver.name = Convert.ToString(reader["driverName"]); * if (driversRejected != null && driversRejected.Contains(eDriver.id.ToString())) { * driverRejectedList.Add(eDriver); * continue;//o driver se recusou * } * eDriver.firebaseToken = Convert.ToString(reader["firebasetoken"]); * //STripLogs.Insert("Encontrou o motorista mais próximo", tripID, null, eDriver.id); * return eDriver; * } * } * } * }*/ } catch (Exception e) { SLogger.LogError(e); } return(null); }
protected override async Task OnAfterRenderAsync(bool firstRender) { try { if (firstRender) { users = await(SharedDefines.BaseURL + "/api/v1/SUsers/GetAll").GetJsonAsync <List <EUser> >(); StateHasChanged(); } } catch (Exception ex) { SLogger.LogError(ex); } }
protected async Task OnBtnLoginClicked() { try { //var eUser = await httpClient.PostJsonAsync<EUser>(SDefines.BaseURL + "/api/v1/SUsers/Authenticate", e); var eUser = await usersService.Authenticate(e); if (eUser != null) { NavigationManager.NavigateTo(ClientDefines.RouteDashboard); } } catch (Exception ex) { SLogger.LogError(ex); } }
public EFile GetCompanyLogoByURL([FromBody] string url) { var eCompany = SCompanies.GetByLabSite(url); if (eCompany == null) { SLogger.LogError("(GetCompanyLogoByURL)não foi possível encontrar pela url: " + url); return(null); } EFile eFile = SFiles.GetCompanyLogo(eCompany.id); eFile.companyName = eCompany.name; eFile.contentBase64 = Convert.ToBase64String(eFile.content); return(eFile); }
static public string TranslateToLanguageCode(string content, LanguageCode languageCode) { try { //STable table = new STable(SDefines.TableTranslations); //List<ETranslation> list = table.SelectWhere<ETranslation>("content = '" + content + "'").ToList(); //if (!list.Any()) return content; //ETranslation eTranslation = list.First(); //switch (languageCode) { // case LanguageCode.PortugueseBrazil: // return string.IsNullOrEmpty(eTranslation.contentPTBR) ? content : eTranslation.contentPTBR; // case LanguageCode.Italian: // return string.IsNullOrEmpty(eTranslation.contentIT) ? content : eTranslation.contentIT; //} //return content; } catch (Exception e) { SLogger.LogError(e); } return(content); }