Esempio n. 1
0
        /// <summary>
        /// Generate the collapsing XSLT
        /// </summary>
        public void GenerateCollapsingXslt(Interaction interaction)
        {

            requiredTemplates = new List<String>();

            // Create the writer
            XmlWriterSettings xwsettings = new XmlWriterSettings() { 
                Indent = true
            };

            XmlWriter xw = null;

            if (dataTypeMaps.Count == 0) // Generate the data type maps
                GenerateDataTypeMaps();

            // Try to open the file
            try
            {
                xw = XmlWriter.Create(Path.Combine(OutputDir, String.Format("{0}_Collapse.xslt", interaction.Name)), xwsettings);

                // Write the template
                xw.WriteStartElement("xsl", "stylesheet", NS_XSLT);
                xw.WriteAttributeString("xmlns", "hl7", null, NS_SRC); // HACK: Declare a namespace without using it
                xw.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                xw.WriteAttributeString("exclude-result-prefixes", "hl7 xsl xsi");
                xw.WriteAttributeString("version", "1.0");

                #region Output Method
                xw.WriteStartElement("output", NS_XSLT);
                xw.WriteAttributeString("method", "xml");
                xw.WriteAttributeString("indent", "yes");
                xw.WriteEndElement(); // output method
                #endregion

                #region Root Template

                xw.WriteStartElement("template", NS_XSLT);
                xw.WriteAttributeString("match", String.Format("/hl7:{0}", interaction.Name));
                xw.WriteStartElement(interaction.Name, TargetNamespace);

                // Write the attributes
                WriteXslAttribute(xw, "ITSVersion", string.Format("'{0}'", ItsRenderer.itsString), TargetNamespace);

                WriteInlineForeachCollapse(xw, interaction.MessageType, interaction.MessageType.GenericSupplier, interaction.Name);

                xw.WriteEndElement(); // interaction.Name
                xw.WriteEndElement(); // end template

                #endregion

                #region Other Templates

                for (int i = 0; i < requiredTemplates.Count; i++ )
                {
                    string s = requiredTemplates[i];
                    xw.WriteStartElement("template", NS_XSLT);
                    xw.WriteAttributeString("name", s);

                    Class cls = interaction.MemberOf[s] as Class;
                    WriteInlineForeachCollapse(xw, cls.CreateTypeReference(), interaction.MessageType.GenericSupplier, interaction.Name);
                    xw.WriteEndElement();
                }

                #endregion

                xw.WriteEndElement(); // stylesheet

                //            // Write the 
                //<?xml version="1.0" encoding="utf-8"?>
                //<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                //    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                //>
                //    <xsl:output method="xml" indent="yes"/>

                //    <xsl:template match="@* | node()">
                //        <xsl:copy>
                //            <xsl:apply-templates select="@* | node()"/>
                //        </xsl:copy>
                //    </xsl:template>
                //</xsl:stylesheet>

                
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Could not write to the file '{0}_Collapse' ({1})...", interaction.Name, e.Message), "error");
            }
            finally
            {
                if (xw != null) xw.Close();
            }

        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        /// <summary>
        /// Generate the expanding XSLT
        /// </summary>
        public void GenerateExpandingXslt(Interaction interaction)
        {

        }
Esempio n. 4
0
 public void AddTraversalName(string TraversalName, TypeReference CaseWhen, Interaction InteractionOwner)
 {
     if (CaseWhen != null && CaseWhen.MemberOf == null)
         CaseWhen.MemberOf = this.MemberOf ?? this.Container.MemberOf;
     if (AlternateTraversalNames == null) AlternateTraversalNames = new List<AlternateTraversalData>();
     AlternateTraversalNames.Add(new AlternateTraversalData() { CaseWhen = CaseWhen, TraversalName = TraversalName, InteractionOwner = InteractionOwner }); 
 }
Esempio n. 5
0
        /// <summary>
        /// Generate a rim graph that maps an interaction into is RIM representation
        /// </summary>
        /// <param name="interaction"></param>
        public void GenerateRIMGraph(Interaction interaction)
        {
            templateClasses.Clear();

            if (interaction.MessageType == null || interaction.MessageType.Class == null ||
                interaction.MessageType.Class.Realizations == null ||
                interaction.MessageType.Class.Realizations.Count == 0)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Interaction '{0}' does not have a RIM realization...", interaction.Name), "error");
                return;
            }

            requiredTemplates = new List<String>();

            // Create the writer
            XmlWriterSettings xwsettings = new XmlWriterSettings()
            {
                Indent = true
            };

            XmlWriter xw = null;

            if (dataTypeMaps.Count == 0) // Generate the data type maps
                GenerateDataTypeMaps();

            // Try to open the file
            try
            {
                xw = XmlWriter.Create(Path.Combine(OutputDir, String.Format("{0}_RimGraph.xslt", interaction.Name)), xwsettings);

                // Write the template
                xw.WriteStartElement("xsl", "stylesheet", NS_XSLT);
                xw.WriteAttributeString("xmlns", "hl7", null, NS_SRC); // HACK: Declare a namespace without using it
                xw.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                xw.WriteAttributeString("xmlns", "marc", null, "urn:marc-hi:ca/hial");
                xw.WriteAttributeString("exclude-result-prefixes", "hl7 xsl");
                xw.WriteAttributeString("version", "1.0");

                #region Output Method
                xw.WriteStartElement("output", NS_XSLT);
                xw.WriteAttributeString("method", "xml");
                xw.WriteAttributeString("indent", "yes");
                xw.WriteEndElement(); // output method
                #endregion

                #region Root Template

                xw.WriteStartElement("template", NS_XSLT);
                xw.WriteAttributeString("match", String.Format("/hl7:{0}", interaction.Name));
                xw.WriteStartElement(interaction.MessageType.Class.Realizations[0].Class.Name, NS_SRC);

                // The Tag is used by BizTalk orchestrations to determing if the message is an acknowledging message
                xw.WriteStartElement("attribute", NS_XSLT);
                xw.WriteAttributeString("name", "tag");
                xw.WriteStartElement("value-of", NS_XSLT);
                xw.WriteAttributeString("select", "''");
                xw.WriteEndElement(); // value-of
                xw.WriteEndElement(); // attribute

                // Write the attributes
                WriteInlineForeachCollapse(xw, interaction.MessageType, interaction.MessageType.GenericSupplier, interaction.Name);

                xw.WriteEndElement(); // interaction.Name
                xw.WriteEndElement(); // end template

                #endregion

                #region Other Templates

                #region DT Copy Template
                xw.WriteStartElement("template", NS_XSLT);
                xw.WriteAttributeString("name", "dtMap");
                xw.WriteStartElement("for-each", NS_XSLT);
                xw.WriteAttributeString("select", "@*|child::node()");
                xw.WriteStartElement("copy-of", NS_XSLT);
                xw.WriteAttributeString("select", ".");
                xw.WriteEndElement(); // copy
                xw.WriteEndElement(); // for-each
                xw.WriteEndElement(); // template
                #endregion

                for (int i = 0; i < requiredTemplates.Count; i++)
                {
                    string s = requiredTemplates[i];
                    xw.WriteStartElement("template", NS_XSLT);
                    xw.WriteAttributeString("name", s);

                    xw.WriteStartElement("attribute", NS_XSLT);
                    xw.WriteAttributeString("name", "type");
                    xw.WriteAttributeString("namespace", "urn:marc-hi:ca/hial");
                    xw.WriteString(s);

                    xw.WriteEndElement(); // attribute

                    Class cls = templateClasses[s] as Class;
                    WriteInlineForeachCollapse(xw, cls.CreateTypeReference(), interaction.MessageType.GenericSupplier, interaction.Name);
                    xw.WriteEndElement();
                }

                #endregion

                xw.WriteEndElement(); // stylesheet

                //            // Write the 
                //<?xml version="1.0" encoding="utf-8"?>
                //<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                //    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                //>
                //    <xsl:output method="xml" indent="yes"/>

                //    <xsl:template match="@* | node()">
                //        <xsl:copy>
                //            <xsl:apply-templates select="@* | node()"/>
                //        </xsl:copy>
                //    </xsl:template>
                //</xsl:stylesheet>


            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Could not write to the file '{0}_RimGraph' ({1})...", interaction.Name, e.Message), "error");
            }
            finally
            {
                if (xw != null) xw.Close();
            }

        }
