public override int Execute() { try { IJsonTreeDB profileDB = GetFactory().Create(GlobalConfig.PROFILE); JObject profile = profileDB.Store.SelectToken(Profile) as JObject; if (profile == null) { Console.WriteLine($"Profile '{Profile}' not found."); return(-1); } TransformCommand cmd = new TransformCommand() { PackageName = Package, DestinationPath = profile["Config"].ToObject <IEnumerable <string> >(), TemplatePath = profile["Template"].ToObject <string>() }; return(cmd.Execute()); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } }
public override int Execute() { try { ValidatePaths(ConfigPaths); ValidatePaths(TemplatePath); ConfigPaths = ConfigPaths.Select(p => System.IO.Path.GetFullPath(p)).ToList(); JObject profileValues = new JObject { ["Template"] = JToken.FromObject(TemplatePath), ["Config"] = JToken.FromObject(ConfigPaths) }; IJsonTreeDB profileDB = GetFactory().Create(GlobalConfig.PROFILE); profileDB.Store.CreateProperty(Profile, profileValues); Console.WriteLine($"Added Profile {Profile}"); profileDB.Write(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
private void ValidatePaths(IEnumerable <string> paths) { IJsonTreeDB storeDB = GetFactory().Create(GlobalConfig.STORE); foreach (string p in paths) { if (storeDB.Store.SelectTokens(p).ToList().Count == 0) { throw new Exception($"Error: the configuration store path {p} does not exist"); } } }
public override int Execute() { try { IJsonTreeDB db = GetFactory().Create(GlobalConfig.STORE); db.Store.CreateProperty(Path, Value); Console.WriteLine($"Added {Path} to store with value {Value}"); db.Write(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
protected int ExecuteDelete(string dbPath, string jsonPath, string messageContext) { try { IJsonTreeDB db = GetFactory().Create(dbPath); db.Store.DeleteProperty(jsonPath); Console.WriteLine(messageContext); db.Write(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
public override int Execute() { try { IJsonTreeDB db = GetFactory().Create(GlobalConfig.STORE); db.Store.MoveProperty(SourcePath, DestPath); Console.WriteLine($"Moved {SourcePath} to {DestPath}"); db.Write(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
public override int Execute() { try { ValidatePaths(Value); IJsonTreeDB packageDB = GetFactory().Create(GlobalConfig.PACKAGE); packageDB.Store.CreateProperty(Path, Value); Console.WriteLine($"Added Package {Path} with value {Value}"); packageDB.Write(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
public override int Execute() { try { IJsonTreeDB db = GetFactory().Create(GlobalConfig.STORE); IEnumerable <JToken> results = db.Store.FindAllProperties(Path); Console.WriteLine($"Results for {Path} :"); if (results.ToList().Count == 0) { Console.WriteLine("No results"); } foreach (JToken t in results) { Console.WriteLine($"{t.Path}: {(t as JProperty)?.Value}"); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
public override int Execute() { try { IJsonTreeDB db = GetFactory().Create(GlobalConfig.PACKAGE); Console.WriteLine($"Results for {Path} :"); JToken results = db.Store.SelectToken(Path)?.Parent; if (results != null) { Console.WriteLine($"{results.Path}: {(results as JProperty)?.Value}"); } else { Console.WriteLine("No Results"); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }
public override int Execute() { if (ObjectPath == null && PackageName == null) { Console.WriteLine("Missing required argument --package or --object"); return(-1); } try { IDictionary <string, object> results; string errorNotFound; if (PackageName != null) { IJsonTreeDB packageDB = GetFactory().Create(GlobalConfig.PACKAGE); IEnumerable <string> paths = (packageDB.Store.SelectToken(PackageName).Parent as JProperty).Value.ToObject <IEnumerable <string> >(); results = new Dictionary <string, object>(); IJsonTreeDB configDB = GetFactory().Create(GlobalConfig.STORE); foreach (string p in paths) { IDictionary <string, object> r = configDB.Store .FindAllProperties(p) .Cast <JProperty>() .ToDictionary(kvp => kvp.Name, kvp => kvp.Value.ToObject(typeof(Object))); results = results.Concat(r) .ToLookup(x => x.Key, x => x.Value) .ToDictionary(x => x.Key, g => g.First()); } errorNotFound = $"Error in transform: Package {PackageName} not found"; } else { JsonTreeDB configDB = new JsonTreeDB(GlobalConfig.STORE); results = configDB.Store .FindAllProperties(ObjectPath) .Cast <JProperty>() .ToDictionary(kvp => kvp.Name, kvp => kvp.Value.ToObject(typeof(Object))); errorNotFound = $"Error in transform: Config {ObjectPath} not found"; } if (results == null || results.Count == 0) { Console.WriteLine(errorNotFound); return(-1); } Console.WriteLine($"Reading file {TemplatePath}"); string content = File.ReadAllText(TemplatePath); string transformedContent = Transformer.Transform(content, results); foreach (string p in DestinationPath) { Console.WriteLine($"Transforming file {p}"); Console.WriteLine($"Saving file {p}"); File.WriteAllText(p, transformedContent); } } catch (Exception ex) { Console.WriteLine("Error in transform: " + ex.Message); return(-1); } Console.WriteLine("Completed Successfully"); return(0); }