コード例 #1
0
ファイル: MFsh.cs プロジェクト: goelalex/Eir.MFSH
        public void Process(MIPreFsh fsh)
        {
            const String fcn = "Process";

            if (Path.GetExtension(fsh.RelativePath).ToLower() == MINCSuffix)
            {
                return;
            }

            this.usings = fsh.Usings;
            String relativeFshPath = this.SetProfileVariables(fsh.RelativePath);

            this.variableBlocks = new List <VariablesBlock>();
            this.variableBlocks.Insert(0, this.GlobalVars);
            this.variableBlocks.Insert(0, this.profileVariables);

            if (this.GetFileData(relativeFshPath, this.variableBlocks, out FileData fd) == false)
            {
                this.ConversionError(ClassName, fcn, $"Output file {fd.AbsoluteOutputPath} already exists!");
                return;
            }

            this.Process(fsh.Items, fd, this.variableBlocks);

            this.variableBlocks   = null;
            this.profileVariables = null;
        }
コード例 #2
0
ファイル: MFsh.cs プロジェクト: goelalex/Eir.MFSH
        void ProcessFragment(MIPreFsh fragTempCmds,
                             MIFragment frag)
        {
            const String fcn = "ProcessFragment";

            this.appliedMacros.Clear();
            this.incompatibleMacros.Clear();

            String relativePath = this.SetProfileVariables(frag.SourceFile);

            if (String.IsNullOrEmpty(frag.Parent) == true)
            {
                this.ConversionError(ClassName, fcn, $"Fragment {frag.Name} missing parent!");
                return;
            }

            if (relativePath.ToUpper().StartsWith(@"FRAGMENTS\"))
            {
                relativePath = relativePath.Substring(10);
            }
            String absolutePath = Path.Combine(this.FragDir, relativePath);

            absolutePath = Path.GetFullPath(absolutePath);

            if (this.FileItems.TryGetValue(absolutePath.ToUpper().Trim(), out FileData fd) == false)
            {
                fd = new FileData();
                fd.AbsoluteOutputPath = absolutePath;
                this.FileItems.Add(absolutePath.ToUpper().Trim(), fd);
            }
            else
            {
                fd.AppendLine("");
                fd.AppendLine("");
                fd.AppendLine("");
            }

            VariablesBlock        localVb = StartNewFrag(frag, out String name);
            List <VariablesBlock> local   = new List <VariablesBlock>();

            local.Insert(0, this.GlobalVars);
            local.Insert(0, this.profileVariables);
            local.Insert(0, localVb);

            this.skipRedirects = false;
            this.Process(fragTempCmds.Items, fd, local);
            this.skipRedirects = true;

            this.Process(frag.Items, fd, local);
        }
コード例 #3
0
ファイル: MFsh.cs プロジェクト: goelalex/Eir.MFSH
        void ProcessApplyFrag(MIApply apply,
                              FileData fd,
                              MIFragment frag,
                              List <VariablesBlock> local)
        {
            const String fcn = "ProcessApplyMacro";

            if (apply.Parameters.Count != 0)
            {
                String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Fragment {apply.Name} takes no parameters.";
                fullMsg += this.ApplyLongStackTrace();
                this.ConversionError(ClassName, fcn, fullMsg);
                return;
            }

            bool firstFlag = false;

            if (this.appliedMacros.Contains(apply.Name) == false)
            {
                this.appliedMacros.Add(apply.Name);
                firstFlag = true;
            }

            if ((frag.OnceFlag == true) && (firstFlag == false))
            {
                return;
            }

            if (this.incompatibleMacros.Contains(apply.Name))
            {
                String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} {apply.Name} has been marked as incompatible with this profile";
                fullMsg += this.ApplyLongStackTrace();
                this.ConversionError(ClassName, fcn, fullMsg);
                return;
            }

            VariablesBlock        localVb   = StartNewFrag(frag, out String name);
            List <VariablesBlock> fragLocal = new List <VariablesBlock>();

            fragLocal.AddRange(local);
            fragLocal.Insert(0, localVb);

            FileData macroData = fd;

            this.applyStack.Push(apply);                    // this is for stack tracing during errors
            this.Process(frag.Items, macroData, fragLocal);
            this.applyStack.Pop();
        }
コード例 #4
0
ファイル: MFsh.cs プロジェクト: goelalex/Eir.MFSH
        String SetProfileVariables(String relativePath)
        {
            String relativeFshPath = Path.Combine(
                Path.GetDirectoryName(relativePath),
                Path.GetFileNameWithoutExtension(relativePath) + ".fsh"
                );

            this.profileVariables = new VariablesBlock();
            {
                String baseRPath           = relativePath;
                String baseName            = Path.GetFileName(baseRPath);
                String baseNameNoExtension = Path.GetFileNameWithoutExtension(baseRPath);
                String baseDir             = Path.GetDirectoryName(baseRPath);

                this.profileVariables.Set("%BasePath%", baseRPath);
                this.profileVariables.Set("%BaseDir%", baseDir);
                this.profileVariables.Set("%BaseName%", baseNameNoExtension);
                this.profileVariables.Set("%SavePath%", $"{relativeFshPath}");
            }
            return(relativeFshPath);
        }
コード例 #5
0
ファイル: MFsh.cs プロジェクト: goelalex/Eir.MFSH
        VariablesBlock StartNewFrag(MIFragment frag,
                                    out String name)
        {
            name = frag.Name;
            if (name.Contains('.'))
            {
                name = name.Substring(name.LastIndexOf('.') + 1);
            }

            VariablesBlock localVb = new VariablesBlock();

            localVb.Add("%Id%", name);
            localVb.Add("%FragmentId%", name);
            localVb.Add("%FParent%", frag.Parent);
            localVb.Add("%FTitle%", frag.Title);
            localVb.Add("%FDescription%", frag.Description);
            String fragmentUrl = $"{this.BaseUrl}/StructureDefinition/{name}";

            localVb.Add("%FUrl%", fragmentUrl);

            //this.appliedMacros.Clear();
            //this.incompatibleMacros.Clear();
            return(localVb);
        }
コード例 #6
0
ファイル: MFsh.cs プロジェクト: goelalex/Eir.MFSH
        void ProcessApplyMacro(MIApply apply,
                               FileData fd,
                               MIMacro macro,
                               List <VariablesBlock> local)
        {
            const String fcn = "ProcessApplyMacro";

            if (macro.Parameters.Count != apply.Parameters.Count)
            {
                String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Macro {apply.Name} requires {macro.Parameters.Count} parameters, called with {apply.Parameters.Count}.";
                fullMsg += this.ApplyLongStackTrace();
                this.ConversionError(ClassName, fcn, fullMsg);
                return;
            }

            macro.AppliedFlag = true;
            bool firstFlag = false;

            if (this.appliedMacros.Contains(apply.Name) == false)
            {
                this.appliedMacros.Add(apply.Name);
                firstFlag = true;
            }

            if ((macro.OnceFlag == true) && (firstFlag == false))
            {
                return;
            }

            if (this.incompatibleMacros.Contains(apply.Name))
            {
                String fullMsg = $"{apply.SourceFile}, line {apply.LineNumber} Macro {apply.Name} has been marked as incompatible with this profile";
                fullMsg += this.ApplyLongStackTrace();
                this.ConversionError(ClassName, fcn, fullMsg);
                return;
            }

            local.Insert(0, macro.ApplicableVariables);
            VariablesBlock vbParameters = new VariablesBlock();

            for (Int32 i = 0; i < apply.Parameters.Count; i++)
            {
                String pName  = macro.Parameters[i];
                String pValue = apply.Parameters[i];
                if (this.variableBlocks != null)
                {
                    pValue = this.variableBlocks.ReplaceText(pValue);
                }
                vbParameters.Add(pName, pValue);
            }

            vbParameters.Add("%ApplySourceFile%", apply.SourceFile.Replace("\\", "/"));
            vbParameters.Add("%ApplyLineNumber%", apply.LineNumber.ToString());

            local.Insert(0, vbParameters);

            FileData macroData = fd;

            if (String.IsNullOrEmpty(macro.Redirect) == false)
            {
                if (this.skipRedirects == true)
                {
                    return;
                }
                this.GetFileData(macro.Redirect, local, out macroData);
            }

            this.applyStack.Push(apply);                    // this is for stack tracing during errors
            vbParameters.Add("%ApplyStackFrame%", this.ApplyShortStackTrace().Replace("\\", "/"));
            this.Process(macro.Items, macroData, local);
            this.applyStack.Pop();
        }