public void TestSimpleSingleProperty() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(PathUtility.GetDirectory(), "Mocks/simpleSingleProperty.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Name", JSchemaType.String); }
public void TestSimpleSingleProperty() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(TestContext.DeploymentDirectory, "simpleSingleProperty.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Name", JSchemaType.String); }
public void LoadAllFederationAssemblies() { if (m_typesAssemblies != null && m_typesAssemblies.Length > 0) { m_schemaInfo = SchemaExtractor.Extract(m_typesAssemblies, m_typesDependencyAssemblies); } }
public DaoAssemblyGenerator(SchemaExtractor schemaExtractor, string workspacePath = null) { this.SchemaExtractor = schemaExtractor ?? new MsSqlSmoSchemaExtractor("Default"); this.ReferenceAssemblies = new Assembly[] { }; this._referenceAssemblyPaths = new List <string>(AdHocCSharpCompiler.DefaultReferenceAssemblies); this.Workspace = workspacePath ?? "."; }
public void TestNoRequiredPropertys() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(TestContext.DeploymentDirectory, "noRequiredProperty.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Name", JSchemaType.String, false); }
public void TestBooleanProperty() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(PathUtility.GetDirectory(), "Mocks/booleanProperty.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Name", JSchemaType.String); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "HasName", JSchemaType.Boolean, false); }
public void TestMultipleProperties() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(TestContext.DeploymentDirectory, "multipleProperties.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Title", JSchemaType.String); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Name", JSchemaType.String); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Age", JSchemaType.String); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Order", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"].Properties["Order"], "Count", JSchemaType.String); }
public VelocityDBBuilder(VelocityDBDynamicDriver pDriver, VelocityDBProperties pProperties) { schema = SchemaExtractor.Extract(pProperties.ClassesFilenamesArray, pProperties.DependencyFilesArray); sessionInfo = new SessionInfo() { DBFolder = pProperties.DBFolder, Host = pProperties.Host, PessimisticLocking = pProperties.PessimisticLocking, SessionType = pProperties.SessionType, WindowsAuth = pProperties.WindowsAuth }; }
public Task<JSchema> GetSchemaFromTemplateAsync(TemplateInfo template) { var extractor = new SchemaExtractor(new HandlebarsParser()); var helperHandlers = _helperHandlerFactory != null ? _helperHandlerFactory.Create().ToArray() : null; // TODO: Use async var schema = extractor.Run(template.Id, new StreamReader(template.Open()), _memberLocator, helperHandlers); if (schema != null && string.IsNullOrEmpty(schema.Title)) schema.Title = string.Concat(template.Id, "Model"); return Task.FromResult(schema); }
public void TestArrayProperty() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(TestContext.DeploymentDirectory, "arrayProperty.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Addresses", JSchemaType.Array); Assert.IsNotNull(schema.Properties["Customer"].Properties["Addresses"].Items, "an items array should be given for an array type."); Assert.AreEqual(1, schema.Properties["Customer"].Properties["Addresses"].Items.Count, "expectects exactly on item inside items"); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"].Properties["Addresses"].Items[0], "Street", JSchemaType.String); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"].Properties["Addresses"].Items[0], "ZipCode", JSchemaType.String); }
public Task <JSchema> GetSchemaFromTemplateAsync(TemplateInfo template) { var extractor = new SchemaExtractor(new HandlebarsParser()); var helperHandlers = _helperHandlerFactory != null?_helperHandlerFactory.Create().ToArray() : null; // TODO: Use async var schema = extractor.Run(template.Id, new StreamReader(template.Open()), _memberLocator, helperHandlers); if (schema != null && string.IsNullOrEmpty(schema.Title)) { schema.Title = string.Concat(template.Id, "Model"); } return(Task.FromResult(schema)); }
public override void DisplayObjectInGrid(object objectToDisplay, GridOptions options) { Type lType = objectToDisplay.GetType(); // If it objectToDisplay is enumerable, get its type argument. if (lType.IsGenericType) { Type lEnumerable = lType.GetInterface("System.Collections.Generic.IEnumerable`1"); if (lEnumerable != null) { lType = lEnumerable.GetGenericArguments()[0]; } } string[] lIgnore = { "IOptimizedPersistable", "OptimizedPersistable" }; // Customize only if it is a persistable object. // Note: Unluckly IOptimizedPersistable members that have // a name overridden by derived class can't be filtered. if (lType.GetInterface("IOptimizedPersistable") != null) { // Keep properties public instance fields and properties // that are not defined by IOptimizedPersistable. string[] lKeep = SchemaExtractor .GetDataMembers(lType) .Select(lMember => lMember.Name).ToArray(); // Select to exclude all members that should not be kept... options.MembersToExclude = lType.GetMembers() .Select(lMember => lMember.Name) .Where(lName => !lKeep.Contains(lName)) .ToArray(); // If a OptimizedPersistable (i.e. the type being used is the // same as the object's instead of a element type) // is send to render on grid, // an exception is raised because LINQPad assumes to be an // enumerable of only one kind, which is not true for // OptimizedPersistable. In this case, wrap on a list. if (lType.Equals(objectToDisplay.GetType())) { objectToDisplay = new List <object>() { objectToDisplay }; } } // TODO: Some problem with duplicated members. // On BI.Model, Customer -> Items -> Items -> PartyRole ->?? base.DisplayObjectInGrid(objectToDisplay, options); }
public void TestIgnoreHelpers() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var helper = new Mock<IHelperHandler>(); helper.Setup(m => m.IsSupported(It.IsAny<string>())).Returns((string s) => s.StartsWith("helper")); var helperHandlers = new [] { helper.Object }; var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(TestContext.DeploymentDirectory, "ignoreHelpers.mustache")), null, helperHandlers); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Name", JSchemaType.String); Assert.IsFalse(schema.Properties.ContainsKey("helper param=\"val1\""), "No property helper should be inside the schema."); //Assert.IsTrue(schema.Properties.ContainsKey("noregistredHelper param=\"val1\""), "The none registred helpers should be still included."); SchemaAssertions.AssertSingleProperty(schema, "variableExpressionWithWhitespace", JSchemaType.String); }
/// <summary> /// Displays a dialog prompting the user for connection details. The isNewConnection /// parameter will be true if the user is creating a new connection rather than editing an /// existing connection. This should return true if the user clicked OK. If it returns false, /// any changes to the IConnectionInfo object will be rolled back.</summary> public override bool ShowConnectionDialog(IConnectionInfo pCxInfo, bool pIsNewConnection) { VelocityDBProperties lProp; if (pIsNewConnection) { lProp = new VelocityDBProperties(pCxInfo) { Host = Dns.GetHostName(), WindowsAuth = false, PessimisticLocking = false }; } else { lProp = new VelocityDBProperties(pCxInfo); } bool?result = new ConnectionDialog(pCxInfo).ShowDialog(); if (result != true) { return(false); } // This function, as well as GetSchemaAndBuildAssembly, runs on a separeted appdomain. But different from // GetSchemaAndBuildAssembly, pCxInfo gets persisted if true is returned. So this is the best (found) place to create // a list of dependencies. // Save already loaded assemblies. SchemaInfo lSchema = SchemaExtractor.Extract(lProp.ClassesFilenamesArray, lProp.DependencyFilesArray); SessionInfo lSessionInfo = new SessionInfo() { DBFolder = lProp.DBFolder, Host = lProp.Host, PessimisticLocking = lProp.PessimisticLocking, SessionType = lProp.SessionType, WindowsAuth = lProp.WindowsAuth }; VelocityDBAccessBuilder lBuilder = new VelocityDBAccessBuilder(lSchema, lSessionInfo); lBuilder.BuildAssembly(new AssemblyName("DummyName"), "DummyName", "DummyName", false); lProp.ActualDepencies = lSchema.LoadedAssemblies; return(true); }
public void TestIgnoreHelpers() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var helper = new Mock <IHelperHandler>(); helper.Setup(m => m.IsSupported(It.IsAny <string>())).Returns((string s) => s.StartsWith("helper")); var helperHandlers = new [] { helper.Object }; var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(TestContext.DeploymentDirectory, "ignoreHelpers.mustache")), null, helperHandlers); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Name", JSchemaType.String); Assert.IsFalse(schema.Properties.ContainsKey("helper param=\"val1\""), "No property helper should be inside the schema."); //Assert.IsTrue(schema.Properties.ContainsKey("noregistredHelper param=\"val1\""), "The none registred helpers should be still included."); SchemaAssertions.AssertSingleProperty(schema, "variableExpressionWithWhitespace", JSchemaType.String); }
public List <ExplorerItem> BuildSchema() { // Create a ExplorerItem for each persistable type. List <ExplorerItem> lSchema = ( from Type lType in schema.PersistableTypes let lName = schema.TypesNameToPluralName[lType.FullName] orderby lName select new ExplorerItem(lName, ExplorerItemKind.QueryableObject, ExplorerIcon.Table) { IsEnumerable = true, // Use tag to create lookup below. Tag = lType }).ToList(); // Lookup from items to types. This helps creating links between Schema items. var lItemLookup = lSchema.ToLookup(lItem => ((Type)lItem.Tag)); foreach (ExplorerItem lItem in lSchema) { Type lType = (Type)lItem.Tag; // Create a element schema for each persistable type. ExplorerItem lElementProperties = new ExplorerItem( //schema.TypesNameToPluralName[lType.ToGenericTypeString()] + " Properties", lType.ToGenericTypeString() + " Properties", ExplorerItemKind.Schema, ExplorerIcon.Schema); lItem.Children = new List <ExplorerItem> { lElementProperties }; // Fill the element schema with ExplorerItems based on // fields and properties of Type. lElementProperties.Children = SchemaExtractor.GetDataMembers(lType) .OrderBy(lChildMember => lChildMember.Name) .Select(lChildMember => GetChildItem(lItemLookup, lType, lChildMember)) .OrderBy(lChildItem => lChildItem.Kind) .ToList(); } return(lSchema); }
public void ExtractSchemaOnClick(object sender, EventArgs e) { try { SchemaExtractor extractor = GetExtractor(); extractor.NameMap = MappedSchemaDefinition.SchemaNameMap; extractor.ProcessingTable += (o, args) => { FormModelBinder.AppendText(Form.TextBoxOutput, "Reading meta data for table {0}\r\n"._Format(((SchemaExtractorEventArgs)args).Table)); Form.TextBoxOutput.Refresh(); Thread.Sleep(3); }; extractor.ProcessingColumn += (o, args) => { FormModelBinder.AppendText(Form.TextBoxOutput, " Reading meta data for column {0}\r\n"._Format(((SchemaExtractorEventArgs)args).Column)); Form.TextBoxOutput.Refresh(); Thread.Sleep(3); }; FormModelBinder.SetText(Form.TextBoxOutput, ""); DisableInputs(); SchemaDefinition schema = extractor.Extract(); schema.Save(Path.Combine(extractor.SchemaTempPathProvider(schema), "{0}.schema.json"._Format(schema.Name))); MappedSchemaDefinition.SchemaDefinition = schema; MappedSchemaDefinition.SchemaNameMap = extractor.NameMap; FormModelBinder.AppendText(Form.TextBoxOutput, "\r\n... Extraction Done ..."); FormModelBinder.AppendText(Form.TextBoxOutput, "\r\nPopulating schema tab ..."); Task.Run(() => { PopulateTableNameMapList(); FormModelBinder.AppendText(Form.TextBoxOutput, "\r\n... Schema tab populated ..."); }); EnableInputs(); Form.TabControlMain.SelectedTab = Form.TabPageSchemaInfo; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public CleanPersistable(object pObj) { obj = pObj; members = SchemaExtractor.GetDataMembers(pObj.GetType()); }
public static void Setup(TestContext testContext) { _extractor = SchemaExtractor.Instance; _database = _extractor.Extract(new ChinookContext()); }
public void TestArrayProperty() { var schemaExtractor = new SchemaExtractor(new HandlebarsParser()); var schema = schemaExtractor.Run("test", new StreamReader(Path.Combine(PathUtility.GetDirectory(), "Mocks/arrayProperty.mustache")), null, null); SchemaAssertions.AssertSingleProperty(schema, "Customer", JSchemaType.Object); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"], "Addresses", JSchemaType.Array); Assert.NotNull(schema.Properties["Customer"].Properties["Addresses"].Items);// an items array should be given for an array type. Assert.Equal(1, schema.Properties["Customer"].Properties["Addresses"].Items.Count);// expectects exactly on item inside items. SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"].Properties["Addresses"].Items[0], "Street", JSchemaType.String); SchemaAssertions.AssertSingleProperty(schema.Properties["Customer"].Properties["Addresses"].Items[0], "ZipCode", JSchemaType.String); }