Ejemplo n.º 1
0
        public StateMachineProject Create()
        {
            var project = new StateMachineProject();

            project.Massage();

            return(project);
        }
Ejemplo n.º 2
0
        public void Generate(StateMachineProject project, string projectPath)
        {
            // Get the model that we will use to generate the binary / code
            var generationModel = _generationModelFactory.GetGenerationModel(project);

            //Generate the binary part
            var binaryResult = _binaryGenerator.Generate(generationModel);

            string header = _headerFileGenerator.GenerateHeader(generationModel, binaryResult);
            string code   = _codeFileGenerator.GenerateCode(generationModel, binaryResult);

            if ((project.GenerationOptions.DebugMode == DebugMode.None) || (project.GenerationOptions.DebugMode == DebugMode.Embedded))
            {
                if (!string.IsNullOrWhiteSpace(project.GenerationOptions.HeaderFilePath))
                {
                    var fullPath = project.GenerationOptions.HeaderFilePath;
                    var path     = Path.Combine(projectPath, Path.GetDirectoryName(fullPath));
                    Directory.CreateDirectory(path);
                    path = Path.Combine(path, Path.GetFileName(fullPath));
                    File.WriteAllText(path, header);
                }

                if (!string.IsNullOrWhiteSpace(project.GenerationOptions.CodeFilePath))
                {
                    var fullPath = project.GenerationOptions.CodeFilePath;
                    var path     = Path.Combine(projectPath, Path.GetDirectoryName(fullPath));
                    Directory.CreateDirectory(path);
                    path = Path.Combine(path, Path.GetFileName(fullPath));
                    File.WriteAllText(path, code);
                }
            }
            else
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(projectPath);

                /*Clean up the directory by deleting all files not part of the platform (i.e. delete the generated files).*/
                foreach (var file in directoryInfo.GetFiles())
                {
                    if ((file.Name != "efsm_core.h") &&
                        (file.Name != "efsm_core.c") &&
                        (file.Name != "efsm_binary_protocol.h"))
                    {
                        file.Delete();
                    }
                }

                var fileName = Path.GetFileName(project.GenerationOptions.HeaderFilePath);
                var path     = Path.Combine(projectPath, fileName);

                File.WriteAllText(path, header);

                fileName = Path.GetFileName(project.GenerationOptions.CodeFilePath);
                path     = Path.Combine(projectPath, fileName);

                File.WriteAllText(path, code);
            }
        }
        private void AddStateMachineProject(string fileName)
        {
            StateMachineProject stateMachineProject = _persistor.LoadProject(fileName);

            Project = ApplicationContainer.Container.Resolve <ProjectViewModel>
                      (
                new TypedParameter(typeof(StateMachineProject), stateMachineProject)
                      );
        }
Ejemplo n.º 4
0
        public void GetModel_InsertedStateMachineView_ProjectHasStateMachine()
        {
            var viewModel = new ProjectViewModel(new StateMachineProject(), new ViewService());

            viewModel.StateMachineViewModels.Add(new StateMachineReferenceViewModel(new StateMachine(), new ViewService()));
            StateMachineProject projectModel = viewModel.GetModel();

            Assert.Equal(1, projectModel.StateMachines.Length);
        }
Ejemplo n.º 5
0
        internal ProjectGenerationModel GetGenerationModel(StateMachineProject project)
        {
            //Create the state machines
            //var stateMachines = project.StateMachines.Select(GenerateStateMachine).ToArray();
            List <StateMachineGenerationModel> localStateMachineList = new List <StateMachineGenerationModel>();

            for (int i = 0; i < project.StateMachines.Length; i++)
            {
                localStateMachineList.Add(GenerateStateMachine(project.StateMachines[i], i));
            }

            return(new ProjectGenerationModel(project, localStateMachineList.ToArray()));
        }
        public ProjectViewModel(StateMachineProject project, IMarkDirty dirtyService, IMessageBoxService messageBoxService)
        {
            _project           = project;
            _dirtyService      = dirtyService;
            _messageBoxService = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService));

            if (_project.StateMachines != null)
            {
                StateMachines.AddRange(_project.StateMachines
                                       .Select(sm => ApplicationContainer.Container.Resolve <StateMachineReferenceViewModel>(
                                                   new TypedParameter(typeof(StateMachine), sm),
                                                   new TypedParameter(typeof(IDirtyService), _dirtyService)
                                                   )));
            }

            _generationOptions = new GenerationOptionsViewModel(project.GenerationOptions, dirtyService, _messageBoxService);

            NewStateMachineCommand    = new RelayCommand(NewStateMachine);
            DeleteStateMachineCommand = new RelayCommand(DeleteStateMachine, CanDeleteStateMachine);
            GenerateCommand           = new RelayCommand <string>((s) => GenerateWithNoDebug(s), (s) => CanGenerate(s));
            GenerateAndDebugCommand   = new RelayCommand <string>((s) => GenerateAndDebug(s), (s) => CanGenerate(s));
        }
        public static StateMachineProject CreateSimple()
        {
            Guid state1Id = new Guid("3757ee04-6b20-4f53-8ad9-08d68ad10a16");
            Guid state2Id = new Guid("c5063b61-c6a7-48f0-a895-b604e46d4bcb");

            var state1 = new State()
            {
                Id           = state1Id,
                Name         = "Start State",
                EntryActions = new Guid[] { }
            };

            var state2 = new State()
            {
                Id           = state2Id,
                Name         = "End State",
                EntryActions = new Guid[] { },
            };

            var project = new StateMachineProject()
            {
                StateMachines = new StateMachine[]
                {
                    new StateMachine
                    {
                        States = new State[]
                        {
                            state1,
                            state2
                        }
                    }
                }
            };

            return(project);
        }
Ejemplo n.º 8
0
        public void SaveProject(StateMachineProject project, string path)
        {
            string json = JsonConvert.SerializeObject(project, Formatting.Indented);

            File.WriteAllText(path, json);
        }
        public static void Massage(this StateMachineProject project)
        {
            if (project == null)
            {
                project = new StateMachineProject();
            }

            //options
            if (project.GenerationOptions == null)
            {
                project.GenerationOptions = new GenerationOptions();
            }

            //State machines
            if (project.StateMachines == null)
            {
                project.StateMachines = new StateMachine[] { }
            }
            ;

            //State Machine
            foreach (var stateMachine in project.StateMachines)
            {
                if (stateMachine.Transitions == null)
                {
                    stateMachine.Transitions = new StateMachineTransition[] { };
                }
                else
                {
                    //Transitions
                    foreach (var transition in stateMachine.Transitions)
                    {
                        if (transition.TransitionActions == null)
                        {
                            transition.TransitionActions = new Guid[] { };
                        }
                    }
                }

                //Inputs
                if (stateMachine.Inputs == null)
                {
                    stateMachine.Inputs = new StateMachineInput[] { };
                }

                //Outputs
                if (stateMachine.Actions == null)
                {
                    stateMachine.Actions = new StateMachineOutputAction[] { };
                }

                //States
                if (stateMachine.States == null)
                {
                    stateMachine.States = new State[] { };
                }
                else
                {
                    foreach (var state in stateMachine.States)
                    {
                        if (state.EntryActions == null)
                        {
                            state.EntryActions = new Guid[] { };
                        }

                        if (state.ExitActions == null)
                        {
                            state.ExitActions = new Guid[] { };
                        }
                    }
                }
            }
        }
    }