internal Case(Delegate idGetter, Delegate solutionGetter, Delegate[] getters, CaseSchema schema) { Schema = schema; this.idGetter = idGetter; this.solutionGetter = solutionGetter; this.getters = GenerateGetters(getters); }
public static ICaseFrame Load <TCase>(IList <TCase> cases, CaseSchema schema = null) where TCase : class { if (cases == null) { throw new ArgumentNullException(nameof(cases)); } return(new EnumerableCaseFrame <TCase>(cases, schema)); }
protected TypedCaseFrame(CaseSchema schema) { Definition = new CaseDefinitionBuilder(typeof(TCase), schema).Build(); Schema = schema ?? Definition.GetCaseSchema(); IdGetter = DynamicCodeUtils.GenerateGetter <TCase>(Definition.IdAttribute); SolutionGetter = DynamicCodeUtils.GenerateGetter <TCase>(Definition.SolutionAttribute); Getters = GenerateGetters(Definition); }
public Case(TCase caseData, CaseSchema schema = null) { Data = caseData ?? throw new ArgumentNullException(nameof(caseData)); definition = new CaseDefinitionBuilder(typeof(TCase), schema).Build(); Schema = schema ?? definition.GetCaseSchema(); idGetter = DynamicCodeUtils.GenerateGetter <TCase>(definition.IdAttribute); solutionGetter = DynamicCodeUtils.GenerateGetter <TCase>(definition.SolutionAttribute); getters = GenerateGetters(); }
public static ICaseFrame Load <TCase>(string path, CaseSchema schema = null) where TCase : class { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (!File.Exists(path)) { throw new FileNotFoundException($"Case file {path} does not exist."); } return(new FileCaseFrame <TCase>(path, schema)); }
public void BuildDDL(CaseSchema currentSchema, Version lowVersion, Version highVersion, ref StringBuilder strCreateDDL, ref StringBuilder strDropDDL) { if (currentSchema == null) { return; } SchemaBuilder builder = new SchemaBuilder(DBMSPlatformEnum.SqlServer, SqlSvrDictionary); builder.SetSchemaVersion(lowVersion, highVersion); builder.BuildDDL(currentSchema, ref strCreateDDL, ref strDropDDL); }
public bool DropSchema(CaseSchema currentSchema, ref string strErrMsg) { Debug.Assert((currentSchema != null), "Invalid CaseSchema"); if (currentSchema == null) { return(false); } StringBuilder strCreateDDL = null; StringBuilder strDropDDL = null; BuildDDL(currentSchema, Version.MINVERSION, Version.MAXVERSION, ref strCreateDDL, ref strDropDDL); //return RunSQL(strDropDDL.ToString(), ref strErrMsg); return(true); }
public bool DeploySchema(CaseSchema currentSchema, Version lowVersion, Version highVersion, ref string strErrMsg) { Debug.Assert((currentSchema != null), "Invalid CaseSchema"); if (currentSchema == null) { return(false); } StringBuilder strCreateDDL = null; StringBuilder strDropDDL = null; BuildDDL(currentSchema, lowVersion, highVersion, ref strCreateDDL, ref strDropDDL); //return RunSQL(strCreateDDL.ToString(), ref strErrMsg); return(true); }
private void OnGenerateSQL(object sender, System.EventArgs e) { if (_umlSchema == null) { _umlSchema = new CaseSchema(); _umlSchema.LoadXml(Zen.DBAToolbox.Resources.Resource.ulmschema); } StringBuilder strCreateDDL = null; StringBuilder strDropDDL = null; BuildDDL(_umlSchema, Version.MINVERSION, Version.MAXVERSION, ref strCreateDDL, ref strDropDDL); sqlTextBox.Text = strCreateDDL.ToString(); }
private void BindSelectedAttributes(CaseSchema schema) { AttributeBinding = new AttributeBinding(schema, attributeNames); attributeMin = new double[AttributeBinding.Count]; attributeMax = new double[AttributeBinding.Count]; foreach (var binding in AttributeBinding) { if (schema[binding.Attribute].Type != typeof(double)) { throw new InvalidOperationException($"Only {typeof(double)} attributes are allowed for normalizer."); } attributeMin[binding.Binding] = double.PositiveInfinity; attributeMax[binding.Binding] = double.NegativeInfinity; } }
public AttributeBinding(CaseSchema schema, string[] attributes = null) { if (schema == null) { throw new ArgumentNullException(nameof(schema)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } if (attributes.Length > schema.Count) { throw new InvalidOperationException("Attribute count exceeds schema."); } attributeBinding = new Dictionary <int, int>(); if (attributes.Length == 0) { bindingPairs = new BindingPair[schema.Count]; for (var i = 0; i < schema.Count; i++) { bindingPairs[i] = new BindingPair(i, schema[i].Index); attributeBinding[schema[i].Index] = i; } } else { bindingPairs = new BindingPair[attributes.Length]; for (var i = 0; i < attributes.Length; i++) { var attribute = schema.TryGetAttribute(attributes[i]); if (attribute == null) { throw new InvalidOperationException($"Selected attribute {attributes[i]} is missing in schema."); } bindingPairs[i] = new BindingPair(i, attribute.Value.Index); attributeBinding[attribute.Value.Index] = i; } } }
public FileCaseFrame(string path, CaseSchema schema) : base(schema) { fileLoader = new FileLoader <TCase>(path, Definition); }
public EnumerableCaseFrame(IList <TCase> cases, CaseSchema schema) : base(schema) { Data = cases ?? throw new ArgumentNullException(nameof(cases)); }
public void BuildDDL(CaseSchema currentSchema, ref StringBuilder strCreateDDL, ref StringBuilder strDropDDL) { if (currentSchema == null) { return; } if (strCreateDDL == null) { strCreateDDL = new StringBuilder(); } strCreateDDL.Capacity = 36 * ByteUnit.KiloByte; // reserve 36K if (strDropDDL == null) { strDropDDL = new StringBuilder(); } strDropDDL.Capacity = 12 * ByteUnit.KiloByte; // reserve 12K ////////////////////////////// // Build objects // Initialize... ArrayList roleList = new ArrayList(); ArrayList grantList = new ArrayList(); ArrayList denyList = new ArrayList(); ArrayList tableList = new ArrayList(); ArrayList indexList = new ArrayList(); ArrayList foreignKeyList = new ArrayList(); ArrayList primaryKeyList = new ArrayList(); ArrayList uniqkeyList = new ArrayList(); ArrayList colAlterList = new ArrayList(); StringBuilder strRowDataSql = new StringBuilder(4 * ByteUnit.KiloByte); // Build! GlobalTableCollection globalTables = currentSchema.GlobalTables; foreach (GlobalTableDef tableDef in globalTables) { Anonymous.SafeAdd(ref tableList, BuildTable(tableDef, ref indexList, ref primaryKeyList, ref uniqkeyList, ref foreignKeyList, ref strRowDataSql, ref colAlterList)); } CaseTableDefCollection caseTables = currentSchema.CaseTables; foreach (CaseTableDef caseTableDef in caseTables) { Anonymous.SafeAdd(ref tableList, BuildTable(caseTableDef, ref indexList, ref primaryKeyList, ref uniqkeyList, ref foreignKeyList, ref strRowDataSql, ref colAlterList)); } ArrayList procedureList = new ArrayList(); ArrayList functionList = new ArrayList(); SQLStoredProcedureCollection spList = currentSchema.SQLStoredProcedures; foreach (SQLStoredProcedure spDef in spList) { Anonymous.SafeAdd(ref procedureList, BuildStoredProc(spDef, ref grantList, ref denyList)); } ArrayList viewList = new ArrayList(); ViewCollection globalViews = currentSchema.Views; foreach (View viewDef in globalViews) { Anonymous.SafeAdd(ref viewList, BuildView(viewDef)); } BuildRoleList(ref roleList, grantList, denyList); ////////////////////////////// // Build SQL // initialize temp stringBuilder... StringBuilder strPKConstraint = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strUKConstraint = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strFKConstraint = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strAlterColumn = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropIndex = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropProc = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropView = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropTable = new StringBuilder(1 * ByteUnit.KiloByte); StringBuilder strDropRole = new StringBuilder(1 * ByteUnit.KiloByte); // build... BuildSQL(ref strCreateDDL, ref strDropRole, roleList); BuildSQL(ref strCreateDDL, ref strDropTable, tableList); BuildSQL(ref strCreateDDL, ref strDropIndex, indexList); BuildAlterSQL(ref strCreateDDL, ref strPKConstraint, primaryKeyList); BuildAlterSQL(ref strCreateDDL, ref strUKConstraint, uniqkeyList); BuildAlterSQL(ref strCreateDDL, ref strFKConstraint, foreignKeyList); BuildAlterSQL(ref strCreateDDL, ref strAlterColumn, colAlterList); BuildSQL(ref strCreateDDL, ref strDropProc, procedureList); BuildSQL(ref strCreateDDL, ref strDropView, viewList); ObjPermSQLBuilder permBuilder = new ObjPermSQLBuilder(); foreach (GranteeMeta granteeTmp in grantList) { AppendBatch(ref strCreateDDL, permBuilder.BuildGrantSQL(granteeTmp), _dbmsPlatform); } strCreateDDL.Append(strRowDataSql); strDropDDL.Append(strFKConstraint); strDropDDL.Append(strUKConstraint); strDropDDL.Append(strPKConstraint); strDropDDL.Append(strDropIndex); strDropDDL.Append(strDropProc); strDropDDL.Append(strDropView); strDropDDL.Append(strDropTable); strDropDDL.Append(strDropRole); }