예제 #1
0
파일: App.xaml.cs 프로젝트: ali60/NOTAM
        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);
예제 #2
0
using System;