Пример #1
0
        public virtual ActionResult Generate(string language, string version, string key, bool all)
        {
            if (DebugHelper.IsDebug() == false)
            {
                return(RedirectToAction(MVC.Docs.ActionNames.Index, MVC.Docs.Name));
            }

            var parserOptions = GetParserOptions(all);

            var parser = new DocumentationParser(parserOptions, new NoOpGitFileInformationProvider());

            var indexQuery = DocumentSession
                             .Advanced
                             .DocumentQuery <DocumentationPage>();

            if (all == false)
            {
                indexQuery = indexQuery.WhereEquals(x => x.Version, CurrentVersion);
            }

            var query = indexQuery.GetIndexQuery();

            DocumentStore
            .Operations
            .Send(new DeleteByQueryOperation(query))
            .WaitForCompletion();

            query = DocumentSession
                    .Advanced
                    .DocumentQuery <TableOfContents>()
                    .GetIndexQuery();

            DocumentStore
            .Operations
            .Send(new DeleteByQueryOperation(query))
            .WaitForCompletion();

            DocumentSession.SaveChanges();

            var toDispose    = new List <IDisposable>();
            var parserOutput = parser.Parse();

            try
            {
                foreach (var page in parserOutput.Pages)
                {
                    DocumentSession.Store(page);

                    foreach (var image in page.Images)
                    {
                        var fileInfo = new FileInfo(image.ImagePath);
                        if (fileInfo.Exists == false)
                        {
                            continue;
                        }

                        var file = fileInfo.OpenRead();
                        toDispose.Add(file);

                        var documentId = page.Id;
                        var fileName   = Path.GetFileName(image.ImagePath);

                        DocumentSession.Advanced.Attachments.Store(documentId, fileName, file, AttachmentsController.FileExtensionToContentTypeMapping[fileInfo.Extension]);
                    }
                }

                foreach (var toc in parserOutput.TableOfContents)
                {
                    DocumentSession.Store(toc);
                }

                DocumentSession.SaveChanges();
            }
            finally
            {
                foreach (var disposable in toDispose)
                {
                    disposable?.Dispose();
                }
            }

            return(RedirectToDocPage(language, version, key));
        }
Пример #2
0
        public virtual ActionResult Generate(string language, string version, string key, bool all)
        {
            if (DebugHelper.IsDebug() == false)
            {
                return(RedirectToAction(MVC.Docs.ActionNames.Index, MVC.Docs.Name));
            }

            var versionsToParse = new List <string>();

            if (all == false)
            {
                versionsToParse.Add(CurrentVersion);
            }

            var parser =
                new DocumentationParser(
                    new ParserOptions
            {
                PathToDocumentationDirectory = GetDocumentationDirectory(),
                VersionsToParse = versionsToParse,
                RootUrl         = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")),
                ImagesUrl       = GetImagesUrl(DocumentStore)
            }, new NoOpGitFileInformationProvider());


            foreach (var attachment in DocumentStore.DatabaseCommands.GetAttachments(0, Etag.Empty, 1024))
            {
                DocumentStore.DatabaseCommands.DeleteAttachment(attachment.Key, null);
            }

            DocumentStore
            .DatabaseCommands
            .DeleteByIndex("Raven/DocumentsByEntityName", new IndexQuery {
                Query = "Tag:DocumentationPages OR Tag:TableOfContents"
            })
            .WaitForCompletion();

            foreach (var page in parser.Parse())
            {
                DocumentSession.Store(page);

                Parallel.ForEach(
                    page.Images,
                    image =>
                {
                    if (System.IO.File.Exists(image.ImagePath) == false)
                    {
                        return;
                    }

                    using (var file = System.IO.File.OpenRead(image.ImagePath))
                    {
                        DocumentStore.DatabaseCommands.PutAttachment(image.ImageKey, null, file, new RavenJObject());
                    }
                });
            }

            foreach (var toc in parser.GenerateTableOfContents())
            {
                DocumentSession.Store(toc);
            }

            DocumentSession.SaveChanges();

            if (string.IsNullOrEmpty(key))
            {
                return(RedirectToAction(MVC.Docs.ActionNames.Welcome, MVC.Docs.Name, new { language = language, version = version }));
            }

            while (true)
            {
                var stats = DocumentStore.DatabaseCommands.GetStatistics();
                if (stats.StaleIndexes.Any() == false)
                {
                    break;
                }

                Thread.Sleep(500);
            }

            return(RedirectToAction(
                       MVC.Docs.ActionNames.Articles,
                       MVC.Docs.Name,
                       new { language = CurrentLanguage, version = CurrentVersion, key = key }));
        }
