void PostReq() { Dbg.Log("Sending connection request."); string tmpFile = Path.GetTempFileName(); m_exHandler = ReqExceptionHandler; using (new AutoReleaser(() => File.Delete(tmpFile))) { var netEngin = new NetEngin(Program.NetworkSettings); SetProgressMessage("Envoi des données au serveur..."); netEngin.Download(tmpFile, Urls.ConnectionReqURL, true); List <HubCore.DLG.Message> msgs = DialogEngin.ReadConnectionsReq(tmpFile).ToList(); m_msgID = msgs.Count == 0 ? 1 : msgs.Max(m => m.ID) + 1; var ms = new MemoryStream(); byte[] ciBytes = m_clInfo.GetBytes(); byte[] ceBytes = GetEnvironment().GetBytes(); ms.Write(ciBytes, 0, ciBytes.Length); ms.Write(ceBytes, 0, ceBytes.Length); var msg = new HubCore.DLG.Message(m_msgID, 0, Message_t.NewConnection, ms.ToArray()); msgs.Add(msg); DialogEngin.WriteConnectionsReq(tmpFile, msgs); netEngin.Upload(Urls.ConnectionReqURL, tmpFile, true); StartTimer(); SetProgressMessage("Attente de la réponse du serveur..."); } }
//private: void PostReqAsync() { Action upload = () => { var msg = new Message(++m_lastMsgID, 0, Message_t.Resume, BitConverter.GetBytes(m_clientID)); IEnumerable <Message> msgs = DialogEngin.ReadConnectionsReq(m_cxnReqFile); DialogEngin.WriteConnectionsReq(m_cxnReqFile, msgs.Add(msg)); var netEngin = new NetEngin(Program.NetworkSettings); try { netEngin.Upload(Urls.ConnectionReqURL, m_cxnReqFile, true); m_timer.Change(TIMER_INTERVALL, TIMER_INTERVALL); } catch (Exception ex) { Dbg.Log(ex.Message); m_callback(Result_t.Error); m_callback = null; } }; new Task(upload, TaskCreationOptions.LongRunning).Start(); }
//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 PostReq() { Dbg.Log("Posting start msg..."); //posting to cnx file string tmpFile = Path.GetTempFileName(); var netEngin = new NetEngin(Program.NetworkSettings); try { netEngin.Download(tmpFile, Urls.ConnectionReqURL, true); IEnumerable <Message> msgsCnx = DialogEngin.ReadConnectionsReq(tmpFile); if (msgsCnx.Any()) { m_reqID = msgsCnx.Max(m => m.ID); } else { m_reqID = 0; } Message req = new Message(++m_reqID, 0, Message_t.Start, m_msgData); DialogEngin.WriteConnectionsReq(tmpFile, msgsCnx.Add(req)); netEngin.Upload(Urls.ConnectionReqURL, tmpFile, true); m_cnxAttempts = 0; Dbg.Log("Posting start msg done."); } catch (Exception ex) { Dbg.Log(ex.Message); } finally { m_timer.Start(); File.Delete(tmpFile); } }