Esempio n. 1
0
        private static void GenerateCodeFor(string input, string output, string name)
        {
            EPackage        package = EcoreInterop.LoadPackageFromFile(input);
            INamespace      nMeta   = EcoreInterop.Transform2Meta(package);
            CodeCompileUnit code    = MetaFacade.CreateCode(nMeta, name);

            MetaFacade.GenerateCode(code, new CSharpCodeProvider(), output, true);
        }
Esempio n. 2
0
        public static int GenerateAndCompile(INamespace ns, Action <string, int> afterCompileAction, out string error, out string log)
        {
            lock (codeGenLock)
            {
                var path = Path.GetTempFileName();
                File.Delete(path);
                Directory.CreateDirectory(path);

                try
                {
                    var projectFile = Path.Combine(path, "project.csproj");
                    var codeFile    = Path.Combine(path, "code.cs");

                    var code = MetaFacade.CreateCode(ns, "TemporaryGeneratedCode");
                    MetaFacade.GenerateCode(code, new Microsoft.CSharp.CSharpCodeProvider(), codeFile, false);

                    File.WriteAllText(projectFile, GenerateProjectFile(codeFile));

                    var startInfo = new ProcessStartInfo("dotnet.exe", "build " + projectFile);
                    startInfo.CreateNoWindow         = true;
                    startInfo.ErrorDialog            = false;
                    startInfo.UseShellExecute        = false;
                    startInfo.RedirectStandardError  = true;
                    startInfo.RedirectStandardOutput = true;
                    startInfo.WorkingDirectory       = path;

                    var buildJob      = Process.Start(startInfo);
                    var outputBuilder = new StringBuilder();
                    var errorBuilder  = new StringBuilder();

                    buildJob.ErrorDataReceived += (o, e) =>
                    {
                        errorBuilder.AppendLine(e.Data);
                        Debug.WriteLine(e.Data);
                    };
                    var line = buildJob.StandardOutput.ReadLine();
                    while (line != null)
                    {
                        outputBuilder.AppendLine(line);
                        line = buildJob.StandardOutput.ReadLine();
                    }
                    buildJob.WaitForExit();
                    error = errorBuilder.ToString();
                    log   = outputBuilder.ToString();
                    afterCompileAction?.Invoke(path, buildJob.ExitCode);
                    return(buildJob.ExitCode);
                }
                finally
                {
                    try
                    {
                        Directory.Delete(path, true);
                    }
                    // In code coverage analysis, another process is usually accessing our temporary folder
                    catch (Exception) { }
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var core = CreateCoreNamespace();
            var unit = MetaFacade.CreateCode(core, "FZI.SoftwareEngineering.DeepModeling");

            MetaFacade.GenerateCode(unit, new Microsoft.CSharp.CSharpCodeProvider(), @"..\..\..\DeepADL\DeepADL", true);
            using (var fs = File.Create(@"..\..\..\DeepADL.nmf"))
            {
                MetaRepository.Instance.Serializer.Serialize(core.Model, fs);
            }
        }
Esempio n. 4
0
        public static int GenerateAndCompile(INamespace ns, out string error, out string log)
        {
            lock (codeGenLock)
            {
                var path = Path.GetTempFileName();
                File.Delete(path);
                Directory.CreateDirectory(path);

                try
                {
                    var projectFile = Path.Combine(path, "project.csproj");
                    var codeFile    = Path.Combine(path, "code.cs");

                    var code = MetaFacade.CreateCode(ns, "Test");
                    MetaFacade.GenerateCode(code, new Microsoft.CSharp.CSharpCodeProvider(), codeFile, false);

                    File.WriteAllText(projectFile, GenerateProjectFile(codeFile));

                    var startInfo = new ProcessStartInfo("MSBuild.exe", projectFile);
                    startInfo.CreateNoWindow         = true;
                    startInfo.ErrorDialog            = false;
                    startInfo.UseShellExecute        = false;
                    startInfo.RedirectStandardError  = true;
                    startInfo.RedirectStandardOutput = true;
                    startInfo.WorkingDirectory       = path;

                    var    buildJob = Process.Start(startInfo);
                    string buildLog = null;

                    buildJob.ErrorDataReceived += (o, e) =>
                    {
                        buildLog += e.Data;
                        Debug.WriteLine(e.Data);
                    };
                    log = null;
                    var line = buildJob.StandardOutput.ReadLine();
                    while (line != null)
                    {
                        log += line;
                        line = buildJob.StandardOutput.ReadLine();
                    }
                    buildJob.WaitForExit();
                    error = buildLog;
                    return(buildJob.ExitCode);
                }
                finally
                {
                    Directory.Delete(path, true);
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var uri          = new Uri("http://github.com/georghinkel/mediaStore/Repository");
            var mediaStoreL1 = CreateMediaStoreRepository(uri);
            var model        = new Model()
            {
                ModelUri = uri
            };

            model.RootElements.Add(mediaStoreL1);
            var unit = MetaFacade.CreateCode(mediaStoreL1, "FZI.SoftwareEngineering.DeepModeling");

            MetaFacade.GenerateCode(unit, new Microsoft.CSharp.CSharpCodeProvider(), @"..\..\..\MediaStoreRepository\MediaStoreRepository", true);
            using (var fs = File.Create(@"..\..\..\MediaStoreRepository.nmf"))
            {
                MetaRepository.Instance.Serializer.Serialize(mediaStoreL1, fs);
            }
        }
Esempio n. 6
0
        private static void GenerateMediaStoreAssembly(int?factor, string codeLocation, string metamodelLocation)
        {
            var uri = new Uri("http://github.com/georghinkel/mediaStore/Assembly" + (factor.HasValue ? "X" + factor.Value.ToString() : ""));

            var system = new MediaStoreSystem()
            {
                Name = "MediaStore" + (factor.HasValue ? "X" + factor.Value.ToString() : "")
            };
            var mediaStoreL2 = new Namespace()
            {
                Name   = "Assembly" + (factor.HasValue ? "X" + factor.Value.ToString() : ""),
                Uri    = uri,
                Prefix = "mediaStore" + (factor.HasValue ? "X" + factor.Value.ToString() : "")
            };

            mediaStoreL2.Types.Add(system);
            if (!factor.HasValue)
            {
                CreateMediaStoreAssembly(system, string.Empty);
            }
            else
            {
                for (int i = 1; i <= factor.Value; i++)
                {
                    CreateMediaStoreAssembly(system, i.ToString());
                }
            }
            var model = new Model()
            {
                ModelUri = uri
            };

            model.RootElements.Add(mediaStoreL2);
            var unit = MetaFacade.CreateCode(mediaStoreL2, "FZI.SoftwareEngineering.DeepModeling");

            MetaFacade.GenerateCode(unit, new Microsoft.CSharp.CSharpCodeProvider(), codeLocation, true);
            using (var fs = File.OpenWrite(metamodelLocation))
            {
                MetaRepository.Instance.Serializer.Serialize(mediaStoreL2, fs);
            }
        }