void Compile() { MaxCsharp = MaxCPlus = MaxJava = int.MinValue; MinCsharp = MinCPlus = MinJava = int.MaxValue; for (int i = 0; i < listBoxFiles.Items.Count; i++) { string folderName = ""; string[] files = Directory.GetFiles(listBoxFiles.Items[i].ToString(), "*.txt", SearchOption.AllDirectories); foreach (string file in files) { // folderName = new DirectoryInfo(file).Parent.ToString(); string FileName = Path.GetFileNameWithoutExtension(file); if (FileName.Equals("C++") || FileName.Equals("c++") || FileName.Equals("C#") || FileName.Equals("c#")) { //This condition becasue this version does not support C# or C++ language //we will try to add this on next version continue; } txtReport.AppendText("Program : "); txtReport.SelectionColor = Color.BlueViolet; txtReport.AppendText(folderName); txtReport.SelectionColor = Color.Black; txtReport.AppendText(" , Language : "); txtReport.SelectionColor = Color.DarkGreen; txtReport.AppendText(FileName + "\n"); StreamReader readfile = new StreamReader(file); string code = readfile.ReadToEnd(); readfile.Close(); txtInput.Text = code; lblProgramInfo.Text = "Program : " + folderName + " , Language : " + FileName + " , " + txtInput.Lines.Count() + " Lines"; lblProgramInfo.Refresh(); Thread.Sleep(1); ClassCompiler c = new ClassCompiler(txtInput.Text); c.Compile(); Halestead clsHalsterd = new Halestead(); ClassCycloma2 clsCC = new ClassCycloma2(txtInput.Text); ClassShaoWang ShaoWang = new ClassShaoWang(txtInput.Text); int SW = ShaoWang.GetShaoWangComplexity(); txtReport.SelectionColor = Color.Black; SaveData(folderName, FileName, c.GetReport(), clsHalsterd.calc_halested(txtInput.Text), clsCC.GetNumIfAndSwitch(), txtInput.Lines.Count(), SW); txtReport.AppendText(c.PrintData1() + "\n====================\n\n"); } }//End Read Files dataSet1.StaticalCPlus.AddStaticalCPlusRow(MaxCPlus, MinCPlus); dataSet1.StaticalCsharp.AddStaticalCsharpRow(MaxCsharp, MinCsharp); dataSet1.StaticalJava.AddStaticalJavaRow(MaxJava, MinJava); dataSet1.Statical.AddStaticalRow(MaxCPlus, MinCPlus, "C++"); dataSet1.Statical.AddStaticalRow(MaxCsharp, MinCsharp, "C#"); dataSet1.Statical.AddStaticalRow(MaxJava, MinJava, "Java"); }
private static void CompileTableLike(ITableInfoModel tableInfoModel, IMsSqlCreator sourceCreator, string typeName, Stream to = null) { if (tableInfoModel.Exclude) { return; } var targetCsName = tableInfoModel.GetClassName(); var compiler = new ClassCompiler(sourceCreator.TargetDir, targetCsName); compiler.Type = typeName; compiler.CompileHeader = sourceCreator.GenerateCompilerHeader; compiler.Namespace = sourceCreator.Namespace; compiler.TableName = tableInfoModel.Info.TableName; if (to != null) { compiler.WriteAllways = true; } compiler.GenerateConfigMethod = sourceCreator.GenerateConfigMethod; if (tableInfoModel.WrapNullables || sourceCreator.WrapNullables) { compiler.AddAttribute(new CodeAttributeDeclaration(typeof(WrapDbNullablesAttribute).Name)); } if (tableInfoModel.CreateSelectFactory || sourceCreator.GenerateConstructor) { compiler.GenerateTypeConstructorBasedOnElements(tableInfoModel.ColumnInfos.Where(s => !s.Exclude)); } foreach (var columInfoModel in tableInfoModel.ColumnInfos) { if (columInfoModel.Exclude) { continue; } var codeMemberProperty = compiler.AddProperty(columInfoModel); if (columInfoModel.PrimaryKey) { codeMemberProperty.CustomAttributes.Add( new CodeAttributeDeclaration(typeof(PrimaryKeyAttribute).Name)); } if (columInfoModel.InsertIgnore) { codeMemberProperty.CustomAttributes.Add( new CodeAttributeDeclaration(typeof(InsertIgnoreAttribute).Name)); } if (columInfoModel.ForgeinKeyDeclarations != null) { var isRefTypeKnown = sourceCreator.Tables.FirstOrDefault(s => s.Info.TableName == columInfoModel.ForgeinKeyDeclarations.TableName); if (isRefTypeKnown == null) { codeMemberProperty.CustomAttributes.Add( new CodeAttributeDeclaration(typeof(ForeignKeyDeclarationAttribute).Name, new CodeAttributeArgument(new CodePrimitiveExpression(columInfoModel.ForgeinKeyDeclarations.TargetColumn)), new CodeAttributeArgument(new CodePrimitiveExpression(columInfoModel.ForgeinKeyDeclarations.TableName)))); } else { codeMemberProperty.CustomAttributes.Add( new CodeAttributeDeclaration(typeof(ForeignKeyDeclarationAttribute).Name, new CodeAttributeArgument(new CodePrimitiveExpression(columInfoModel.ForgeinKeyDeclarations.TargetColumn)), new CodeAttributeArgument(new CodeTypeOfExpression(isRefTypeKnown.GetClassName())))); } } if (columInfoModel.ColumnInfo.SqlType == SqlDbType.Timestamp) { codeMemberProperty.CustomAttributes.Add( new CodeAttributeDeclaration(typeof(RowVersionAttribute).Name)); } } if (tableInfoModel.CreateFallbackProperty) { compiler.AddFallbackProperty(); } Logger.WriteLine("Compile Class {0}", compiler.Name); compiler.Compile(tableInfoModel.ColumnInfos, sourceCreator.SplitByType, to); }
private static void CompileTableLike(ITableInfoModel tableInfoModel, IMsSqlCreator sourceCreator, string typeName, Stream to = null) { if (tableInfoModel.Exclude) { return; } var targetCsName = tableInfoModel.GetClassName(); var compiler = new ClassCompiler(sourceCreator.TargetDir, targetCsName); compiler.Type = typeName; compiler.CompileHeader = sourceCreator.GenerateCompilerHeader; compiler.Namespace = sourceCreator.Namespace; compiler.TableName = tableInfoModel.Info.TableName; if (to != null) { compiler.WriteAlways = true; } compiler.GenerateConfigMethod = sourceCreator.GenerateConfigMethod; foreach (var columInfoModel in tableInfoModel.ColumnInfos) { if (columInfoModel.Exclude) { continue; } var codeMemberProperty = compiler.AddProperty(columInfoModel); if (columInfoModel.PrimaryKey) { codeMemberProperty.Attributes.Add(new AttributeInfo() { Name = nameof(PrimaryKeyAttribute) }); } if (columInfoModel.InsertIgnore) { codeMemberProperty.Attributes.Add(new AttributeInfo() { Name = nameof(InsertIgnoreAttribute) }); } if (columInfoModel.ForgeinKeyDeclarations != null) { var isRefTypeKnown = sourceCreator.Tables .FirstOrDefault(s => s.Info.TableName == columInfoModel.ForgeinKeyDeclarations.TableName); if (isRefTypeKnown == null) { codeMemberProperty.Attributes.Add(new AttributeInfo() { Name = nameof(ForeignKeyDeclarationAttribute), ConstructorSetters = { { "foreignKey", "\"" + columInfoModel.ForgeinKeyDeclarations.TargetColumn + "\"" }, { "foreignTable", "\"" + columInfoModel.ForgeinKeyDeclarations.TableName + "\"" }, } }); } else { codeMemberProperty.Attributes.Add(new AttributeInfo() { Name = nameof(ForeignKeyDeclarationAttribute), ConstructorSetters = { { "foreignKey", $"\"{columInfoModel.ForgeinKeyDeclarations.TargetColumn}\"" }, { "foreignTable", $"typeof({isRefTypeKnown.GetClassName()})" }, } }); } } if (columInfoModel.ColumnInfo.SqlType == SqlDbType.Timestamp) { codeMemberProperty.Attributes.Add(new AttributeInfo() { Name = nameof(RowVersionAttribute) }); } if (tableInfoModel.CreateFallbackProperty) { compiler.AddFallbackProperty(); } } foreach (var columInfoModel in tableInfoModel.ColumnInfos) { if (columInfoModel.Exclude) { continue; } if (columInfoModel.ForgeinKeyDeclarations != null) { var isRefTypeKnown = sourceCreator.Tables .FirstOrDefault(s => s.Info.TableName == columInfoModel.ForgeinKeyDeclarations.TableName); if (isRefTypeKnown != null) { compiler.Generator.NamespaceImports.Add(typeof(EagarDataRecord).Namespace); compiler.Generator.NamespaceImports.Add(typeof(DbAccessLayerHelper).Namespace); var navPropertyName = isRefTypeKnown.GetClassName(); if (!navPropertyName.EndsWith("s")) { navPropertyName = navPropertyName.TrimEnd('s'); } var tempName = navPropertyName; var counter = 1; while (compiler.Generator.Properties.Any(f => f.Name == tempName || tempName == tableInfoModel.GetClassName())) { tempName = navPropertyName + counter++; } navPropertyName = tempName; var refProp = compiler.AddProperty(navPropertyName, null, new ClassType() { Name = isRefTypeKnown.GetClassName(), }); refProp.ForeignKey = new PropertyInfo.ForeignKeyDeclaration(columInfoModel.ForgeinKeyDeclarations.SourceColumn, columInfoModel.ForgeinKeyDeclarations.TargetColumn); refProp.Attributes.Add(new AttributeInfo() { Name = nameof(ForeignKeyAttribute), ConstructorSetters = { { "foreignKey", columInfoModel.ForgeinKeyDeclarations.SourceColumn.AsStringOfString() }, { "referenceKey", columInfoModel.ForgeinKeyDeclarations.TargetColumn.AsStringOfString() }, } }); } } } foreach (var infoModel in sourceCreator.Tables) { foreach (var columInfoModel in infoModel .ColumnInfos .Where(f => f.ForgeinKeyDeclarations?.TableName == tableInfoModel.Info.TableName)) { compiler.Generator.NamespaceImports.Add(typeof(EagarDataRecord).Namespace); compiler.Generator.NamespaceImports.Add(typeof(DbAccessLayerHelper).Namespace); var navPropertyName = infoModel.GetClassName(); if (!navPropertyName.EndsWith("s")) { navPropertyName = navPropertyName.TrimEnd('s'); } var tempName = navPropertyName; var counter = 1; while (compiler.Generator.Properties.Any(f => f.Name == tempName || tempName == tableInfoModel.GetClassName())) { tempName = navPropertyName + counter++; } navPropertyName = tempName; var refProp = compiler.AddProperty(navPropertyName, null, new ClassType() { Name = $"{nameof(DbCollection<object>)}", IsList = true, GenericTypes = { new ClassType() { Name = infoModel.GetClassName() } } }); refProp.ForeignKey = new PropertyInfo.ForeignKeyDeclaration(columInfoModel.ForgeinKeyDeclarations.SourceColumn, columInfoModel.ForgeinKeyDeclarations.TargetColumn); refProp.ForeignKey.DirectionFromParent = true; refProp.Attributes.Add(new AttributeInfo() { Name = nameof(ForeignKeyAttribute), ConstructorSetters = { { "referenceKey", columInfoModel.ForgeinKeyDeclarations.SourceColumn.AsStringOfString() }, { "foreignKey", columInfoModel.ForgeinKeyDeclarations.TargetColumn.AsStringOfString() }, } }); } } compiler.GenerateConfigMethod = true; compiler.Generator.GenerateFactory = tableInfoModel.CreateSelectFactory || sourceCreator.GenerateFactory; compiler.Generator.GenerateConstructor = sourceCreator.GenerateConstructor; Logger.WriteLine("Compile Class {0}", compiler.Name); compiler.Compile(tableInfoModel.ColumnInfos, sourceCreator.SplitByType, sourceCreator.SetNotifyProperties, to); }