Пример #1
0
        /// <summary>
        ///     Errore nel client
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Application_Error(object sender, EventArgs e)
        {
            var exc = Server.GetLastError();

            Log.Error("### ERROR ###", exc);
            Response.Clear();
            if (exc.GetType() == typeof(UnauthorizedAccessException))
            {
                var controller = new AutenticazioneController();
                controller.Logout();
                Response.Redirect($"~/Login?ReturnUrl={Request.Url.LocalPath}");
            }
        }
Пример #2
0
        public Login(AutenticazioneController controller, IGestioneUtentiController gestioneUtentiController,
                     IGestioneStazioniController stazioniController, IStoricoController storicoController,
                     SorgenteFactory factory, GestoreEventi gestoreEventi)
        {
            InitializeComponent();
            _controller = controller;
            _gestioneUtentiController = gestioneUtentiController;
            _stazioniController       = stazioniController;
            _storicoController        = storicoController;
            _factory       = factory;
            _gestoreEventi = gestoreEventi;

            var materialSkinManager = MaterialSkinManager.Instance;

            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme       = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = SismioColor.Scheme;
            this.background.BackColor       = SismioColor.Scheme.DarkPrimaryColor;
            //
            // Load Font
            //
            byte[] fontData = Properties.Resources.RobotoMono_Bold;
            IntPtr fontPtr  = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(fontData.Length);

            System.Runtime.InteropServices.Marshal.Copy(fontData, 0, fontPtr, fontData.Length);
            uint dummy = 0;

            fonts.AddMemoryFont(fontPtr, Properties.Resources.RobotoMono_Bold.Length);
            AddFontMemResourceEx(fontPtr, (uint)Properties.Resources.RobotoMono_Bold.Length, IntPtr.Zero, ref dummy);
            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(fontPtr);

            robotoMono = new Font(fonts.Families[0], 14.0F);

            this.textUsername.Font = robotoMono;
            this.title.Font        = new Font(fonts.Families[0], 56.0F);

            // Focus at the startup
            this.ActiveControl = this.textUsername;

            // Precompilo il form
            this.textUsername.Text = "admin";
            this.textPassword.Text = "admin";

            // Carico la combo box
            CaricaSorgenti();
        }
Пример #3
0
        public MainForm(IGestioneUtentiController gestioneUtentiController,
                        IGestioneStazioniController gestioneStazioniController,
                        IStoricoController storico,
                        ISorgente sorgente, GestoreEventi gestoreEventi,
                        AutenticazioneController autenticazioneController)
        {
            InitializeComponent();

            this.homeDashboard1.Sorgente      = sorgente;
            this.homeDashboard1.GestoreEventi = gestoreEventi;
            this.homeDashboard1.GestioneStazioniController = gestioneStazioniController;

            this.storico1.StoricoController               = storico;
            this.homeGestioneUtenti1.UtentiController     = gestioneUtentiController;
            this.homeGestioneStazioni1.StazioniController = gestioneStazioniController;

            var materialSkinManager = MaterialSkinManager.Instance;

            materialSkinManager.AddFormToManage(this);
            materialSkinManager.Theme       = MaterialSkinManager.Themes.LIGHT;
            materialSkinManager.ColorScheme = SismioColor.Scheme;
            this.navbar.BackColor           = SismioColor.Scheme.DarkPrimaryColor;
            //this.BackColor = SismioColor.BackColor;

            this.tabControl.SelectedTab = this.tabDashboard;

            this.tabDashboard.BackColor        = SismioColor.BackColor;
            this.tabGestioneStazioni.BackColor = SismioColor.BackColor;
            this.tabGestioneUtenti.BackColor   = SismioColor.BackColor;
            this.tabStorico.BackColor          = SismioColor.BackColor;

            // Nascondo i pulsanti in base ai permessi
            IUtente utenteCorrente = autenticazioneController.UtenteAttivo;

            if (utenteCorrente == null)
            {
                this.navGestioneStazioni.Visible = false;
                this.navGestioneUtenti.Visible   = false;
            }
            else
            {
                this.navGestioneStazioni.Visible = utenteCorrente.PuoModificareStazioni();
                this.navGestioneUtenti.Visible   = utenteCorrente.PuoModificareUtenti();
            }
        }
Пример #4
0
        static void Main()
        {
            // Inizializzo il sensore
            ISensore sensore = new MockSensore();
            //ISensore sensore = new SensoreSeriale("COM10", 74880);
            //sensore.RicevitoriDatiSensore += dati => Console.WriteLine(String.Join(",", dati));

            // Creo il thread del sensore e lo avvio
            Thread threadSensore = new Thread(() => sensore.CicloPrincipale());

            threadSensore.Name = "Thread Sensore";
            threadSensore.Start();

            IGestioneStazioniController stazioniController = new GestioneStazioniController(PERCORSO_DATABASE);

            Stazione stazione = new Stazione
            {
                Nome                   = "BolognaA1",
                Locazione              = "Bologna",
                IndirizzoDiRete        = IPAddress.Parse("127.0.0.1"),
                Porta                  = 8001,
                ImprontaChiavePubblica = "E2C9153221FE658AFDCEBE095EE5D2392AF8C4AE"
            };

            /*
             * // Inizializzo il gestore delle stazioni
             *
             * IGestioneStazioniController stazioniController = new GestioneStazioniController(PERCORSO_DATABASE);
             * stazioniController.Registra(stazione);
             *
             * stazione.Nome = "ReggioEmiliaA1";
             * stazione.Locazione = "Reggio Emilia";
             * stazione.IndirizzoDiRete = IPAddress.Parse("10.1.45.230");
             * stazione.Porta = 5555;
             *
             * stazioniController.Registra(stazione);*/

            // Inizializzo il gestore utenti

            IGestioneUtentiController gestioneUtentiController = new GestioneUtentiController(PERCORSO_DATABASE);
            AutenticazioneController  autenticazioneController = new AutenticazioneController(gestioneUtentiController);

            // Aggiungo l'utente tizio
            Utente utente = new UtenteNormale
            {
                Nome        = "tizio",
                Cognome     = "caio",
                Email       = "*****@*****.**",
                LoginRemoto = true,
                Username    = "******"
            };

            utente.ImpostaPasswordDaOriginale("password");
            if (gestioneUtentiController.ValidaCredenziali("tizio", "password") == null)
            {
                gestioneUtentiController.Registra(utente);
            }

            EventoSismico evento = new EventoSismico
            {
                Messaggio = "Frequenza",
                Priorita  = Priorita.Fatal,
                Stazione  = stazione,
                Tag       = "Frequenza",
                Timestamp = 1234
            };
            IStoricoController storicoController = new StoricoController(PERCORSO_DATABASE);

            storicoController.RegistraEvento(evento);

            GestoreEventi gestoreEventi = new GestoreEventi(storicoController);

            gestoreEventi.RicevitoriEventoSismico += sismico => Console.WriteLine(sismico);

            // Avvio il server della stazione
            ServerStazione server = new ServerStazione(sensore, gestioneUtentiController, Sismio.CertificatoResource.certificato, "passwordsismio");

            server.IndirizzoServer = "127.0.0.1";  // TODO: cambiare con il proprio locale ( tipo 192.168.1.105 )
            server.Avvia();

            CreatoreConnessioni creatore = new CreatoreConnessioni(stazioniController);
            SorgenteFactory     factory  = new SorgenteFactory(creatore, sensore, gestoreEventi);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Form loginForm = new Login(autenticazioneController, gestioneUtentiController, stazioniController, storicoController, factory, gestoreEventi);

            Application.Run(loginForm);
        }