public void Generate(IGeneratorSettings generatorSettings) { if (String.IsNullOrWhiteSpace(this.txtPassword.Text)) { MessageBox.Show(base.ParentForm, "Provide a source password to be processed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IEntropyCalculator entropyCalculator = CalculatorFactory.Create <IEntropyCalculator>(); IStrengthCalculator strengthCalculator = CalculatorFactory.Create <IStrengthCalculator>(); ISecurityCalculator securityCalculator = CalculatorFactory.Create <ISecurityCalculator>(); String password = this.txtPassword.Text; Double entropy = entropyCalculator.Calculate(password); Strength strength = strengthCalculator.Calculate(entropy); Scenario scenario = this.cmbScenario.SelectedValue as Scenario; // Don't change this order. this.cntEntropy.Strength = strength; this.cntEntropy.Entropy = entropy; this.cntEntropy.Percent = strengthCalculator.ToPercent(entropy); this.cntEntropy.Summary = strengthCalculator.ToSummary(strength); if (entropy > 0d) { Duration duration = securityCalculator.Calculate(scenario, entropy); this.cntDuration.SetDuration(duration); } }
/// <summary> /// Initializes a new instance of the <see cref="BindingWriter"/> class. /// </summary> /// <param name="generatorSettings">The generator settings.</param> /// <param name="profile">The profile.</param> /// <param name="documentation">The documentation for the profile.</param> public BindingWriter ( [NotNull] IGeneratorSettings generatorSettings, [NotNull] ApiProfile profile, [NotNull] ProfileDocumentation documentation ) { _generatorSettings = generatorSettings ?? throw new ArgumentNullException(nameof(generatorSettings)); _profile = profile ?? throw new ArgumentNullException(nameof(profile)); _documentation = documentation ?? throw new ArgumentNullException(nameof(documentation)); var allFunctions = profile.NativeSignatures.Concat(profile.Overloads).ToList(); var enumerationUsages = new Dictionary <EnumerationSignature, IReadOnlyList <FunctionSignature> >(); foreach (var e in profile.Enumerations) { // Initialize the dictionary var functionsUsingThisEnum = allFunctions .Where(f => f.Parameters.Any(p => p.Type.Name == e.Name)) .ToList(); enumerationUsages.Add(e, functionsUsingThisEnum); } _enumerationUsages = enumerationUsages; _entrypointSlots = profile.NativeSignatures .Select((ns, i) => (ns.NativeEntrypoint, i)) .ToDictionary(t1 => t1.Item1, t2 => t2.Item2); _identifierTranslator = new NativeIdentifierTranslator(); }
public void Generate(IGeneratorSettings generatorSettings) { if (generatorSettings is null) { throw new ArgumentNullException(nameof(generatorSettings)); } String source = this.txtSource.Text; if (String.IsNullOrWhiteSpace(source)) { MessageBox.Show(base.ParentForm, "Provide a source password to be processed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { this.qwertyValidator.Validate(source.ToLower(), KeyType.Lower); this.txtResult.Text = "Doesn't seem to be a QWERTY password on current keyboard."; } catch (QwertyException exception) { this.txtResult.Text = exception.Message; } }
/// <summary> /// Writes the given profile to a directory. /// </summary> /// <param name="generatorSettings">The generator settings to use for the profile writer.</param> /// <param name="profile">The profile to write.</param> /// <param name="docs">The profile's documentation.</param> /// <param name="nc">The name container for this profile.</param> public static void Write ( IGeneratorSettings generatorSettings, ApiProfile profile, ProfileDocumentation docs, NameContainer nc ) { var rootFolder = Path.Combine(Program.Arguments.OutputPath, generatorSettings.OutputSubfolder); var rootNamespace = generatorSettings.Namespace; if (!Directory.Exists(rootFolder)) { Directory.CreateDirectory(rootFolder); } if (!Directory.Exists(Path.Combine(rootFolder, rootNamespace))) { Directory.CreateDirectory(Path.Combine(rootFolder, rootNamespace)); } if (!Directory.Exists(Path.Combine(rootFolder, ExtensionsFolder))) { Directory.CreateDirectory(Path.Combine(rootFolder, ExtensionsFolder)); } foreach (var project in GetProjects(profile)) { WriteProject(project, generatorSettings, nc, docs); } }
private IReadOnlyList <DocumentApi> GenerateApiDocumentation(IGeneratorSettings generatorSettings) { var asm = generatorSettings.Assembly; var controllers = asm.GetExportedTypes() .Where(x => x.CustomAttributes.Any(y => y.AttributeType.FullName.Contains("ApiController"))); return((from controller in controllers select GenerateDocumentApi(controller)).ToList()); }
public IDocument Generate(IDocumentSettings documentSettings, IGeneratorSettings generatorSettings) { var document = new Document(); var pages = new List <DocumentPage>(); document.Settings = documentSettings; document.Apis = GenerateApiDocumentation(generatorSettings); document.Pages = pages; return(document); }
public async void Generate(IGeneratorSettings generatorSettings) { if (generatorSettings is null) { throw new ArgumentNullException(nameof(generatorSettings)); } String source = this.txtSource.Text; if (String.IsNullOrWhiteSpace(source)) { MessageBox.Show(base.ParentForm, "Provide a source password to be processed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { this.RaiseUpdateStatus(null, "Running..."); this.Cursor = Cursors.WaitCursor; this.txtResult.Text = String.Empty; this.txtResult.BackColor = Color.Transparent; this.txtResult.TextAlign = ContentAlignment.TopLeft; Int64 result = await this.passwordCounter.GetPwnCountAsync(source, new CancellationToken()); if (result > 0) { this.txtResult.Text = $"Bad news! This password has been seen at least {result:N0} times before."; this.txtResult.BackColor = this.color1; this.txtResult.TextAlign = ContentAlignment.MiddleCenter; } else { this.txtResult.Text = "Good news! This password may not have been seen yet."; this.txtResult.BackColor = this.color2; this.txtResult.TextAlign = ContentAlignment.MiddleCenter; } } catch (Exception exception) { this.txtResult.Text = exception.Message; this.txtResult.BackColor = Color.Transparent; this.txtResult.TextAlign = ContentAlignment.TopLeft; } finally { this.Cursor = Cursors.Default; this.RaiseUpdateStatus(); } }
public async Task ProcessAsync(IGeneratorSettings settings, IDocument document) { var data = JSON.Stringify(document); var folder = System.IO.Path.Combine(settings.OutputFolder, "assets"); var filePath = System.IO.Path.Combine(folder, "documentation.data.js"); if (!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } await System.IO.File.WriteAllTextAsync(filePath, "var data = " + data + ";"); }
private void cmbGenerator_SelectedIndexChanged(object sender, EventArgs e) { settingsControl = Controller.GetGeneratorSettingsControl(SelectedGenerator); if (settingsControl != null) { LoadSettingsControl(); } else { MessageBox.Show("This Generator has no settings to configure. Click Finish to continue."); } }
public IEnumerable <String> Generate(IExtendedSettings settings, IGeneratorSettings source) { if (settings is null) { throw new ArgumentNullException(nameof(settings)); } if (source is null) { throw new ArgumentNullException(nameof(source)); } return(this.Generate(source.CollectSource(), settings.Length, settings.Amount)); }
public IEnumerable <String> Generate(ICommonSettings settings, IGeneratorSettings source) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } if (settings.Amount < 1) { throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Amount)} must be greater than zero."); } if (settings.Length < 1) { throw new ArgumentOutOfRangeException(nameof(settings), $"Settings value {nameof(ICommonSettings.Length)} must be greater than zero."); } IPoolsCollector collector = CollectorFactory.Create <IPoolsCollector>(); switch (settings.Type) { case CommonType.InternetPassword1: case CommonType.InternetPassword2: case CommonType.InternetPassword3: case CommonType.InternetPasswordX: return(this.GenerateInternetPasswords(settings, collector)); case CommonType.PasswordManager1: case CommonType.PasswordManager2: case CommonType.PasswordManager3: return(this.GenerateManagerPasswords(settings, collector)); case CommonType.WepKey64Bit: case CommonType.WepKey128Bit: case CommonType.WepKey152Bit: case CommonType.WepKey256Bit: case CommonType.WepKeyCustom: case CommonType.WpaKey: case CommonType.Wpa2Key: return(this.GenerateWirelessPasswords(settings, collector)); default: throw new NotSupportedException($"Common type of {settings.Type} is not supported."); } }
/// <summary> /// Writes a mixed mode class for the given project. /// </summary> /// <param name="project">The project to write a mixed-mode class for.</param> /// <param name="settings">The generator settings used to configure the mixed-mode class writer.</param> /// <param name="docs">The profile's documentation, used to write summaries to overloads.</param> public static void WriteMixedModeClass(Project project, IGeneratorSettings settings, ProfileDocumentation docs) { var ext = project.Extension != "Core"; var ns = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension); var dir = project.Extension == "Core" ? Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, settings.Namespace, settings.ClassName) : Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, ProfileWriter.ExtensionsFolder, ns); WriteOverloadsMixedModePart(project, settings, docs); WriteNativeMixedModePart(project, settings); if (!File.Exists(Path.Combine(dir, $"{settings.ClassName}.cs")) && !ext) { WriteTemplateMixedModePart(project, settings); } }
public void Generate(IGeneratorSettings generatorSettings) { if (generatorSettings is null) { throw new ArgumentNullException(nameof(generatorSettings)); } if (this.cmbTypes.SelectedValue is CommonSubset selected) { if (selected.Type == CommonType.Nothing) { MessageBox.Show(base.ParentForm, "Please choose one of the password types.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (selected.Type == CommonType.WepKeyCustom && this.txtPhrase.TextLength < 1) { MessageBox.Show(base.ParentForm, "Please provide a custom password phrase.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (selected.IsPoolsEnabled && !this.chkUppers.Checked && !this.chkLowers.Checked && !this.chkDigits.Checked && !this.chkExtras.Checked) { MessageBox.Show(base.ParentForm, "Please choose at least one of the character pools.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.chbDelete.Checked) { this.lstPasswords.Items.Clear(); } ICommonGenerator generator = GeneratorFactory.Create <ICommonGenerator>(); this.lstPasswords.Items.AddRange(generator.Generate(this.controlSettings, generatorSettings).ToArray()); } }
public void Apply(IGeneratorSettings settings) { foreach (var pair in settings.Factories) { SetFactory(pair.Key, pair.Value); } foreach (var pair in settings.MemberFactories) { this.SetMemberFactory(pair.Key, pair.Value); } foreach(var action in settings.CustomActions) { this.AddCustomAction(action); } this.MaxDepth = settings.MaxDepth; this.OverrideChildSettings = settings.OverrideChildSettings; }
public void Generate(IGeneratorSettings generatorSettings) { if (generatorSettings is null) { throw new ArgumentNullException(nameof(generatorSettings)); } String source = this.txtSource.Text; if (String.IsNullOrWhiteSpace(source)) { MessageBox.Show(base.ParentForm, "Provide a source password to be processed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IExchangeGenerator generator = GeneratorFactory.Create <IExchangeGenerator>(); this.txtResult.Text = generator.Generate(this.controlSettings, this.txtSource.Text); }
/// <summary> /// Asynchronously writes the given profile to a directory. /// </summary> /// <param name="generatorSettings">The generator settings to use for the profile writer.</param> /// <param name="profile">The profile to write.</param> /// <param name="docs">The profile's documentation.</param> /// <param name="nc">The name container for this profile.</param> /// <returns>An asynchronous task.</returns> public static Task WriteAsync ( IGeneratorSettings generatorSettings, ApiProfile profile, ProfileDocumentation docs, NameContainer nc ) { var rootFolder = Path.Combine(Program.Arguments.OutputPath, generatorSettings.OutputSubfolder); var rootNamespace = generatorSettings.Namespace; if (!Directory.Exists(rootFolder)) { Directory.CreateDirectory(rootFolder); } if (!Directory.Exists(Path.Combine(rootFolder, rootNamespace))) { Directory.CreateDirectory(Path.Combine(rootFolder, rootNamespace)); } if (!Directory.Exists(Path.Combine(rootFolder, ExtensionsFolder))) { Directory.CreateDirectory(Path.Combine(rootFolder, ExtensionsFolder)); } return(Task.WhenAll ( GetProjects(profile) .Select ( x => WriteProjectAsync( x, generatorSettings, nc, docs) ) )); }
private static async Task WriteTemplateMixedModePartAsync( Project project, IGeneratorSettings settings) { var dir = Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, settings.Namespace, settings.ClassName); using (var sw = new StreamWriter(File.Open(Path.Combine(dir, settings.ClassName + ".cs"), FileMode.Create, FileAccess.ReadWrite, FileShare.Inheritable))) { sw.WriteLine(EmbeddedResources.LicenseText(Path.GetFileName(settings.ClassName + ".cs"))); sw.WriteLine("using System;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine("using AdvancedDLSupport;"); sw.WriteLine("using OpenToolkit.Core.Loader;"); sw.WriteLine("using OpenToolkit.Core.Native;"); sw.WriteLine(); sw.WriteLine("namespace " + settings.Namespace); sw.WriteLine("{"); var nm = settings.NameContainer.ClassName; sw.WriteLine(" public partial class " + settings.ClassName + " : NativeLibraryBase, I" + settings.ClassName); sw.WriteLine(" {"); sw.WriteLine(" /// <inheritdoc cref=\"NativeLibraryBase\"/>"); sw.WriteLine(" protected " + settings.ClassName + "(string path, ImplementationOptions options)"); sw.WriteLine(" : base(path, options)"); sw.WriteLine(" {"); sw.WriteLine(" }"); sw.WriteLine(); sw.WriteLine(" /// <summary>"); sw.WriteLine(" /// Gets the library name container for this profile."); sw.WriteLine(" /// </summary>"); sw.Write(" public IPlatformLibraryNameContainer NameContainer => new"); sw.WriteLine(" " + nm + "();"); sw.WriteLine(" }"); sw.WriteLine("}"); await sw.FlushAsync(); } }
public void Generate(IGeneratorSettings generatorSettings) { if (generatorSettings is null) { throw new ArgumentNullException(nameof(generatorSettings)); } if (!generatorSettings.IsValid) { MessageBox.Show(base.ParentForm, "Provide at least one of the character pools.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.chbDelete.Checked) { this.lstPasswords.Items.Clear(); } IExtendedGenerator generator = GeneratorFactory.Create <IExtendedGenerator>(); this.lstPasswords.Items.AddRange(generator.Generate(this.controlSettings, generatorSettings).ToArray()); }
public TableGenerator(IGeneratorSettings settings) { _settings = settings; }
private static void WriteProject ( Project project, IGeneratorSettings settings, NameContainer nc, ProfileDocumentation doc ) { var folder = Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder); var ns = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension); var dir = project.Extension == "Core" ? Path.Combine(folder, ns, settings.ClassName) : Path.Combine(folder, ExtensionsFolder, ns); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (!Directory.Exists(Path.Combine(dir, InterfacesFolder))) { Directory.CreateDirectory(Path.Combine(dir, InterfacesFolder)); } if (!Directory.Exists(Path.Combine(dir, EnumsFolder))) { Directory.CreateDirectory(Path.Combine(dir, EnumsFolder)); } foreach (var interfaceDef in project.Interfaces) { var path = Path.Combine(dir, InterfacesFolder, interfaceDef.InterfaceName + ".cs"); InterfaceWriter.WriteInterface(interfaceDef, path, ns, settings.FunctionPrefix, doc, settings.Namespace); } foreach (var enumSignature in project.Enums) { var path = Path.Combine(dir, EnumsFolder, enumSignature.Name + ".cs"); EnumWriter.WriteEnum(enumSignature, path, ns, settings.ConstantPrefix); } if (project.Extension == "Core") { InterfaceWriter.WriteMetaInterface ( ns, Path.Combine(dir, InterfacesFolder, "I" + settings.ClassName + ".cs"), settings.ClassName, project.Interfaces.Select(x => x.InterfaceName) ); NameContainerWriter.WriteNameContainer ( Path.Combine(dir, $"{settings.APIIdentifier}LibraryNameContainer.cs"), ns, settings.APIIdentifier, nc ); } else { // we expect the project file to already be created ProjectFileWriter.WriteProjectFile(ns, dir, settings.OutputSubfolder, settings.Namespace, project.Extension != "Core"); } ClassWriter.WriteMixedModeClass(project, settings, doc); }
private static async Task WriteOverloadsMixedModePartAsync(Project project, IGeneratorSettings settings, ProfileDocumentation docs) { var file = project.Extension == "Core" ? settings.ClassName : NativeIdentifierTranslator.TranslateIdentifierName(project.Extension); var ns = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension); var dir = project.Extension == "Core" ? Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, settings.Namespace, settings.ClassName) : Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, ProfileWriter.ExtensionsFolder, ns); using (var sw = new StreamWriter(File.Open(Path.Combine(dir, file + ".Overloads.cs"), FileMode.Create, FileAccess.ReadWrite, FileShare.Inheritable))) { sw.WriteLine("// <auto-generated />"); sw.WriteLine(EmbeddedResources.LicenseText(Path.GetFileName(file))); sw.WriteLine("using AdvancedDLSupport;"); sw.WriteLine("using OpenToolkit.Core.Native;"); sw.WriteLine("using OpenToolkit.Core.Extensions;"); sw.WriteLine("using System;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine("using " + settings.Namespace + ";"); sw.WriteLine(); sw.WriteLine("namespace " + ns); sw.WriteLine("{"); sw.WriteLine(" /// <summary>"); sw.WriteLine(" /// Contains bindings to the " + settings.APIIdentifier + " API."); sw.WriteLine(" /// </summary>"); sw.WriteLine(" public partial class " + file); sw.WriteLine(" {"); foreach (var overload in project.Overloads) { sw.WriteLine(" /// <summary>"); if (docs.HasDocumentation(overload.Item1)) { sw.WriteLine(" /// " + docs.GetDocumentation(overload.Item1)?.Purpose); } else { sw.WriteLine(" /// To be added."); } sw.WriteLine(" /// </summary>"); if (overload.Item1.IsDeprecated) { var str = "Deprecated"; if (overload.Item1.DeprecatedIn != null) { str += " since " + overload.Item1.DeprecatedIn.ToString(2); } if (!string.IsNullOrWhiteSpace(overload.Item1.DeprecationReason)) { str += " - " + overload.Item1.DeprecationReason; } sw.WriteLine($" [Obsolete(\"{str}\")]"); } sw.WriteLine( " " + "[AutoGenerated(" + $"Category = \"{overload.Item1.Categories.First()}\", " + $"Version = \"{overload.Item1.IntroducedIn}\", " + $"EntryPoint = \"{settings.FunctionPrefix}{overload.Item1.NativeEntrypoint}\", " + $"Source = \"{overload.Item1.Source}\"" + ")]"); sw.Write(" public "); var decl = Utilities.GetDeclarationString(overload.Item1); if (!decl.Contains("unsafe ")) { sw.Write("unsafe "); } sw.WriteLine(decl); sw.WriteLine(" {"); foreach (var line in overload.Item2.ToString() .Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) { sw.Write(" " + line); } sw.WriteLine(" }"); sw.WriteLine(); } sw.WriteLine(" }"); sw.WriteLine("}"); await sw.FlushAsync(); } }
private static async Task WriteProjectAsync ( Project project, IGeneratorSettings settings, NameContainer nc, ProfileDocumentation doc ) { var folder = Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder); var ns = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension); var dir = project.Extension == "Core" ? Path.Combine(folder, ns, settings.ClassName) : Path.Combine(folder, ExtensionsFolder, ns); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (!Directory.Exists(Path.Combine(dir, InterfacesFolder))) { Directory.CreateDirectory(Path.Combine(dir, InterfacesFolder)); } if (!Directory.Exists(Path.Combine(dir, EnumsFolder))) { Directory.CreateDirectory(Path.Combine(dir, EnumsFolder)); } await Task.WhenAll( project.Interfaces.Select ( x => InterfaceWriter.WriteInterfaceAsync ( x, Path.Combine(dir, InterfacesFolder, x.InterfaceName + ".cs"), ns, settings.FunctionPrefix, doc, settings.Namespace ) ).Concat ( project.Enums.Select( x => EnumWriter.WriteEnumAsync ( x, Path.Combine(dir, EnumsFolder, x.Name + ".cs"), ns, settings.ConstantPrefix ) ) ) ); if (project.Extension == "Core") { await InterfaceWriter.WriteMetaInterfaceAsync ( ns, Path.Combine(dir, InterfacesFolder, "I" + settings.ClassName + ".cs"), settings.ClassName, project.Interfaces.Select(x => x.InterfaceName) ); await NameContainerWriter.WriteNameContainerAsync ( Path.Combine(dir, $"{settings.APIIdentifier}LibraryNameContainer.cs"), ns, settings.APIIdentifier, nc ); } else { // we expect the project file to already be created await ProjectFileWriter.WriteProjectFileAsync(ns, dir, settings.OutputSubfolder, settings.Namespace, project.Extension != "Core"); } await ClassWriter.WriteMixedModeClassAsync(project, settings, doc); }
private static async Task WriteNativeMixedModePartAsync(Project project, IGeneratorSettings settings) { var ns = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension); var dir = project.Extension == "Core" ? Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, settings.Namespace, settings.ClassName) : Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder, ProfileWriter.ExtensionsFolder, ns); var file = project.Extension == "Core" ? settings.ClassName : NativeIdentifierTranslator.TranslateIdentifierName(project.Extension); using (var sw = new StreamWriter(File.Open(Path.Combine(dir, file + ".Native.cs"), FileMode.Create, FileAccess.ReadWrite, FileShare.Inheritable))) { sw.WriteLine("// <auto-generated />"); sw.WriteLine(EmbeddedResources.LicenseText(Path.GetFileName(file))); sw.WriteLine("using AdvancedDLSupport;"); sw.WriteLine("using OpenToolkit.Core.Native;"); sw.WriteLine("using OpenToolkit.Core.Loader;"); sw.WriteLine("using OpenToolkit.Core.Extensions;"); sw.WriteLine("using " + settings.Namespace + ";"); sw.WriteLine("using System;"); sw.WriteLine("using System.Runtime.InteropServices;"); sw.WriteLine("using System.Text;"); sw.WriteLine(); sw.WriteLine("namespace " + ns); sw.WriteLine("{"); if (project.Extension != "Core") { sw.WriteLine($" [Extension(\"{settings.ConstantPrefix}{project.Extension}\")]"); } sw.Write(" public abstract partial class " + file); if (project.Extension != "Core") { sw.WriteLine(" : ExtensionBase, I" + file); sw.WriteLine(" {"); sw.WriteLine(" /// <inheritdoc cref=\"ExtensionBase\"/>"); sw.WriteLine($" protected {file}(string path, ImplementationOptions options)"); sw.WriteLine(" : base(path, options)"); sw.WriteLine(" {"); sw.WriteLine(" }"); sw.WriteLine(); } else { sw.WriteLine(); sw.WriteLine(" {"); } foreach (var function in project.Interfaces.SelectMany(x => x.Functions)) { sw.WriteLine(" /// <inheritdoc/>"); if (function.IsDeprecated) { var str = "Deprecated"; if (function.DeprecatedIn != null) { str += " since " + function.DeprecatedIn.ToString(2); } if (!string.IsNullOrWhiteSpace(function.DeprecationReason)) { str += " - " + function.DeprecationReason; } sw.WriteLine($" [Obsolete(\"{str}\")]"); } sw.Write(" public abstract "); sw.WriteLine(Utilities.GetDeclarationString(function) + ";"); sw.WriteLine(); } sw.WriteLine(" }"); sw.WriteLine("}"); await sw.FlushAsync(); } }
public void Apply(IGeneratorSettings settings) { settings.OverrideChildSettings = @override; }
/// <summary> /// Sets the Generator used by AutoRest /// </summary> /// <param name="settings">Settings</param> /// <param name="gen">Desired code generator (any <see cref="CodeGenerator"/> member)</param> /// <param name="genSettings">Optional generator-specific settings to use</param> /// <returns>The updated settings object</returns> public static AutoRestSettings WithGenerator(this AutoRestSettings settings, CodeGenerator gen, IGeneratorSettings genSettings = null) { settings.Generator = gen; if (genSettings != null) { settings.GeneratorSettings = genSettings; } return(settings); }
public BasicClient(IGeneratorSettings generatorSettings, IServiceSettings serviceSettings, TokenTableSet tokenTableSet) : this(new TableGenerator(generatorSettings), new BasicService(serviceSettings, new Encryption(), new Compression()), new Serialisation(), new Compression(), new Encryption(), tokenTableSet) { }
/// <summary> /// Asynchronously generates bindings for the API described by the given <see cref="IGeneratorSettings"/> /// object. /// /// Broadly, this takes the following steps: /// 1) Load the base API. /// 2) Bake overrides into the API /// 3) Bake Documentation into the API /// 4) Create mappings between OpenGL types and C# types /// 5) Apply the mappings to the API /// 6) Bake convenience overloads into the API (adding unsafe, etc) /// 7) Write the bindings to the files. /// /// </summary> /// <param name="generatorSettings">The settings describing the API.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private static async Task GenerateBindingsAsync([NotNull] IGeneratorSettings generatorSettings) { var signaturePath = Path.Combine(Arguments.InputPath, generatorSettings.SpecificationFile); if (!_cachedProfiles.TryGetValue(signaturePath, out var profiles)) { profiles = SignatureReader.GetAvailableProfiles(signaturePath).ToList(); _cachedProfiles.TryAdd(signaturePath, profiles); } var profileOverrides = OverrideReader .GetProfileOverrides(generatorSettings.OverrideFiles.ToArray()) .ToList(); var baker = new ProfileBaker(profiles, profileOverrides); var bakedProfile = baker.BakeProfile ( generatorSettings.ProfileName, generatorSettings.Versions, generatorSettings.BaseProfileName ); var documentationPath = Path.Combine ( Arguments.DocumentationPath, generatorSettings.SpecificationDocumentationPath ); var docs = DocumentationReader.ReadProfileDocumentation(documentationPath); var bakedDocs = new DocumentationBaker(bakedProfile).BakeDocumentation(docs); var languageTypemapPath = Path.Combine(Arguments.InputPath, generatorSettings.LanguageTypemap); if (!_cachedTypemaps.TryGetValue(languageTypemapPath, out var languageTypemap)) { using (var fs = File.OpenRead(languageTypemapPath)) { languageTypemap = new TypemapReader().ReadTypemap(fs); _cachedTypemaps.TryAdd(languageTypemapPath, languageTypemap); } } var apiTypemapPath = Path.Combine(Arguments.InputPath, generatorSettings.APITypemap); if (!_cachedTypemaps.TryGetValue(apiTypemapPath, out var apiTypemap)) { using (var fs = File.OpenRead(apiTypemapPath)) { apiTypemap = new TypemapReader().ReadTypemap(fs); _cachedTypemaps.TryAdd(apiTypemapPath, apiTypemap); } } var bakedMap = TypemapBaker.BakeTypemaps(apiTypemap, languageTypemap); var mapper = new ProfileMapper(bakedMap); var mappedProfile = mapper.Map(bakedProfile); var overloadedProfile = OverloadBaker.BakeOverloads(mappedProfile); var bindingsWriter = new BindingWriter(generatorSettings, overloadedProfile, bakedDocs); await bindingsWriter.WriteBindingsAsync(); }
public MacroResolver(IGeneratorSettings settings) { Settings = settings; }
public void Apply(IGeneratorSettings settings) { settings.MaxDepth = maxDepth; }
public Parser(IGeneratorSettings settings) { Settings = settings; }
public void Apply(IGeneratorSettings settings) { settings.SetFactory(targetType, factory); }
public void Apply(IGeneratorSettings settings) { settings.SetMemberFactory(memberInfo, factory); }