private void OnPHPcmdDone(Object sender,UploadValuesCompletedEventArgs e) // Ricevere un messaggio e lo accoda, solo se senza errori. { // L'handler può non essere statico, così da poter gestire più oggetti Connessione differenti. bool answer = false; PHPanswer tmp = new PHPanswer(); try { var responseString = Encoding.UTF8.GetString(e.Result); // Legge il messaggio di risposta... tmp.rsp = responseString.ToString(); answer = true; // Imposta il flag, c'è una risposta } catch(Exception ex) { tmp.errList.Add(ex.Message); // Legge il messaggio di errore ma non aggiunge nulla alla coso } if(answer) // Se c`è almeno una risposta... { if((tmp.errList.Count == 0) && (tmp.rsp.Length > 0) ) { bool bok = false; PHPanswer dectmp = new PHPanswer(); dectmp.rsp = DecryptMsg(tmp.rsp, ref bok); // Decodifica il messaggio in dectmp if(bok == true) // Se non vi sono errori... { this.phpmsgqueue.Enqueue(dectmp); // ...la accoda } } } }
public string QueueMessage() { string msg = "Coda vuota"; if(this.phpmsgqueue.Count > 0) { this.phpmsg = this.phpmsgqueue.Dequeue(); msg = ConnectionMessages(); } return msg; }
public void ImpostaParametri(string user,string password,string key,string url="",int timer_sec=default_timer) // Inizializza valori { int msec = max_timer * 1000; if((timer_sec >= min_timer) && (timer_sec<= max_timer)) { msec = timer_sec * 1000; } this.refreshTimer = new System.Timers.Timer(msec); this.refreshTimer.Elapsed += OnTimedEvent; this.user = user; this.password = password; this.key = key; this.CommandUrl = url; phpmsg = new PHPanswer(); phpmsgqueue = new Queue<PHPanswer>(); this.client = new WebClientWithCookies(); this.client.UploadValuesCompleted += new UploadValuesCompletedEventHandler(OnPHPcmdDone); // Hander se esecuzione completa }