Пример #3
0
 internal BaseParser(ParserOptions parserOptions)
 {
     ParserOptions = parserOptions;
     DocumentationParser = new DocumentationParser(parserOptions.SeeTokens);
 }
Пример #4
0
        private void CompileFolder(Folder folder)
        {
            var fullFolderSlug = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
            var fullPath       = Path.Combine(_fullPath, fullFolderSlug);

            if (!File.Exists(Path.Combine(fullPath, DocsListFileName)))
            {
                return;
            }

            var docs = DocsListParser.Parse(Path.Combine(fullPath, DocsListFileName)).ToArray();

            foreach (var item in docs)
            {
                if (item.Slug != null)
                {
                    item.Slug = item.Slug.TrimStart('\\', '/');
                }
                item.Trail = Path.Combine(folder.Trail, folder.Slug ?? string.Empty);
                folder.Items.Add(item);

                var document = item as Document;
                if (document != null)
                {
                    var strippedSlug = document.Slug.Replace(".markdown", string.Empty);
                    document.Content = DocumentationParser.Parse(this, null, Path.Combine(fullPath, document.Slug), document.Trail);
                    document.Slug    = strippedSlug;
                    Output.SaveDocItem(document);
                    continue;
                }

                var subFolder = item as Folder;
                if (subFolder != null)
                {
                    CompileFolder(subFolder);
                    continue;
                }
            }

            var contents = DocumentationParser.Parse(this, folder, Path.Combine(fullPath, "index.markdown"),
                                                     string.IsNullOrWhiteSpace(folder.Trail) ? folder.Slug : folder.Trail + "/" + folder.Slug
                                                     );

            Output.SaveDocItem(new Document
            {
                Title   = folder.Title,
                Content = contents,
                Trail   = fullFolderSlug,
                Slug    = "index"
            });

            // Copy images
            var imagesPath = Path.Combine(fullPath, "images");

            if (Directory.Exists(imagesPath))
            {
                var images = Directory.GetFiles(imagesPath);
                foreach (var image in images)
                {
                    var imageFileName = Path.GetFileName(image);
                    if (imageFileName == null)
                    {
                        continue;
                    }
                    Output.SaveImage(folder, image);
                }
            }
        }
