Пример #1
0
        internal static void ImportMvd(mvdXML mvd, DocProject docProject, string filepath)
        {
            if (mvd.Templates != null)
            {
                Dictionary<EntityRule, DocModelRuleEntity> fixups = new Dictionary<EntityRule, DocModelRuleEntity>();
                foreach (ConceptTemplate mvdTemplate in mvd.Templates)
                {
                    DocTemplateDefinition docDef = docProject.GetTemplate(mvdTemplate.Uuid);
                    if (docDef == null)
                    {
                        docDef = new DocTemplateDefinition();
                        docProject.Templates.Add(docDef);
                    }

                    ImportMvdTemplate(mvdTemplate, docDef, fixups);
                }

                foreach(EntityRule er in fixups.Keys)
                {
                    DocModelRuleEntity docEntityRule = fixups[er];
                    if(er.References != null)
                    {
                        foreach(TemplateRef tr in er.References)
                        {
                            DocTemplateDefinition dtd = docProject.GetTemplate(tr.Ref);
                            if(dtd != null)
                            {
                                docEntityRule.References.Add(dtd);
                            }
                        }
                    }
                }
            }

            if (mvd.Views != null)
            {
                foreach (ModelView mvdView in mvd.Views)
                {
                    DocModelView docView = docProject.GetView(mvdView.Uuid);
                    if (docView == null)
                    {
                        docView = new DocModelView();
                        docProject.ModelViews.Add(docView);
                    }

                    ImportMvdObject(mvdView, docView);

                    docView.BaseView = mvdView.BaseView;
                    docView.Exchanges.Clear();
                    Dictionary<Guid, ExchangeRequirement> mapExchange = new Dictionary<Guid, ExchangeRequirement>();
                    foreach (ExchangeRequirement mvdExchange in mvdView.ExchangeRequirements)
                    {
                        mapExchange.Add(mvdExchange.Uuid, mvdExchange);

                        DocExchangeDefinition docExchange = new DocExchangeDefinition();
                        ImportMvdObject(mvdExchange, docExchange);
                        docView.Exchanges.Add(docExchange);

                        docExchange.Applicability = (DocExchangeApplicabilityEnum)mvdExchange.Applicability;

                        // attempt to find icons if exists -- remove extention
                        try
                        {
                            string iconpath = filepath.Substring(0, filepath.Length - 7) + @"\mvd-" + docExchange.Name.ToLower().Replace(' ', '-') + ".png";
                            if (System.IO.File.Exists(iconpath))
                            {
                                docExchange.Icon = System.IO.File.ReadAllBytes(iconpath);
                            }
                        }
                        catch
                        {

                        }
                    }

                    foreach (ConceptRoot mvdRoot in mvdView.Roots)
                    {
                        // find the entity
                        DocEntity docEntity = LookupEntity(docProject, mvdRoot.ApplicableRootEntity);
                        if (docEntity != null)
                        {
                            DocConceptRoot docConceptRoot = docView.GetConceptRoot(mvdRoot.Uuid);
                            if (docConceptRoot == null)
                            {
                                docConceptRoot = new DocConceptRoot();
                                if (docView.ConceptRoots == null)
                                {
                                    docView.ConceptRoots = new List<DocConceptRoot>();
                                }
                                docView.ConceptRoots.Add(docConceptRoot);
                            }

                            ImportMvdObject(mvdRoot, docConceptRoot);
                            docConceptRoot.ApplicableEntity = docEntity;

                            if (mvdRoot.Applicability != null)
                            {
                                docConceptRoot.ApplicableTemplate = docProject.GetTemplate(mvdRoot.Applicability.Template.Ref);
                                if(mvdRoot.Applicability.TemplateRules != null)
                                {
                                    docConceptRoot.ApplicableOperator = (DocTemplateOperator)Enum.Parse(typeof(TemplateOperator), mvdRoot.Applicability.TemplateRules.Operator.ToString());
                                    foreach (TemplateRule r in mvdRoot.Applicability.TemplateRules.TemplateRule)
                                    {
                                        DocTemplateItem docItem = ImportMvdItem(r, docProject, mapExchange);
                                        docConceptRoot.ApplicableItems.Add(docItem);
                                    }
                                }
                            }

                            docConceptRoot.Concepts.Clear();
                            foreach (Concept mvdNode in mvdRoot.Concepts)
                            {
                                DocTemplateUsage docUse = new DocTemplateUsage();
                                docConceptRoot.Concepts.Add(docUse);
                                ImportMvdConcept(mvdNode, docUse, docProject, mapExchange);
                            }
                        }
                        else
                        {
                            //TODO: log error
                        }
                    }
                }
            }
        }
