//private: void Initialize() { AppContext.LogManager.LogSysActivity("Démarrage de la réinitialisation des fichiers sur le serveur", true); string reqFilePath = AppPaths.ConnectionReqPath; DialogEngin.WriteConnectionsReq(reqFilePath, Enumerable.Empty <Message>()); string respFilePath = AppPaths.ConnectionRespPath; DialogEngin.WriteConnectionsResp(respFilePath, Enumerable.Empty <Message>()); try { var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); netEngin.Upload(Urls.ConnectionReqURL, reqFilePath); netEngin.Upload(Urls.ConnectionRespURL, respFilePath); m_initializationDone = true; AppContext.LogManager.LogSysActivity("Réinitialisation des fichiers sur le serveur terminée", true); } catch (Exception ex) { AppContext.LogManager.LogSysError("Une erreur est survenue lors de l’initialisation du serveur: " + ex.Message, true); } }
void ProcessResp() { StopTimer(); string tmpFile = Path.GetTempFileName(); Dbg.Log($"Processing Response, attempts = {m_attemptsCount + 1}."); m_exHandler = RespExceptionHandler; var netEngin = new NetEngin(Program.NetworkSettings); using (new AutoReleaser(() => File.Delete(tmpFile))) { SetProgressMessage("Réception des données à partir du serveur..."); try { netEngin.Download(tmpFile, Urls.ConnectionRespURL, true); } catch (Exception ex) { Dbg.Log(ex.Message); DialogEngin.WriteConnectionsResp(tmpFile, Enumerable.Empty <HubCore.DLG.Message>()); } IEnumerable <HubCore.DLG.Message> messages = DialogEngin.ReadConnectionsResp(tmpFile); HubCore.DLG.Message[] msgs = (from resp in messages where resp.ReqID >= m_msgID select resp).ToArray(); HubCore.DLG.Message msg = msgs.Where(m => m.ReqID == m_msgID).SingleOrDefault(); uint clID = msg == null ? 0 : BitConverter.ToUInt32(msg.Data, 0); if (msg != null && clID == m_clInfo.ClientID) { switch (msg.MessageCode) { case Message_t.InvalidID: Dbg.Log($"Got invalid ID! (ClientID = {m_clInfo.ClientID})."); ClientInfo clInfo = ClientInfo.CreateClient(m_clInfo.ProfileID); clInfo.ContaclEMail = m_clInfo.ContaclEMail; clInfo.ContactName = m_clInfo.ContactName; clInfo.ContactPhone = m_clInfo.ContactPhone; m_clInfo = clInfo; if (++m_attemptsCount >= SettingsManager.MaxConnectAttemps) { if (ShowMessage(MAX_ATTEMPTS_ERROR, MessageBoxButtons.YesNo) != DialogResult.Yes) { CloseDialog(); return; } else { m_attemptsCount = 0; } } PostReq(); break; case Message_t.Ok: Dbg.Log("Client registered :-)!"); Program.Settings.ClientInfo = m_clInfo; SetProgressMessage("Enregistrement terminé."); //creation des fichier dlg string dlgFile = SettingsManager.GetClientDialogFilePath(clID); DialogEngin.WriteHubDialog(dlgFile, clID, Enumerable.Empty <HubCore.DLG.Message>()); try { netEngin.Upload(SettingsManager.GetClientDialogURL(clID), dlgFile, true); } catch (Exception ex) { Dbg.Log(ex.Message); } ShowMessage("Votre enregistrement est maintenant terminé. " + "Vous pouvez commencer à utiliser l’application."); IsRegistered = true; CloseDialog(); break; case Message_t.InvalidProfile: Dbg.Log($"Got invalid Profile! (ProfileID: = {m_clInfo.ProfileID})."); ShowMessage(SRV_ERROR); CloseDialog(); return; case Message_t.Rejected: Dbg.Log("Got reject connection!"); ShowMessage(REJECT_CONNCTION_ERROR); CloseDialog(); return; default: Dbg.Log("Got invalid response!!!!"); Dbg.Assert(false); break; } } else if (msgs.Length > 0) { Dbg.Log("Request message lost."); if (++m_attemptsCount >= SettingsManager.MaxConnectAttemps) { if (ShowMessage(MAX_ATTEMPTS_ERROR, MessageBoxButtons.YesNo) != DialogResult.Yes) { CloseDialog(); return; } else { m_attemptsCount = 0; } } PostReq(); } else if (++m_attemptsCount >= SettingsManager.MaxConnectAttemps) { Dbg.Log("Timeout."); if (ShowMessage(MAX_ATTEMPTS_ERROR, MessageBoxButtons.YesNo) == DialogResult.Yes) { StartTimer(); m_attemptsCount = 0; PostReq(); } else { CloseDialog(); } } else { StartTimer(); SetProgressMessage("Attente de la réponse du serveur..."); } } }