/// <summary> /// Generates an internal field that holds a delegate to a function that selects an unmodified record for a query. /// </summary> public SelectSelfField(ClassSchema classSchema) { // private static System.Func<Sandbox.WorkingOrder.AskPrice, FluidTrade.Sandbox.WorkingOrder.AskPrice> selectSelf; this.Attributes = MemberAttributes.Private | MemberAttributes.Static; this.Type = new CodeTypeReference(string.Format("System.Func<{0}, {0}>", classSchema.Type)); this.Name = "selectSelf"; }
// Delete a ClassSchema from the database public void DeleteClassSchema(int id) { ClassSchema classSchema = db.ClassSchemas.Find(id); db.ClassSchemas.Remove(classSchema); db.SaveChanges(); }
public Dictionary <string, Dictionary <string, object> > ValidateStep(int stepId) { Dictionary <string, Dictionary <string, object> > fieldValidations = new Dictionary <string, Dictionary <string, object> >(); bool stepValidated = true; ClassSchema <T> me = ClassSchema <T> .Instance; foreach (AspectMember member in me.GetMembers()) { WizardStep stepAttr = member.GetAttribute <WizardStep>(true); if (stepAttr != null) { if (stepId == stepAttr.StepId) { fieldValidations.Add(member.Name, new Dictionary <string, object>()); bool validation = Restrictions.RestrictionAspect <T> .Instance.Validate(this, member.Name); string message = Restrictions.RestrictionAspect <T> .Instance.GetRestrictionMessage(this, member.Name, 1046); fieldValidations[member.Name].Add("validated", validation); fieldValidations[member.Name].Add("message", message); if (!validation) { stepValidated = false; } } } } fieldValidations.Add("step", new Dictionary <string, object>()); fieldValidations["step"].Add("validated", stepValidated); return(fieldValidations); }
/// <summary> /// Generates the constructor for the generated class. /// </summary> /// <param name="classSchema">A description of a Type.</param> public SchemaConstructor(ClassSchema classSchema) { // /// <summary> // /// Creates a FluidTrade.Sandbox.WorkingOrder.WorkingOrder. // /// </summary> // public WorkingOrder(FluidTrade.Sandbox.WorkingOrderRow workingOrderRow) // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Creates a {0}.", classSchema.Type), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public; // This will run through each of the members of the class an initialize the complex data types. If the element allows // only one occurance of an element, then a single object is created. If the element allows many, then a list is // created. Basic data types are not constructred here. foreach (PropertySchema propertySchema in classSchema.Properties) { // For scalar properties, the property is created and then populated using the setters. if (propertySchema.MaxOccurs == 1) { // this.askPrice = new FluidTrade.Sandbox.WorkingOrder.AskPrice(); CodeFieldReferenceExpression fieldExpression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name)); this.Statements.Add(new CodeAssignStatement(fieldExpression, new CodeObjectCreateExpression(new CodeTypeReference(propertySchema.Type)))); } } }
private static (Endpoint endpoint, IEnumerable <ISchema> schemas) ReturnsRealEndpoint() { var numberSchema = new SimpleSchema(SchemaType.Number); var stringSchema = new SimpleSchema(SchemaType.String); var responseSchema = new ClassSchema( Response, new Dictionary <string, ISchema> { { StringKey, stringSchema } }, new List <string>() ); var requestSchema = new ClassSchema( Request, new Dictionary <string, ISchema> { { NumberKey, numberSchema }, { StringKey, stringSchema }, }, new List <string>() ); var endpoint = new Endpoint( OperationId, Path, EndpointType.Get, new HashSet <IParameter> { new Parameter( "parameter", ParameterType.Header, stringSchema, false, false, false ) }, new RequestBody( new Dictionary <string, ISchema> { { ApplicationJson, requestSchema }, }, true), new[] { new HttpResponse( 200, new Response(new Dictionary <string, ISchema> { { ApplicationJson, responseSchema } })), }); return(endpoint, new List <ISchema> { numberSchema, stringSchema, requestSchema, responseSchema });
/// <summary> /// Generates the static constructor for the class. /// </summary> /// <param name="classSchema">A description of the type.</param> public StaticConstructor(ClassSchema classSchema) { // /// <summary> // /// Creates the static resources required for this class. // /// </summary> // static WorkingOrderHeader() // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement("Creates the static resources required for this class.", true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); // FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader.selectSelf = new System.Func<Sandbox.WorkingOrderHeader.WorkingOrderHeader, FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader>(FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader.SelectFromSelf); this.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(classSchema.Type), "selectSelf"), new CodeObjectCreateExpression(new CodeTypeReference(string.Format("System.Func<{0}, {0}>", classSchema.Type)), new CodeMethodReferenceExpression(new CodeTypeReferenceExpression(classSchema.Type), "SelectFromSelf")))); // } }
/// <summary> /// Gestione chiavi /// </summary> /// <param name="oSchema"></param> /// <param name="oProp"></param> /// <param name="oAttrKey"></param> /// <returns></returns> private static Key fillKeyAttribute(ClassSchema oSchema, Property oProp, SearchKey oAttrKey) { Key oKey; if (!oSchema.Keys.TryGetValue(oAttrKey.KeyName, out oKey)) { //Crea le key oKey = new Key(oAttrKey.KeyName); oKey.HashCode = BdoHash.Instance.Hash(string.Concat(oSchema.OriginalType.FullName, @".BdoKeys.", oKey.Name)); if (oAttrKey is PrimaryKey) { //E' la Primary Key oSchema.PrimaryKey = oKey; } //Aggiunge ad elenco oSchema.Keys.Add(oAttrKey.KeyName, oKey); } else { //Controllo Anomalie //1) Nome chiave PK if (!(oAttrKey is PrimaryKey) && oKey.Name == ClassSchema.PRIMARY_KEY) { throw new TypeFactoryException("{0}.{1} - Il nome di chiave '{1}' e' riservato", oSchema.ClassName, oProp.Name, ClassSchema.PRIMARY_KEY); } } ////Chiave definita su proprieta' semplice //if (!(oProp is PropertySimple)) // throw new TypeFactoryException("{0}.{1} - E' ammesso definire una chiave su una proprieta' semplice (non mappata)", oSchema.ClassName, oProp.Name, ClassSchema.PRIMARY_KEY); //La property non puo' essere di tipo LoadOnAccess if (oProp.IsSqlSelectExcluded) { throw new TypeFactoryException(Resources.SchemaMessages.Prop_KeyNeedValueQuery, oSchema.ClassName, oProp.Name); } //Aggiunge property a key oKey.AddProperty(oProp); //Ritorna Key return(oKey); }
/// <summary> /// Crea un codice hash in formato stringa leggibile /// </summary> /// <param name="slot"></param> /// <param name="schema"></param> /// <param name="pkvalues"></param> /// <returns></returns> internal static string GetObjectHashString(BusinessSlot slot, ClassSchema schema, object[] pkvalues) { const string SEP = @"|"; var db = slot.DbGet(schema); return(string.Concat((schema.IsDefaultDb ? Constants.STR_DB_DEFAULT : schema.DbConnDef.Name), SEP, db.HashCode.ToString(), SEP, schema.InternalID.ToString(), SEP, slot.DbPrefixGetTableName(schema.TableDef), SEP, JoinString(SEP, pkvalues))); //Versione compressa con doppio hash inverso //var sHashBase = string.Concat((schema.IsDefaultDb ? Constants.STR_DB_DEFAULT : schema.DbConnDef.Name), // SEP, db.HashCode.ToString(), // SEP, slot.DbPrefixGetTableName(schema.TableDef), // SEP, JoinString(SEP, pkvalues)); //return string.Concat(sHashBase.GetHashCode().ToString(),SEP, StringHelper.Reverse(sHashBase).GetHashCode().ToString() ); }
public static void WriteHiddenFields <T>(T entity, TextWriter writer, IFormatProvider formatProvider) { ClassSchema <T> schema = ClassSchema <T> .Instance; foreach (AspectMember uca in schema) { if (uca.DataType.IsValueType || uca.DataType.IsEnum || uca.DataType == PrimitiveTypes.String) { writer.Write("<input type=\"hidden\" name=\""); writer.Write(uca.Name); writer.Write("\" value=\""); object value = uca.GetValue(entity); string attributeValue = string.Format(formatProvider, "{0}", value); writer.Write(HtmlDoubleQuoted(attributeValue)); writer.WriteLine("\" />"); } } }
/// <summary> /// Generates the method that is used in queries where no transformation is to take place. /// </summary> public SelectFromSelfMethod(ClassSchema classSchema) { // /// <summary> // /// Selects a record from itself. // /// </summary> // private static FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader SelectFromSelf(FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader workingOrderHeader) // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement("Selects a record from itself.", true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Private | MemberAttributes.Static; this.ReturnType = new CodeTypeReference(classSchema.Type); this.Name = "SelectFromSelf"; this.Parameters.Add(new CodeParameterDeclarationExpression(this.ReturnType, CommonConversion.ToCamelCase(classSchema.Name))); // return workingOrderHeader; this.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression(CommonConversion.ToCamelCase(classSchema.Name)))); // } }
/// <summary> /// Creates a property used to get the delegate used to select an unmodified record for a query. /// </summary> public SelectSelfProperty(ClassSchema classSchema) { // /// <summary> // /// Gets the selector delegate for FluidTrade.Sandbox.WorkingOrder.AskPrice records. // /// <summary> // public static System.Func<Sandbox.WorkingOrder.AskPrice, FluidTrade.Sandbox.WorkingOrder.AskPrice> SelectSelf // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Gets the selector delegate for {0} records.", classSchema.Type), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Static; this.Type = new CodeTypeReference(string.Format("System.Func<{0}, {0}>", classSchema.Type)); this.Name = "SelectSelf"; // get // { // return FluidTrade.Sandbox.WorkingOrder.AskPrice.selectSelf; // } this.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(classSchema.Type), "selectSelf"))); // } }
/// <summary> /// Generates the class that transforms a schema into a Presentation Layer. /// </summary> /// <param name="classSchema">A description of a class.</param> public PresentationClass(ClassSchema classSchema) { // /// <summary> // /// This class provides the WorkingOrderHeader data for a report. // /// </summary> // [global::System.CodeDom.Compiler.GeneratedCodeAttribute("FluidTrade.Core.Presentation.PresentationGenerator", "1.0.0.0")] // [global::System.ComponentModel.DesignerCategoryAttribute("code")] // [global::System.ComponentModel.ToolboxItemAttribute(true)] // public class WorkingOrderHeader : FluidTrade.Core.IContent // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(String.Format("This class provides the {0} data for a report.", classSchema.Name), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.CustomAttributes.Add(new CodeGeneratedCodeAttribute(typeof(PresentationGenerator))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ComponentModel.DesignerCategoryAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression("code")))); this.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeGlobalTypeReference(typeof(System.ComponentModel.ToolboxItemAttribute)), new CodeAttributeArgument(new CodePrimitiveExpression(true)))); this.Name = classSchema.Name; this.BaseTypes.Add(new CodeTypeReference(typeof(IContent))); foreach (PropertySchema propertySchema in classSchema.Properties) { if (propertySchema.IsSimpleType) { this.BaseTypes.Add(new CodeTypeReference(typeof(INotifyPropertyChanged))); break; } } // Fields List <CodeMemberField> fieldList = new List <CodeMemberField>(); fieldList.Add(new SelectSelfField(classSchema)); fieldList.Add(new KeyField()); foreach (PropertySchema propertySchema in classSchema.Properties) { if (propertySchema.MaxOccurs == 1) { fieldList.Add(new SchemaScalarField(propertySchema)); } if (propertySchema.MaxOccurs > 1) { fieldList.Add(new SchemaVectorField(propertySchema)); } foreach (QuerySchema querySchema in propertySchema.Queries) { if (querySchema is OrderBySchema) { fieldList.Add(new ComplexComparerField(querySchema as OrderBySchema)); } if (querySchema is SelectSchema) { fieldList.Add(new SelectField(querySchema as SelectSchema)); } if (querySchema is WhereSchema) { fieldList.Add(new ComplexFilterField(querySchema as WhereSchema)); } } } fieldList.Sort((first, second) => { return(first.Name.CompareTo(second.Name)); }); this.Members.AddRange(fieldList.ToArray()); // Constructors this.Members.Add(new StaticConstructor(classSchema)); foreach (PropertySchema propertySchema in classSchema.Properties) { if (!propertySchema.IsSimpleType) { this.Members.Add(new SchemaConstructor(classSchema)); break; } } // Properties List <CodeMemberProperty> propertyList = new List <CodeMemberProperty>(); propertyList.Add(new KeyProperty()); propertyList.Add(new SelectSelfProperty(classSchema)); foreach (PropertySchema propertySchema in classSchema.Properties) { propertyList.Add(new SchemaProperty(propertySchema)); foreach (QuerySchema querySchema in propertySchema.Queries) { if (querySchema is WhereSchema) { propertyList.Add(new ComplexFilterProperty(querySchema as WhereSchema)); } if (querySchema is OrderBySchema) { propertyList.Add(new ComplexComparerProperty(querySchema as OrderBySchema)); } if (querySchema is SelectSchema) { propertyList.Add(new SelectProperty(querySchema as SelectSchema)); } } } propertyList.Sort((first, second) => { return(first.Name.CompareTo(second.Name)); }); this.Members.AddRange(propertyList.ToArray()); // Events foreach (PropertySchema propertySchema in classSchema.Properties) { if (propertySchema.IsSimpleType) { this.Members.Add(new PropertyChangedEvent()); break; } } // Methods List <CodeMemberMethod> methodList = new List <CodeMemberMethod>(); methodList.Add(new CopyMethod(classSchema)); if (classSchema.Constructor.Arguments.Count == 1) { methodList.Add(new SchemaSelect(classSchema)); } methodList.Add(new SelectFromSelfMethod(classSchema)); methodList.Sort((first, second) => { return(first.Name.CompareTo(second.Name)); }); this.Members.AddRange(methodList.ToArray()); }
// GET: Schema/Edit/5 public ActionResult Edit(int id = 0) { ClassSchema classSchema = LMSRepo.GetClassSchemaByID(id); return(View(classSchema)); }
/// <summary> /// Legge il tipo e ritorna lo schema pronto /// </summary> /// <param name="originalType"></param> /// <param name="InternalID"></param> /// <param name="properties"></param> /// <returns></returns> private static ClassSchema readClassSchemaWithSQL(Type originalType, long InternalID, PropertyInfo[] properties) { short iPropertyIndex = 0; List <SearchKey> oListKeys = new List <SearchKey>(2); StringBuilder sbSqlSelect = new StringBuilder(1000); StringBuilder sbSqlReload = new StringBuilder(100); StringBuilder sbSqlInsertF = new StringBuilder(400); StringBuilder sbSqlInsertP = new StringBuilder(400); sbSqlSelect.Append("SELECT "); sbSqlReload.Append("SELECT "); //Crea Schema ClassSchema oSchema = new ClassSchema(originalType); //Imposta ID Interno Schema oSchema.InternalID = InternalID; //Imposta info schema (tabella) se fornite foreach (Attribute att in originalType.GetCustomAttributes(false)) { oSchema.FillFromAttribute(att); } //Nome tabella insert //Legge definizione campi for (int i = 0; i < properties.Length; i++) { PropertyInfo propInfo = properties[i]; if (propInfo == null) { continue; } //Azzera variabili ciclo oListKeys.Clear(); //Crea nuova Property Property oProp; //Verifica il tipo di proprietà if (propInfo.PropertyType.IsSubclassOf(typeof(DataObjectBase))) { oProp = new PropertyObject(propInfo.Name, propInfo.PropertyType, oSchema.ObjCount); oSchema.ObjCount++; //Incrementa contatore generale } else if (propInfo.PropertyType.IsSubclassOf(typeof(DataListBase))) { oProp = new PropertyDataList(propInfo.Name, propInfo.PropertyType); } else { oProp = new PropertySimple(propInfo.Name, propInfo.PropertyType); } oProp.Schema = oSchema; oProp.IsReadonly = !propInfo.CanWrite; //Inizia valorizzazione foreach (Attribute attr in propInfo.GetCustomAttributes(false)) { if (!(attr is BaseAttribute)) { continue; } //Primary Key, UniqueKey o SearchKey if (attr is SearchKey) { oListKeys.Add((SearchKey)attr); } //ALTRI ATTRIBUTI else { //Carica attributi try { oProp.FillFromAttribute((BaseAttribute)attr); } catch (NotImplementedException) { throw new TypeFactoryException("{0}.{1} - Attrinuto '{2}' non previsto per il tipo di propieta'", oSchema.ClassName, oProp.Name, attr.GetType()); } catch (Exception ex) { throw new TypeFactoryException("{0}.{1} - {2}", oSchema.ClassName, oProp.Name, ex.Message); } } //FINE LOOP ATTRIBUTI } //Se non sono presenti campi definiti esplicitamente e non e' una mappatura interna ne crea uno di default if (oProp is PropertySimple) { if (oProp.Column == null) { oProp.Column = new Column(oProp.Name); } } //Gestisce una o più chiavi for (int j = 0; j < oListKeys.Count; j++) { fillKeyAttribute(oSchema, oProp, oListKeys[j]); } //Esegue validazione proprietà oProp.ValidateDefinition(); //Imposta indice e incrementa oProp.PropertyIndex = iPropertyIndex++; //Aggiunge a schema oSchema.Properties.Add(oProp); //Imposta flag di nuovo caricamento if (oProp.IsAutomatic) { oSchema.MustReload = true; } //Select: esclude loadonaccess e mappature property-property if (!oProp.IsSqlSelectExcluded) { sbSqlSelect.Append(oProp.Column.Name); sbSqlSelect.Append(@", "); } //Se READONLY NON GENERA nulla if (!oSchema.IsReadOnly) { //Reload: if (oProp.IsAutomatic) { //Imposta sql reload sbSqlReload.Append(oProp.Column.Name); sbSqlReload.Append(@", "); } //Insert if (!oProp.ExcludeInsert) { //Nomi campi insert sbSqlInsertF.Append(oProp.Column.Name); sbSqlInsertF.Append(@", "); //Parametri o costanti if (oProp.IsAutomatic) { sbSqlInsertP.Append(@"CURRENT_TIMESTAMP, "); } else { sbSqlInsertP.Append(oProp.Column.ParamName); sbSqlInsertP.Append(@", "); } } } //FINE LOOP PROPRIETA' } //Esegue validazione schema oSchema.Validate(); //SQLSELECT - Tabella sbSqlSelect.Remove(sbSqlSelect.Length - 2, 2); sbSqlSelect.Append(@" FROM "); oSchema.TableDef.SQL_Select_Item = sbSqlSelect.ToString(); //SQLSELECT - Per ogni chiave prepara la where foreach (var key in oSchema.Keys.Values) { sbSqlSelect.Length = 0;//Resetta sbSqlSelect.Append(@" WHERE "); for (int i = 0; i < key.Properties.Count; i++) { sbSqlSelect.Append(key.Properties[i].Column.Name); sbSqlSelect.Append(@"="); sbSqlSelect.Append(key.Properties[i].Column.GetKeyParamName()); sbSqlSelect.Append(@" AND "); } sbSqlSelect.Remove(sbSqlSelect.Length - 5, 5); //Imposta SQL completo key.SQL_Where_Clause = sbSqlSelect.ToString(); //Se PK genera query base per lista if (key.Name.Equals(ClassSchema.PRIMARY_KEY)) { //Prepara la query base per la lista sbSqlSelect.Length = 0;//Resetta sbSqlSelect.Append(@"SELECT "); for (int i = 0; i < key.Properties.Count; i++) { sbSqlSelect.Append(key.Properties[i].Column.Name); sbSqlSelect.Append(@", "); } sbSqlSelect.Remove(sbSqlSelect.Length - 2, 2); sbSqlSelect.Append(@" FROM "); //Aggiunge oSchema.TableDef.SQL_Select_List = sbSqlSelect.ToString(); } } if (!oSchema.IsReadOnly) { //Rimuove caratteri sbSqlInsertF.Remove(sbSqlInsertF.Length - 2, 2); sbSqlInsertP.Remove(sbSqlInsertP.Length - 2, 2); //Sql reload if (sbSqlReload.Length > 7) { //Rimuove caratteri sbSqlReload.Remove(sbSqlReload.Length - 2, 2); sbSqlReload.Append(@" FROM "); oSchema.TableDef.SQL_Select_Reload = sbSqlReload.ToString(); } //Insert oSchema.TableDef.SQL_Insert = string.Concat(@" (", sbSqlInsertF.ToString(), @") VALUES (", sbSqlInsertP.ToString(), @") "); } //Ritorna schema letto return(oSchema); }
// Add a ClassSchemas to the database public void AddClassSchema(ClassSchema classSchema) { db.ClassSchemas.Add(classSchema); db.SaveChanges(); }
internal SchemaReaderException(ClassSchema schema, string messageFmt) : base(string.Format(messageFmt, schema.ClassName)) { }
/// <summary> /// Creates a method that copies the values from one object to another. /// </summary> /// <param name="classSchema">A description of the type.</param> public CopyMethod(ClassSchema classSchema) { // /// <summary> // /// Copies one FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader to another. // /// </summary> // public void Copy(FluidTrade.Core.IContent iContent) // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Copies one {0} to another.", classSchema.Type), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.Name = "Copy"; this.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IContent), "iContent")); // FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader workingOrderHeader = ((FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader)(iContent)); CodeVariableReferenceExpression parentRecordExpression = new CodeVariableReferenceExpression(CommonConversion.ToCamelCase(classSchema.Name)); this.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(classSchema.Type), parentRecordExpression.VariableName, new CodeCastExpression(new CodeTypeReference(classSchema.Type), new CodeArgumentReferenceExpression("iContent")))); // This creates instructions to copy each of the properties from the source to the target. foreach (PropertySchema propertySchema in classSchema.Properties) { // Normally, the 'Set' operator would be used to copy the source value to the target value. However, two-way data // binding presented a problem: when the user set the data in the user interface element, the data element would // also be modified. When the data element was modified, the next pass of refreshed data would find the value // modified by the user and change it back to the original value (this only happened when the data entered by the // user had not filtered back through the data model refresh). This would cause the user interface value to 'jump' // spastically. The solution is to make the 'Set' operation basically do nothing. It still needs to be provided // so the binding will find it. Then the reponsibility of setting the value and triggering and update falls to // this function. if (propertySchema.IsSimpleType) { // if ((this.isEnabled != askPrice.isEnabled)) // { // this.isEnabled = askPrice.isEnabled; // if ((this.PropertyChanged != null)) // { // this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("IsEnabled")); // } // } CodeConditionStatement ifValueStatement = new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name)), CodeBinaryOperatorType.IdentityInequality, new CodeFieldReferenceExpression(parentRecordExpression, CommonConversion.ToCamelCase(propertySchema.Name)))); ifValueStatement.TrueStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name)), new CodePropertyReferenceExpression(parentRecordExpression, CommonConversion.ToCamelCase(propertySchema.Name)))); CodeConditionStatement ifEventStatement = new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "PropertyChanged"), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null))); ifEventStatement.TrueStatements.Add(new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "PropertyChanged"), new CodeThisReferenceExpression(), new CodeObjectCreateExpression(typeof(System.ComponentModel.PropertyChangedEventArgs), new CodePrimitiveExpression(propertySchema.Name)))); ifValueStatement.TrueStatements.Add(ifEventStatement); this.Statements.Add(ifValueStatement); } else { // As long as the element isn't a list, the 'Copy' member of the 'IContent' interface is called to recurse into // the structure and copy all the child elements into the new structure. if (propertySchema.MinOccurs == 1) { // this.askPrice.Copy(workingOrderHeader.askPrice); this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name)), "Copy", new CodeFieldReferenceExpression(parentRecordExpression, CommonConversion.ToCamelCase(propertySchema.Name)))); } } } // } }
// Edit a ClassSchema in the database public void EditClassSchema(ClassSchema classSchema) { db.Entry(classSchema).State = EntityState.Modified; db.SaveChanges(); }
/// <summary> /// Generates the constructor for the generated class. /// </summary> /// <param name="classSchema">A description of a Type.</param> public SchemaSelect(ClassSchema classSchema) { // /// <summary> // /// Creates a FluidTrade.Sandbox.WorkingOrder.WorkingOrder. // /// </summary> // public Sandbox.WorkingOrderRow Select(FluidTrade.Sandbox.WorkingOrderRow workingOrderRow) // { this.Comments.Add(new CodeCommentStatement("<summary>", true)); this.Comments.Add(new CodeCommentStatement(string.Format("Creates a {0}.", classSchema.Type), true)); this.Comments.Add(new CodeCommentStatement("</summary>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.ReturnType = new CodeTypeReference(classSchema.Type); this.Name = "Select"; foreach (ArgumentSchema argumentSchema in classSchema.Constructor.Arguments) { this.Parameters.Add(new CodeParameterDeclarationExpression(argumentSchema.Type, argumentSchema.Name)); } // this.key = workingOrderRow; foreach (SnippetSchema snippetSchema in classSchema.Constructor.Snippets) { if (snippetSchema is SetterSchema) { SetterSchema setterSchema = snippetSchema as SetterSchema; string[] statementList = setterSchema.Value.Split(';'); for (int index = 0; index < statementList.Length - 1; index++) { this.Statements.Add(new CodeSnippetStatement(statementList[index] + ';')); } this.Statements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), setterSchema.Property), new CodeSnippetExpression(statementList[statementList.Length - 1]))); } else { string[] statementList = snippetSchema.Value.Split(';'); for (int index = 0; index < statementList.Length; index++) { this.Statements.Add(new CodeSnippetStatement(statementList[index] + ';')); } } } // This will run through each of the members of the class an initialize the complex data types. If the element allows // only one occurance of an element, then a single object is created. If the element allows many, then a list is // created. Basic data types are not constructred here. foreach (PropertySchema propertySchema in classSchema.Properties) { // For scalar properties, the property is created and then populated using the setters. if (propertySchema.MaxOccurs == 1) { // this.askPrice = new FluidTrade.Sandbox.WorkingOrder.AskPrice(); CodeFieldReferenceExpression fieldExpression = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name)); // this.askPrice.isEnabled = workingOrderRow.StatusCode != FluidTrade.Sandbox.Status.Filled; // this.askPrice.price = workingOrderRow.PriceRow.AskPrice; foreach (SnippetSchema snippetSchema in propertySchema.Snippets) { if (snippetSchema is SetterSchema) { SetterSchema setterSchema = snippetSchema as SetterSchema; string[] statementList = setterSchema.Value.Split(';'); for (int index = 0; index < statementList.Length - 1; index++) { this.Statements.Add(new CodeSnippetStatement(statementList[index] + ';')); } this.Statements.Add(new CodeAssignStatement( new CodeFieldReferenceExpression(fieldExpression, CommonConversion.ToCamelCase(setterSchema.Property)), new CodeSnippetExpression(statementList[statementList.Length - 1]))); } else { string[] statementList = snippetSchema.Value.Split(';'); for (int index = 0; index < statementList.Length; index++) { this.Statements.Add(new CodeSnippetStatement(statementList[index] + ';')); } } } } // Vectors are populated using the LINQ libraries to select, filter, sort and transform the source data. if (propertySchema.MaxOccurs == Decimal.MaxValue) { // The index is used as an indicator to set the destination property instead of creating an intermediate // step. The general idea is to set up a series of queries that will select, sort, filter and otherwise // transform the source data into a format that relects the users' preferences. for (int queryIndex = 0; queryIndex < propertySchema.Queries.Count; queryIndex++) { // This schema will generate a step that transforms the source data. QuerySchema querySchema = propertySchema.Queries[queryIndex]; // The results will either be stored in an intermediate variable or the property that the ultimate // destination for this data. The source of the data is computed independently of the destination and // stored here until a decision about where the results are held is made. CodeExpression initializationExpression = null; // Transform the 'Where' particle into a CodeDOM expression. if (querySchema is WhereSchema) { // System.Linq.Enumerable.Where<Sandbox.WorkingOrderRow>(DataModel.WorkingOrder, FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader.prefilter.Filter); WhereSchema whereSchema = querySchema as WhereSchema; initializationExpression = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("System.Linq.Enumerable"), string.Format("Where<{0}>", whereSchema.SourceType), new CodeVariableReferenceExpression(whereSchema.Source), new CodePropertyReferenceExpression( new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(whereSchema.Predicate)), "Filter")); } // Transform the 'Select' particle into a CodeDOM expression. if (querySchema is SelectSchema) { // System.Linq.Enumerable.Select<Sandbox.WorkingOrderRow, FluidTrade.Sandbox.WorkingOrder.WorkingOrder>(a811c4058ea3a4d79af050b1d46fcda0d, FluidTrade.Sandbox.WorkingOrder.WorkingOrder.Select); SelectSchema selectSchema = querySchema as SelectSchema; initializationExpression = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("System.Linq.Enumerable"), string.Format("Select<{0}, {1}>", selectSchema.SourceType, selectSchema.ResultType), new CodeVariableReferenceExpression(selectSchema.Source), new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(selectSchema.Selector))); } // Transform the 'OrderBy' particle into a CodeDOM expression. if (querySchema is OrderBySchema) { // System.Linq.Enumerable.OrderBy<Sandbox.WorkingOrder.WorkingOrder, FluidTrade.Sandbox.WorkingOrder.WorkingOrder>(n65cf68c24b3e423da4e8bb4ade1c20cc, FluidTrade.Sandbox.WorkingOrder.WorkingOrder.SelectSelf, FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader.comparer); OrderBySchema orderBySchema = querySchema as OrderBySchema; initializationExpression = new CodeMethodInvokeExpression( new CodeTypeReferenceExpression("System.Linq.Enumerable"), string.Format("OrderBy<{0}, {1}>", orderBySchema.SourceType, orderBySchema.KeyType), new CodeVariableReferenceExpression(orderBySchema.Source), new CodeVariableReferenceExpression(orderBySchema.KeySelector), new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(orderBySchema.Comparer))); } // System.Collections.Generic.IEnumerable<Sandbox.WorkingOrder.WorkingOrder> list0 = System.Linq.Enumerable.Where<Sandbox.WorkingOrder.WorkingOrder>(y22c1b202d41f47a19511dce0cbc80e65, FluidTrade.Sandbox.WorkingOrderHeader.WorkingOrderHeader.filter.Filter); this.Statements.Add(new CodeVariableDeclarationStatement( new CodeTypeReference(string.Format("System.Collections.Generic.IEnumerable<{0}>", querySchema.ResultType)), querySchema.Name, initializationExpression)); // The last query particle will populate the property. All the others are stored in intermediate variables. if (queryIndex == propertySchema.Queries.Count - 1) { // this.workingOrderList = System.Linq.Enumerable.ToArray<Sandbox.WorkingOrder.WorkingOrder>(foobar); this.Statements.Add( new CodeAssignStatement( new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CommonConversion.ToCamelCase(propertySchema.Name)), new CodeMethodInvokeExpression( new CodeTypeReferenceExpression(typeof(System.Linq.Enumerable)), "ToArray", new CodeVariableReferenceExpression(querySchema.Name)))); } } } } // return this; this.Statements.Add(new CodeMethodReturnStatement(new CodeThisReferenceExpression())); }
private HtmlComposite BuildTableBody <T>(ClassSelectResult <T> result) { ClassSchema <T> aspect = ClassSchema <T> .Instance; HtmlComposite tbody = new HtmlComposite("tbody"); AspectMember[] onclickMembers = OnClickColumns != null && OnClickColumns.Length > 0 ? new AspectMember[OnClickColumns.Length] : null; if (onclickMembers != null) { for (int i = 0; i < onclickMembers.Length; i++) { onclickMembers[i] = aspect[OnClickColumns[i]]; } } object[] onclickValues = OnClickColumns != null && OnClickColumns.Length > 0 ? new object[OnClickColumns.Length] : null; AspectMember[] members = new AspectMember[columns.Count]; for (int i = 0; i < members.Length; i++) { members[i] = aspect[columns[i].Name]; } foreach (T child in result) { HtmlComposite tr = tbody.AppendComposite("tr"); if (!string.IsNullOrEmpty(this.OnClickFormatString)) { if (onclickValues != null) { for (int i = 0; i < onclickValues.Length; i++) { onclickValues[i] = onclickMembers[i].GetValue(child); } tr .AppendAttribute("style", "cursor:pointer") .AppendAttribute("onclick", string.Format(this.OnClickFormatString, onclickValues)); } else { tr .AppendAttribute("style", "cursor:pointer") .AppendAttribute("onclick", this.OnClickFormatString); } } for (int i = 0; i < members.Length; i++) { BootstrapQueryHelperColumn col = columns[i]; HtmlComposite td = tr.AppendComposite("td"); if (!string.IsNullOrEmpty(col.CssStyle)) { td.AppendAttribute("style", col.CssStyle); } if (!string.IsNullOrEmpty(col.CssClass)) { td.AppendAttribute("class", col.CssClass); } object value = members[i].GetValue(child); string content = col.Formatter.Format(value, CultureInfo.CurrentUICulture); if (col.IsHtmlRaw) { td.Children.AddLast(new HtmlRaw(content)); } else { td.AppendText(content); } } } return(tbody); }