예제 #1
0
        /// <summary>
        ///     Persists changes to LuceneController without running validation checks.
        /// </summary>
        /// <param name="DocData"></param>
        /// <param name="DocSubmittedByEmail"></param>
        /// <param name="RelayUrl"></param>
        /// <param name="SubmittedDate"></param>
        /// <param name="DocKeys"></param>
        /// <param name="DocTitle"></param>
        /// <returns></returns>
        public LightDoc Import(Stream DocData)
        {
            LightDoc _LightDoc = SubmitStream(DocData, WindowsIdentity.GetCurrent()
                                              .Name);
            string TargetDocName = _LightDoc.GetTargetDocName(), TargetDocVer = _LightDoc.GetTargetDocVer();

            //#if !FAST
            Version existingVersion;

            // DOCREVs are only submitted via Text, there is no need to worry about them enter the system in another fusion.
            if (_LightDoc.DocTypeName == EmbededInterpreter.MY_ONLY_DOC_NAME)
            {
                // if the DocRev submitted supersedes the current or this is no current..
                if (!Version.TryParse(TemplateController.Instance.TopDocRev(TargetDocName), out existingVersion) || Version.Parse(TargetDocVer) >= existingVersion)
                {
                    // if there is no representation of this DocRev as a directory in the file system (as this trumps the submitted one no matter what
                    if (Directory.Exists(FilesystemTemplateController.GetDocDirectoryPath(TargetDocName)))
                    {
                        // notice the true parameter value to clear the cache as well as assert we have the correct DocRev in the system now
                        if (TemplateController.Instance.TopDocRev(TargetDocName, true) != TargetDocVer)
                        {
                            throw new PocosImportException();
                        }
                    }
                }
            }
            return(_LightDoc);
        }
예제 #2
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);
        }
예제 #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);
        }