Esempio n. 6
0
        /// <summary>
        /// Generate complex types
        /// </summary>
        private List<XmlSchemaComplexType> GenerateComplexTypes(TypeReference typeReference, Interaction parent, List<String> includedModels, List<TypeReference> additionalCompileTargets)
        {

            // Is this a valid type reference
            if (typeReference.Class == null) return new List<XmlSchemaComplexType>();

            // Generate the complex types
            List<XmlSchemaComplexType> retVal = new List<XmlSchemaComplexType>();
            // Iterate through the complex types
            foreach (TypeReference tr in typeReference.GenericSupplier ?? new List<TypeReference>())
                retVal.AddRange(GenerateComplexTypes(tr, parent, includedModels, additionalCompileTargets));

            if (typeReference.Class.TypeParameters != null &&
                typeReference.Class.TypeParameters.Count > 0)
                retVal.Add(GenerateComplexType(typeReference.Class, parent.Name, typeReference.GenericSupplier, includedModels, additionalCompileTargets));
            return retVal;
        }
Esempio n. 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();
        }
Esempio n. 8
0
        private void ProcessSpecializations(ParameterModel p, List <AssociationEndSpecialization> list, TypeReference baseRef, MohawkCollege.EHR.gpmr.COR.Interaction interactionModel, TypeReference hint)
        {
            TypeReference parmRef = null;

            foreach (var specialization in list) // This shouldn't ever be done ... ever, but this is v3 land
            {
                Class specClass = (ClassRepository[p.ToString(MifCompiler.NAME_FORMAT)] as MohawkCollege.EHR.gpmr.COR.SubSystem).OwnedClasses.Find(c => c.Name == specialization.ClassName);
                if (specClass == null && hint != null)
                {
                    // Find all sub-classes and see if the hint contains them
                    TypeReference specClassRef = hint.Class.SpecializedBy.Find(o => o.Class.Name == specialization.ClassName);
                    // Make the reference a concreate COR class
                    if (specClassRef != null)
                    {
                        specClass = specClassRef.Class;
                    }
                }
                if (specClass == null) // Do a CMET lookup
                {
                    MohawkCollege.EHR.gpmr.COR.Feature cmetFeature = null;
                    if (ClassRepository.TryGetValue(specialization.ClassName, out cmetFeature))
                    {
                        specClass = (cmetFeature as CommonTypeReference).Class.Class;
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(string.Format("Can't find specialization '{0}' for parameter '{1}' this traversal will be ignored.", specialization.ClassName, p.ParameterName), "warn");
                        continue;
                    }
                }

                parmRef = specClass.CreateTypeReference();
                // Append the traversal name
                AppendTraversalName(baseRef, p.ParameterName, specialization.TraversalName, parmRef, interactionModel, new Stack <string>());
                if (specialization.Specialization.Count > 0)
                {
                    ProcessSpecializations(p, specialization.Specialization, baseRef, interactionModel, parmRef);
                }
            }
        }