Пример #2
0
        private static void ImportMvdConcept(Concept mvdNode, DocTemplateUsage docUse, DocProject docProject, Dictionary<Guid, ExchangeRequirement> mapExchange)
        {
            // special case for attributes
            DocTemplateDefinition docTemplateDef = docProject.GetTemplate(mvdNode.Template.Ref);
            if (docTemplateDef != null)
            {
                ImportMvdObject(mvdNode, docUse);

                docUse.Definition = docTemplateDef;
                docUse.Override = mvdNode.Override;

                // exchange requirements
                foreach (ConceptRequirement mvdReq in mvdNode.Requirements)
                {
                    ExchangeRequirement mvdExchange = null;
                    if (mapExchange.TryGetValue(mvdReq.ExchangeRequirement, out mvdExchange))
                    {
                        DocExchangeItem docReq = new DocExchangeItem();
                        docUse.Exchanges.Add(docReq);

                        foreach (DocModelView docModel in docProject.ModelViews)
                        {
                            foreach (DocExchangeDefinition docAnno in docModel.Exchanges)
                            {
                                if (docAnno.Uuid.Equals(mvdReq.ExchangeRequirement))
                                {
                                    docReq.Exchange = docAnno;
                                    break;
                                }
                            }
                        }

                        docReq.Applicability = (DocExchangeApplicabilityEnum)mvdReq.Applicability;

                        switch(mvdReq.Requirement)
                        {
                            case RequirementEnum.Mandatory:
                                docReq.Requirement = DocExchangeRequirementEnum.Mandatory;
                                break;

                            case RequirementEnum.Recommended:
                                docReq.Requirement = DocExchangeRequirementEnum.Optional;
                                break;

                            case RequirementEnum.NotRelevant:
                                docReq.Requirement = DocExchangeRequirementEnum.NotRelevant;
                                break;

                            case RequirementEnum.NotRecommended:
                                docReq.Requirement = DocExchangeRequirementEnum.NotRecommended;
                                break;

                            case RequirementEnum.Excluded:
                                docReq.Requirement = DocExchangeRequirementEnum.Excluded;
                                break;
                        }
                    }
                }

                // rules as template items
                if (mvdNode.TemplateRules != null)
                {
                    docUse.Operator = (DocTemplateOperator)Enum.Parse(typeof(DocTemplateOperator), mvdNode.TemplateRules.Operator.ToString());
                    foreach (TemplateRule rule in mvdNode.TemplateRules.TemplateRule)
                    {
                        DocTemplateItem docItem = ImportMvdItem(rule, docProject, mapExchange);
                        docUse.Items.Add(docItem);
                    }

                    if (mvdNode.TemplateRules.InnerRules != null)
                    {
                        mvdNode.ToString();
                    }
                }

            }
        }
Пример #3
0
        private static void ImportMvdConcept(Concept mvdNode, DocTemplateUsage docUse, DocProject docProject, Dictionary<Guid, ExchangeRequirement> mapExchange)
        {
            // special case for attributes                            
            DocTemplateDefinition docTemplateDef = docProject.GetTemplate(mvdNode.Template.Ref);
            if (docTemplateDef != null)
            {
                // lookup use definition
                docUse.Uuid = mvdNode.Uuid;
                docUse.Name = mvdNode.Name;
                docUse.Definition = docTemplateDef;
                docUse.Override = mvdNode.Override;

                // content
                if (mvdNode.Definitions != null)
                {
                    foreach (Definition mvdDef in mvdNode.Definitions)
                    {
                        if (mvdDef.Body != null)
                        {
                            docUse.Documentation = mvdDef.Body.Content;
                        }
                    }
                }

                // exchange requirements
                foreach (ConceptRequirement mvdReq in mvdNode.Requirements)
                {
                    ExchangeRequirement mvdExchange = null;
                    if (mapExchange.TryGetValue(mvdReq.ExchangeRequirement, out mvdExchange))
                    {
                        DocExchangeItem docReq = new DocExchangeItem();
                        docUse.Exchanges.Add(docReq);

                        foreach (DocModelView docModel in docProject.ModelViews)
                        {
                            foreach (DocExchangeDefinition docAnno in docModel.Exchanges)
                            {
                                if (docAnno.Uuid.Equals(mvdReq.ExchangeRequirement))
                                {
                                    docReq.Exchange = docAnno;
                                    break;
                                }
                            }
                        }

                        docReq.Applicability = (DocExchangeApplicabilityEnum)mvdReq.Applicability;
                        docReq.Requirement = (DocExchangeRequirementEnum)mvdReq.Requirement;
                    }
                }

                // rules as template items
                if (mvdNode.TemplateRules != null)
                {
                    docUse.Operator = (DocTemplateOperator)Enum.Parse(typeof(DocTemplateOperator), mvdNode.TemplateRules.Operator.ToString());
                    foreach (TemplateRule rule in mvdNode.TemplateRules.TemplateRule)
                    {
                        DocTemplateItem docItem = ImportMvdItem(rule, docProject, mapExchange);
                        docUse.Items.Add(docItem);
                    }

                    if (mvdNode.TemplateRules.InnerRules != null)
                    {
                        mvdNode.ToString();
                    }
                }

            }
        }