private void btnAccedi_Click(object sender, EventArgs e) { string nomeSorgente = (string)comboBoxSorgente.SelectedItem; ISorgente sorgente = null; if (nomeSorgente == "Locale") { if (_controller.Autentica(this.textUsername.Text, this.textPassword.Text)) { sorgente = _factory.NuovaSorgenteLocale(); } else { MessageBox.Show("Coppia utente e password non corretta. Impossibile accedere.", "Credenziali non valide", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { IStazione stazione = _stazioniController.Cerca(nomeSorgente)[0]; try { sorgente = _factory.NuovaSorgenteRemota(stazione, this.textUsername.Text, this.textPassword.Text); } catch (CredenzialiInvalideEccezione e1) { MessageBox.Show("Coppia utente e password non corretta. Il server ha rifiutato la connessione.", "Credenziali non valide", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NonFidatoEccezione e2) { MessageBox.Show("Il certificato della stazione remota non è valido.", "Errore certificato", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (RispostaInvalidaEccezione e3) { MessageBox.Show("Il server non ha restituito una risposta valida", "Risposta invalida", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (sorgente != null) { this.Hide(); Form mainForm = new MainForm(_gestioneUtentiController, _stazioniController, _storicoController, sorgente, _gestoreEventi, _controller); DialogResult res = mainForm.ShowDialog(); CaricaSorgenti(); this.Show(); } }
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(); } }
static void Main(string[] args) { Stazione stazione = new Stazione { Nome = "BolognaA1", Locazione = "Bologna", IndirizzoDiRete = IPAddress.Parse("127.0.0.1"), Porta = 8001, ImprontaChiavePubblica = "E2C9153221FE658AFDCEBE095EE5D2392AF8C4AE" }; if (File.Exists("test_client.db")) { File.Delete("test_client.db"); } GestioneStazioniController stazioni = new GestioneStazioniController("test_client.db"); stazioni.Registra(stazione); CreatoreConnessioni creatore = new CreatoreConnessioni(stazioni); SorgenteFactory factory = new SorgenteFactory(creatore, null, null); ISorgente sorgenteRemota = factory.NuovaSorgenteRemota(stazione, "tizio", "password"); Thread threadSorgente = new Thread(() => sorgenteRemota.CicloPrincipale()); threadSorgente.Start(); //IAnalisi analisi = new AnalisiGrezza(); //sorgenteRemota.AggiungiAnalisi(analisi); //IAnalisi magnitudo = new AnalisiMagnitudine(); //sorgenteRemota.AggiungiAnalisi(magnitudo); //magnitudo.RicevitoriRisultato += valore => Console.WriteLine(valore); threadSorgente.Join(); }