Ejemplo n.º 1
0
		private void WriteDataSet(CsDbCodeBundleForDb dbBundle)
		{
			CsDb.CodeGen.Tracing.Trace($"Writing dataset", 2);
			var fi = new FileInfo(Path.Combine(dbBundle.DataSetDirectory, dbBundle.DataSet.Name + CodeBundle.FileExtension));

			var ns = new CsDbCodeNamespace { Namespace = dbBundle.DataSetNameSpace };
			if (dbBundle.Views.Length != 0)
				ns.Usings.Add(dbBundle.ViewsNameSpace);
			ns.Usings.Add(dbBundle.RowsNameSpace);
			ns.Usings.Add(dbBundle.TablesNameSpace);
			ns.Usings.Add(CodeBundle.NameSpace);

			WriteFile(fi, ns, dbBundle.DataSet);
		}
Ejemplo n.º 2
0
		private void WriteRows(CsDbCodeBundleForDb dbBundle)
		{
			CsDb.CodeGen.Tracing.Trace($"Writing {dbBundle.Tables.Length + dbBundle.Views.Length} rows", 2);
			foreach (var model in dbBundle.Tables.Select(x => x.Row))
			{
				var fi = new FileInfo(Path.Combine(dbBundle.RowsDirectory, model.Name + CodeBundle.FileExtension));

				var ns = new CsDbCodeNamespace { Namespace = dbBundle.RowsNameSpace };
				ns.Usings.Add(dbBundle.DataSetNameSpace);
				ns.Usings.Add(dbBundle.TablesNameSpace);
				ns.Usings.Add(dbBundle.RowInterfacesNameSpace);
				ns.Usings.Add(dbBundle.PocoRowsNameSpace);

				WriteFile(fi, ns, model);
			}
			foreach (var model in dbBundle.Views.Select(x => x.Row))
			{
				var fi = new FileInfo(Path.Combine(dbBundle.RowsDirectory, model.Name + CodeBundle.FileExtension));

				var ns = new CsDbCodeNamespace { Namespace = dbBundle.RowsNameSpace };
				ns.Usings.Add(dbBundle.DataSetNameSpace);
				if (dbBundle.Views.Length != 0)
					ns.Usings.Add(dbBundle.ViewsNameSpace);

				WriteFile(fi, ns, model);
			}
		}
Ejemplo n.º 3
0
		private void WriteViews(CsDbCodeBundleForDb dbBundle)
		{
			CsDb.CodeGen.Tracing.Trace($"Writing {dbBundle.Views.Length} Tables", 2);
			foreach (var view in dbBundle.Views)
			{
				var fi = new FileInfo(Path.Combine(dbBundle.ViewsDirectory, view.Name + CodeBundle.FileExtension));

				var ns = new CsDbCodeNamespace { Namespace = dbBundle.ViewsNameSpace };

				ns.Usings.Add(dbBundle.DataSetNameSpace);
				ns.Usings.Add($"{view.Row.Name}={dbBundle.RowsNameSpace}.{view.Row.Name}");

				WriteFile(fi, ns, view);
			}
		}
Ejemplo n.º 4
0
		private void WritePocoRows(CsDbCodeBundleForDb dbBundle)
		{
			CsDb.CodeGen.Tracing.Trace($"Writing {dbBundle.Tables.Length} poco rows", 2);
			foreach (var pocoRow in dbBundle.PocoRows)
			{
				var fi = new FileInfo(Path.Combine(dbBundle.PocoRowsDirectory, pocoRow.Name + CodeBundle.FileExtension));

				var ns = new CsDbCodeNamespace { Namespace = dbBundle.PocoRowsNameSpace };


				ns.Usings.Add(dbBundle.RowInterfacesNameSpace);
				ns.Usings.Add($"{pocoRow.Name}={dbBundle.PocoRowsNameSpace}.{pocoRow.Name}");

				WriteFile(fi, ns, pocoRow);
			}
		}
Ejemplo n.º 5
0
		/// <summary>Creates the code base from an existing <see cref="CsDbArcDatabase" />.</summary>
		public static CsDbCodeBundleForDb FromArchitecture(CsDbCodeBundle owner, CsDbArcDatabase architecture)
		{
			var bundleForDb = new CsDbCodeBundleForDb(owner, architecture);
			bundleForDb.DataSet = new CsDbCodeDataSet(architecture, bundleForDb);

			var rvTables = new List<CsDbCodeDataTable>();
			var rvViews = new List<CsDbCodeDataView>();

			var columnMapping = new Dictionary<CsDbArcColumn, CsDbcTableRow_Column>();

			foreach (var table in architecture.Tables)
			{
				var rvTable = new CsDbCodeDataTable(table, bundleForDb);

				var columns = rvTable.Row.Columns.ToList();
				foreach (var archiColumn in table.Columns)
				{
					var codeColumn = columns.FirstOrDefault(x => x.Architecture == archiColumn);
					columnMapping.Add(archiColumn, codeColumn);
				}
				rvTables.Add(rvTable);
			}

			foreach (var view in architecture.Views)
			{
				var rvView = new CsDbCodeDataView(view, bundleForDb);
				rvViews.Add(rvView);
			}


			bundleForDb.Tables = rvTables.ToArray();
			bundleForDb.Views = rvViews.ToArray();

			foreach (var relation in architecture.Relations)
			{
				var pkColumn = columnMapping[relation.PrimaryKey];
				var fkColumn = columnMapping[relation.ForeignKey];
				var csDbCodeRelation = CsDbCodeRelation.Create(relation, pkColumn, fkColumn);
				csDbCodeRelation.ReferencingProperty = new CsDbcTableRow_ReferencingProperty(csDbCodeRelation);
				csDbCodeRelation.AssociatedProperty = new CsDbcTableRow_AssociatedProperty(csDbCodeRelation);
			}

			return bundleForDb;
		}