Пример #5
0
        public virtual ActionResult Generate(string language, string version, string key, bool all)
        {
            if (DebugHelper.IsDebug() == false)
            {
                return(RedirectToAction(MVC.Docs.ActionNames.Index, MVC.Docs.Name));
            }

            var versionsToParse = new List <string>();

            if (all == false)
            {
                versionsToParse.Add(CurrentVersion);
            }

            var parser =
                new DocumentationParser(
                    new ParserOptions
            {
                PathToDocumentationDirectory = GetDocumentationDirectory(),
                VersionsToParse   = versionsToParse,
                RootUrl           = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~")),
                ImageUrlGenerator = GetImageUrlGenerator(HttpContext, DocumentStore)
            }, new NoOpGitFileInformationProvider());

            var indexQuery = DocumentSession
                             .Advanced
                             .DocumentQuery <DocumentationPage>();

            if (all == false)
            {
                indexQuery = indexQuery.WhereEquals(x => x.Version, CurrentVersion);
            }

            var query = indexQuery.GetIndexQuery();

            DocumentStore
            .Operations
            .Send(new DeleteByQueryOperation(query))
            .WaitForCompletion();

            query = DocumentSession
                    .Advanced
                    .DocumentQuery <TableOfContents>()
                    .GetIndexQuery();

            DocumentStore
            .Operations
            .Send(new DeleteByQueryOperation(query))
            .WaitForCompletion();

            DocumentSession.SaveChanges();

            var toDispose    = new List <IDisposable>();
            var parserOutput = parser.Parse();

            try
            {
                foreach (var page in parserOutput.Pages)
                {
                    DocumentSession.Store(page);

                    foreach (var image in page.Images)
                    {
                        var fileInfo = new FileInfo(image.ImagePath);
                        if (fileInfo.Exists == false)
                        {
                            continue;
                        }

                        var file = fileInfo.OpenRead();
                        toDispose.Add(file);

                        var documentId = page.Id;
                        var fileName   = Path.GetFileName(image.ImagePath);

                        DocumentSession.Advanced.Attachments.Store(documentId, fileName, file, AttachmentsController.FileExtensionToContentTypeMapping[fileInfo.Extension]);
                    }
                }

                foreach (var toc in parserOutput.TableOfContents)
                {
                    DocumentSession.Store(toc);
                }

                DocumentSession.SaveChanges();
            }
            finally
            {
                foreach (var disposable in toDispose)
                {
                    disposable?.Dispose();
                }
            }

            if (string.IsNullOrEmpty(key))
            {
                return(RedirectToAction(MVC.Docs.ActionNames.ArticlePage, MVC.Docs.Name, new { language = language, version = version }));
            }

            while (true)
            {
                var stats = DocumentStore.Maintenance.Send(new GetStatisticsOperation());
                if (stats.StaleIndexes.Any() == false)
                {
                    break;
                }

                Thread.Sleep(500);
            }

            return(RedirectToAction(
                       MVC.Docs.ActionNames.ArticlePage,
                       MVC.Docs.Name,
                       new { language = CurrentLanguage, version = CurrentVersion, key = key }));
        }
