/// <summary> /// Converts this statement for a particular programming language destination /// </summary> /// <param name="converter">converter object</param> /// <param name="proc">process object</param> /// <param name="file">final file</param> public void Convert(Converters.ICodeConverter converter, IProcessInstance proc, FinalFile file) { string name = null; List <string> skeletonPath = null; string modifier = null; if (this.ParseCommand(this.command, out name, out skeletonPath, out modifier)) { // rechercher le MOP source CreateMOP mopSrc = this.cachedComp.GetMOP(this.language, name); // charge l'extrait de code du mop XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml("<code>" + mopSrc.XmlCode + "</code>"); if (skeletonPath.Count == 0 || String.IsNullOrEmpty(modifier)) { // cas lorsque l'on insère dans le processus en cours // fabrication d'un processus Process subProcess = new Process(); subProcess.Name = this.MOPToFunctionName(mopSrc.Language + "_" + mopSrc.Name); // ajouter les affectations pour chaque paramètre string[] tab; if (!String.IsNullOrEmpty(this.expression)) { tab = this.expression.Split(','); } else { tab = new string[0]; } int index = 0; Dictionary <string, string> values = new Dictionary <string, string>(); while (index < mopSrc.References.Count) { if (index < tab.Length) { values.Add(mopSrc.References[index], tab[index]); } ++index; } if (index < tab.Length && mopSrc.References.Count > 0) { values[mopSrc.References[mopSrc.References.Count - 1]] += "array(" + String.Join(",", tab, index, tab.Length - index) + ")"; } foreach (KeyValuePair <string, string> kv in values) { Converters.Parameter param = new Parameter(); param.FormalParameter = kv.Key.Trim(); param.ReplacementParameter = kv.Value.Trim(); o2Mate.Expression expr = new o2Mate.Expression(); o2Mate.IData res = expr.Evaluate(kv.Value.Trim(), proc.CurrentScope); param.EffectiveParameter = res.ValueString; param.IsComputable = res.IsComputable; subProcess.Replacements.Add(param); } if (this.localInjector != null) { // on recherche le début de l'injection this.localInjector.InjectedProcess.Remove(this.localInjector.Current, this.localInjector.After - 1); this.localInjector.InjectedProcess.Remove(this.localInjector.Before, this.localInjector.Current - 1); this.localInjector.Current = this.localInjector.Before; this.localInjector.After = this.localInjector.Before + 1; } else { this.localInjector = new Injector(); this.localInjector.Current = this.localInjector.Before = proc.Objects.IndexOf(this); this.localInjector.After = this.localInjector.Before + 1; this.localInjector.InjectedProcess = proc; } this.cachedComp.Injection(this.localInjector, doc.DocumentElement, "after"); // on implémente une fonction avec ce processus Call c = new Call(this.cachedComp, proc); c.ProcessName = subProcess.Name; c.Convert(converter, proc, file); } else { // cas d'utilisation d'un inserteur string insert = String.Empty; bool first = true; foreach (string path in skeletonPath) { if (!first) { insert += "/"; } else { first = false; } insert += path; } Injector j = this.cachedComp.GetInjector(insert); // lorsque l'injecteur a déjà été utilisé if (!j.IsEmpty && modifier == "replace") { // on efface tout // on recherche le début de l'injection j.InjectedProcess.Remove(j.Current, j.After - 1); j.InjectedProcess.Remove(j.Before, j.Current - 1); j.Current = j.Before; j.After = j.Before + 1; } // ajouter les affectations pour chaque paramètre string[] tab; if (!String.IsNullOrEmpty(this.expression)) { tab = this.expression.Split(','); } else { tab = new string[0]; } int index = 0; Dictionary <string, string> values = new Dictionary <string, string>(); while (index < mopSrc.References.Count) { if (index < tab.Length) { values.Add(mopSrc.References[index], tab[index]); } ++index; } if (index < tab.Length && mopSrc.References.Count > 0) { values[mopSrc.References[mopSrc.References.Count - 1]] += "array(" + String.Join(",", tab, index, tab.Length - index) + ")"; } j.InjectedProcess.Replacements.Clear(); foreach (KeyValuePair <string, string> kv in values) { Converters.Parameter param = new Parameter(); param.FormalParameter = kv.Key.Trim(); param.ReplacementParameter = kv.Value.Trim(); o2Mate.Expression expr = new o2Mate.Expression(); o2Mate.IData res = expr.Evaluate(kv.Value.Trim(), proc.CurrentScope); param.EffectiveParameter = res.ValueString; param.IsComputable = res.IsComputable; j.InjectedProcess.Replacements.Add(param); } this.cachedComp.Injection(j, doc.DocumentElement, modifier); // le processus a été modifié j.InjectedProcess.HasChanged = true; } } else { throw new FormatException("Format de la commande '" + this.command + "' inattendue"); } }
/// <summary> /// Process this statement and writes results in a file /// </summary> /// <param name="proc">process object</param> /// <param name="file">final file object</param> public void WriteToFile(IProcessInstance proc, FinalFile file) { proc.CurrentProject.Add(new ProjectItem(proc.Name, proc.CurrentPositionExecution, "use mop", this.Language, this.Command)); string name = null; List <string> skeletonPath = null; string modifier = null; if (this.ParseCommand(this.command, out name, out skeletonPath, out modifier)) { // rechercher le MOP source CreateMOP mopSrc = this.cachedComp.GetMOP(this.language, name); // évaluation de l'expression (liste) string[] tab; if (!String.IsNullOrEmpty(this.expression)) { o2Mate.Expression expr = new o2Mate.Expression(); IData result = expr.Evaluate("array(" + this.expression + ")", proc.CurrentScope); tab = result.ValueString.Split(','); } else { tab = new string[0]; } // remplacement des valeurs int index = 0; Dictionary <string, string> values = new Dictionary <string, string>(); while (index < mopSrc.References.Count) { if (index < tab.Length) { values.Add(mopSrc.References[index], tab[index]); } ++index; } if (index < tab.Length && mopSrc.References.Count > 0) { values[mopSrc.References[mopSrc.References.Count - 1]] += String.Join(",", tab, index, tab.Length - index); } string code = mopSrc.ReplaceParams(values); // charge dans le compilateur l'extrait de code du mop XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = false; doc.LoadXml("<code>" + code + "</code>"); if (skeletonPath.Count == 0 || String.IsNullOrEmpty(modifier)) { if (this.localInjector != null) { // on recherche le début de l'injection this.localInjector.InjectedProcess.Remove(this.localInjector.Current, this.localInjector.After - 1); this.localInjector.InjectedProcess.Remove(this.localInjector.Before, this.localInjector.Current - 1); this.localInjector.Current = this.localInjector.Before; this.localInjector.After = this.localInjector.Before + 1; } else { this.localInjector = new Injector(); this.localInjector.Current = this.localInjector.Before = proc.Objects.IndexOf(this); this.localInjector.After = this.localInjector.Before + 1; this.localInjector.InjectedProcess = proc; } this.cachedComp.Injection(this.localInjector, doc.DocumentElement, "after"); } else { string insert = String.Empty; bool first = true; foreach (string path in skeletonPath) { if (!first) { insert += "/"; } else { first = false; } insert += path; } Injector j = this.cachedComp.GetInjector(insert); if (modifier == "replace") { // on recherche le début de l'injection j.InjectedProcess.Remove(j.Current, j.After - 1); j.InjectedProcess.Remove(j.Before, j.Current - 1); j.Current = j.Before; j.After = j.Before + 1; } this.cachedComp.Injection(j, doc.DocumentElement, modifier); } } else { throw new FormatException("Format de la commande '" + this.command + "' inattendue"); } }