public string GenerateDomain( PadConfig config )
        {
            if (!config.DataContext.AutoGen)
                return string.Empty;

            StringBuilder classesCode = new StringBuilder();

            foreach (MapConfig map in config.Mappings) {
                XDocument mapDoc;
                if (map.IsAssembly) {
                    mapDoc = XDocument.Load(new XmlTextReader(Assembly.ReflectionOnlyLoadFrom(map.Assembly).GetManifestResourceStream(map.ResourceName)));
                } else if (map.IsFile) {
                    mapDoc = XDocument.Load(map.Map);
                } else
                    continue;

                if (!mapDoc.Root.HasElements)
                    continue;

                var clazz = mapDoc.Root.Elements().SingleOrDefault();
                if (clazz == null)
                    continue;

                classesCode.Append(CreateClassCode(clazz));
            }

            StringBuilder domain = new StringBuilder();
            domain.Append(CreateDomainUsings());
            domain.Append(CreateDomainCode(config.DataContextAutoGenNamespace, classesCode.ToString()));
            return domain.ToString();
        }
Esempio n. 2
0
        public static void Main( string[] args )
        {
            try{
                _log = LogManager.GetCurrentClassLogger();
            }catch(Exception ex ){
                Console.WriteLine(ex.Message);
            }

            _log.InfoFormat("{0} ready to serve.", APP_NAME);
            // BATCH
            if (args.Length > 0) {
                CodeRunner codeRunner = new CodeRunner();
                try {
                    string padFile = args[0];
                    _log.InfoFormat("File argument: {0}", padFile);

                    // load configuration
                    PadConfig padConfig = new PadConfig();
                    if (!padConfig.Load(padFile)) {
                        _log.ErrorFormat("Error loading pad file!");
                        return;
                    }

                    // setup single factory (fast calls optimization)
                    if (padConfig.DataContext.Enabled) {
                        CustomConfiguration cfg = ServiceHelper.GetService<CustomConfiguration>();
                        cfg.FactoryRebuildOnTheFly = bool.FalseString;
                        cfg.IsConfigured = true;
                    }

                    // run
                    codeRunner.Build(padConfig);
                    codeRunner.Run();

                } catch (Exception ex) {

                    _log.ErrorFormat(ex.Message);

                } finally {

                    codeRunner.Release();
                }

            } else {

                // GUI
                try {
                    Application.Init();
                    SpoolPadWindow win = new SpoolPadWindow();
                    win.Show();
                    Application.Run();
                } catch (Exception ex) {
                    MessageHelper.ShowError(ex);
                }

            }

            _log.Info("SpoolPad goes to sleep.");
        }
Esempio n. 3
0
    public SpoolPadWindow()
        : base(Gtk.WindowType.Toplevel)
    {
        _currentConfigPad = new PadConfig();
        _codeRunner = new CodeRunner(_currentConfigPad);

        foreach (ISpoolerService spoolerService in SpoolerHelper.Spoolers) {
            Widget temp = spoolerService.GetSpoolerWidget();
            if (temp != null) {
                if (!ExistResultView)
                    _resultView = temp;
                else
                    throw new Exception("The Spooling services MUST be consistent.\nMore than one UI Widget is defined!\nCannot continue.");
            }
        }

        Build();
        InitControls();
        Reset();
    }
Esempio n. 4
0
 public void Build( PadConfig config )
 {
     _config = config;
     Build();
 }
Esempio n. 5
0
 public DataContextBuilder( PadConfig config )
 {
     _config = config;
 }
Esempio n. 6
0
        bool Compile( CodeDomProvider provider, string dataContextCode, PadConfig config, String dllFile )
        {
            if (!dllFile.EndsWith(".dll"))
                dllFile += ".dll";

            dcAutoGenFile = dllFile;

            CompilerParameters cp = new CompilerParameters();

            // Generate a class library.
            cp.GenerateExecutable = false;

            // Generate debug information.
            cp.IncludeDebugInformation = false;

            // Add assembly references.
            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("Iesi.Collections.dll");

            // Save the assembly as a physical file.
            cp.GenerateInMemory = false;

            cp.OutputAssembly = dcAutoGenFile;

            // Set the level at which the compiler
            // should start displaying warnings.
            cp.WarningLevel = 3;

            // Set whether to treat all warnings as errors.
            cp.TreatWarningsAsErrors = false;

            // Set compiler argument to optimize output.
            cp.CompilerOptions = "/optimize";

            string workDir = Path.Combine(Path.GetTempPath(), "SpoolPad$temp$" + config.Name);

            if (!Directory.Exists(workDir))
                Directory.CreateDirectory(workDir);

            foreach (MapConfig map in config.Mappings) {

                if (map.IsValid) {
                    if (provider.Supports(GeneratorSupport.Resources)) {
                        if (!config.DataContext.AutoGen) {
                            if (map.IsFile)
                                cp.EmbeddedResources.Add(map.Map); else if (map.IsAssembly) {

                                string tempFile = Path.Combine(workDir, Path.GetFileName(map.ResourceName));
                                TextReader tr = new StreamReader(Assembly.ReflectionOnlyLoadFrom(map.Assembly).GetManifestResourceStream(map.ResourceName));
                                File.WriteAllText(tempFile, tr.ReadToEnd());
                                cp.EmbeddedResources.Add(tempFile);

                            } else
                                continue;

                        } else {

                            XDocument doc = null;
                            if (map.IsAssembly) {
                                doc = XDocument.Load(new XmlTextReader(Assembly.ReflectionOnlyLoadFrom(map.Assembly).GetManifestResourceStream(map.ResourceName)));
                            } else if (map.IsFile) {
                                doc = XDocument.Load(map.Map);
                            } else
                                continue;

                            var hibmap = doc.Root;
                            if (hibmap != null) {
                                hibmap.SetAttributeValue("assembly", config.Name);
                                hibmap.SetAttributeValue("namespace", config.DataContextAutoGenNamespace);

                                string tempFile = Path.Combine(workDir, Path.GetFileName(map.Map));
                                doc.Save(tempFile);
                                cp.EmbeddedResources.Add(tempFile);
                            }
                        }
                    }
                }
            }

            CompilerResults cr = provider.CompileAssemblyFromSource(cp, dataContextCode);

            Directory.Delete(workDir, true);

            if (cr.Errors.Count > 0) {
                // Display compilation errors.
                _log.ErrorFormat("Errors building {0}", cr.PathToAssembly);
                foreach (CompilerError ce in cr.Errors) {
                    _log.DebugFormat("  {0}", ce.ToString());
                }
            } else {
                _log.DebugFormat("Source built into {0} successfully.", cr.PathToAssembly);
            }

            // Return the results of compilation.
            if (cr.Errors.Count > 0) {
                return false;
            } else {
                return true;
            }
        }
Esempio n. 7
0
 public void Run( PadConfig config )
 {
     _config = config;
     Run();
 }
Esempio n. 8
0
 public CodeRunner( PadConfig config )
 {
     _config = config;
 }
Esempio n. 9
0
 public CodeRunner()
 {
     _config = null;
 }