Esempio n. 9
0
        private void ProcessTypeParameters(List <ParameterModel> parms, TypeReference baseRef, MohawkCollege.EHR.gpmr.COR.Interaction ownerInteraction)
        {
            if (parms != null && baseRef.Class != null && baseRef.Class.TypeParameters != null && parms.Count != baseRef.Class.TypeParameters.Count)
            {
                Trace.WriteLine(
                    string.Format("The argument message '{0}.{1}' requires {2} parameter messages however interaction '{3}' only specifies {4}",
                                  baseRef.Class.ContainerName, baseRef.Class.Name, baseRef.Class.TypeParameters.Count, ownerInteraction.Name, parms.Count)
                    , "warn");
            }
            else if (parms == null || parms.Count == 0)
            {
                return;                                         // Check for null
            }
            // Setup the parameters
            foreach (ParameterModel p in parms)
            {
                // Check if the parameter model exists
                if (!ClassRepository.ContainsKey(p.ToString(MifCompiler.NAME_FORMAT)))
                {
                    PackageParser.Parse(p.ToString(MifCompiler.NAME_FORMAT), repository, ClassRepository); // Process the package if it doesn't
                }
                // Check again, if this fails all hell breaks loose
                var model = (ClassRepository[p.ToString(MifCompiler.NAME_FORMAT)] as MohawkCollege.EHR.gpmr.COR.SubSystem);
                if (model == null)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Could not find the parameter model '{0}'",
                                                                     p.ToString(MifCompiler.NAME_FORMAT)), "error");
                    return;
                }
                else if (model.EntryPoint.Count == 0)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Parameter model '{0}' must have an entry point",
                                                                     p.ToString(MifCompiler.NAME_FORMAT)), "error");
                    return;
                }
                else if (model.EntryPoint.Count != 1)
                {
                    System.Diagnostics.Trace.WriteLine(string.Format("Ambiguous entry point for parameter model '{0}'",
                                                                     p.ToString(MifCompiler.NAME_FORMAT)), "error");
                    return;
                }

                // Entry class for p
                TypeReference parmRef = model.EntryPoint[0].CreateTypeReference();

                // Find any reference and set an alternate traversal name for that property
                if (p.Specialization.Count == 0)
                {
                    AppendTraversalName(baseRef, p.ParameterName, p.TraversalName, parmRef, ownerInteraction, new Stack <string>());
                }
                else
                {
                    ProcessSpecializations(p, p.Specialization, baseRef, ownerInteraction, null);
                }

                // Process Children
                ProcessTypeParameters(p.ParameterModel, parmRef, ownerInteraction);

                // Assign for tr as a parameter reference
                try
                {
                    baseRef.AddGenericSupplier(p.ParameterName, parmRef);
                }
                catch (ArgumentException e) // This is thrown when there are more than one supplier binding
                {
                    // Was more than one specified
                    if (baseRef.GenericSupplier.Exists(o => (o as TypeParameter).ParameterName == p.ParameterName))
                    {
                        //baseRef.GenericSupplier.RemoveAll(o => (o as TypeParameter).ParameterName == p.ParameterName);  // remove the existing type reference
                        // Add the generic supplier manually for the new type
                        baseRef.AddGenericSupplier(p.ParameterName, parmRef, false);
                        Trace.WriteLine(String.Format("Generic supplier {0} has been specified more than once, will use base object in it's place", p.ParameterName), "warn");
                    }
                }
                catch (Exception e)
                {
                    // JF - Some UV models attempt to bind to classes that don't support binding
                    if (baseRef.Class.TypeParameters == null)
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("{0} can't force bind because the target class has not template parameters", e.Message), "error");
                        if (MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                        {
                            System.Diagnostics.Trace.WriteLine(String.Format("{0} will ignore this binding in order to continue. This interaction will effectively be useless", ownerInteraction.Name));
                        }
                        else
                        {
                            throw new InvalidOperationException(String.Format("Cannot bind parameter '{0}' to class '{1}' because '{1}' does not support templates", parmRef.Name, baseRef.Name));
                        }
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("{0} will try force binding", e.Message), "error");
                        foreach (var t in baseRef.Class.TypeParameters)
                        {
                            if (baseRef.GenericSupplier.Find(o => o.Name.Equals(t.ParameterName)) == null)
                            {
                                baseRef.AddGenericSupplier(t.ParameterName, parmRef);
                                System.Diagnostics.Trace.WriteLine(String.Format("Bound {0} to {1} in {2}", parmRef, t.ParameterName, baseRef), "warn");
                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private void AppendTraversalName(TypeReference ClassRef, string ParameterName, string TraversalName, TypeReference CaseWhen, MohawkCollege.EHR.gpmr.COR.Interaction InteractionOwner, Stack <String> processStack)
        {
            if (processStack.Contains(ClassRef.ToString()))
            {
                return;
            }

            processStack.Push(ClassRef.ToString());

            // Iterate through each of the class contents
            foreach (ClassContent cc in ClassRef.Class.Content)
            {
                if (cc is Property)
                {
                    // Assign Alternative traversal name if the type of property matches the paramter name
                    // and the new traversal name is not the same as the old
                    if ((cc as Property).Type.Name == ParameterName &&
                        TraversalName != cc.Name)
                    {
                        (cc as Property).AddTraversalName(TraversalName, CaseWhen, InteractionOwner);
                    }
                    else if ((cc as Property).Type.Class != null)
                    {
                        AppendTraversalName((cc as Property).Type, ParameterName, TraversalName, CaseWhen, InteractionOwner, processStack);
                    }
                }
            }

            if (processStack.Pop() != ClassRef.ToString())
            {
                throw new PipelineExecutionException(MifCompiler.hostContext, Pipeline.PipelineStates.Error, MifCompiler.hostContext.Data,
                                                     new Exception("Error occurred traversing traversal name to populate parameter"));
            }
        }