public override void ExecuteCommand(DeployClient client, IBufferedPackageInfo packageInfo) { base.ExecuteCommand(client, packageInfo); try { var body = base.GetCommandBody(packageInfo); int len = body[0] * 256 + body[1]; var desc = Encoding.UTF8.GetString(body.Skip(2).Take(len).ToArray()); int fileLength = body.Length - len - 2; var info = JsonConvert.DeserializeObject<SendFileInfo>(desc); if (info.Length != fileLength) throw new Exception("bad file body content"); info.FileBytes = body.Skip(len + 2).ToArray(); string sha = HashAlgorithmProvider.ComputeHash(HashAlgorithmType.SHA1, info.FileBytes, true); if (!info.SHA.Equals(sha)) throw new Exception("bad file body content"); string file = string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(info.Name) , DateTimeExtension.ConvertToTimestamp(info.CreateTime), Path.GetExtension(info.Name)); string path = Path.Combine(AppConfig.SendFileSaveFolder, file); using (var fs = new FileStream(path, FileMode.Create)) { fs.Write(info.FileBytes, 0, (int)info.Length); fs.Flush(); fs.Close(); } //send ack client.Send(CommandCodes.SENDFILE_ACK, Encoding.UTF8.GetBytes(info.FileId)); ConsoleLogger.InfoFormat("{0} sendfile {1} complete", DateTime.Now, info.FileId); } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public override void ExecuteCommand(DeployClient client, IBufferedPackageInfo packageInfo) { base.ExecuteCommand(client, packageInfo); try { client.Send(CommandCodes.PONG, base.GetCommandBody(packageInfo)); } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public override void ExecuteCommand(DeployClient client, IBufferedPackageInfo packageInfo) { base.ExecuteCommand(client, packageInfo); try { string dst = Path.Combine(AppConfig.BackupDstDir, AppConfig.BackupDstDirPrefix + "_" + DateTime.Now.ToString("yyyy-MM-dd")); CopyDirectory(AppConfig.BackupSrcDir, dst); //send ack client.Send(CommandCodes.BACKUP_ACK, base.GetCommandBody(packageInfo)); ConsoleLogger.InfoFormat("{0} backup mission {1} complete", DateTime.Now, new Guid(base.GetCommandBody(packageInfo))); } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }