public IHttpActionResult GetDistancesbetweenAddress([FromBody] Input input) { string path = "Data\\address list australia.txt"; Coords locationCoords = HelperExtension.GetLatLngFromAddress(input.Address); string[] lines = HelperExtension.ReadFile(path); List <Distance> distances = new List <Distance>(); if (lines != null) { foreach (var line in lines) { Coords destinationCoords = HelperExtension.GetLatLngFromAddress(line); double distance = HelperExtension.GetDistanceBetweenTwoPoints(locationCoords, destinationCoords); var dist = new Distance(input.Address, line, distance); distances.Add(dist); } } if (distances.Count > 0) { return(Ok(distances.OrderBy(x => x.Distanceinkm).Take(input.NoOfResults).ToList())); } else { return(NotFound()); } }
private static string GetLastLoadedData() { var last = HelperExtension.GetFiles().Select(s => new FileInfo(s)).OrderBy(w => { var dateStr = w.FullName.GetDate(); if (DateTime.TryParse(dateStr, out var dt)) { return(dt); } return(DateTime.MinValue); }).ToArray(); return(!last.Any() ? string.Empty : last.Last().FullName); }
public HttpResponseMessage UpSertGenerateSchedule(HttpRequestMessage request, DateTime?fromdatepicker = null, DateTime?todatepicker = null, int doctorid = 0, int hospitalid = 0, string hospitalname = null) { List <DateTime> days_list = new List <DateTime>(); DateTime temp_start = fromdatepicker.Value.Date; DateTime temp_end = todatepicker.Value.Date; //temp_start = new DateTime(fromdatepicker.Value.Year, fromdatepicker.Value.Month, fromdatepicker.Value.Day); //temp_end = new DateTime(todatepicker.Value.Year, todatepicker.Value.Month, todatepicker.Value.Day); for (DateTime date = temp_start; date <= temp_end; date = date.AddDays(1)) { days_list.Add(date); } List <tbScheduleData> schdatalist = new List <tbScheduleData>(); foreach (var item in days_list) { var day = item.DayOfWeek.ToString(); List <tbSchedule> schedules = dbContext.tbSchedules.Where(a => a.IsDeleted != true && a.DoctorID == doctorid).Where(iQueryService.daysQuery(day)).ToList(); foreach (var sch in schedules) { //added skip existed scheduledata var appointmentDatetime = HelperExtension.getCombinedDateTime(item, sch.Fromtime); tbScheduleData existedData = dbContext.tbScheduleDatas.Where(a => a.DoctorID == doctorid && a.HospitalID == hospitalid && a.AppointmentDatetime == appointmentDatetime).FirstOrDefault(); if (existedData == null) { tbScheduleData sd = new tbScheduleData(); sd.AppointmentDatetime = appointmentDatetime; // HelperExtension.getCombinedDateTime(item, sch.Fromtime); sd.Day = day; sd.HospitalID = hospitalid; sd.HospitalName = hospitalname; sd.DoctorID = doctorid; sd.DoctorName = dbContext.tbDoctors.Where(a => a.ID == doctorid).Select(a => a.Name).FirstOrDefault(); sd.ScheduleID = sch.ID; sd.Fromtime = sch.Fromtime; sd.Totime = sch.Totime; sd.MaxPatientCount = sch.PatientLimit; sd.DefaultPatientCount = sch.PatientLimit; sd.AppointmentTime = sch.Fromtime.Value.ToShortDateString(); sd = scheduledataRepo.AddWithGetObj(sd); } } } return(request.CreateResponse <tbScheduleData>(HttpStatusCode.OK, null)); }
void IBinaryConverter.WriteBinary(IBinaryWriter writer, object value, SerializeMetadata context, IHolySerializer serializer) { var buffer = new List <byte>(); context.Childs.ForEach(b => { var val = HelperExtension.GetValue(b.Name, value); var childWriter = serializer.WriterCreator.Create(); foreach (var c in serializer.Converters) { if (c.CanConvert(b)) { c.WriteBinary(childWriter, val, b, serializer); break; } } ; buffer.AddRange(childWriter.ToArray()); }); writer.Write(buffer.ToArray(), context.IsReverse); }
object IBinaryConverter.ReadBinary(IBinaryReader reader, SerializeMetadata context, IHolySerializer serializer) { var array = reader.Read(context.Length == 0 ? reader.ReadRemainderLength() : context.Length, context.IsReverse); var value = Activator.CreateInstance(context.ObjectType); var childReader = serializer.ReaderCreator.Create(array); context.Childs.ForEach(b => { foreach (var c in serializer.Converters) { if (c.CanConvert(b)) { var val = c.ReadBinary(childReader, b, serializer); HelperExtension.SetValue(b.Name, value, new object[] { val }); break; } } ; }); return(value); }
public int Run(string path) { var newComponent = RkiCoronaLandkreiseComponent.GetInstance(); var files = this.GetRkiFiles(path).ToList(); foreach (var item in files) { var legacyData = JsonConvert.DeserializeObject <LegacyDataFormat>(File.ReadAllText(item)); var date = legacyData.lastUpdate.RemoveTimeFromLastUpdateString(); var newFilename = $"{HelperExtension.SubFolderRkiData()}/{HelperExtension.RkiFilename}-{date}.json"; if (File.Exists(newFilename)) { continue; } var landkreise = new Landkreise(); var d = DateTime.Parse(date); landkreise.Date = d; landkreise.Districts = legacyData.districts.Select(s => new Landkreis { Name = s.name, Date = d, Deaths = s.deaths, WeekIncidence = s.weekIncidence } ).ToList(); newComponent.SaveToFile(landkreise, newFilename); } return(files.Count()); }
public Landkreise LoadData(out Action <bool> saveIf, bool loadForceFromInternet = false) { saveIf = null; var filename = HelperExtension.CreateFilename(); if (!UserSettingsLoader.GetInstance().Load().LoadRkiDataByApplicationStart&& !loadForceFromInternet) { filename = GetLastLoadedData(); } if (!string.IsNullOrEmpty(filename) && File.Exists(filename)) { var reload = this.LoadLocalOrReloadOnlineFromRki(filename); if (reload != null) { return(reload); } } if (string.IsNullOrEmpty(filename)) { return(new Landkreise { Date = DateTime.MinValue, Districts = new List <Landkreis>() }); } var result = this.ConvertToLandkreise(this.LoadActualData()); if (result == null) { return(null); } result.Districts.InsertGermanyIfNotList(result.Date); if (filename != HelperExtension.CreateFilename()) { return(result); } if (!File.Exists(filename)) { this.SaveToFile(result, filename); } else { if (IsDifferent(filename, result)) { saveIf = canSave => { if (!canSave) { return; } this.SaveToFile(result, filename); }; } } return(result); }
public IActionResult CreateClient(ClientModel model) { if (model.SelectedScopes == null) { ModelState.AddModelError("Client", "Please select or insert at least a scope."); } if (model.AllowedGrantType == null) { ModelState.AddModelError("Client", "Please select a grnt type."); } if (model.RedirectUris == null) { ModelState.AddModelError("Client", "Please insert at least a RedirectUris."); } if (model.PostLogoutRedirectUris == null) { ModelState.AddModelError("Client", "Please insert at least a PostLogoutRedirectUris."); } var grantType = HelperExtension.GetPropValue <GrantTypes>(model.AllowedGrantType) as ICollection <string>; if (grantType == null) { ModelState.AddModelError("Client", "grant Type not valid."); } if (!ModelState.IsValid) { PropertyInfo[] grantInfo; grantInfo = typeof(GrantTypes).GetProperties(BindingFlags.Public | BindingFlags.Static); model.AllowedGrantTypes = grantInfo.Select(s => s.Name).ToList(); FieldInfo[] scopesInfo; scopesInfo = typeof(StandardScopes).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) .Where(fi => fi.IsLiteral && !fi.IsInitOnly).ToArray(); model.AllowedScopes = scopesInfo.Select(s => s.GetValue(s).ToString()).ToList(); return(View(model)); } var client = new IdentityServer4.Models.Client { ClientId = Guid.NewGuid().ToString(), ClientName = model.ClientName, AllowedGrantTypes = grantType, Description = model.Description, RequireConsent = model.RequireConsent, ClientSecrets = { new Secret(model.SecretCode.Sha256()) }, RedirectUris = model.RedirectUris, PostLogoutRedirectUris = model.PostLogoutRedirectUris, AllowedScopes = model.SelectedScopes, AllowOfflineAccess = model.AllowOfflineAccess, AlwaysSendClientClaims = model.AlwaysSendClientClaims, AlwaysIncludeUserClaimsInIdToken = model.AlwaysIncludeUserClaimsInIdToken, }; _configContext.Clients.Add(client.ToEntity()); _configContext.SaveChanges(); return(RedirectToAction("ClientList")); }