private static void ProcessPattern(StringBuilder sb, string exp, GenerationConfig config) { bool isEscaped = false; var curNdx = 0; while (curNdx < exp.Length) { var chx = exp[curNdx]; if (chx == _Escape) { if (isEscaped) { // "\\" handling isEscaped = false; } else { // "...\..." detected, entering escaped symbol handling on next pass. isEscaped = true; curNdx++; continue; } } if (!isEscaped && chx == _Section_Start) { AppendContentFromSectionExpression(sb, exp, ref curNdx, config); continue; // skip to next character - index has already been forwarded to new position } // check are we entering a set pattern that may include a quantifier // Format = "[Vv]{4}" = generate 4 random ordered characters comprising of either V or v characters if (!isEscaped && chx == _Set_Start) { AppendContentFromSetExpression(sb, exp, ref curNdx, config); continue; // skip to next character - index has already been forwarded to new position } if (!isEscaped && chx == _NamedPattern_Start) { AppendContentFromNamedPattern(sb, exp, ref curNdx, config); continue; } // check are we entering a repeat symbol section // Format = "L{4}" = repeat L symbol 4 times. // Format = "\\{4}" = repeat \ symbol 4 times. bool repeatSymbol = curNdx < exp.Length - 1 && exp[curNdx + 1] == _Quantifier_Start; if (repeatSymbol) { AppendRepeatedSymbol(sb, exp, ref curNdx, isEscaped, config); isEscaped = false; continue; // skip to next character - index has already been forwarded to new position } AppendCharacterDerivedFromSymbol(sb, chx, isEscaped, config); curNdx++; // increment to move to next character. isEscaped = false; } }
/// <summary> /// Takes in a string that contains 0 or more <<placeholder>> values and replaces the placeholder item with the expression it defines. /// </summary> /// <param name="template"></param> /// <param name="random"></param> /// <returns></returns> public static string GenerateFromTemplate(string template, Random random) { var config = new GenerationConfig(); config.Random = random; return(GenerateFromTemplate(template, null, config)); }
private void FixTiles(GenerationConfig config) { var sw = Stopwatch.StartNew(); var tilesToFix = GetTilesToFix(); int i = 0; while (tilesToFix.Count > 0) { Vector2Int pos = tilesToFix.Dequeue(); map.SetTile(pos, TileType.Ground); i++; foreach (var adj in pos.GetAdjacent()) { if (!map.ContainsTileAt(adj) && CheckIfTileNeedsFix(adj) && !tilesToFix.Contains(adj)) { tilesToFix.Enqueue(adj); } } if (i > config.cellsLimit) { Debug.LogWarning("Something went wrong during tile fixing, aborting."); return; } } sw.Stop(); Debug.Log($"Tile fixing completed in {sw.ElapsedMilliseconds} ms, {i} tiles placed."); }
public static string GenerateFromPattern(string pattern, GenerationConfig config) { var sb = new StringBuilder(); InternalGenerateFromPattern(sb, pattern, null, config, null); return(sb.ToString()); }
private static void AppendPatternsFromConfigToCollection(GenerationConfig config, NamedPatterns patternCollection) { if (config.PatternFiles == null) { return; } foreach (var patternFile in config.PatternFiles) { var correctedPath = FileReader.GetPatternFilePath(patternFile); try { var patt = FileReader.LoadNamedPatterns(correctedPath); foreach (var pattern in patt.Patterns) { patternCollection.Patterns.Add(pattern); } } catch (Exception ex) { throw new GenerationException("Error loading PatternFile:" + patternFile + "\n\n" + ex.Message); } } }
private static void OutputToConsole(CommandLineArgs cla, string template) { var config = new GenerationConfig(); if (!string.IsNullOrEmpty(cla.Seed)) { config.Seed = cla.Seed; } if (!string.IsNullOrEmpty(cla.NamedPatterns)) { cla.NamedPatterns.Split(';').ToList().ForEach(config.PatternFiles.Add); } int ct = 0; while (ct < cla.Count) { string item = ""; if (!string.IsNullOrEmpty(cla.Pattern)) { item = AlphaNumericGenerator.GenerateFromPattern(template, config: config); } else { item = AlphaNumericGenerator.GenerateFromTemplate(template, config); } Console.WriteLine(item); ct++; } }
private static string GetRandomAlphaItemFromRange(bool isNegated, GenerationConfig config, string[] items, string possibles) { string ret = ""; if (_ShortHands["l"].Contains(items[0])) { possibles = _ShortHands["l"]; } if (_ShortHands["L"].Contains(items[0])) { possibles = _ShortHands["L"]; } var start = possibles.IndexOf(items[0].ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal); if (start > -1) { var end = possibles.IndexOf(items[1].ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal); possibles = possibles.Substring(start, end - start + 1); if (isNegated) { possibles = Regex.Replace(_ShortHands["."], "[" + possibles + "]", ""); } ret = possibles[config.Random.Next(0, possibles.Length)].ToString(CultureInfo.InvariantCulture); } return(ret); }
private static void GenerateFromPattern(StringBuilder sb, string pattern, NamedPatterns namedPatterns = null, GenerationConfig config = null, Random random = null) { if (pattern == null || string.IsNullOrEmpty(pattern)) { throw new GenerationException("Argument 'pattern' cannot be null."); } if (namedPatterns == null) { namedPatterns = LoadDefaultNamedPatterns(config); } if (config != null && config.PatternFiles != null) { // Load all from the PatternFiles in config AppendPatternsFromConfigToCollection(config, namedPatterns); } if (config == null) { config = new GenerationConfig(); } if (random == null) { random = config.Random; } ProcessPattern(sb, pattern, namedPatterns, random); }
private static void GenerateFromPattern(StringBuilder sb, string pattern, GenerationConfig config) { if (string.IsNullOrEmpty(pattern)) { throw new GenerationException("Argument 'pattern' cannot be null."); } ProcessPattern(sb, pattern, config); }
public GamblingConfig() { BetRoll = new BetRollConfig(); WheelOfFortune = new WheelOfFortuneSettings(); Waifu = new WaifuConfig(); Currency = new CurrencyConfig(); BetFlip = new BetFlipConfig(); Generation = new GenerationConfig(); Timely = new TimelyConfig(); Decay = new DecayConfig(); }
private static GenerationConfig LoadAndRemoveConfigFromTemplate(ref string template) { int index = 0; // If we have no provided config attempt to get one from the template. GenerationConfig config = GetConfiguration(template, ref index); if (config != null) { // Remove all config sections from template. template = template.Substring(index); } return(config); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.IntField("Current Seed", gen.CurrentSeed ?? -1); EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!Application.isPlaying); manualGeneration = GUILayout.Toggle(manualGeneration, "Manual Generation", "Button"); if (!manualGeneration) { return; } if (configs == null) { configs = GenerationConfigs.GetAvailable(); } useRandomSeed = EditorGUILayout.Toggle("Use random seed", useRandomSeed); if (!useRandomSeed) { seed = Math.Abs(EditorGUILayout.IntField("New Seed", seed)); } selectedConfig = EditorGUILayout.Popup("Generation Config", selectedConfig, configs); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Proceed")) { int newSeed = useRandomSeed ? UnityEngine.Random.Range(0, int.MaxValue) : seed; GenerationConfig config = GenerationConfigs.Load(configs[selectedConfig]); gen.Generate(newSeed, config); SceneView.RepaintAll(); } if (GUILayout.Button("Reload configs")) { configs = null; } EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); }
private static void OutputToFile(CommandLineArgs cla, string template) { GenerationConfig config = new GenerationConfig(); if (!string.IsNullOrEmpty(cla.Seed)) { config.Seed = cla.Seed; } if (!string.IsNullOrEmpty(cla.NamedPatterns)) { cla.NamedPatterns.Split(';').ToList().ForEach(config.PatternFiles.Add); } using (var fs = new StreamWriter(cla.OutputFilePath)) { int itemCount = 0; while (itemCount < cla.Count) { int bufferCount = 0; var buffer = new StringBuilder(5000); int numToBuffer = cla.Count - itemCount; if (numToBuffer > 10) { numToBuffer = 10; } while (bufferCount < numToBuffer) { if (!string.IsNullOrEmpty(cla.Pattern)) { buffer.AppendLine(AlphaNumericGenerator.GenerateFromPattern(template, config: config)); } else { buffer.AppendLine(AlphaNumericGenerator.GenerateFromTemplate(template, config)); } bufferCount++; itemCount++; // Console.WriteLine("numberToBuffer " + numToBuffer + " bufferCount " + bufferCount + " itemCount " + itemCount); } // Console.WriteLine("Writing item"); fs.Write(buffer.ToString()); } } }
private static NamedPatterns LoadDefaultNamedPatterns(GenerationConfig generationConfig) { var patterns = new NamedPatterns(); if (generationConfig == null || generationConfig.LoadDefaultPatternFile == false) { return(patterns); // Dont attempt to load default pattern files with every execution -- too slow. } var path = FileReader.GetPatternFilePath("default"); if (File.Exists(path)) { patterns = FileReader.LoadNamedPatterns(path, false); } return(patterns); }
public void Generate(int seed, GenerationConfig config) { if (seed < 0) { throw new ArgumentOutOfRangeException(nameof(seed)); } Debug.Log($"Starting world generation. Seed: {seed}"); var random = new Random(seed); PerformRandomWalk(random, config); FixTiles(config); SmoothTiles(); PlaceWalls(); CurrentSeed = seed; CurrentConfig = config; }
public CompilationContext() { _container = new Lazy <IContainer>(() => new Container(services)); _graph = new Lazy <RouteGraph>(() => { config = new GenerationConfig("Jasper.Testing.Codegen.Generated"); var container = _container.Value; config.Sources.Add(new StructureMapServices(container)); config.Assemblies.Add(typeof(IContainer).GetTypeInfo().Assembly); config.Assemblies.Add(GetType().GetTypeInfo().Assembly); var graph = new RouteGraph(); var methods = typeof(T).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) .Where(x => x.DeclaringType != typeof(object) && x != null && !x.IsSpecialName); foreach (var method in methods) { graph.AddRoute(typeof(T), method); } return(graph); }); _code = new Lazy <string>(() => Graph.GenerateCode(config)); _routes = new Lazy <Dictionary <string, RouteHandler> >(() => { var routers = Graph.CompileAndBuildAll(config, _container.Value); var dict = new Dictionary <string, RouteHandler>(); foreach (var router in routers) { dict.Add(router.Chain.Action.Method.Name, router); } return(dict); }); }
public JasperRegistry() { var assembly = this.GetType().GetAssembly(); var isFeature = assembly.GetCustomAttribute <JasperFeatureAttribute>() != null; if (!Equals(assembly, typeof(JasperRegistry).GetAssembly()) && !isFeature) { ApplicationAssembly = assembly; } else { ApplicationAssembly = findTheCallingAssembly(); } Generation = new GenerationConfig($"{ApplicationAssembly.GetName().Name}.Generated"); Logging = new Logging(this); Settings = new JasperSettings(this); }
private static string GetRandomNumericItemFromRange(bool isNegated, GenerationConfig config, string[] items, string possibles) { string ret = ""; double min; if (double.TryParse(items[0], NumberStyles.Number, CultureInfo.InvariantCulture, out min)) { double max; if (double.TryParse(items[1], NumberStyles.Number, CultureInfo.InvariantCulture, out max)) { int scale = 0; if (items[0].Contains(".")) { scale = items[0].Split('.')[1].Length; } if (isNegated) { if (scale > 0 || min < 0 || min > 9 || max < 0 || max > 9) { throw new GenerationException("Negated numeric sets are restricted to integers between 0 and 9."); } var negs = ExpandNegatedMinMax(min, max); possibles = Regex.Replace(possibles, "[" + negs + "]", ""); if (possibles.Length == 0) { return(""); // No allowable values remain - return empty string } ret = possibles[config.Random.Next(0, possibles.Length)].ToString(CultureInfo.InvariantCulture); } else { var t = config.Random.NextDouble(); min = min + (t * (max - min)); ret = min.ToString(GenerateFloatingFormatWithScale(scale), CultureInfo.InvariantCulture); } } } return(ret); }
private static void ApplicationOperation(Arguments parsedArguments) { if (String.IsNullOrEmpty(parsedArguments.ApplicationDescriptionPath) || String.IsNullOrEmpty(parsedArguments.GeneratedApplicationPackagePath)) { Console.WriteLine("ApplicationDescriptionPath and GeneratedApplicationPackagePath should be specified for SingleInstance"); return; } try { Application application = null; using (StreamReader file = File.OpenText(parsedArguments.ApplicationDescriptionPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Converters.Add(new DiagnosticsSinkJsonConverter()); serializer.Converters.Add(new VolumeMountJsonConverter()); application = (Application)serializer.Deserialize(file, typeof(Application)); } ApplicationManifestType appManifest; IList <ServiceManifestType> serviceManifest; GenerationConfig config = new GenerationConfig() { RemoveServiceFabricRuntimeAccess = true, IsolationLevel = "hyperV" }; var generator = new ApplicationPackageGenerator("TestType", "1.0", application, true, false, "C:\\settings", true, config); Dictionary <string, Dictionary <string, SettingsType> > settingsType; generator.Generate(out appManifest, out serviceManifest, out settingsType); DockerComposeUtils.GenerateApplicationPackage(appManifest, serviceManifest, settingsType, parsedArguments.GeneratedApplicationPackagePath); } catch (Exception e) { Console.WriteLine(e); } }
public GeneratorViewModel() { config = new GenerationConfig(); Red = 255; Green = 255; Blue = 255; Alpha = 255; FontSize = 14; TextureSize = 1024; OpenFontFileCommand = new DelegateCommand { CommandHandler = OpenFontFile }; OpenTextFileCommand = new DelegateCommand { CommandHandler = OpenTextFile }; OpenExportPathCommand = new DelegateCommand { CommandHandler = OpenExportPath }; SaveConfigurationCommand = new DelegateCommand { CommandHandler = SaveConfiguration }; LoadConfigurationCommand = new DelegateCommand { CommandHandler = LoadConfiguration }; OutlineAlpha = 255; OutlineSize = 0; OutlineSampling = 1; Observable.FromEventPattern <PropertyChangedEventArgs>(this, "PropertyChanged") .Where(x => x.EventArgs.PropertyName != "PreviewImage") .Throttle(TimeSpan.FromMilliseconds(500)) .Subscribe(x => GeneratePreviewAsync()); CanGenerate = true; }
public static string GenerateFromPattern(string pattern, GenerationConfig config = null) { if (config == null) { config = new GenerationConfig(); } var sb = new StringBuilder(); // add default pattern file entries if (config.LoadDefaultPatternFile) { GetDefaultNamedPatterns(config).Patterns.ForEach(config.NamedPatterns.Patterns.Add); } if (config.PatternFiles != null) { // Load all from the PatternFiles in config AppendPatternsFromConfigToCollection(config, config.NamedPatterns); } GenerateFromPattern(sb, pattern, config); return(sb.ToString()); }
private static void AppendRandomCharacterFromString(StringBuilder sb, string allowedCharacters, GenerationConfig config) { sb.Append(allowedCharacters[config.Random.Next(allowedCharacters.Length)]); }
public static string GenerateFromPattern(string pattern, NamedPatterns namedPatterns = null, GenerationConfig config = null, Random random = null) { var sb = new StringBuilder(); GenerateFromPattern(sb, pattern, namedPatterns, config, random); return(sb.ToString()); }
/// <summary> /// Calculates the content from a set expression when the following form is enountered '[exp]{repeat}'. /// </summary> /// <param name="sb"></param> /// <param name="characters"></param> /// <param name="index"></param> /// <param name="config"></param> private static void AppendContentFromSetExpression(StringBuilder sb, string characters, ref int index, GenerationConfig config) { var contentOptions = GetContentOptions(characters, ref index, _Set_Start.ToString(CultureInfo.InvariantCulture), _Set_End.ToString(CultureInfo.InvariantCulture), config); if (contentOptions.IsAnagram) { GenerateFromAnagramPattern(sb, contentOptions.Content, contentOptions, config); return; } if (contentOptions.Content.Contains("-")) // Ranged - [0-7] or [a-z] or [1-9A-Za-z] for fun. { MatchCollection ranges = new Regex(@"[A-Za-z]-[A-Za-z]|\d+\.?\d*-\d+\.?\d*|.").Matches(contentOptions.Content); if (contentOptions.IsNegated) { var possibles = _ShortHands["."]; foreach (var range in ranges) { if (range.ToString().Contains("-")) { //TODO - Cleanup - Only here to throw an exception for invalid ranges GetRandomCharacterFromRange(range.ToString(), contentOptions.IsNegated, config); var regex = new Regex("[" + range + "]"); possibles = regex.Replace(possibles, ""); } else { // single character item to negate, just remove it from the list of possibles. possibles = possibles.Replace(range.ToString(), ""); } } for (int i = 0; i < contentOptions.Repeat; i++) { sb.Append(possibles[config.Random.Next(0, possibles.Length)]); } } else { for (int i = 0; i < contentOptions.Repeat; i++) { var range = ranges[config.Random.Next(0, ranges.Count)].ToString(); sb.Append(range.Contains("-") ? GetRandomCharacterFromRange(range, contentOptions.IsNegated, config) : range); } } } else { var possibles = contentOptions.Content; if (contentOptions.IsNegated) { possibles = Regex.Replace(_ShortHands["."], "[" + possibles + "]", ""); } for (int i = 0; i < contentOptions.Repeat; i++) { sb.Append(possibles[config.Random.Next(0, possibles.Length)]); } } }
private static void AppendCharacterDerivedFromSymbol(StringBuilder sb, char symbol, bool isEscaped, GenerationConfig config) { if (!isEscaped) { sb.Append(symbol); // not a symbol - append as is. return; } var symbolAsString = symbol.ToString(); if (_ShortHands.ContainsKey(symbolAsString)) { AppendRandomCharacterFromString(sb, _ShortHands[symbolAsString], config); } else { switch (symbol) { case 'n': sb.Append("\n"); break; case 'r': sb.Append("\r"); break; case 't': sb.Append("\t"); break; default: // Just append the character as it is not a symbol. sb.Append(symbol); break; } } }
/// <summary> /// Takes in a string that contains 0 or more <<placeholder>> values and replaces the placeholder item with the expression it defines. /// </summary> /// <param name="template"></param> /// <param name="config"></param> /// <returns></returns> public static string GenerateFromTemplate(string template, GenerationConfig config) { return(GenerateFromTemplate(template, null, config)); }
/// <summary> /// Takes in a string that contains 0 or more <<placeholder>> values and replaces the placeholder item with the expression it defines. /// </summary> /// <param name="template"></param> /// <param name="namedPatterns"></param> /// <param name="generationConfig"></param> /// <returns></returns> public static string GenerateFromTemplate(string template, NamedPatterns namedPatterns, GenerationConfig generationConfig) { int index = 0; // CONFIG if (generationConfig == null) { generationConfig = LoadAndRemoveConfigFromTemplate(ref template); } if (generationConfig == null) { generationConfig = new GenerationConfig(); } var random = generationConfig.Random; // PATTERNS var generationPatterns = LoadDefaultNamedPatterns(generationConfig); // Load provided ones as well if there are any. if (namedPatterns != null && namedPatterns.Patterns != null) { namedPatterns.Patterns.ForEach(generationPatterns.Patterns.Add); } // Load all from the PatternFiles in config AppendPatternsFromConfigToCollection(generationConfig, generationPatterns); var sb = new StringBuilder(); while (index < template.Length) { // Find our next placeholder int start = FindPositionOfNext(template, index, _Placeholder_Start, _Placeholder_End); if (start == -1) { sb.Append(template.Substring(index)); //add remaining string. break; // all done! } bool isEscaped = IsEscaped(template, start); //start >= 1 && template[start - 1].Equals(_Escape); if (isEscaped) { start = start - 1; } sb.Append(template.Substring(index, start - index)); // Append everything up to start as it is. if (isEscaped) { start = start + 1; } start = start + _Placeholder_Start.Length; // move past '<<' to start of expression int end = FindPositionOfNext(template, start, _Placeholder_End, _Placeholder_Start); // find end of placeholder if (end == -1) { throw new GenerationException("Unable to find closing placeholder after " + start); } var pattern = template.Substring(start, end - start); // grab our expression if (isEscaped) { sb.Append("<<" + pattern + ">>"); } else { GenerateFromPattern(sb, pattern, generationPatterns, null, random); // generate value from expression } index = end + 2; // update our index. } return(sb.ToString()); }
private void PerformRandomWalk(Random random, GenerationConfig config) { var sw = Stopwatch.StartNew(); int mainDirection = random.Next(4); int[] baseWeights = new int[4]; int[] altWeights = new int[4]; for (int i = 0; i < 4; i++) { int value; if (i == mainDirection) { value = config.increasedWeight; } else { value = config.baseWeight; } baseWeights[i] = value; altWeights[i] = value; } baseWeights[(mainDirection + 5) % 4] = config.increasedWeight; altWeights[(mainDirection + 3) % 4] = config.increasedWeight; var walkers = new List <Walker>() { new Walker(Vector2Int.zero, random.PickFromParams(baseWeights, altWeights)) }; map.Clear(); map.SetTile(Vector2Int.zero, TileType.Ground); while (map.TileCount + walkers.Count <= config.cellsLimit) { for (int i = walkers.Count - 1; i >= 0; i--) { Walker walker = walkers[i]; walker.MakeStep(random, map); if (walker.Steps == config.stepsToBranch) { if (i == 0) { walker.ResetStepCounter(); walker.Weights = random.PickFromParams(baseWeights, altWeights); if (random.NextDouble() < config.branchChance) { var weights = walker.Weights == baseWeights ? altWeights : baseWeights; walkers.Add(new Walker(walker.Position, weights)); } } else { walkers.RemoveAt(i); } } } } sw.Stop(); Debug.Log($"Random walk completed in {sw.ElapsedMilliseconds} ms, {map.TileCount} tiles placed."); }
public TypeConstructorGenerator(GenerationConfig config, ICompilationSymbolParser symbolParser) { _config = config; _symbolParser = symbolParser; }
/// return 0 if program completes successfully, -1 otherwise. public static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("This is for internal use only"); return(-1); } #if DEBUG // To add a sleep time while debugging add a "Sleep" key (in milliseconds) to the following registry location: HKLM\\Software\\Microsoft\\Service Fabric try { using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(FabricConstants.FabricRegistryKeyPath, true)) { var sleepRegVal = registryKey.GetValue("Sleep"); if (sleepRegVal != null) { int sleepinms = int.Parse(sleepRegVal.ToString()); ImageBuilderExe.TraceSource.WriteNoise(ImageBuilderExe.TraceType, "ImageBuilderExe: Sleep time requested: {0}", sleepinms.ToString()); Thread.Sleep(sleepinms); } } } catch (Exception e) { ImageBuilderExe.TraceSource.WriteNoise(ImageBuilderExe.TraceType, "ImageBuilderExe: Exception code:{0}, msg:{1} when attempting to read registry value \"Sleep\" in {2}.", e.HResult, e.Message, FabricConstants.FabricRegistryKeyPath); } #endif // Parameters // /schemaPath:<The xsd schema file of Windows Fabric ServiceModel> - optional. Default: <Current Working Directory>\ServiceFabricServiceModel.xsd // /workingDir:<The root of working directory of the node> - optional. Default: <Current Working Directory> // /storeRoot:<The root path of ImageStore> - optional // /output: <The root folder|file where output will be placed> - required // /input: <The root folder|file where input will be read from> - required for Delete // /progress: <The file where operation progress will be read from> - optional. Used by BuildApplicationType and DownloadAndBuildApplicationType. // /operation:<BuildApplicationTypeInfo | BuildApplicationType | BuildApplication | BuildComposeDeployment | ValidateComposeDeployment | UpgradeApplication | GetFabricVersion | ProvisionFabric | UpgradeFabric | Delete | TestErrorDetails | DownloadAndBuildApplicationType> - required // /timeout:<ticks> - optional /* ImageBuilder arguments for DownloadAndBuildApplicationType */ // /downloadPath: <path to .sfpkg file from a store that supports GET method> - required // /appTypeName:<Application Type Name> - required. Expected application type name in the downloaded package. // /appTypeVersion:<Application Type Version> - required. Expected application type version in the downloaded package. // /progress: <The file where operation progress will be read from> - optional. // /output: <The root folder|file where output will be placed> - required // /timeout:<ticks> - optional /* ImageBuilder arguments for BuildComposeDeployment */ // /cf:<Compose File path> - required // /of:<Overrides File path> - optional // /appTypeName:<Application Type Name> - required // /appTypeVersion:<Application Type Version> - required // /output: <The root folder|file where output application package will be placed> - required // /ocf:<Output Merged compose file path> - required // /repoUserName:<Repository User Name> - optional // /repoPwd:<Repository Password> - optional // /pwdEncrypted:<Is Repository Password encrypted> - optional // /cleanup:<Cleanup the compose files> - optional // /timeout:<ticks> - optional /* ImageBuilder arguments for ValidateComposeDeployment */ // /cf:<Compose File path> - required // /of:<Overrides File path> - optional // /appTypeName:<Application Type Name> - optional // /appTypeVersion:<Application Type Version> - optional // /cleanup:<Cleanup the compose files> - optional // /timeout:<ticks> - optional /* ImageBuilder arguments for Application */ // /appTypeName:<Application Type Name> - required for BuildApplication and UpgradeApplication operation // /appTypeVersion:<Application Type Version> - required for BuildApplication and UpgradeApplication operation // /appId:<Application ID> - required for BuildApplication and UpgradeApplication operation // /nameUri:<Name URI> - required for BuildApplication operation // /appParam:<semi-colon separated key-value pair>. Multiple such parameters can be passed. Key cannot have ';'. // /buildPath: <The root folder of build layout> - required for ApplicationTypeInfo and BuildApplicationType operation // /currentAppInstanceVersion: <The current app instance of the Application that needs to be upgraded> - required for UpgradeApplication operation /* ImageBuilder arguments for Fabric Upgrade */ // /codePath: <The path to MSP for FabricUpgrade> // /configPath: <The path to ClusterManifest for FabricUpgrade> // /currentFabricVersion: <The current FabricVersion> // /targetFabricVersion: <The target FabricVersion> // /im: <Path to InfrastructureManifest.xml file> // Dictionary <string, string> commandArgs = null; Exception exception = null; string errorDetailsFile = null; try { commandArgs = ParseParameters(args); // Ensure that required parameters are present EnsureRequiredCommandLineParameters(commandArgs); Dictionary <string, string> applicationParameters = ParseAppParameters(commandArgs); errorDetailsFile = commandArgs.ContainsKey(StringConstants.ErrorDetails) ? commandArgs[StringConstants.ErrorDetails] : null; string workingDirectory = commandArgs.ContainsKey(StringConstants.WorkingDir) ? commandArgs[StringConstants.WorkingDir] : Directory.GetCurrentDirectory(); string imageStoreConnectionString; if (commandArgs.ContainsKey(StringConstants.StoreRoot)) { imageStoreConnectionString = commandArgs[StringConstants.StoreRoot]; } else { ImageBuilderExe.TraceSource.WriteInfo(ImageBuilderExe.TraceType, "Loading ImageStoreConnectionString from config."); bool isEncrypted; NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(); var configValue = configStore.ReadString("Management", "ImageStoreConnectionString", out isEncrypted); if (isEncrypted) { var secureString = NativeConfigStore.DecryptText(configValue); var secureCharArray = FabricValidatorUtility.SecureStringToCharArray(secureString); imageStoreConnectionString = new string(secureCharArray); } else { imageStoreConnectionString = configValue; } if (string.IsNullOrEmpty(imageStoreConnectionString)) { throw new ArgumentException(StringResources.Error_MissingImageStoreConnectionStringInManifest); } } StringBuilder stringToTrace = new StringBuilder(); foreach (var commandArg in commandArgs) { // Skipping tracing StoreRoot since it could be a secret value if (!ImageBuilderUtility.Equals(commandArg.Key, StringConstants.StoreRoot)) { stringToTrace.AppendFormat("{0}:{1}", commandArg.Key, commandArg.Value); stringToTrace.AppendLine(); } } ImageBuilderExe.TraceSource.WriteInfo( ImageBuilderExe.TraceType, "ImageBuilderExe called with - {0}", stringToTrace.ToString()); string currentExecutingDirectory = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); string schemaPath = commandArgs.ContainsKey(StringConstants.SchemaPath) ? commandArgs[StringConstants.SchemaPath] : Path.Combine( currentExecutingDirectory, StringConstants.DefaultSchemaPath); TimeSpan timeout = commandArgs.ContainsKey(StringConstants.Timeout) ? TimeSpan.FromTicks(long.Parse(commandArgs[StringConstants.Timeout])) : TimeSpan.MaxValue; Timer timer = null; if (timeout != TimeSpan.MaxValue) { ImageBuilderExe.TraceSource.WriteInfo( ImageBuilderExe.TraceType, "ImageBuilderExe enabled timeout monitor: {0}", timeout); timer = new Timer(OnTimeout, errorDetailsFile, timeout, TimeSpan.FromMilliseconds(-1)); } IImageStore imageStore = ImageStoreFactoryProxy.CreateImageStore( imageStoreConnectionString, null, workingDirectory, true /*isInternal*/); ImageBuilder imageBuilder = new ImageBuilder(imageStore, schemaPath, workingDirectory); string operationValue = commandArgs[StringConstants.Operation]; bool sfVolumeDiskServiceEnabled = commandArgs.ContainsKey(StringConstants.SFVolumeDiskServiceEnabled) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.SFVolumeDiskServiceEnabled]) : false; imageBuilder.IsSFVolumeDiskServiceEnabled = sfVolumeDiskServiceEnabled; if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationDownloadAndBuildApplicationType)) { string progressFile = commandArgs.ContainsKey(StringConstants.Progress) ? commandArgs[StringConstants.Progress] : null; bool shouldSkipChecksumValidation = commandArgs.ContainsKey(StringConstants.DisableChecksumValidation) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.DisableChecksumValidation]) : false; imageBuilder.DownloadAndBuildApplicationType( commandArgs[StringConstants.DownloadPath], commandArgs[StringConstants.AppTypeName], commandArgs[StringConstants.AppTypeVersion], commandArgs[StringConstants.Output], timeout, progressFile, shouldSkipChecksumValidation); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildApplicationTypeInfo)) { imageBuilder.GetApplicationTypeInfo(commandArgs[StringConstants.BuildPath], timeout, commandArgs[StringConstants.Output]); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildApplicationType)) { string outputFile = commandArgs.ContainsKey(StringConstants.Output) ? commandArgs[StringConstants.Output] : null; string progressFile = commandArgs.ContainsKey(StringConstants.Progress) ? commandArgs[StringConstants.Progress] : null; bool shouldSkipChecksumValidation = commandArgs.ContainsKey(StringConstants.DisableChecksumValidation) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.DisableChecksumValidation]) : false; bool shouldSkipServerSideCopy = commandArgs.ContainsKey(StringConstants.DisableServerSideCopy) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.DisableServerSideCopy]) : false; imageBuilder.BuildApplicationType(commandArgs[StringConstants.BuildPath], timeout, outputFile, progressFile, shouldSkipChecksumValidation, shouldSkipServerSideCopy); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildSingleInstanceApplication)) { bool generateDnsNames = commandArgs.ContainsKey(StringConstants.GenerateDnsNames) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.GenerateDnsNames]) : false; bool useOpenNetworkConfig = commandArgs.ContainsKey(StringConstants.UseOpenNetworkConfig) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.UseOpenNetworkConfig]) : false; Application application = null; using (StreamReader file = File.OpenText(commandArgs[StringConstants.SingleInstanceApplicationDescription])) { JsonSerializer serializer = new JsonSerializer(); serializer.Converters.Add(new DiagnosticsSinkJsonConverter()); serializer.Converters.Add(new VolumeMountJsonConverter()); application = (Application)serializer.Deserialize(file, typeof(Application)); } GenerationConfig config = null; if (commandArgs.ContainsKey(StringConstants.GenerationConfig)) { using (StreamReader file = File.OpenText(commandArgs[StringConstants.GenerationConfig])) { JsonSerializer serializer = new JsonSerializer(); config = (GenerationConfig)serializer.Deserialize(file, typeof(GenerationConfig)); } } imageBuilder.BuildSingleInstanceApplication( application, commandArgs[StringConstants.AppTypeName], commandArgs[StringConstants.AppTypeVersion], commandArgs[StringConstants.AppId], new Uri(commandArgs[StringConstants.AppName]), generateDnsNames, timeout, commandArgs[StringConstants.BuildPath], commandArgs[StringConstants.Output], useOpenNetworkConfig, config); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildSingleInstanceApplicationForUpgrade)) { bool generateDnsNames = commandArgs.ContainsKey(StringConstants.GenerateDnsNames) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.GenerateDnsNames]) : false; bool useOpenNetworkConfig = commandArgs.ContainsKey(StringConstants.UseOpenNetworkConfig) ? ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.UseOpenNetworkConfig]) : false; Application application = null; using (StreamReader file = File.OpenText(commandArgs[StringConstants.SingleInstanceApplicationDescription])) { JsonSerializer serializer = new JsonSerializer(); serializer.Converters.Add(new VolumeMountJsonConverter()); application = (Application)serializer.Deserialize(file, typeof(Application)); } GenerationConfig config = null; if (commandArgs.ContainsKey(StringConstants.GenerationConfig)) { using (StreamReader file = File.OpenText(commandArgs[StringConstants.GenerationConfig])) { JsonSerializer serializer = new JsonSerializer(); config = (GenerationConfig)serializer.Deserialize(file, typeof(GenerationConfig)); } } imageBuilder.BuildSingleInstanceApplicationForUpgrade( application, commandArgs[StringConstants.AppTypeName], commandArgs[StringConstants.CurrentAppTypeVersion], commandArgs[StringConstants.TargetAppTypeVersion], commandArgs[StringConstants.AppId], int.Parse(commandArgs[StringConstants.CurrentAppInstanceVersion], CultureInfo.InvariantCulture), new Uri(commandArgs[StringConstants.AppName]), generateDnsNames, timeout, commandArgs[StringConstants.BuildPath], commandArgs[StringConstants.Output], useOpenNetworkConfig, config); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildApplication)) { imageBuilder.BuildApplication( commandArgs[StringConstants.AppTypeName], commandArgs[StringConstants.AppTypeVersion], commandArgs[StringConstants.AppId], new Uri(commandArgs[StringConstants.NameUri]), applicationParameters, timeout, commandArgs[StringConstants.Output]); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationUpgradeApplication)) { imageBuilder.UpgradeApplication( commandArgs[StringConstants.AppId], commandArgs[StringConstants.AppTypeName], int.Parse(commandArgs[StringConstants.CurrentAppInstanceVersion], CultureInfo.InvariantCulture), commandArgs[StringConstants.AppTypeVersion], applicationParameters, timeout, commandArgs[StringConstants.Output]); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationDelete)) { imageBuilder.Delete(commandArgs[StringConstants.Input], timeout); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationCleanupApplicationPackage)) { imageBuilder.DeleteApplicationPackage(commandArgs[StringConstants.BuildPath], timeout); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationGetFabricVersion)) { imageBuilder.GetFabricVersionInfo( commandArgs[StringConstants.CodePath], commandArgs[StringConstants.ConfigPath], timeout, commandArgs[StringConstants.Output]); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationProvisionFabric)) { string configurationCsvFilePath = Path.Combine(currentExecutingDirectory, StringConstants.ConfigurationsFileName); imageBuilder.ProvisionFabric( commandArgs[StringConstants.CodePath], commandArgs[StringConstants.ConfigPath], configurationCsvFilePath, commandArgs[StringConstants.InfrastructureManifestFile], timeout); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationGetClusterManifest)) { imageBuilder.GetClusterManifestContents( commandArgs[StringConstants.ConfigVersion], commandArgs[StringConstants.Output], timeout); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationUpgradeFabric)) { string configurationCsvFilePath = Path.Combine(currentExecutingDirectory, StringConstants.ConfigurationsFileName); imageBuilder.UpgradeFabric( commandArgs[StringConstants.CurrentFabricVersion], commandArgs[StringConstants.TargetFabricVersion], configurationCsvFilePath, timeout, commandArgs[StringConstants.Output]); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationGetManifests)) { imageBuilder.GetManifests(commandArgs[StringConstants.Input], timeout); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationValidateComposeDeployment)) { bool cleanupComposeFiles = commandArgs.ContainsKey(StringConstants.CleanupComposeFiles) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.CleanupComposeFiles]); HashSet <string> ignoredKeys; imageBuilder.ValidateComposeDeployment( commandArgs[StringConstants.ComposeFilePath], commandArgs.ContainsKey(StringConstants.OverrideFilePath) ? commandArgs[StringConstants.OverrideFilePath] : null, commandArgs.ContainsKey(StringConstants.AppName) ? commandArgs[StringConstants.AppName] : null, commandArgs.ContainsKey(StringConstants.AppTypeName) ? commandArgs[StringConstants.AppTypeName] : null, commandArgs.ContainsKey(StringConstants.AppTypeVersion) ? commandArgs[StringConstants.AppTypeVersion] : null, timeout, out ignoredKeys, cleanupComposeFiles); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildComposeDeployment)) { bool cleanupComposeFiles = commandArgs.ContainsKey(StringConstants.CleanupComposeFiles) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.CleanupComposeFiles]); bool shouldSkipChecksumValidation = commandArgs.ContainsKey(StringConstants.DisableChecksumValidation) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.DisableChecksumValidation]); bool isPasswordEncrypted = commandArgs.ContainsKey(StringConstants.IsRepositoryPasswordEncrypted) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.IsRepositoryPasswordEncrypted]); bool generateDnsNames = commandArgs.ContainsKey(StringConstants.GenerateDnsNames) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.GenerateDnsNames]); imageBuilder.BuildComposeDeploymentPackage( commandArgs[StringConstants.ComposeFilePath], commandArgs.ContainsKey(StringConstants.OverrideFilePath) ? commandArgs[StringConstants.OverrideFilePath] : null, timeout, commandArgs.ContainsKey(StringConstants.AppName) ? commandArgs[StringConstants.AppName] : null, commandArgs[StringConstants.AppTypeName], commandArgs[StringConstants.AppTypeVersion], commandArgs.ContainsKey(StringConstants.RepositoryUserName) ? commandArgs[StringConstants.RepositoryUserName] : null, commandArgs.ContainsKey(StringConstants.RepositoryPassword) ? commandArgs[StringConstants.RepositoryPassword] : null, isPasswordEncrypted, generateDnsNames, commandArgs[StringConstants.OutputComposeFilePath], commandArgs[StringConstants.Output], cleanupComposeFiles, shouldSkipChecksumValidation); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.OperationBuildComposeApplicationForUpgrade)) { bool cleanupComposeFiles = commandArgs.ContainsKey(StringConstants.CleanupComposeFiles) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.CleanupComposeFiles]); bool shouldSkipChecksumValidation = commandArgs.ContainsKey(StringConstants.DisableChecksumValidation) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.DisableChecksumValidation]); bool isPasswordEncrypted = commandArgs.ContainsKey(StringConstants.IsRepositoryPasswordEncrypted) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.IsRepositoryPasswordEncrypted]); bool generateDnsNames = commandArgs.ContainsKey(StringConstants.GenerateDnsNames) && ImageBuilderUtility.ConvertString <bool>(commandArgs[StringConstants.GenerateDnsNames]); imageBuilder.BuildComposeDeploymentPackageForUpgrade( commandArgs[StringConstants.ComposeFilePath], commandArgs.ContainsKey(StringConstants.OverrideFilePath) ? commandArgs[StringConstants.OverrideFilePath] : null, timeout, commandArgs.ContainsKey(StringConstants.AppName) ? commandArgs[StringConstants.AppName] : null, commandArgs[StringConstants.AppTypeName], commandArgs[StringConstants.CurrentAppTypeVersion], commandArgs[StringConstants.TargetAppTypeVersion], commandArgs.ContainsKey(StringConstants.RepositoryUserName) ? commandArgs[StringConstants.RepositoryUserName] : null, commandArgs.ContainsKey(StringConstants.RepositoryPassword) ? commandArgs[StringConstants.RepositoryPassword] : null, isPasswordEncrypted, generateDnsNames, commandArgs[StringConstants.OutputComposeFilePath], commandArgs[StringConstants.Output], cleanupComposeFiles, shouldSkipChecksumValidation); } else if (ImageBuilderUtility.Equals(operationValue, StringConstants.TestErrorDetails)) { throw new Exception(StringConstants.TestErrorDetails); } else { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, StringResources.Error_ImageBuilderExeCommandLineInvalidOperation, StringConstants.Operation, operationValue)); } } catch (AggregateException ae) { exception = ae.InnerException; StringBuilder exceptionStringBuilder = new StringBuilder("Aggregate exception has "); exceptionStringBuilder.Append(ae.InnerExceptions.Count); exceptionStringBuilder.Append(" exceptions. "); ae.InnerExceptions.ForEach(innerException => exceptionStringBuilder.AppendLine(innerException.Message)); ImageBuilderExe.TraceSource.WriteWarning( ImageBuilderExe.TraceType, "AggregateException: {0}", exceptionStringBuilder.ToString()); } catch (Exception e) { exception = e; } if (exception != null) { OnFailure(exception, errorDetailsFile); return(unchecked ((int)NativeTypes.FABRIC_ERROR_CODE.FABRIC_E_IMAGEBUILDER_UNEXPECTED_ERROR)); } else { ImageBuilderExe.TraceSource.WriteInfo( ImageBuilderExe.TraceType, "ImageBuilderExe operation completed successfully."); return(0); } }