public string Write <T>(T source, bool includeProcessingInformation = true) where T : DocProcessingInstructions { string DocTypeName, DocRev; if (!RuntimeTypeNamer.TryParseDocNameAndRev(source.GetType().Namespace, out DocTypeName, out DocRev)) { throw new Exception("Can't determine DocTypeName/DocRev"); } return(InstanceLocatorByName(DocTypeName, DocRev).Write(source, includeProcessingInformation)); }
/// <summary> /// </summary> /// <param name="_DocDirectoryInfo"></param> /// <param name="DocTypeName"></param> /// <param name="DocProperties"></param> /// <param name="DocRev"></param> /// <returns>TODO:Needs to return a DocRev & not write files to a physical directory</returns> public static BaseDoc Templify(string DocTypeName, List <CompositeProperty> DocProperties, string DocRev = null) { DirectoryInfo _DocDirectoryInfo = new DirectoryInfo(FilesystemTemplateController.GetDocDirectoryPath(DocTypeName)).mkdir(); if (string.IsNullOrWhiteSpace(DocRev)) { DocRev = DateTime.UtcNow.AsDocRev(); } string temporaryNamespace = RuntimeTypeNamer.CalcCSharpNamespace(DocTypeName, DocRev, typeof(DocTempleter).Name); string cSharpClassFullName = RuntimeTypeNamer.CalcCSharpNamespace(DocTypeName, DocRev); FileInfo _XsdFileInfo = new FileInfo(String.Format(@"{0}\{1}", _DocDirectoryInfo.FullName, Runtime.MYSCHEMA_XSD_FILE_NAME)); Type _template_docx_type = new CompositeType(temporaryNamespace, _DocDirectoryInfo.Name, DocProperties.ToArray()); // the "lazy-load" CompositeType requires activation in order for the _template_docx_obj.GetType().Assembly to register as having any types defined object _template_docx_obj = Activator.CreateInstance(_template_docx_type); string xsd = XsdExporter.ExportSchemas( _template_docx_obj.GetType().Assembly, new List <string> { DocTypeName }, RuntimeTypeNamer.CalcSchemaUri(DocTypeName, DocRev)).First(); File.WriteAllText(_XsdFileInfo.FullName, xsd, Encoding.Unicode); string myclasses_cs = new Xsd().ImportSchemasAsClasses( new[] { xsd }, cSharpClassFullName, CodeGenerationOptions.GenerateOrder | CodeGenerationOptions.GenerateProperties, new StringCollection()); myclasses_cs = Runtime.CustomizeXsdToCSharpOutput(DocTypeName, myclasses_cs, null, new[] { nameof(IDocModel) }); if (Directory.Exists(RequestPaths.GetPhysicalApplicationPath(Resources.App_Code_DirectoryPath))) { File.WriteAllText(RequestPaths.GetPhysicalApplicationPath(Resources.App_Code_DirectoryPath, DocTypeName + ".cs"), myclasses_cs, Encoding.Unicode); } else { File.WriteAllText(_DocDirectoryInfo.FullName + @"\\example.cs", myclasses_cs, Encoding.Unicode); } BaseDoc _BaseDoc = Runtime.FindBaseDoc(Runtime.CompileCSharpCode(myclasses_cs), DocTypeName); // reset the values critical to this import that were implicitly set by the Rand() _BaseDoc.solutionVersion = DocRev; _BaseDoc.DocTypeName = DocTypeName; _BaseDoc.href = String.Empty; return(_BaseDoc); }
public SqlDbMigrationsConfiguration() { string DocTypeName, DocRev; if (RuntimeTypeNamer.TryParseDocNameAndRev(typeof(TContext).Namespace, out DocTypeName, out DocRev)) { ContextKey = DocTypeName; } AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = true; }
/// <inheritdoc /> public override void Apply(ConventionTypeConfiguration configuration, TableAttribute attribute) { string docTypeName, docRev; if (RuntimeTypeNamer.TryParseDocNameAndRev(configuration.ClrType.Namespace, out docTypeName, out docRev)) { configuration.ToTable(attribute.Name, docTypeName); } else { configuration.ToTable(attribute.Name, SqlDB.InitializingDocTypeName); } }
/// <summary> /// </summary> /// <param name="_SubmittedBaseDoc"></param> /// <returns>Something that Entity Framework Code First would contract the same SQL objects read to create this type</returns> private static Type ReverseEngineerCodeFirst(BaseDoc _SubmittedBaseDoc) { if (!ReverseEngineerCodeFirstDic.ContainsKey(_SubmittedBaseDoc.DocTypeName)) { string sqlAsCharp = string.Empty; try { // attempt to observe any tables that would accommodate this DocTypeName in the database now as this will be needed the remaining execution of this appdomain to assess code first auto-migrations // in the database itself, the namespace of a given document has no baring on how the doc it persisted in sql or the structure it may spawn sqlAsCharp = Handler.ReverseEngineerCodeFirst( RuntimeTypeNamer.CalcCSharpFullname(_SubmittedBaseDoc.DocTypeName, "0.0.0.0", "SqlToNonBaseDoc"), _SubmittedBaseDoc.DocTypeName, SqlDbContext.GetConnectionString()); } catch (Exception) { /*TODO:Check for database instead of letting this fail*/ } ReverseEngineerCodeFirstDic[_SubmittedBaseDoc.DocTypeName] = ClassMerger.Instance.MergeOnPropertyNames( RuntimeTypeNamer.CalcCSharpFullname(_SubmittedBaseDoc.DocTypeName, "0.0.0.0"), new[] { _SubmittedBaseDoc.GetType(), string.IsNullOrWhiteSpace(sqlAsCharp) ? _SubmittedBaseDoc.GetType() : Runtime.CompileCSharpCode( sqlAsCharp, _SubmittedBaseDoc.DocTypeName, "0.0.0.0", "PostMergeTo", _SubmittedBaseDoc.solutionVersion).GetTypes().First(t => t.Name == _SubmittedBaseDoc.DocTypeName) }, _SubmittedBaseDoc.DocTypeName, new[] { "Any", "Xml_Element" }, // ignore XmlElement Any properties true, typeof(BaseDoc)); } return(ReverseEngineerCodeFirstDic[_SubmittedBaseDoc.DocTypeName]); }