Example #1
0
        public AllUsersViewModel(AuthenticationService authenticationService)
        {
            if (authenticationService == null)
                throw new ArgumentNullException("authenticationService");

            base.DisplayName = Entity.AllUsersViewModel_DisplayName;

            _authService = authenticationService;

            // Subscribe for notifications of when a new customer is saved.
            _authService.UserAdded += this.OnUserAddedToRepository;
            _authService.UserDeleted += this.OnUserDeletedToRepository;
            // Populate the AllCustomers collection with CustomerViewModels.
            this.CreateAllUsers();              
        }
Example #2
0
        public MainWindowViewModel(NotamDataContext  dataContext )
        {
            base.DisplayName = Entity.MainWindowViewModel_DisplayName;

            _originService = new OriginService(dataContext);
            _firService = new FIRService(dataContext);
            _notamService = new NotamService(dataContext);
            _aerodomService = new AerodomService(dataContext);
            _notamCodeService = new NotamCodeService(dataContext);
            _snowtamService = new SnowtamService(dataContext);
            _authService = new AuthenticationService(dataContext);
            _aftnService = new AftnService(dataContext);
            _intlNotamService = new IntlNotamService(dataContext);
            var workspace = new NotamSearchViewModel(_notamService, Workspaces);
            this.Workspaces.Add(workspace);
            this.SetActiveWorkspace(workspace);
            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0,1,0);
            dispatcherTimer.Start();


        }
Example #3
0
        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);