internal void WriteSrt(string p, Encoding chosenEncoding) { /* * 1 * 00:00:01,000 --> 00:00:04,074 * Subtitles downloaded from www.OpenSubtitles.org * * 2 * 00:00:18,977 --> 00:00:20,728 * (BOY COUGHlNG) * * 3 * 00:00:26,484 --> 00:00:29,278 * (TAKE ME OUT TO THE BALL GAME * PLAYlNG ON VlDEO GAME) */ StringBuilder sb = new StringBuilder(); int globalLineCounter = 1; for (int i = 0; i < TimeMarkers.Count(); ++i) { var time = TimeMarkers[i]; sb.AppendLine(globalLineCounter.ToString()); string strFromTime = TimespanToString(TimeSpan.FromMilliseconds(time.FromTime + time.Correction));//.ToString("hh\\:mm\\:ss\\,fff"); var ToTime = TimeSpan.FromMilliseconds(time.FromTime + time.Correction + time.Duration); //truncate duration so it will not overlap next sub if (i < (TimeMarkers.Count() - 1)) { var ntime = TimeMarkers[i + 1]; var nToTime = TimeSpan.FromMilliseconds(ntime.FromTime + ntime.Correction); ToTime = (ToTime <= nToTime) ? ToTime : nToTime - TimeSpan.FromMilliseconds(100); } string strToTime = TimespanToString(ToTime); sb.AppendLine(strFromTime + " --> " + strToTime); foreach (var lineinf in time.Lines) { sb.AppendLine(lineinf.Line); } sb.AppendLine(); ++globalLineCounter; } File.WriteAllText(p, sb.ToString(), chosenEncoding); }
public DateTime GetDate(string category, string action) { string value = TimeMarkers.FirstOrDefault(tm => tm.Category == category && tm.Action == action)?.Date; if (value == null) { return(new DateTime(0)); } DateTime dt; if (DateTime.TryParseExact(value, "yyyyMMddHHmmss.fff", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { return(dt.Subtract(TimeSpan.FromSeconds(43))); } return(new DateTime(0)); }
// Transform the given rental orders to custom appointments ready to be bound to the scheduler public ObservableCollection <CustomAppointment> LoadAppointments(IEnumerable <Reservations> rentalOrders) { IEnumerable <Chambres> cars = GlobalData.model.Chambres.Where(c => c.Etat != "SUPPRIMER"); IEnumerable <ReservationTypes> cats = GlobalData.model.ReservationTypes.Where(c => c.Etat != "SUPPRIMER"); IEnumerable <TimeMarkers> tm = GlobalData.model.TimeMarkers; ObservableCollection <CustomAppointment> appointments = new ObservableCollection <CustomAppointment>(); if (rentalOrders != null) { foreach (Reservations order in rentalOrders) { try { CustomAppointment app = new CustomAppointment(); Chambres cham = cars.First(x => x.ID == order.idChambre); ReservationTypes category = cats.First(x => x.ID == order.idReservationType); TimeMarkers timemarker = tm.First(x => x.TimeMarkerName == order.EtatOperation); app.UniqueId = order.ID.ToString(); app.ReservationID = order.ID; app.ChambreID = order.idChambre.ToString(); app.Start = order.DateArrive.Value; app.End = order.DateDepart.Value; app.Category = category; app.TimeMarker = timemarker; app.Chambre = "Chambres : " + cham.Numero; //app.TypeChambreID = cham.TypeChambre.ToString(); if (order.ReservationTypes.ReservationType == "PASSAGE") { app.Subject = order.ReservationTypes.ReservationType; int nbr = -order.DateArrive.Value.Subtract(order.DateDepart.Value).Hours; app.NbreHeure = "" + nbr + " Hr"; } else if (order.ReservationTypes.ReservationType == "MAINTENANCE") { app.Subject = order.ReservationTypes.ReservationType; app.NbreHeure = "" + order.NbreNuit + " Nuit"; } else { app.Subject = order.Clients.Noms; app.NbreHeure = "" + order.NbreNuit + " Nuit"; } if (order.Etat == "RESERVER") { ReservationTypes Dcategory = cats.First(x => x.CategoryName == "RESERVATION"); Dcategory.ReservationEtat = order.Etat; app.Category = Dcategory; } if (order.Etat == "DUE OUT") { ReservationTypes Dcategory = cats.First(x => x.CategoryName == "DUE OUT"); Dcategory.ReservationEtat = order.Etat; app.Category = Dcategory; } //category.ReservationEtat = order.Etat; app.Etat = order.Etat; //app.Localite = order.Localite; appointments.Add(app); } catch (Exception) { } } } return(appointments); }