//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); } }
private void UploadDataUpdates_Click(object sender, EventArgs e) { var dlg = new Jobs.ProcessingDialog(); Action upload = () => { KeyIndexer ndxerInc = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.INCREMENT); IEnumerable <uint> ids = from UpdateIncrement inc in ndxerInc.Source.Enumerate() where inc.IsDeployed == false select inc.ID; var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); foreach (var id in ids) { string fileName = id.ToString("X"); string src = Path.Combine(AppPaths.DataUpdateFolder, fileName); string dst = Urls.DataUpdateDirURL + fileName; netEngin.Upload(dst, src); } netEngin.Upload(Urls.DataManifestURL, AppPaths.DataManifestPath); netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath); foreach (uint id in ids) { var inc = ndxerInc.Get(id) as UpdateIncrement; inc.DeployTime = DateTime.Now; ndxerInc.Source.Replace(ndxerInc.IndexOf(id), inc); } }; Action <Task> onErr = t => { dlg.Dispose(); this.ShowError(t.Exception.InnerException.Message); }; Action onSuccess = () => { dlg.Dispose(); m_tsbUploadDataUpdates.Enabled = false; }; var task = new Task(upload, TaskCreationOptions.LongRunning); task.OnSuccess(onSuccess); task.OnError(onErr); task.Start(); dlg.ShowDialog(Parent); }
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(); }
void ProcessTimer(object unused) { m_timer.Change(Timeout.Infinite, Timeout.Infinite); var netEngin = new NetEngin(Program.NetworkSettings); string tmpFile = Path.GetTempFileName(); netEngin.Download(tmpFile, Urls.ConnectionRespURL, true); var seq = from msg in DialogEngin.ReadConnectionsResp(tmpFile) where msg.ReqID >= m_lastMsgID select msg; if (!seq.Any()) { m_timer.Change(Timeout.Infinite, Timeout.Infinite); } else { Message resp = (from msg in seq where msg.ReqID == m_lastMsgID select msg).SingleOrDefault(); if (resp == null) { PostReqAsync(); } else { switch (resp.MessageCode) { case Message_t.Ok: //reset dlg file try { string dlgFile = SettingsManager.GetClientDialogFilePath(m_clientID); DialogEngin.WriteHubDialog(dlgFile, m_clientID, Enumerable.Empty <Message>()); netEngin.Upload(SettingsManager.GetClientDialogURL(m_clientID), dlgFile, true); m_callback(Result_t.Ok); } catch (Exception ex) { Dbg.Log(ex.Message); PostReqAsync(); } break; case Message_t.InvalidID: case Message_t.Rejected: m_callback(Result_t.Rejected); break; default: Dbg.Assert(false); break; } } } }
void ProcessUploads() { List <string> files = null; lock (m_pendingUploads) if (m_pendingUploads.Count > 0) { files = m_pendingUploads.ToList(); m_pendingUploads.Clear(); } if (files != null) { string dlgFolder = AppPaths.DialogFolderPath; var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); for (int i = files.Count - 1; i >= 0; --i) { string localDlgDir = AppPaths.DialogFolderPath; string fileName = files[i]; string srcPath = Path.Combine(localDlgDir, fileName); string destURI = Urls.DialogDirURL + fileName; try { netEngin.Upload(destURI, srcPath); files.RemoveAt(i); } catch (Exception ex) { AppContext.LogManager.LogSysError("Traitement des transferts vers le serveur: " + ex.Message, true); continue; } } foreach (string file in files) { AddUpload(file); } } }
void PostSyncMessage() { Action post = () => { var netEngin = new NetEngin(Program.NetworkSettings); string tmpFile = Path.GetTempFileName(); var ms = new MemoryStream(); var writer = new RawDataWriter(ms, Encoding.UTF8); writer.Write(m_clInfo.ClientID); writer.Write(m_srvLastMsgID); writer.Write(m_clientLastMsgID); byte[] msgData = ms.ToArray(); try { netEngin.Download(tmpFile, Urls.ConnectionReqURL); var seq = DialogEngin.ReadConnectionsReq(tmpFile); uint msgID = 0; if (seq.Any()) { msgID = seq.Max(m => m.ID); } var msg = new Message(msgID + 1, 0, Message_t.Sync, msgData); DialogEngin.AppendConnectionsReq(tmpFile, new Message[] { msg }); netEngin.Upload(Urls.ConnectionReqURL, tmpFile); } catch (Exception ex) { Dbg.Log("PostSyncMessage: " + ex.Message); } finally { File.Delete(tmpFile); } }; var task = new Task(post, TaskCreationOptions.LongRunning); task.Start(); }
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); } }
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..."); } } }
private void UploadAppUpdates_Click(object sender, EventArgs e) { var filesNames = new Dictionary <AppArchitecture_t, string> { { AppArchitecture_t.Win7SP1, WIN7SP1_UPDATE_FILENAME }, { AppArchitecture_t.Win7SP1X64, WIN7SP1X64_UPADTE_FILENAME }, { AppArchitecture_t.WinXP, WINXP_UPADTE_FILENAME } }; var waitDlg = new Jobs.ProcessingDialog(); Action run = () => { KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE); var seq = (from AppUpdate up in ndxer.Source.Enumerate() where up.DeployTime == AppUpdate.NOT_YET select up).ToArray(); //maj app manifest + manifest global Dictionary <AppArchitecture_t, string> appManifest; try { appManifest = UpdateEngin.ReadAppManifest(AppPaths.AppManifestPath); } catch (Exception ex) { TextLogger.Warning(ex.Message); appManifest = new Dictionary <AppArchitecture_t, string>(); } IUpdateManifest gManifest; try { gManifest = UpdateEngin.ReadUpdateManifest(AppPaths.ManifestPath); } catch (Exception ex) { TextLogger.Warning(ex.Message); gManifest = new UpdateManifest(0, 0); } var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); foreach (AppUpdate up in seq) { gManifest.Versions[up.AppArchitecture] = up.Version; appManifest[up.AppArchitecture] = filesNames[up.AppArchitecture]; string srcFileName = up.ID.ToString("X"); string destFileName = filesNames[up.AppArchitecture]; string dst = Urls.AppUpdateDirURL + destFileName; waitDlg.Message = $"Transfert du fichier {destFileName}. Cette opération peut durer plusieurs minutes."; netEngin.Upload(dst, Path.Combine(AppPaths.AppUpdateFolder, srcFileName)); up.DeployTime = DateTime.Now; ndxer.Source.Replace(ndxer.IndexOf(up.ID), up); } waitDlg.Message = "Transfert du manifest des applications..."; UpdateEngin.WriteAppManifest(AppPaths.AppManifestPath, appManifest); netEngin.Upload(Urls.AppManifestURL, AppPaths.AppManifestPath); waitDlg.Message = "Transfert du manifest global..."; UpdateEngin.WriteUpdateManifest(gManifest, AppPaths.ManifestPath); netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath); }; Action onSucces = () => { m_tsbUploadAppUpdates.Enabled = false; waitDlg.Dispose(); }; Action <Task> onErr = t => { waitDlg.Dispose(); this.ShowError(t.Exception.InnerException.Message); TextLogger.Error(t.Exception.InnerException.Message); }; var task = new Task(run, TaskCreationOptions.LongRunning); task.OnSuccess(onSucces); task.OnError(onErr); task.Start(); waitDlg.ShowDialog(this); }