public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("extract command param error"); } var source = hobj.GetKey("Source").GetString(); var destination = hobj.GetKey("Destination").GetString(); var overwritekey = hobj.GetKey("OverWrite"); var overwrite = overwritekey == null ? true : overwritekey.GetBoolean(); if (!File.Exists(source)) { return($"source file not exists -> {source}"); } File.Copy(source, destination, true); return($"copy file ,from {source} to {destination}"); }
public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("site-newapplication command param error"); } var siteName = hobj.GetKey("SiteName").GetString(); var application = $"/{hobj.GetKey("Application").GetString()}"; var path = hobj.GetKey("PhysicPath").GetString(); using (var iisManager = new ServerManager()) { var site = iisManager.Sites[siteName]; if (site == null) { throw new Exception($"site[{siteName}] not exists!"); } var app = site.Applications[application]; if (app != null) { return($"application {application} exists!"); } site.Applications.Add(application, path); iisManager.CommitChanges(); return($"application {application} create success!"); } }
public static bool IsSubstitution(this IHoconElement value) { switch (value) { case HoconValue v: foreach (var val in v) { if (val is HoconSubstitution) { return(true); } } return(false); case HoconField f: foreach (var v in f.Value) { if (v is HoconSubstitution) { return(true); } } return(false); case HoconSubstitution _: return(true); default: return(false); } }
public override string Execute(IHoconElement param) { var filename = $"temp_{DateTime.Now.Ticks}.bat"; var content = param.GetString(); base.Send(content); var bytes = Encoding.UTF8.GetBytes("@echo off\r\n" + content); using (var ms = File.Create(filename)) ms.Write(bytes, 0, bytes.Length); try { var runAppCmd = new OriginCommand(); runAppCmd.Name = filename; runAppCmd.Param = ""; CommandExecutor.RunExeWithParam(Session, runAppCmd); } catch { throw; } finally { File.Delete(filename); } return($"execute batch success!"); }
public override string Execute(IHoconElement param) { string siteName = param.GetString(); using (ServerManager serverManager = new ServerManager()) { var sites = serverManager.Sites; var site = sites[siteName]; if (site == null) { return($"site {siteName} not exist! can not start"); } Thread.Sleep(200);//让site有准备的时间,sites为Lazy加载,否则有可能在site.State调用出错(not a valid object) if (site.State == ObjectState.Stopped) { site.Start(); } else { return($"site {siteName} status is {site.State.ToString()}!"); } serverManager.CommitChanges(); } return($"site {siteName} start success!"); }
public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("extract command param error"); } var packageName = hobj.GetKey("PackageName").GetString(); var version = hobj.GetKey("Version").GetString(); var path = hobj.GetKey("Path")?.GetString() ?? "null"; if (path != "null") { if (File.Exists(path)) { File.Delete(path); return($"delete file -> {path} success!"); } return($"file not exists -> {path}"); } string zipName = $"{packageName}-{version}.zip"; var filename = Path.Combine(CommandExecutor.WorkSpace, "Packages", zipName);//$"{dir}{zipName}"; if (File.Exists(filename)) { File.Delete(filename); return($"delete file -> {filename} success!"); } return($"file not exists -> {filename}"); }
public override string Execute(IHoconElement param) { string msg = param.GetString(); base.Send(msg); return($"log msg!"); }
private HoconArray ParsePlusEqualAssignArray(IHoconElement owner) { // sanity check if (_tokens.Current.Type != TokenType.PlusEqualAssign) { throw HoconParserException.Create(_tokens.Current, Path, "Failed to parse Hocon field with += operator. " + $"Expected {TokenType.PlusEqualAssign}, found {{_tokens.Current.Type}} instead."); } var currentArray = new HoconArray(owner); // consume += operator token ConsumeWhitelines(); switch (_tokens.Current.Type) { case TokenType.Include: currentArray.Add(ParseInclude(currentArray)); break; case TokenType.StartOfArray: // Array inside of arrays are parsed as values because it can be value concatenated with another array. currentArray.Add(ParseValue(currentArray)); break; case TokenType.StartOfObject: currentArray.Add(ParseObject(currentArray)); break; case TokenType.LiteralValue: if (_tokens.Current.IsNonSignificant()) { ConsumeWhitelines(); } if (_tokens.Current.Type != TokenType.LiteralValue) { break; } currentArray.Add(ParseValue(currentArray)); break; case TokenType.SubstituteOptional: case TokenType.SubstituteRequired: var pointerPath = HoconPath.Parse(_tokens.Current.Value); HoconSubstitution sub = new HoconSubstitution(currentArray, pointerPath, _tokens.Current, _tokens.Current.Type == TokenType.SubstituteRequired); _substitutions.Add(sub); currentArray.Add(sub); _tokens.Next(); break; default: throw HoconParserException.Create(_tokens.Current, Path, $"Failed to parse Hocon array. Expected {TokenType.EndOfArray} but found {_tokens.Current.Type} instead."); } return(currentArray); }
public override bool Equals(IHoconElement other) { if (other is null) { return(false); } return(other.Type == HoconType.Empty); }
public HoconMergedObject(IHoconElement parent, List <HoconObject> objects) : base(parent) { Objects = objects; foreach (var obj in objects) { base.Merge(obj); } }
private static void Flatten(IHoconElement node) { if (!(node is HoconValue v)) { return; } switch (v.Type) { case HoconType.Object: var o = v.GetObject(); v.Clear(); v.Add(o); foreach (var item in o.Values) { Flatten(item); } break; case HoconType.Array: var a = v.GetArray(); v.Clear(); var newArray = new HoconArray(v); foreach (var item in a) { Flatten(item); newArray.Add(item); } v.Add(newArray); break; case HoconType.Literal: if (v.Count == 1) { return; } var value = v.GetString(); v.Clear(); if (value == null) { v.Add(new HoconNull(v)); } else if (value.NeedTripleQuotes()) { v.Add(new HoconTripleQuotedString(v, value)); } else if (value.NeedQuotes()) { v.Add(new HoconQuotedString(v, value)); } else { v.Add(new HoconUnquotedString(v, value)); } break; } }
/// <summary> /// Initializes a new instance of the <see cref="HoconObject" /> class. /// </summary> public HoconObject(IHoconElement parent) { if (!(parent is HoconValue)) { throw new HoconException("HoconObject parent can only be a HoconValue."); } Parent = parent; }
public IHoconElement Clone(IHoconElement newParent) { var newArray = new HoconArray(newParent); foreach (var value in this) { newArray.Add(value.Clone(newArray) as HoconValue); } return(newArray); }
public IHoconElement Clone(IHoconElement newParent) { var newField = new HoconField(Key, (HoconObject)newParent); foreach (var internalValue in _internalValues) { newField._internalValues.Add(internalValue); } return(newField); }
/// <inheritdoc /> public IHoconElement Clone(IHoconElement newParent) { var clone = new HoconObject(newParent); foreach (var kvp in this) { clone.SetField(kvp.Key, kvp.Value.Clone(clone) as HoconField); } return(clone); }
public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("jenkins-build command param error"); } var source = hobj.GetKey("Source")?.GetString(); var job = hobj.GetKey("JobName").GetString(); var credential = hobj.GetKey("Credential")?.GetString(); if (source.IndexOf("http://") < 0) { source = $"http://{source}"; } var buildTask = PostJenkinsBuild(source, job, credential); string buildResponse = buildTask.Result; if (buildResponse == "") { Send("$Prepare Progress Bar$"); bool building = true; while (building) { var task = GetProgressMessage(source, job, credential); var msg = task.Result; var model = JsonConvert.DeserializeObject <ProgressModel>(msg); if (model == null) { continue; } if (model.result == "SUCCESS") { Send("100", false); building = false; } else { int progress = model.executor.progress; Send(progress.ToString(), false); } Thread.Sleep(200); } Send("$Finish Progress Bar$"); } else { throw new Exception(buildResponse); } Thread.Sleep(400); return($"build {job} success!"); }
private void VisitPrimitive(IHoconElement data) { var key = _currentPath; if (_data.ContainsKey(key)) { throw new FormatException(string.Format(Resources.Error_KeyIsDuplicated, key)); } _data[key] = data.GetString(); }
public bool Equals(IHoconElement other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(other is HoconField field && Path.Equals(field.Path) && Value.Equals(other)); }
public bool Equals(IHoconElement other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(other is HoconArray array && Equals(array)); }
public bool Equals(IHoconElement other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Type == other.Type && string.Equals(Value, other.GetString())); }
public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("new-site command param error"); } var siteName = hobj.GetKey("SiteName").GetString(); var poolName = hobj.GetKey("PoolName").GetString(); var binding = hobj.GetKey("Binding").GetString(); // http://yourdoman.com:96 var path = hobj.GetKey("PhysicPath").GetString(); var msg = CreateWebsite(siteName, poolName, path, binding); return(msg); }
public bool Equals(IHoconElement other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (other.Type != HoconType.Object) { return(false); } return(this.AsEnumerable().SequenceEqual(other.GetObject().AsEnumerable())); }
public override string Execute(IHoconElement param) { string siteName = param.GetString(); using (ServerManager serverManager = new ServerManager()) { var sites = serverManager.Sites; var site = sites[siteName]; if (site == null) { return($"site {siteName} not exist! can not delete!"); } sites.Remove(site); serverManager.CommitChanges(); } return($"site {siteName} stop success!"); }
public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("extract command param error"); } var configPath = hobj.GetKey("Path")?.GetString(); var searchPattern = hobj.GetKey("Patterns").GetArray().Select(item => item.GetString()); string response = ReplaceConfig(configPath, searchPattern); return(response); }
public HoconObject GetObject() { //TODO: merge objects? IHoconElement raw = Values.FirstOrDefault(); var o = raw as HoconObject; var sub = raw as IMightBeAHoconObject; if (o != null) { return(o); } if (sub != null && sub.IsObject()) { return(sub.GetObject()); } return(null); }
public override string Execute(IHoconElement param) { var cmds = typeof(HelpCommand).Assembly.GetTypes().Where(item => item.IsClass && !item.IsAbstract && typeof(CommandBase).IsAssignableFrom(item)); foreach (var cmd in cmds) { var attr = cmd.GetCustomAttribute <CommandNameAttribute>(); if (attr == null) { continue; } base.Send($"{attr.CommandName,-20}\t\t{attr.Description}"); } return(""); }
public override string Execute(IHoconElement param) { var hobj = param as HoconObject; if (hobj == null) { throw new Exception("change-site command param error"); } var siteName = hobj.GetKey("SiteName").GetString(); var poolName = hobj.GetKey("PoolName").GetString(); var hostName = hobj.GetKey("PoolName")?.GetString() ?? ""; var path = hobj.GetKey("PhysicPath").GetString(); var port = hobj.GetKey("Port")?.GetInt() ?? 80; var msg = ChangeWebsite(siteName, poolName, port, path, hostName); return(msg); }
public override string Execute(IHoconElement param) { string serviceName = param.GetString(); var service = ServiceManager.QueryService(serviceName); if (service == null) { return($"service {serviceName} do not exist"); } if (service.Status == ServiceControllerStatus.Running) { service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30)); return($"service {serviceName} stop success!"); } return($"service {serviceName} current status is {service.Status.ToString()}, can not stop!"); }
public override string Execute(IHoconElement param) { string serviceName = param.GetString(); var service = ServiceManager.QueryService(serviceName); if (service == null) { return($"service {serviceName} do not exist"); } var uninstallCmd = new OriginCommand { Name = "sc", Param = "delete " + serviceName }; CommandExecutor.RunCommand(uninstallCmd); return($"uninstall service {serviceName} success!"); }
public override string Execute(IHoconElement param) { string poolName = param.GetString(); using (ServerManager serverManager = new ServerManager()) { var pools = serverManager.ApplicationPools; var pool = pools[poolName]; if (pool == null) { return($"pool {poolName} not exist! can not delete"); } pools.Remove(pool); serverManager.CommitChanges(); } return($"pool {poolName} delete success!"); }
public void AppendValue(IHoconElement value) { values.Add(value); }
public void NewValue(IHoconElement value) { values.Clear(); values.Add(value); }