Пример #6
0
        public void Compile()
        {
            System.Diagnostics.Trace.WriteLine(string.Format("Processing global vocabulary model '{0}'...", vocabularyModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT)), "debug");

            // JF: This is safe to ignore here, this is handled by each of the individual binding
            //     realms
            // Bind all contexts so that property parsing will perform normally
            //foreach (ContextBinding cb in vocabularyModel.ContextBinding)
            //    if (cb.BindingRealmName == MifCompiler.BindingRealm && cb.BindingPriority == 0)
            //        PropertyParser.defaultCodingStrengths.Add(cb.ConceptDomain, cb.CodingStrength == CodingStrengthKind.CNE ? Property.CodingStrengthKind.CodedNoExceptions : Property.CodingStrengthKind.CodedWithExceptions);

            // Try to compile all concept domains from the model
            #region ConceptDomains
            foreach (MohawkCollege.EHR.HL7v3.MIF.MIF20.Vocabulary.ConceptDomain cd in vocabularyModel.ConceptDomain)
            {
                // Process
                if (ClassRepository.Find(o => o.Name == cd.Name && o is MohawkCollege.EHR.gpmr.COR.ConceptDomain) == null)
                {
                    EnumerationParser.Parse(cd, vocabularyModel, repository, ClassRepository);

                    // Specialize domains now and get them out of the way
                    foreach (ConceptDomainRef cdr in cd.SpecializesDomain)
                    {
                        // Has the specialized domain been processed?
                        if (!ClassRepository.ContainsKey(cdr.Name))
                        {
                            // Find the model that contains this concept domain
                            GlobalVocabularyModel gvm = repository.Find(delegate(PackageArtifact p)
                            {
                                if (!(p is GlobalVocabularyModel))
                                {
                                    return(false);                               // Don't search anything but vocab
                                }
                                // Try to find something in this model
                                GlobalVocabularyModel gvc = p as GlobalVocabularyModel;

                                return((gvc.CodeSystem.Find(o => o.Name == cdr.Name) as object ??
                                        gvc.ValueSet.Find(o => o.Name == cdr.Name) as object) != null);
                            }) as GlobalVocabularyModel;

                            // Was a global vocab model found
                            if (gvm != null)
                            {
                                // Sometimes there is no concept domain, but a code system only
                                MohawkCollege.EHR.HL7v3.MIF.MIF20.Vocabulary.CodeSystem cs = gvm.CodeSystem.Find(o => o.Name == cdr.Name);
                                MohawkCollege.EHR.HL7v3.MIF.MIF20.Vocabulary.ValueSet   vs = gvm.ValueSet.Find(o => o.Name == cdr.Name);
                                if (cs != null) // We found a code system, built it out
                                {
                                    Enumeration enumeration = new MohawkCollege.EHR.gpmr.COR.CodeSystem();
                                    enumeration.Name = cs.Name;
                                    EnumerationParser.Parse(cs, enumeration, ClassRepository, vocabularyModel);
                                    enumeration.FireParsed();
                                }
                                else if (vs != null)
                                {
                                    Enumeration enumeration = new MohawkCollege.EHR.gpmr.COR.ValueSet();
                                    enumeration.Name = vs.Name;
                                    EnumerationParser.Parse(vs, enumeration, ClassRepository, vocabularyModel);
                                    enumeration.FireParsed();
                                }
                            }
                        }

                        // Lookup the specialized domain in COR format
                        if (ClassRepository.ContainsKey(cdr.Name) && ClassRepository.ContainsKey(cd.Name))
                        {
                            Enumeration specializor = ClassRepository[cd.Name] as Enumeration;  // One who specializes
                            Enumeration specializee = ClassRepository[cdr.Name] as Enumeration; // One who is specialized

                            // Add properties
                            specializee.Literals.AddRange(specializor.Literals);
                        }
                    }
                }
                else
                {
                    Trace.WriteLine(String.Format("Concept domain '{0}' is already represented, skipping...", cd.Name), "warn");
                }
            }
            #endregion

            #region Code Systems

            // Any un-parsed code-systems
            foreach (MohawkCollege.EHR.HL7v3.MIF.MIF20.Vocabulary.CodeSystem cs in vocabularyModel.CodeSystem)
            {
                if (ClassRepository.Find(o => o.Name == cs.Name && o is MohawkCollege.EHR.gpmr.COR.CodeSystem) == null)
                {
                    Enumeration enumeration = new MohawkCollege.EHR.gpmr.COR.CodeSystem();
                    enumeration.Name = cs.Name;
                    EnumerationParser.Parse(cs, enumeration, ClassRepository, vocabularyModel);
                    enumeration.FireParsed();
                }
                else
                {
                    Trace.WriteLine(String.Format("Code system '{0}' is already represented, skipping...", cs.Name), "warn");
                }
            }

            #endregion

            #region Value Sets

            // Any un-parsed value-sets
            foreach (MohawkCollege.EHR.HL7v3.MIF.MIF20.Vocabulary.ValueSet vs in vocabularyModel.ValueSet)
            {
                string realm = vocabularyModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT),
                                                                           name = vs.Name;

                // Contains the key
                if (ClassRepository.Find(o => o.Name == vs.Name && o is MohawkCollege.EHR.gpmr.COR.ValueSet) == null)
                {
                    Enumeration enumeration = new MohawkCollege.EHR.gpmr.COR.ValueSet();
                    enumeration.Name = name;
                    EnumerationParser.Parse(vs, enumeration, ClassRepository, vocabularyModel);
                    enumeration.FireParsed();
                }
                else
                {
                    Trace.WriteLine(String.Format("Value set '{0}' is already represented, skipping...", vs.Name), "warn");
                }
            }
            #endregion

            #region Default Coding Strengths

            foreach (var strength in vocabularyModel.ContextBinding)
            {
                string id       = strength.ValueSet;
                var    valueSet = ClassRepository.Find(o => o is MohawkCollege.EHR.gpmr.COR.ValueSet && (o as MohawkCollege.EHR.gpmr.COR.ValueSet).Id == id);
                if (valueSet != null && !PropertyParser.defaultCodingStrengths.ContainsKey(valueSet.Name))
                {
                    PropertyParser.defaultCodingStrengths.Add(valueSet.Name, strength.CodingStrength == CodingStrengthKind.CNE ? Property.CodingStrengthKind.CodedNoExtensions : Property.CodingStrengthKind.CodedWithExtensions);
                }
                else if (valueSet == null)
                {
                    Trace.WriteLine(String.Format("Value set '{0}' was not parsed, therefore context binding cannot be placed on it", id));
                }
                else if (PropertyParser.defaultCodingStrengths[valueSet.Name] != (strength.CodingStrength == CodingStrengthKind.CNE ? Property.CodingStrengthKind.CodedNoExtensions : Property.CodingStrengthKind.CodedWithExtensions))
                {
                    System.Diagnostics.Trace.WriteLine(String.Format("Binding strength for '{0}' is declared twice and both instances don't match!", strength.ConceptDomain), "warn");
                }

                var conceptDomain = EnumerationParser.GetOrParseConceptDomainByName(strength.ConceptDomain, ClassRepository, PackageRepository as PackageRepository);
                // Context binding
                if (valueSet is MohawkCollege.EHR.gpmr.COR.ValueSet)
                {
                    (valueSet as MohawkCollege.EHR.gpmr.COR.ValueSet).ContextBinding = conceptDomain;
                }
                if (conceptDomain != null && valueSet != null)
                {
                    if (conceptDomain.ContextBinding == null)
                    {
                        conceptDomain.ContextBinding = new List <Enumeration>();
                    }
                    // Add the binding realm
                    (valueSet as Enumeration).OwnerRealm = strength.BindingRealmName;
                    conceptDomain.ContextBinding.Add(valueSet as Enumeration);
                }
            }

            #endregion

            #region Supplements

            // Code systems supplement:
            // Apparently in v3 it is possible to add codes to a code system
            // after it has been defined
            foreach (var css in vocabularyModel.CodeSystemSupplement)
            {
                // First, find the code system to supplement
                var cs = EnumerationParser.GetOrParseCodeSystem(css.CodeSystemId, this.ClassRepository, this.vocabularyModel.MemberOfRepository);
                if (cs == null && MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                {
                    // Try to find a value set
                    Trace.WriteLine(String.Format("Could not supplement code system '{0}' as it was not defined in the repository", css.CodeSystemId), "quirks");
                    continue;
                }
                else if (css == null)// not in quirks
                {
                    throw new InvalidOperationException(String.Format("Could not find target code system '{0}' of supplement '{1}', aborting", css.CodeSystemId, css.SupplementId));
                }

                string docTitle = "Supplement";
                if (css.Header != null && css.Header.ResponsibleGroup != null && css.Header.ResponsibleGroup.Count > 0)
                {
                    docTitle = String.Format("{0} Supplement:", css.Header.ResponsibleGroup[0].GroupName ?? css.Header.ResponsibleGroup[0].OrganizationName);
                }

                // Create documentation
                var doc = new MohawkCollege.EHR.gpmr.COR.Documentation.TitledDocumentation()
                {
                    Name  = "supplement",
                    Title = docTitle
                };

                // Add text
                if (css.Annotations != null)
                {
                    var docContent = DocumentationParser.ParseAddPrefix(doc.Title, css.Annotations.Documentation);
                    if (cs.Documentation == null)
                    {
                        cs.Documentation = new COR.Documentation();
                    }
                    cs.Documentation.Merge(docContent);
                }

                // Now supplement the appropriate codes
                if (css.CodeSystemVersionSupplement.Count == 0)
                {
                    Trace.WriteLine(String.Format("Supplement '{0}' does not contain a any supplements", css.SupplementId), "warn");
                    continue;
                }
                else if (css.CodeSystemVersionSupplement.Count > 1) // More than one
                {
                    if (MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                    {
                        Trace.WriteLine(String.Format("Supplement '{0}' contains more than one version to supplement. Since GPMR does not version enumeration structures only the first supplement ('{1}') will be used",
                                                      css.SupplementId, css.CodeSystemVersionSupplement[0].AppliesToReleaseDate), "quirks");
                    }
                    else
                    {
                        Trace.WriteLine(String.Format("Supplement '{0}' contains more than one version to supplement. GPMR does not version its enumeration releases and cannot apply this supplement!",
                                                      css.SupplementId, css.CodeSystemVersionSupplement[0].AppliesToReleaseDate), "error");
                        continue;
                    }
                }
                foreach (var concept in css.CodeSystemVersionSupplement[0].ConceptSupplement)
                {
                    // Attempt to find the ev
                    var ev = cs.GetEnumeratedLiterals().Find(o => o.Name == concept.Code);
                    if (ev == null)
                    {
                        Trace.WriteLine(String.Format("Could not find code '{0}' in '{1}' to which the supplemented concept applies", concept.Code, cs.Id), "error");
                        continue;
                    }

                    // Supplement annotations?
                    if (concept.Annotations != null && concept.Annotations.Documentation != null)
                    {
                        var csDocumentation = DocumentationParser.ParseAddPrefix(doc.Name, concept.Annotations.Documentation);
                        // Append the supplement notes as comments
                        if (ev.Documentation == null)
                        {
                            ev.Documentation = new COR.Documentation();
                        }
                        ev.Documentation.Merge(csDocumentation);
                    }
                }
            }

            // These structures seem to needlessly complex the MIF ...
            // Why can't this data be added directly to the
            // exported MIF? Meh, I guess we have to process it :@
            // This is equivalent in C++ to doing this:
            // Include STDIO but add some data to cout and
            // change the name of X to Y ... stupid
            if (vocabularyModel.DependsOnVocabModel != null)
            {
                foreach (var dep in vocabularyModel.DependsOnVocabModel)
                {
                    List <Enumeration> alreadySupplemented = new List <Enumeration>();

                    foreach (var supp in dep.SupplementArtifact)
                    {
                        try
                        {
                            // First we have to find the object that is being supplemented
                            string artifactName = supp.SupplementedObject.Params.Find(o => o.Name == "artifactName").Value;
                            Type   artifactType = supp.SupplementedObject.Params.Exists(o => o.Name == "subArtifact" && o.Value == "VS") ? typeof(MohawkCollege.EHR.gpmr.COR.ValueSet) : typeof(MohawkCollege.EHR.gpmr.COR.ConceptDomain);
                            if (artifactType == null)
                            {
                                throw new InvalidOperationException(String.Format("Cannot supplement object of type '{0}'", supp.SupplementedObject.Name));
                            }
                            Enumeration supplementObject = artifactType == typeof(MohawkCollege.EHR.gpmr.COR.ConceptDomain) ? EnumerationParser.GetOrParseConceptDomainByName(artifactName, ClassRepository, (PackageRepository)PackageRepository) : (Enumeration)EnumerationParser.GetOrParseValueSetByName(artifactName, ClassRepository, (PackageRepository)PackageRepository);

                            // HACK: Does the trick though
                            if (alreadySupplemented.Contains(supplementObject))
                            {
                                if (supplementObject != null)
                                {
                                    Trace.WriteLine(String.Format("Object '{0}' has already been supplemented, skipping", supplementObject.Name), "warn");
                                }
                                continue;
                            }
                            alreadySupplemented.Add(supplementObject);

                            // Supplemented object?
                            //if(supplementObject == null && MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                            //{
                            //    supplementObject = ClassRepository.Find(o=>o.Name == artifactName) as Enumeration;
                            //    if (supplementObject != null)
                            //        Trace.WriteLine(String.Format("Could not find '{0}' of type '{1}' but found '{2}' named '{0}', supplementing that object instead",
                            //            artifactName, artifactType.Name, supplementObject.EnumerationType), "quirks");
                            //    else
                            //        Trace.WriteLine(String.Format("Could not find '{0}' of type '{1}', looked for any vocabulary structure named '{0}' but couldn't find any, will cause an error",
                            //            artifactType, artifactType.Name), "quirks");
                            //}
                            if (supplementObject == null)
                            {
                                Trace.WriteLine(String.Format("Cannot supplement object '{0}' as it was not found in the repository", artifactName), "warn");
                                continue;
                            }

                            Trace.WriteLine(String.Format("Adding supplements to '{0}'...", artifactName), "debug");
                            // Supplement the business name...
                            foreach (var bn in supp.BusinessName)
                            {
                                if (bn.Language == MifCompiler.Language || bn.Language == null)
                                {
                                    supplementObject.BusinessName = bn.Name;
                                }
                            }

                            // Supplement annotations
                            if (supp.Annotations != null)
                            {
                                if (supplementObject.Documentation == null)
                                {
                                    supplementObject.Documentation = new COR.Documentation();
                                }
                                supplementObject.Documentation.Merge(DocumentationParser.Parse(supp.Annotations.Documentation));
                            }
                        }
                        catch (Exception e)
                        {
                            if (MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                            {
                                Trace.WriteLine(String.Format("Won't supplement object due to error : '{0}'.", e.Message), "quirks");
                            }
                            else
                            {
                                throw e;
                            }
                        }
                    }
                }
            }


            #endregion
        }
Пример #7
0
        public void Compile()
        {
            // Already processing?
            if (interactionModel == null || processingStack.Contains(interactionModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT)))
            {
                return;
            }

            // Add to the processing stack
            processingStack.Add(interactionModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT));

            // Otput the name of the package.
            System.Diagnostics.Trace.WriteLine(string.Format("Compiling interaction model package '{0}'...", interactionModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT)), "debug");

            // Check if the package has already been "compiled"
            if (ClassRepository.ContainsKey(interactionModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT)))
            {
                return; // Already compiled
            }
            // Process the interaction
            MohawkCollege.EHR.gpmr.COR.Interaction interaction = new MohawkCollege.EHR.gpmr.COR.Interaction();
            interaction.Name = interactionModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT);
            //interaction.Realm = interactionModel.PackageLocation.Realm;

            // Process business names
            foreach (BusinessName bn in interactionModel.BusinessName ?? new List <BusinessName>())
            {
                if (bn.Language == MifCompiler.Language || bn.Language == null)
                {
                    interaction.BusinessName = bn.Name;
                }
            }

            // Process documentation
            if (interactionModel.Annotations != null)
            {
                interaction.Documentation = DocumentationParser.Parse(interactionModel.Annotations.Documentation);
            }

            // Set the derivation from pointer
            interaction.DerivedFrom = interactionModel;

            // Trigger event
            interaction.TriggerEvent = interactionModel.InvokingTriggerEvent.ToString(MifCompiler.NAME_FORMAT);

            // Types
            TypeReference tr = new TypeReference();

            // Has the entry class been created yet?
            if (!ClassRepository.ContainsKey(interactionModel.ArgumentMessage.ToString(MifCompiler.NAME_FORMAT)))
            {
                // Process
                PackageParser.Parse(interactionModel.ArgumentMessage.ToString(MifCompiler.NAME_FORMAT), repository, ClassRepository);
            }

            var entry = (ClassRepository[interactionModel.ArgumentMessage.ToString(MifCompiler.NAME_FORMAT)] as MohawkCollege.EHR.gpmr.COR.SubSystem);

            // Could we even find the model?
            if (entry == null)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Could not find the argument message '{0}', interaction '{1}' can't be processed",
                                                                 interactionModel.ArgumentMessage.ToString(MifCompiler.NAME_FORMAT), interaction.Name), "error");
                return;
            }
            else if (entry.EntryPoint.Count == 0)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Argument message '{0}' must have an entry point, interaction '{1}' can't be processed",
                                                                 entry.Name, interaction.Name), "error");
                return;
            }
            else if (entry.EntryPoint.Count != 1)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Ambiguous entry point for argument message '{0}', interaction '{1}' can't be processed", entry.Name, interaction.Name), "error");
                return;
            }

            // Set the entry class
            tr          = entry.EntryPoint[0].CreateTypeReference();
            tr.MemberOf = ClassRepository; // Set member of property
            ProcessTypeParameters(interactionModel.ArgumentMessage.ParameterModel, tr, interaction);
            interaction.MessageType = tr;

            #region Response types
            if (interactionModel.ReceiverResponsibilities != null)
            {
                // Create the array
                interaction.Responses = new List <MohawkCollege.EHR.gpmr.COR.Interaction>();

                //  Iterate through
                foreach (ReceiverResponsibility rr in interactionModel.ReceiverResponsibilities)
                {
                    if (rr.InvokeInteraction == null)
                    {
                        System.Diagnostics.Trace.WriteLine("Invoking interaction on receiver responsibility is missing", "warn");
                        continue;
                    }

                    // Does the receiver responsibility exist in the class repository
                    if (!ClassRepository.ContainsKey(rr.InvokeInteraction.ToString(MifCompiler.NAME_FORMAT)))
                    {
                        InteractionCompiler icc = new InteractionCompiler();
                        icc.PackageRepository = repository;
                        icc.Package           = repository.Find(o => o.PackageLocation.ToString(MifCompiler.NAME_FORMAT) == rr.InvokeInteraction.ToString(MifCompiler.NAME_FORMAT));
                        icc.ClassRepository   = ClassRepository;
                        icc.Compile();
                    }

                    MohawkCollege.EHR.gpmr.COR.Feature foundFeature = null;
                    if (ClassRepository.TryGetValue(rr.InvokeInteraction.ToString(MifCompiler.NAME_FORMAT), out foundFeature))
                    {
                        // Reason element for documentation
                        if (rr.Reason != null && (rr.Reason.Language == MifCompiler.Language || rr.Reason.Language == null) &&
                            (rr.Reason.MarkupElements != null || rr.Reason.MarkupText != null))
                        {
                            MohawkCollege.EHR.gpmr.COR.Documentation.TitledDocumentation td = new MohawkCollege.EHR.gpmr.COR.Documentation.TitledDocumentation()
                            {
                                Title = "Reason", Name = "Reason", Text = new List <string>()
                            };
                            if (rr.Reason.MarkupText != null)
                            {
                                td.Text.Add(rr.Reason.MarkupText);
                            }
                            if (rr.Reason.MarkupElements != null)
                            {
                                foreach (XmlElement xe in rr.Reason.MarkupElements)
                                {
                                    td.Text.Add(xe.OuterXml.Replace(" xmlns:html=\"http://www.w3.org/1999/xhtml\"", "").Replace("html:", ""));
                                }
                            }

                            // Append the documentation
                            if (interaction.Documentation == null)
                            {
                                interaction.Documentation = new MohawkCollege.EHR.gpmr.COR.Documentation();
                            }
                            if (interaction.Documentation.Other == null)
                            {
                                interaction.Documentation.Other = new List <MohawkCollege.EHR.gpmr.COR.Documentation.TitledDocumentation>();
                            }
                            interaction.Documentation.Other.Add(td);
                        }
                        interaction.Responses.Add(foundFeature as MohawkCollege.EHR.gpmr.COR.Interaction);
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("Can't find response interaction '{0}'...", rr.InvokeInteraction.ToString(MifCompiler.NAME_FORMAT)), "warn");
                    }
                }
            }
            #endregion

            // Fire the complete method
            interaction.FireParsed();
        }