public void setConnectionTimeout(DeployClient deployClient) { if (deployClient.timeout == 0) _httpClient.getHttpClient().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_SECS); else _httpClient.getHttpClient().setConnectionTimeout(deployClient.timeout); }
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); } }
static void SetupCommand(ConsoleShell shell, DeployClient client, bool isAdmin) { Assembly.GetExecutingAssembly().GetTypes().Where(i => i.IsClass && !i.IsAbstract && typeof(XShellCommandBase).IsAssignableFrom(i)).ToList().ForEach(i => { bool load = false; var attr = i.GetCustomAttribute<ShellAuthorityAttribute>(); if (attr != null) { if (isAdmin) { load = attr.IsAdministrator; } } else { load = true; } if (load) { var instance = Activator.CreateInstance(i, client); if (instance != null) { shell.SetupCommand(instance as IShellCommand); } } }); }
public void setConnectionTimeout(DeployClient deployClient) { if (deployClient.timeout == 0) { _httpClient.getHttpClient().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_SECS); } else { _httpClient.getHttpClient().setConnectionTimeout(deployClient.timeout); } }
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 void setProxy(DeployClient deployClient) { if (deployClient.proxy.IsBypass) return; WebProxy proxy = new WebProxy(deployClient.proxy.Host, deployClient.proxy.Port); proxy.UseDefaultCredentials = false; if (deployClient.proxy.IsCredentialsExists) { proxy.Credentials = new NetworkCredential(deployClient.proxy.Username, deployClient.proxy.Password); } _httpClient.getHttpClient().setProxy(proxy); }
public override void ExecuteCommand(DeployClient client, IBufferedPackageInfo packageInfo) { base.ExecuteCommand(client, packageInfo); try { var body = base.GetCommandBody(packageInfo); ConsoleLogger.InfoFormat("{0} {1}", DateTime.Now, Encoding.UTF8.GetString(body)); } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", GetType().Name, DateTime.Now, e); } }
public override void ExecuteCommand(DeployClient client, IBufferedPackageInfo packageInfo) { base.ExecuteCommand(client, packageInfo); try { var buffer = base.GetCommandBody(packageInfo); long pingTime = BitConverter.ToInt64(buffer.Reverse().ToArray(), 0); ConsoleLogger.InfoFormat("{0} ping time {1}ms", DateTime.Now, DateTimeExtension.CurrentTimestamp - pingTime); } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", base.Name, DateTime.Now, e); } }
public void setProxy(DeployClient deployClient) { if (deployClient.proxy.IsBypass) { return; } WebProxy proxy = new WebProxy(deployClient.proxy.Host, deployClient.proxy.Port); proxy.UseDefaultCredentials = false; if (deployClient.proxy.IsCredentialsExists) { proxy.Credentials = new NetworkCredential(deployClient.proxy.Username, deployClient.proxy.Password); } _httpClient.getHttpClient().setProxy(proxy); }
static void Main(string[] args) { try { var shell = new ConsoleShell(); var client = new DeployClient(); client.Connected += (sender, e) => { ConsoleLogger.InfoFormat("{0} Connected {1} Success", DateTime.Now, client.RemoteEndPoint.ToString()); }; client.OnLogin += (sender, e) => { string json = JObject.FromObject(e.Data).ToString(); if (e.Data.Success) { shell.SetPrefix(AppConfig.UserName + "> ", true); SetupCommand(shell, client, e.Data.IsAdministrator); ConsoleLogger.Info(json); } else { ConsoleLogger.Error(json); } }; client.Error += (sender, e) => { ConsoleLogger.ErrorFormat("{0} --> {1}", DateTime.Now, e.Exception); }; client.Closed += (sender, e) => { shell.SetPrefix("(nil)> ", true); shell.ResetCommand(); SetupCommand(shell, client, false); ConsoleLogger.WarnFormat("{0} Client Closed ", DateTime.Now); }; client.Initialize(new BufferedReceiveFilter()); SetupCommand(shell, client, false); shell.Start(); } catch (Exception e) { Console.WriteLine(e); Console.ReadKey(); } }
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); } }
public override void ExecuteCommand(DeployClient client, IBufferedPackageInfo packageInfo) { base.ExecuteCommand(client, packageInfo); try { var body = base.GetCommandBody(packageInfo); var info = JsonConvert.DeserializeObject<LoginInfo>(Encoding.UTF8.GetString(body)); if(info == null) { info = new LoginInfo(); } client.FireLoginEvent(new LoginEventArgs { Data = info }); } catch (Exception e) { ConsoleLogger.ErrorFormat("{0} --> {1} {2}", GetType().Name, DateTime.Now, e); } }
public Ping(DeployClient client) : base(client, "ping", "PING服务器") { }
public Disconnect(DeployClient client) : base(client, "disconnect", "断开服务器连接") { }
public XShellCommandBase(DeployClient client, string name, string description) : base(name, description) { Client = client; }
public ListClient(DeployClient client) : base(client, "listclient", "列出服务器上客户端列表 listclient [count]") { }
public TransferFile(DeployClient client) : base(client, "transferfile", "上传文件到服务器并让服务器分发文件到所有登录的会话 transferfile [filepath]") { }
public Connect(DeployClient client) : base(client, "connect", "连接服务器 connect [host] [port]") { }