Exemple #1
0
        /// <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);
        }
Exemple #2
0
        XmlSchemaElement GetSchemaElementForPart(MessagePartDescription part, XmlSchema schema)
        {
            XmlSchemaElement element = new XmlSchemaElement();

            element.Name = part.Name;
            XsdExporter.Export(part.Type);
            element.SchemaTypeName = XsdExporter.GetSchemaTypeName(part.Type);
            AddImport(schema, element.SchemaTypeName.Namespace);

            //FIXME: nillable, minOccurs
            if (XsdExporter.GetSchemaType(part.Type) is XmlSchemaComplexType ||
                part.Type == typeof(string))
            {
                element.IsNillable = true;
            }
            element.MinOccurs = 0;

            return(element);
        }
Exemple #3
0
        /// <summary>
        ///     Scans AppDomain for classes implementing the IDocModel & performs all transformations needed to represent them as
        ///     BaseDoc to be served.
        /// </summary>
        /// <param name="DocTypeName">
        ///     Processes only the given DocTypeName the IDocModel represents. If a IDocModel can not be
        ///     located through out the AppDomain nothing will be processed & no IDocRev will be imported. If no DocTypeName is
        ///     specified all IDocModel located will be processed.
        /// </param>
        public static List <ImporterLightDoc> ReadIDocModelCSharpCode()
        {
            List <ImporterLightDoc> List_ImporterLightDoc = new List <ImporterLightDoc>();

            //TODO:Validate POCO utilizes correct title-case underscore separated labeling practices
            //TODO:add a placeholder file describing what goes in the given DocTypeName's form root directory
            var IDocModelItems = AppDomain
                                 .CurrentDomain
                                 .GetAssemblies()
                                 .SelectMany(a => a.GetTypes())
                                 .Distinct()
                                 .Where(typ => (typ.GetInterfaces().Any(i => i == typeof(IDocModel))))
                                 .Select(type => new
            {
                type,
                DirectoryInfo = new DirectoryInfo(FilesystemTemplateController.GetDocDirectoryPath(type.Name)).mkdir(),
                myschemaXsd   = XsdExporter.ExportSchemas(
                    type.Assembly,
                    new List <string> {
                    type.Name
                },
                    RuntimeTypeNamer.CalcSchemaUri(type.Name)).First()
            });

            foreach (var docTypeDirectoryInfo in IDocModelItems)
            {
                string filepath = string.Format(@"{0}{1}", docTypeDirectoryInfo.DirectoryInfo.FullName, Runtime.MYSCHEMA_XSD_FILE_NAME);

                // always (over)write the xsd as this will always be generated by and for Rudine.Core regardless of the IDocInterpreter that is handling
                // compare the existing xsd on disk with the one generated here (excluding the "rolling" namespace) to see if anything has changed
                if (
                    !File.Exists(filepath)
                    ||
                    RuntimeTypeNamer.VALID_CSHARP_NAMESPACE_PART_MATCH.Replace(docTypeDirectoryInfo.myschemaXsd, string.Empty) != RuntimeTypeNamer.VALID_CSHARP_NAMESPACE_PART_MATCH.Replace(File.ReadAllText(filepath), string.Empty)
                    )
                {
                    File.WriteAllText(string.Format(@"{0}{1}", docTypeDirectoryInfo.DirectoryInfo.FullName, Runtime.MYSCHEMA_XSD_FILE_NAME), docTypeDirectoryInfo.myschemaXsd);
                }

                // create placeholder App_Code\DocTypeName.c_ files for developer to get started with myschema.xsd generation via cSharp file editing & thus auto translating
                string App_Code_Directory_Fullname = RequestPaths.GetPhysicalApplicationPath(Resources.App_Code_DirectoryPath);
                if (Directory.Exists(App_Code_Directory_Fullname))
                {
                    Tasker.StartNewTask(() =>
                    {
                        foreach (string DocTypeName in DocExchange.DocTypeDirectories())
                        {
                            if (!IDocModelItems.Any(m => m.DirectoryInfo.Name.Equals(DocTypeName, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                string cSharpCodeFileName = string.Format(@"{0}\{1}.c_", App_Code_Directory_Fullname, DocTypeName);
                                string xsdFileName        = RequestPaths.GetPhysicalApplicationPath("doc", DocTypeName, Runtime.MYSCHEMA_XSD_FILE_NAME);
                                string xsd          = File.ReadAllText(xsdFileName);
                                string myclasses_cs = new Xsd().ImportSchemasAsClasses(
                                    new[] { xsd },
                                    null,
                                    CodeGenerationOptions.GenerateOrder | CodeGenerationOptions.GenerateProperties,
                                    new StringCollection());

                                if (!File.Exists(cSharpCodeFileName) || File.ReadAllText(cSharpCodeFileName) != myclasses_cs)
                                {
                                    File.WriteAllText(cSharpCodeFileName, myclasses_cs);
                                    File.SetAttributes(cSharpCodeFileName, FileAttributes.Hidden);
                                }
                            }
                        }
                        return(true);
                    });
                }
            }
            return(List_ImporterLightDoc);
        }