protected override int OnExecute(CommandOptions options)
        {
            var generateOptions = (GenerateOptions)options;

            var projectFile = Path.Combine(Environment.CurrentDirectory, "shapeflow.config.json");

            if (File.Exists(projectFile) && string.IsNullOrWhiteSpace(generateOptions.ProjectFile))
            {
                generateOptions.ProjectFile = projectFile;
            }

            try
            {
                var parameters = new Dictionary <string, string>
                {
                    { "project-root", Environment.CurrentDirectory }
                };

                var solution = Solution.ParseFile(generateOptions.ProjectFile);
                solution.AddParameters(parameters);
                solution.AddParameters(generateOptions.Parameters);

                var ev     = new SolutionEventContext(solution);
                var engine = _container.Resolve <SolutionEngine>();

                engine.Run(ev);
            }
            catch (ApplicationOptionException ex)
            {
                AppTrace.Error("Invalid command line arguments. See exception for details.", ex);
                Console.WriteLine(ex.Message);
            }

            return(0);
        }
示例#2
0
        public bool ValidateArguments(ModelDeclaration context)
        {
            if (string.IsNullOrWhiteSpace(context.GetParameter(ModelPathParameter)))
            {
                // TODO: this should be a validation service
                AppTrace.Error($"The parameter {ModelPathParameter} is required.");
                return(false);
            }

            return(true);
        }
        public List <Course> Get()
        {
            List <Course> retVal = new List <Course>();

            try {
                retVal = context.Courses.ToList <Course>();
            } catch (Exception ex) {
                AppTrace.Error(ex.Message);
                throw;
            }

            return(retVal);
        }
        public Course Get(int id)
        {
            Course retVal = null;

            try {
                retVal = context.Courses.Where(c => c.Id == id).FirstOrDefault();
            } catch (Exception ex) {
                AppTrace.Error(ex.Message);
                throw;
            }

            return(retVal);
        }
示例#5
0
        public List <Student> Get()
        {
            List <Student> retVal = new List <Student>();

            try {
                //find the object in the database
                retVal = context.Students.ToList <Student>();
            } catch (Exception ex) {
                AppTrace.Error(ex.Message);
                throw;
            }

            return(retVal);
        }
示例#6
0
        public Student Get(int id)
        {
            Student retVal = null;

            try {
                //find the object in the database
                retVal = context.Students.Where(c => c.Id == id).FirstOrDefault();
            } catch (Exception ex) {
                AppTrace.Error(ex.Message);
                throw;
            }

            return(retVal);
        }
        public Course Post(Course course)
        {
            Course retVal = null;

            try {
                //create the object in the database
                retVal = context.Courses.Add(course);

                context.SaveChanges();
            } catch (Exception ex) {
                //Trace the error
                AppTrace.Error(ex.Message);
                throw;
            }

            return(retVal);
        }
示例#8
0
        public void Put(Student student)
        {
            try {
                //create the object in the database
                Student studentItem = context.Students.Where(s => s.Id == student.Id).FirstOrDefault();

                if (student != null)
                {
                    studentItem.Name = student.Name;
                    context.SaveChanges();
                }

                //context.SaveChanges();
            } catch (Exception ex) {
                //Trace the error
                AppTrace.Error(ex.Message);
                throw;
            }
        }
        public ModelToTextOutputFile Transform(ProjectionContext transformationContext, ProjectionInput input, TransformationRuleDeclaration tranformationRule)
        {
            var hash = transformationContext.GetStateEntry <Hash>(HashStateKey);

            if (hash == null)
            {
                hash = PrepareHash(input);
                transformationContext.AddStateEntry(HashStateKey, hash);
            }

            var templateFile = _fileProvider.GetFile(transformationContext, tranformationRule);
            ModelToTextOutputFile result;

            try
            {
                var template = Template.Parse(templateFile.Text);
                var output   = template.Render(hash);

                var outputPath = string.Empty;

                if (string.IsNullOrWhiteSpace(tranformationRule.OutputPathTemplate))
                {
                    var templateFileName  = tranformationRule.TemplateName;
                    var languageExtension = _inferenceService.InferFileExtension(output);
                    outputPath = Path.ChangeExtension(templateFileName, languageExtension);
                }
                else
                {
                    var nameTemplate = Template.Parse(tranformationRule.OutputPathTemplate);
                    outputPath = nameTemplate.Render(hash);
                }

                result = new ModelToTextOutputFile(output, outputPath);
            }
            catch (Exception e)
            {
                AppTrace.Error("Template processing failed:", e);
                throw;
            }

            return(result);
        }
示例#10
0
        public Student Post(Student student)
        {
            Student retVal = null;

            try {
                //construct the object for the database
                Student studentItem = new Student()
                {
                    Name = student.Name
                };

                //create the object in the database
                retVal = context.Students.Add(studentItem);

                context.SaveChanges();
            } catch (Exception ex) {
                //Trace the error
                AppTrace.Error(ex.Message);
                throw;
            }

            return(retVal);
        }