/// <summary> /// Places the specified origin into the repository. /// If the origin is already in the repository, an /// exception is not thrown. /// </summary> public void Insert(IntlNotam notam) { if (notam == null) throw new ArgumentNullException("notam"); if (!_Notams.Contains(notam)) { _Notams.Add(notam); _dataContext.IntlNotams.InsertOnSubmit(notam); #region Refrence IntlNotam if (notam.RefId > 0) { NotamArchive archive = null; var refNotam = _Notams.Where(n => n.Id.Equals(notam.RefId)).First(); if (refNotam != null) refNotam.Status = "A"; if (notam.NotamType.Equals("R")) archive = new NotamArchive() { Id = refNotam.Id, Reason = String.Format(NotamArchive.ReplacedBy, DateTime.Now.ToString()) }; else if (notam.NotamType.Equals("C")) archive = new NotamArchive() { Id = refNotam.Id, Reason = String.Format(NotamArchive.CancledBy, DateTime.Now.ToString()) }; if (archive != null) { _NotamArchives.Add(archive); _dataContext.NotamArchives.InsertOnSubmit(archive); } } #endregion _dataContext.SubmitChanges(); if (this.NotamAdded != null) this.NotamAdded(this, new EntityAddedEventArgs<IntlNotam>(notam)); } }
public IntlNotamViewModel(IntlNotam notam, IntlNotamService notamService) { if (notam == null) throw new ArgumentNullException("notam"); if (notamService == null) throw new ArgumentNullException("notamService"); _notam = notam.Clone(); _notamService = notamService; this.validators = this.GetType() .GetProperties() .Where(p => this.GetValidations(p).Length != 0) .ToDictionary(p => p.Name, p => this.GetValidations(p)); this.propertyGetters = this.GetType() .GetProperties() .Where(p => this.GetValidations(p).Length != 0) .ToDictionary(p => p.Name, p => this.GetValueGetter(p)); }
public IntlNotamViewModel(IntlNotam notam, IntlNotamService notamService, ObservableCollection<WorkspaceViewModel> parent) : this(notam, notamService) { parentWorkSpaces = parent; }
public IntlNotamViewModel(IntlNotam notam, IntlNotamService notamService, ObservableCollection<WorkspaceViewModel> parent,string archiveReason) : this(notam, notamService,parent) { ArchiveReason = archiveReason; }
private void SendRQN(Dictionary<string, string> dic,NotamDataContext dcontext) { if (!dic.ContainsKey("FIR")) { MessageBox.Show("No FIR in RQN"); return; } string strFir = dic["FIR"]; if (strFir.Length != 4) return; Notam notam2=null; if (!strFir.Substring(0, 2).Equals("OI")) { FIR fir = dcontext.FIRs.Where(n => n.Code.Equals(strFir)).FirstOrDefault(); IntlNotam innotam = ( from o in App._dataDC2.IntlNotams where o.Number.Equals(dic["RQNN"]) && (o.Type.Equals(dic["RQNT"]) && o.Year.Equals(dic["RQNY"]) && o.FIR == fir) select o).FirstOrDefault<IntlNotam>(); if (innotam == null) { innotam = new IntlNotam(); innotam.Type = dic["RQNT"]; innotam.Number = dic["RQNN"]; innotam.Year = dic["RQNY"]; innotam.FIR = dcontext.FIRs.Where(n => (n.Code.Length == 4) && n.Code.Substring(0, 2).Equals(strFir.Substring(0, 2))).FirstOrDefault(); innotam.SendTime = DateTime.Now.ToString("yyMMddHHmm"); innotam.Origin = ( from x in App._dataDC2.Origins where x.Code.Equals("OIIIYNYX") select x).FirstOrDefault<Origin>(); innotam.Status = "N"; IntlNotam notam3 = ( from o in App._dataDC2.IntlNotams where o.Type.Equals(dic["RQNT"]) && o.Year.Equals(dic["RQNY"]) && o.FIR == fir select o into x orderby x.Number descending select x).FirstOrDefault<IntlNotam>(); if (int.Parse(notam3.Number) > int.Parse(notam2.Number)) { innotam.Status = "BL"; } } notam2 = IntlNotamService.ConvertToNotam(innotam); } else { notam2 = ( from o in App._dataDC2.Notams where o.Number.Equals(dic["RQNN"]) && (o.Type.Equals(dic["RQNT"]) && o.Year.Equals(dic["RQNY"])) select o).FirstOrDefault<Notam>(); if (notam2 == null) { notam2 = new Notam(); notam2.Type = dic["RQNT"]; notam2.Number = dic["RQNN"]; notam2.Year = dic["RQNY"]; notam2.FIR = dcontext.FIRs.Where(n => (n.Code.Length==4) && n.Code.Substring(0,2).Equals(strFir.Substring(0,2))).FirstOrDefault(); notam2.SendTime = DateTime.Now.ToString("yyMMddHHmm"); notam2.Origin = ( from x in App._dataDC2.Origins where x.Code.Equals("OIIIYNYX") select x).FirstOrDefault<Origin>(); notam2.Status = "N"; Notam notam3 = ( from o in App._dataDC2.Notams where o.Type.Equals(dic["RQNT"]) && o.Year.Equals(dic["RQNY"]) select o into x orderby x.Number descending select x).FirstOrDefault<Notam>(); if (int.Parse(notam3.Number) > int.Parse(notam2.Number)) { notam2.Status = "BL"; } } } NotamSender notamSender = new NotamSender(notam2); if (dic.ContainsKey("Originat")) { notamSender.SendRQNNotam(dic["Originat"]); } return; }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); CustomPrincipal customPrincipal = new CustomPrincipal(); AppDomain.CurrentDomain.SetThreadPrincipal(customPrincipal); AuthenticationService authenticationService = new AuthenticationService(App._dataDC); if (e != null && e.Args != null && e.Args.Count<string>() > 0) { try { Dictionary<string, string> dic = this.MakeDictionary(e.Args); if (dic != null) { try { User user = authenticationService.AuthenticateUser(dic["User"], dic["Pass"]); customPrincipal = (Thread.CurrentPrincipal as CustomPrincipal); if (customPrincipal == null) { throw new ArgumentException("The application's default thread principal must be set to a CustomPrincipal object on startup."); } customPrincipal.Identity = new CustomIdentity(user.Username, user.Role); } catch (UnauthorizedAccessException exp) { MessageBox.Show("Login failed! Please provide some valid credentials."); } catch (Exception ex) { MessageBox.Show("ERROR: {0}", ex.Message); } if (this.IsAuthenticated) { MainWindowViewModel viewModel = null; MainWindow window = new MainWindow(); string notamType = null; try { if (dic.ContainsKey("GetAddr")) { var aftnService = new AftnService(App._dataDC2); var AftnList = aftnService.GetAftnList().OrderBy(t => t.Series).ToList(); string strFinal=""; foreach(var aftn in AftnList) { strFinal += aftn.Series + "=" + aftn.AftnList+"\n"; } System.IO.File.WriteAllText("C:\\NOTDIR\\ADDR.TXT", strFinal); Application.Current.Shutdown(); return; } if (dic["NotamType"] != null) { notamType = dic["NotamType"].Substring(dic["NotamType"].Length - 1); } if (dic["NotamType"].Contains("NOTAM")) { if (dic["Originat"].IndexOf("OI") != 0) { IntlNotam notam = new IntlNotam { Number = dic.ContainsKey("Num") ? dic["Num"] : "", NotamType = notamType, SendTime = dic.ContainsKey("Filling") ? dic["Filling"] : "", Type = dic.ContainsKey("Type") ? dic["Type"] : "", Year = dic.ContainsKey("year") ? dic["year"] : "", RefType = dic.ContainsKey("RefT") ? dic["RefT"] : "", RefYear = dic.ContainsKey("RefY") ? dic["RefY"] : "", RefNum = dic.ContainsKey("RefN") ? dic["RefN"] : "", LowerLimit = dic.ContainsKey("Lower") ? dic["Lower"] : "", HigherLimit = dic.ContainsKey("Upper") ? dic["Upper"] : "", Latitude = dic.ContainsKey("Latitude") ? dic["Latitude"] : "", Longtitude = dic.ContainsKey("Longtitude") ? dic["Longtitude"] : "", Radius = dic.ContainsKey("Radius") ? dic["Radius"] : "", FirAero = dic.ContainsKey("FirAd") ? dic["FirAd"] : "", FromDate = dic.ContainsKey("FromDate") ? dic["FromDate"] : "", ToDate = dic.ContainsKey("ToDate") ? dic["ToDate"] : "", PermEst = dic.ContainsKey("EstPerm") ? dic["EstPerm"] : "", EFreeText = dic.ContainsKey("ItemE") ? dic["ItemE"] : "", DFreeText = dic.ContainsKey("ItemD") ? dic["ItemD"] : "", FFreeText = dic.ContainsKey("ItemF") ? dic["ItemF"] : "", GFreeText = dic.ContainsKey("ItemG") ? dic["ItemG"] : "", Origin = dic.ContainsKey("FIR") ? ( from o in App._dataDC2.Origins where o.Code.Equals(dic["Originat"]) select o).FirstOrDefault<Origin>() : null, FIR = dic.ContainsKey("FIR") ? App._dataDC2.FIRs.Where(n => (n.Code.Length==4) && n.Code.Substring(0,2).Equals(dic["FIR"].Substring(0,2))).FirstOrDefault() : null, Status = "D", NotamCode = dic.ContainsKey("QCode") ? ( from o in App._dataDC2.NotamCodes where (o.Subject + o.Condition).Equals(dic["QCode"]) select o).FirstOrDefault<NotamCode>() : null }; IntlNotamService intlNotamService = new IntlNotamService(App._dataDC2); if (!intlNotamService.ContainsNotam(notam)) { intlNotamService.Insert(notam); // MessageBox.Show("International NOTAM Inserted To Database Successfully"); } else { // MessageBox.Show("International NOTAM Already Inserted To Database"); } Application.Current.Shutdown(); return; } // if (!dic.ContainsKey("FIR")) // { // dic.Add("FIR", "OIIX"); // } // Notam notam2 = new Notam // { // Number = "", // NotamType = notamType, // SendTime = dic.ContainsKey("Filling") ? dic["Filling"] : "", // Type = dic.ContainsKey("Type") ? dic["Type"] : "", // Year = dic.ContainsKey("year") ? dic["year"] : "", // RefType = dic.ContainsKey("RefT") ? dic["RefT"] : "", // RefYear = dic.ContainsKey("RefY") ? dic["RefY"] : "", // RefNum = dic.ContainsKey("RefN") ? dic["RefN"] : "", // LowerLimit = dic.ContainsKey("Lower") ? dic["Lower"] : "", // HigherLimit = dic.ContainsKey("Upper") ? dic["Upper"] : "", // Latitude = dic.ContainsKey("Latitude") ? dic["Latitude"] : "", // Longtitude = dic.ContainsKey("Longtitude") ? dic["Longtitude"] : "", // Radius = dic.ContainsKey("Radius") ? dic["Radius"] : "", // FirAero = dic.ContainsKey("FirAd") ? dic["FirAd"] : "", // FromDate = dic.ContainsKey("FromDate") ? dic["FromDate"] : "", // ToDate = dic.ContainsKey("ToDate") ? dic["ToDate"] : "", // PermEst = dic.ContainsKey("EstPerm") ? dic["EstPerm"] : "", // EFreeText = dic.ContainsKey("ItemE") ? dic["ItemE"] : "", // DFreeText = dic.ContainsKey("ItemD") ? dic["ItemD"] : "", // FFreeText = dic.ContainsKey("ItemF") ? dic["ItemF"] : "", // GFreeText = dic.ContainsKey("ItemG") ? dic["ItemG"] : "", // Origin = ( // from o in App._dataDC2.Origins // where o.Code.Equals(dic["Originat"]) // select o).FirstOrDefault<Origin>(), // FIR = ( // from o in App._dataDC2.FIRs // where o.Code.Equals(dic["FIR"]) // select o).FirstOrDefault<FIR>(), // Status = "D", // NotamCode = dic.ContainsKey("QCode") ? ( // from o in App._dataDC2.NotamCodes // where (o.Subject + o.Condition).Equals(dic["QCode"]) // select o).FirstOrDefault<NotamCode>() : null // }; // viewModel = new MainWindowViewModel(App._dataDC2, notam2); } else { if (dic["NotamType"].Contains("RQN")) { SendRQN(dic, App._dataDC2); } else { SendRQL(dic); } Application.Current.Shutdown(); return; } } catch (System.Exception ex) { MessageBox.Show(ex.Message); Application.Current.Shutdown(); return; } EventHandler handler = null; handler = delegate { viewModel.RequestClose -= handler; window.Close(); }; viewModel.RequestClose += handler; window.DataContext = viewModel; window.ShowDialog(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (!IsAuthenticated) { //Show the login view AuthenticationViewModel viewModel = new AuthenticationViewModel(authenticationService);
string GenerateNotamText(IntlNotam notam) { var ntmBuilder = new StringBuilder(); #region First Line if (notam.Origin != null && !string.IsNullOrEmpty(notam.SendTime)) ntmBuilder.Append(notam.SendTime.Substring(notam.SendTime.Length - 6, 6) + " " + notam.Origin.Code + Environment.NewLine); #endregion #region 3rd line ntmBuilder.Append(openPar + notam.Type + notam.Number + slash + notam.Year + " " + "NOTAM" + notam.NotamType + Environment.NewLine); #endregion #region Q line if (notam.FIR != null) ntmBuilder.Append("Q" + closePar + notam.FIR.Code); if (notam.NotamCode != null) { ntmBuilder.Append(slash + notam.NotamCode.ToString()); if (!string.IsNullOrEmpty(notam.NotamCode.Traffic)) ntmBuilder.Append(slash + notam.NotamCode.Traffic); if (!string.IsNullOrEmpty(notam.NotamCode.Purpose)) ntmBuilder.Append(slash + notam.NotamCode.Purpose); if (!string.IsNullOrEmpty(notam.NotamCode.Scope)) ntmBuilder.Append(slash + notam.NotamCode.Scope); } if (!string.IsNullOrEmpty(notam.LowerLimit)) ntmBuilder.Append(slash + notam.LowerLimit); if (!string.IsNullOrEmpty(notam.HigherLimit)) ntmBuilder.Append(slash + notam.HigherLimit); if (!string.IsNullOrEmpty(notam.Latitude)) ntmBuilder.Append(slash + notam.Latitude); if (!string.IsNullOrEmpty(notam.Longtitude)) ntmBuilder.Append(slash + notam.Longtitude); if (!string.IsNullOrEmpty(notam.Radius)) ntmBuilder.Append(slash + notam.Radius); ntmBuilder.Append(Environment.NewLine); #endregion #region A B C line ntmBuilder.Append("A" + closePar + notam.FirAero); if (!string.IsNullOrEmpty(notam.FirA2)) ntmBuilder.Append(slash + notam.FirA2); if (!string.IsNullOrEmpty(notam.FirA3)) ntmBuilder.Append(slash + notam.FirA3); if (!string.IsNullOrEmpty(notam.FirA4)) ntmBuilder.Append(slash + notam.FirA4); if (!string.IsNullOrEmpty(notam.FirA5)) ntmBuilder.Append(slash + notam.FirA5); ntmBuilder.Append(" B" + closePar + notam.FromDate); ntmBuilder.Append(" C" + closePar + notam.ToDate); if (!string.IsNullOrEmpty(notam.PermEst)) ntmBuilder.Append(" " + notam.PermEst); ntmBuilder.Append(Environment.NewLine); #endregion #region D E line if (!string.IsNullOrEmpty(notam.DFreeText)) ntmBuilder.Append("D" + closePar + notam.DFreeText + Environment.NewLine); if (!string.IsNullOrEmpty(notam.EFreeText)) ntmBuilder.Append("E" + closePar + notam.EFreeText); #endregion #region F G line ntmBuilder.Append(closePar); #endregion return ntmBuilder.ToString(); }
public IntlNotam Clone() { IntlNotam n = new IntlNotam(); n.Code_Id = this.Code_Id; n.Id = this.Id; n.Number = this.Number; n.Origin = this.Origin; n.DFreeText = this.DFreeText; n.EFreeText = this.EFreeText; n.FFreeText = this.FFreeText; n.FIR = this.FIR; n.Fir_Id = this.Fir_Id; n.FirA2 = this.FirA2; n.FirA3 = this.FirA3; n.FirA4 = this.FirA4; n.FirA5 = this.FirA5; n.FirAero = this.FirAero; n.FromDate = this.FromDate; n.FromRDate = this.FromRDate; n.GFreeText = this.GFreeText; n.HigherLimit = this.HigherLimit; n.Latitude = this.Latitude; n.Longtitude = this.Longtitude; n.LowerLimit = this.LowerLimit; n.NotamCode = this.NotamCode; n.NotamType = this.NotamType; n.Origin_Id = this.Origin_Id; n.PermEst = this.PermEst; n.Radius = this.Radius; n.RefId = this.RefId; n.RefNum = this.RefNum; n.RefType = this.RefType; n.RefYear = this.RefType; n.SendTime = this.SendTime; n.Status = this.Status; n.ToDate = this.ToDate; n.ToRDate = this.ToRDate; n.Type = this.Type; n.Year = this.Year; return n; }
public void Archive(IntlNotam notam) { if (notam.Status.Equals("D")) { notam.Status = "A"; // archive = new NotamArchive() // { // Id = notam.Id, // Reason = // String.Format(NotamArchive.ForcedBy, DateTime.Now.ToString()) // }; // _NotamArchives.Add(archive); // _dataContext.NotamArchives.InsertOnSubmit(archive); _dataContext.SubmitChanges(); _Notams = LoadNotams(_dataContext); _ArchNotams = LoadArchiveNotams(_dataContext); } }
public void Delete(IntlNotam notam) { if (notam == null) throw new ArgumentNullException("notam"); List<IntlNotam> listNotams = _Notams; switch (notam.Status[0]) { case 'A': listNotams = _ArchNotams; break; } if (listNotams.Contains(notam)) { listNotams.Remove(notam); _dataContext.IntlNotams.DeleteOnSubmit(notam); _dataContext.SubmitChanges(); } if (this.NotamDeleted != null) this.NotamDeleted(this, new EntityAddedEventArgs<IntlNotam>(notam)); }
public static Notam ConvertToNotam(IntlNotam nt) { Notam n=new Notam(); n.Code_Id = nt.Code_Id; n.Id = nt.Id; n.Number = nt.Number; n.Origin = nt.Origin; n.DFreeText = nt.DFreeText; n.EFreeText = nt.EFreeText; n.FFreeText = nt.FFreeText; n.FIR = nt.FIR; n.Fir_Id = nt.Fir_Id; n.FirA2 = nt.FirA2; n.FirA3 = nt.FirA3; n.FirA4 = nt.FirA4; n.FirA5 = nt.FirA5; n.FirAero = nt.FirAero; n.FromDate = nt.FromDate; n.FromRDate = nt.FromRDate; n.GFreeText = nt.GFreeText; n.HigherLimit = nt.HigherLimit; n.Latitude = nt.Latitude; n.Longtitude = nt.Longtitude; n.LowerLimit = nt.LowerLimit; n.NotamCode = nt.NotamCode; n.NotamType = nt.NotamType; n.Origin_Id = nt.Origin_Id; n.PermEst = nt.PermEst; n.Radius = nt.Radius; n.RefId = nt.RefId; n.RefNum = nt.RefNum; n.RefType = nt.RefType; n.RefYear = nt.RefType; n.SendTime = nt.SendTime; n.Status = nt.Status; n.ToDate = nt.ToDate; n.ToRDate = nt.ToRDate; n.Type = nt.Type; n.Year = nt.Year; return n; }
/// <summary> /// /// </summary> /// <param name="origin"></param> /// <summary> /// Returns true if the specified origin exists in the /// repository, or false if it is not. /// </summary> public bool ContainsNotam(IntlNotam notam) { if (notam == null) throw new ArgumentNullException("notam"); var notamInList = _AllNotams.Where(n => n.Number.Equals(notam.Number) && (n.Type.Equals(notam.Type)) && (n.Year.Equals(notam.Year)) && (string.IsNullOrEmpty(notam.FirAero) || (!string.IsNullOrEmpty(n.FirAero) && n.FirAero.Equals(notam.FirAero))) ).ToList(); return notamInList.Count>0; }
public void UpdateWithNumber(IntlNotam notam) { if (string.IsNullOrEmpty(notam.Number)) { var curNumber = (from n in _Notams where (n.Type.Equals(notam.Type)) orderby n.Number descending select n.Number).FirstOrDefault(); if (string.IsNullOrEmpty(curNumber)) curNumber = "0"; notam.Number = (Int32.Parse(curNumber) + 1).ToString(); } Update(notam); }
/// <summary> /// /// </summary> /// <param name="origin"></param> public void Update(IntlNotam notam) { //_dataContext.Origins.OnSubmit(origin); _dataContext.SubmitChanges(); }