Esempio n. 1
0
        public void Restore(string filePath, string destFolder)
        {
            Initializing?.Invoke();

            using (FileStream fs = File.OpenRead(filePath))
            {
                var    reader = new RawDataReader(fs, Encoding.UTF8);
                byte[] sign   = Signature;

                foreach (byte b in sign)
                {
                    if (reader.ReadByte() != b)
                    {
                        throw new CorruptedFileException(filePath);
                    }
                }

                reader.ReadTime();           //ignore creation time
                int headerLen = reader.ReadInt();
                reader.ReadBytes(headerLen); //ignore header

                Restoring?.Invoke();
                var bag = new FilesBag();

                Clean(destFolder);

                bag.Decompress(fs, destFolder);

                Done?.Invoke();
            }
        }
Esempio n. 2
0
        public IArchiveContent GetArchiveContent(string filePath)
        {
            var archData = new ArchiveContent();

            using (FileStream fs = File.OpenRead(filePath))
            {
                var    reader = new RawDataReader(fs, Encoding.UTF8);
                byte[] sign   = Signature;

                foreach (byte b in sign)
                {
                    if (reader.ReadByte() != b)
                    {
                        throw new CorruptedFileException(filePath);
                    }
                }

                archData.CreationTime = reader.ReadTime();
                int len = reader.ReadInt();
                archData.ArchiveHeader = reader.ReadBytes(len);
                archData.Files         = FilesBag.GetContent(fs);

                return(archData);
            }
        }
        Message ProcessLogMessage(Message msg, uint clID)
        {
            Dbg.Assert(msg.MessageCode == Message_t.Log);

            var ms     = new MemoryStream(msg.Data);
            var reader = new RawDataReader(ms, Encoding.UTF8);

            DateTime tm    = reader.ReadTime();
            bool     isErr = reader.ReadBoolean();
            string   txt   = reader.ReadString();

            if (isErr)
            {
                AppContext.LogManager.LogSysActivity($"Réception log d'erreur du client {ClientStrID(clID)}");
                AppContext.LogManager.LogClientError(clID, txt, tm);
            }
            else
            {
                AppContext.LogManager.LogSysActivity($"Réception d'un log d'activité du client {ClientStrID(clID)}");
                AppContext.LogManager.LogClientActivity(clID, txt, tm);
            }

            return(null);
        }
        Message ProcessStartMessage(Message msg)
        {
            Dbg.Assert(msg.MessageCode == Message_t.Start);

            var  reader               = new RawDataReader(new MemoryStream(msg.Data), Encoding.UTF8);
            uint clID                 = reader.ReadUInt();
            ClientEnvironment clEnv   = ClientEnvironment.Load(reader);
            DateTime          dtStart = reader.ReadTime();

            var client = m_ndxerClients.Get(clID) as HubClient;

            if (client == null)
            {
                AppContext.LogManager.LogSysActivity("Réception d’une notification de démarrage " +
                                                     $"de la part d’un client inexistant ({ClientStrID(clID)}). Réinitialisation du client", true);

                //maj du fichier gov
                string srvDlgFile = AppPaths.GetSrvDialogFilePath(clID);

                //le client n'existe pas => son fichier gov n'existe pas
                var clDlg = new ClientDialog(clID, ClientStatus_t.Reseted, Enumerable.Empty <Message>());
                DialogEngin.WriteSrvDialog(srvDlgFile, clDlg);

                AddUpload(Path.GetFileName(srvDlgFile));
                return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Rejected, msg.Data));
            }


            AppContext.LogManager.LogSysActivity("Réception d’une notification de démarrage " +
                                                 $"de la part du client {ClientStrID(clID)}", true);

            //verifier le statut du client
            var clStatus = m_ndxerClientsStatus.Get(clID) as ClientStatus;

            if (clStatus.Status != ClientStatus_t.Enabled)
            {
                AppContext.LogManager.LogSysActivity($"Démmarage du Client { ClientStrID(clID)} non autorisé. Requête rejetée", true);
                return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Rejected, msg.Data));
            }


            //reset dlg files
            DialogEngin.WriteHubDialog(AppPaths.GetClientDilogFilePath(clID), clID, Enumerable.Empty <Message>());
            DialogEngin.WriteSrvDialog(AppPaths.GetSrvDialogFilePath(clID),
                                       new ClientDialog(clID, clStatus.Status, Enumerable.Empty <Message>()));

            try
            {
                new NetEngin(AppContext.Settings.NetworkSettings).Upload(Urls.DialogDirURL,
                                                                         new string[] { AppPaths.GetClientDilogFilePath(clID), AppPaths.GetSrvDialogFilePath(clID) });
            }
            catch (Exception ex)
            {
                AppContext.LogManager.LogSysError($"Traitement de la requête de démarrage du client {ClientStrID(clID)}: " +
                                                  $"{ ex.Message}. demande ignorée, laisser le client reformuler la requête.", true);

                return(null);    // let the cleint retry req.
            }


            AppContext.LogManager.LogSysActivity($"Client {ClientStrID(clID)} démarré le { dtStart.Date.ToShortDateString()} " +
                                                 $"à { dtStart.ToLongTimeString()}", true);

            //verifier si l'env du client a changé
            UpdateClientEnvironment(clID, clEnv);

            //ajouter client dans running liste
            m_onlineClients.Add(clID, dtStart);
            AppContext.LogManager.StartLogger(clID);
            AppContext.LogManager.LogClientActivity(clID, "Démarrage");

            //maj du last seen
            clStatus.LastSeen = dtStart;
            m_ndxerClientsStatus.Source.Replace(m_ndxerClientsStatus.IndexOf(clID), clStatus);
            ClientStarted?.Invoke(clID);

            return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Ok, msg.Data));
        }