Esempio n. 1
0
 public static void SaveToFile(string fileName, Model model, ModelExchangeFormat format = ModelExchangeFormat.Xmi)
 {
     using (StreamWriter writer = new StreamWriter(fileName))
     {
         writer.WriteLine(ModelExchange.SaveToString(model, format));
     }
 }
Esempio n. 2
0
 public SoalGenerator(Model model, string outputDirectory, ModelCompilerDiagnostics diagnostics, string fileName)
 {
     this.FileName = fileName;
     this.OutputDirectory = outputDirectory;
     this.Model = model;
     this.Diagnostics = diagnostics;
     this.SeparateXsdWsdl = false;
     this.SingleFileWsdl = false;
 }
Esempio n. 3
0
        public static string ToXmi(Model model)
        {
            XDocument doc = new XDocument();
            XNamespace xmi = ModelExchange.XmiNamespace;
            XElement xmiRoot =
                new XElement(xmi + "XMI",
                    new XAttribute(XNamespace.Xmlns + "xmi", xmi.NamespaceName));
            doc.Add(xmiRoot);

            int counter = 0;
            Dictionary<MetaModel, XNamespace> metaModels = new Dictionary<MetaModel, XNamespace>();
            Dictionary<MetaModel, string> prefixes = new Dictionary<MetaModel, string>();

            List<ModelObject> instances = model.CachedInstances;
            foreach (var mo in instances)
            {
                if (mo.MMetaClass != null && mo.MMetaClass.Model != null)
                {
                    MetaModel mm = mo.MMetaClass.Model;
                    if (mm != null && !metaModels.ContainsKey(mm))
                    {
                        ++counter;
                        string prefix = "ns" + counter;
                        XNamespace ns = mm.Uri;
                        metaModels.Add(mm, ns);
                        prefixes.Add(mm, prefix);
                        xmiRoot.Add(new XAttribute(XNamespace.Xmlns + prefix, ns.NamespaceName));
                    }
                }
            }

            foreach (var mo in instances)
            {
                if (mo.MMetaClass != null && mo.MMetaClass.Model != null)
                {
                    if (mo.MParent == null || mo.MParent is RootScope)
                    {
                        XNamespace ns = metaModels[mo.MMetaClass.Model];
                        XElement elem = null;
                        if (ns != null)
                        {
                            elem = new XElement(ns + mo.MMetaClass.Name);
                        }
                        else
                        {
                            elem = new XElement(mo.MMetaClass.Name);
                        }
                        xmiRoot.Add(elem);
                        ModelExchange.SaveToXmi(xmi, metaModels, prefixes, elem, mo);
                    }
                }
            }

            return doc.ToString();
        }
Esempio n. 4
0
 public static string SaveToString(Model model, ModelExchangeFormat format = ModelExchangeFormat.Xmi)
 {
     switch (format)
     {
         case ModelExchangeFormat.Xmi:
             return ModelExchange.ToXmi(model);
         case ModelExchangeFormat.Json:
             return ModelExchange.ToJson(model);
         default:
             return string.Empty;
     }
 }
Esempio n. 5
0
 private bool Test(int index)
 {
     bool result = false;
     string inputFileName = string.Format(@"..\..\InputFiles\wsdl\Wsdl{0:00}.Hello.wsdl", index);
     string expectedFileName = string.Format(@"..\..\ExpectedFiles\soal\Wsdl{0:00}.Hello.soal", index);
     string outputFileName = string.Format(@"..\..\OutputFiles\soal\Wsdl{0:00}.Hello.soal", index);
     string outputLogFileName = string.Format(@"..\..\OutputFiles\soal\Wsdl{0:00}.Hello.log", index);
     string outputDirectory = string.Format(@"..\..\OutputFiles\soal", index);
     Model model = new Model();
     using (ModelContextScope scope = new ModelContextScope(model))
     using (ModelCompilerContextScope compilerScope = new ModelCompilerContextScope(new DefaultModelCompiler()))
     {
         SoalImporter.Import(inputFileName);
         using (StreamWriter writer = new StreamWriter(outputLogFileName))
         {
             foreach (var msg in ModelCompilerContext.Current.Diagnostics.GetMessages(true))
             {
                 writer.WriteLine(msg);
             }
         }
         Assert.IsFalse(ModelCompilerContext.Current.Diagnostics.HasErrors());
         Directory.CreateDirectory(outputDirectory);
         string outputSoal = null;
         SoalPrinter printer = new SoalPrinter(model.Instances);
         using (StreamWriter writer = new StreamWriter(outputFileName))
         {
             outputSoal = printer.Generate();
             writer.WriteLine(outputSoal);
         }
         string expectedSoal = null;
         using (StreamReader reader = new StreamReader(expectedFileName))
         {
             expectedSoal = reader.ReadToEnd();
         }
         Assert.AreEqual(expectedSoal, outputSoal);
         return result;
     }
 }
Esempio n. 6
0
 public SpringGenerator(Model model, ModelCompilerDiagnostics diagnostics, string fileName)
 {
     this.FileName = fileName;
     this.Model = model;
     this.Diagnostics = diagnostics;
 }
Esempio n. 7
0
 internal ModelContext(Model model)
 {
     this.model = model;
 }
Esempio n. 8
0
 public ModelContextScope(Model model)
 {
     if (model == null) throw new ArgumentNullException(nameof(model));
     lock (ModelContext.contextStacks)
     {
         List<ModelContext> contextStack = null;
         if (!ModelContext.contextStacks.TryGetValue(Thread.CurrentThread, out contextStack))
         {
             contextStack = new List<ModelContext>();
             ModelContext.contextStacks.Add(Thread.CurrentThread, contextStack);
         }
         contextStack.Add(new ModelContext(model));
     }
 }
Esempio n. 9
0
 public static string ToJson(Model model)
 {
     return string.Empty;
 }
Esempio n. 10
0
 static void Main(string[] args)
 {
     try
     {
         string inputFileName = null;
         string outputFileName = null;
         for (int i = 0; i < args.Length; i++)
         {
             if (args[i].StartsWith("-"))
             {
                 if (i + 1 < args.Length)
                 {
                     if (args[i] == "-o")
                     {
                         outputFileName = args[++i];
                     }
                     else
                     {
                         Console.WriteLine("Unknown option: '" + args[i] + "'");
                     }
                 }
                 else
                 {
                     Console.WriteLine("Unknown option: '" + args[i] + "'");
                 }
             }
             else
             {
                 inputFileName = args[i];
             }
         }
         if (inputFileName == null)
         {
             Console.WriteLine("Usage:");
             Console.WriteLine("  SoalImport.exe [options] [input.wsdl or input.xsd]");
             Console.WriteLine("Options:");
             Console.WriteLine("  -o [output.soal]: output SOAL file");
             return;
         }
         if (outputFileName == null)
         {
             outputFileName = Path.ChangeExtension(inputFileName, ".soal");
         }
         if (!File.Exists(inputFileName))
         {
             Console.WriteLine("Could not find file: " + inputFileName);
             return;
         }
         Model model = new Model();
         using (ModelContextScope scope = new ModelContextScope(model))
         {
             SoalImporter.Import(inputFileName);
             foreach (var msg in ModelCompilerContext.Current.Diagnostics.GetMessages(true))
             {
                 Console.WriteLine(msg);
             }
             //if (!ModelCompilerContext.Current.Diagnostics.HasErrors())
             {
                 SoalPrinter printer = new SoalPrinter(model.Instances);
                 using (StreamWriter writer = new StreamWriter(outputFileName))
                 {
                     writer.WriteLine(printer.Generate());
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         Console.WriteLine(ex);
     }
 }