public ActionResult Create(FormCollection collection) { try { var model = new PropertyAdvisor(); TryUpdateModel(model, collection); model.CreatedAt = DateTime.Now; model.CreatedBy = "SYSTEM"; if (!ModelState.IsValid) { FlashError("数据验证未通过,请检查是否存在为空的必填项"); return(View(model)); } model.CreatedAt = DateTime.Now; model.CreatedBy = "SYSTEM"; var service = new PropertyAdvisorAccountService(); var r = service.Create(model.Name, model.MobileNo, model.Title.Equals("案场经理"), model.ProjectNo); if (r.HasError) { FlashMessage(r); return(View(model)); } return(RedirectToAction("Index")); } catch (Exception e) { return(View()); } }
public ActionResult Edit(int id, FormCollection collection) { var model = new PropertyAdvisor(); TryUpdateModel(model, collection); if (!ModelState.IsValid) { FlashError("数据验证未通过,请检查是否存在为空的必填项"); return(View(model)); } model.UpdatedBy = "SYSTEM"; model.UpdatedAt = DateTime.Now; var service = new PropertyAdvisorAccountService(); var r1 = service.Remove(model.No, model.ProjectNo); if (r1.HasError) { FlashMessage(r1); return(View(model)); } var r2 = service.Create(model.Name, model.MobileNo, model.Title.Equals("案场经理"), model.ProjectNo); if (r2.HasError) { FlashMessage(r2); return(View(model)); } return(RedirectToAction("Index")); }
public void OpenModelInExternalTool(BlockViewModel model) { var parameters = PropertyAdvisor.GetExternalToolParameter(model.BlockModel.Parameters, "Overture"); var arg = parameters.First(parm => parm.Key == PropertyAdvisor.ARGUMENT).Value; var proj = parameters.First(parm => parm.Key == PropertyAdvisor.PROJECT).Value; var processname = parameters.First(parm => parm.Key == PropertyAdvisor.TOOL).Value; if (!(processname.IsNullOrEmpty() || proj.IsNullOrEmpty())) { var commands = string.Format("{0} {1}", arg, proj); Task.Factory.StartNew(() => { SimpleProcessSpawner.Start(processname, commands); }); } }
public void CreateModel(Block block, object content) { var model = modelFactory.CreateModel(); model.Content = content; model.BlockModel = block; model.Height = 100; model.Width = 70; //TODO: just for testing. customization can be added var keyStem = "Overture"; PropertyAdvisor.SetSelectedExternalToolParameter(block.Parameters, keyStem); PropertyAdvisor.SetExternalToolParameter(block.Parameters, keyStem, string.Empty, string.Empty, string.Empty, string.Empty); PropertyAdvisor.SetExternalResultLocationParameter(block.Parameters, keyStem, string.Empty); AddModel(model); }
private void UpdateConfiguration() { //TODO: simulate each sub-model //resultUpdater.WatchFile(filename); var configs = from item in Watched group item by item.Parent into p select new { PARENT = p.Key, items = p.ToList() }; foreach (var config in configs.ToList()) { var selected = PropertyAdvisor.GetSelectedExternalToolParameter(config.PARENT.Parameters); var path = PropertyAdvisor.GetExternalResultLocationParameter(config.PARENT.Parameters, selected); //TODO: add each config/connector from result file to graph //foreach (var item in config.items) //{ // resultUpdater.ForceUpdate(path); //} resultUpdater.ForceUpdate(path); } }
public MainWindow() { // Dependency injection framework var kernel = new StandardKernel(new InjectModule()); var modelManager = kernel.Get <IModelManager>(); var simManager = kernel.Get <ISimulationManager>(); InitializeComponent(); ParamList.ItemsSource = new Dictionary <string, string>(); PlotView.Model = simManager.Results; AlgorithmSelector.ItemsSource = new List <string> { "Fixed Step-size", "Variable Step-size" }; var scriptList = new List <ScriptConfigurationItemModel> { new ScriptConfigurationItemModel { Location = "SensorFail1", Use = false }, new ScriptConfigurationItemModel { Location = "SensorFail2", Use = false }, new ScriptConfigurationItemModel { Location = "MotorInput", Use = true }, }; scriptListCosim.ItemsSource = scriptList; scriptListDse.ItemsSource = scriptList; var watchedBind = new Binding { Source = simManager, Path = new PropertyPath("Watched"), Mode = BindingMode.OneWay }; WatchedResultVar.SetBinding(ListBox.ItemsSourceProperty, watchedBind); var dseParamBind = new Binding { Source = simManager, Path = new PropertyPath("DSEParameters"), Mode = BindingMode.OneWay }; DseParameterList.SetBinding(DataGrid.ItemsSourceProperty, dseParamBind); var dseProgressBind = new Binding { Source = simManager, Path = new PropertyPath("DseProgress"), Mode = BindingMode.OneWay }; DseProgressBar.SetBinding(ProgressBar.ValueProperty, dseProgressBind); DseProgressLabel.SetBinding(TextBlock.TextProperty, dseProgressBind); var cosimProgressBind = new Binding { Source = simManager, Path = new PropertyPath("CosimProgress"), Mode = BindingMode.OneWay }; CosimProgressBar.SetBinding(ProgressBar.ValueProperty, cosimProgressBind); CosimProgressLabel.SetBinding(TextBlock.TextProperty, cosimProgressBind); modelManager.OnModelAdded += AddModel; modelManager.OnModelRemoved += RemoveModel; modelManager.OnViewModelParameters += UpdateParams; DiagramCanvas.OnModelCreate += p => modelManager.CreateModel(p.X, p.Y); DiagramCanvas.OnConnectionAdded += c => modelManager.AddConnection(c); modelManager.OnEntitiesUpdated += (sender, args) => { simManager.ConfigureConnections(); NotWatchedResultVar.ItemsSource = simManager.NotWatched; DataGridInputOptions.ItemsSource = simManager.Watchable; }; AddWatchableResultVarButton.Click += (sender, e) => { var item = NotWatchedResultVar.SelectedValue as ConfigurationItemModel; if (item != null) { simManager.WatchVariable(item); NotWatchedResultVar.ItemsSource = simManager.NotWatched; } }; WatchedResultVar.KeyDown += (sender, e) => { if (e.Key == Key.Delete) { var item = WatchedResultVar.SelectedValue as ConfigurationItemModel; simManager.UnWatchVariable(item); NotWatchedResultVar.ItemsSource = simManager.NotWatched; } }; BrowseOutputLocationButton.Click += (s, e) => { var dialog = new FolderBrowserDialog(); var result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { BrowseOutputLocationBox.Text = dialog.SelectedPath; } }; CosimulationButton.Click += (sender, e) => { simManager.Cosimulate(); }; StopSimulationButton.Click += (sender, e) => { simManager.StopSimulation(); }; DseButton.Click += (sender, e) => { simManager.DesignSpaceExplore(); }; StopDseButton.Click += (sender, e) => { simManager.StopSimulation(); }; #region model var connector2 = new Connector() { Type = Direction.OUT, Name = "C2" }; var connectors = new PropertyObservingCollection <Connector>() { new Connector() { Type = Direction.IN, Name = "C1" }, connector2, new Connector() { Type = Direction.OUT, Name = "C3" }, }; var block1 = new Block() { Name = "Block1", Position = new Point(60, 100), Connectors = connectors }; var connector4 = new Connector() { Type = Direction.IN, Name = "C4" }; var connectors2 = new PropertyObservingCollection <Connector>() { connector4 }; var block2 = new Block() { Name = "Block2", Position = new Point(300, 100), Connectors = connectors2 }; var selected = "Overture"; PropertyAdvisor.SetSelectedExternalToolParameter(block2.Parameters, selected); PropertyAdvisor.SetExternalToolParameter(block2.Parameters, "Overture", @"C:\Study\Overture\Overture.exe", @"C:\Users\Sam\Documents\Overture\workspace\Nested", "-import", string.Empty); PropertyAdvisor.SetExternalResultLocationParameter(block2.Parameters, selected, @"C:\Users\Sam\Desktop\data2.csv"); PropertyAdvisor.SetSelectedExternalToolParameter(block1.Parameters, selected); PropertyAdvisor.SetExternalToolParameter(block1.Parameters, "Overture", @"C:\Study\Overture\Overture.exe", @"C:\Users\Sam\Documents\Overture\workspace\TestProject", "-import", string.Empty); PropertyAdvisor.SetExternalResultLocationParameter(block1.Parameters, selected, @"C:\Users\Sam\Desktop\data.csv"); // Creating a new Block using the manager //modelManager.CreateModel(block1); //modelManager.CreateModel(block2); #endregion model ImportModelButton.Click += (s, e) => { #region LineFollower Robot Model var controllerConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "sensorSignalLeft", Type = Direction.IN, DataType = "Real" }, new Connector { Name = "sensorSignalRight", Type = Direction.IN, DataType = "Real" }, new Connector { Name = "motorSignalLeft", Type = Direction.OUT, DataType = "Real" }, new Connector { Name = "motorSignalRight", Type = Direction.OUT, DataType = "Real" }, new Connector { Name = "encoderSignalLeft", Type = Direction.IN, DataType = "Real" }, new Connector { Name = "encoderSignalRight", Type = Direction.IN, DataType = "Real" } }; var bodyConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "toBodyLeft", Type = Direction.IN, DataType = "TranslationalForce" }, new Connector { Name = "toBodyRight", Type = Direction.IN, DataType = "TranslationalForce" }, new Connector { Name = "robotPosition", Type = Direction.OUT, DataType = "Position" } }; var lineConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "robotPosition", Type = Direction.IN, DataType = "Position" }, new Connector { Name = "opticalReflectionLeft", Type = Direction.OUT, DataType = "Real" }, new Connector { Name = "opticalReflectionRight", Type = Direction.OUT, DataType = "Real" } }; var motorLeftConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "motorSignalLeft", Type = Direction.IN, DataType = "Real" }, new Connector { Name = "toEncoderLeft", Type = Direction.OUT, DataType = "RotationForce" }, new Connector { Name = "toWheelLeft", Type = Direction.OUT, DataType = "RotationForce" } }; var encoderLeftConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "toEncoderLeft", Type = Direction.IN, DataType = "RotationForce" }, new Connector { Name = "encoderSignalLeft", Type = Direction.OUT, DataType = "Real" }, }; var wheelLeftConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "toWheelLeft", Type = Direction.IN, DataType = "RotationForce" }, new Connector { Name = "toBodyLeft", Type = Direction.OUT, DataType = "TranslationalForce" } }; var sensorLeftConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "sensorSignalLeft", Type = Direction.OUT, DataType = "Real" }, new Connector { Name = "opticalReflectionLeft", Type = Direction.IN, DataType = "Real" } }; var motorRightConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "motorSignalRight", Type = Direction.IN, DataType = "Real" }, new Connector { Name = "toEncoderRight", Type = Direction.OUT, DataType = "RotationForce" }, new Connector { Name = "toWheelRight", Type = Direction.OUT, DataType = "RotationForce" } }; var encoderRightConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "toEncoderRight", Type = Direction.IN, DataType = "RotationForce" }, new Connector { Name = "encoderSignalRight", Type = Direction.OUT, DataType = "Real" }, }; var wheelRightConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "toWheelRight", Type = Direction.IN, DataType = "RotationForce" }, new Connector { Name = "toBodyRight", Type = Direction.OUT, DataType = "TranslationalForce" } }; var sensorRightConnectors = new PropertyObservingCollection <Connector> { new Connector { Name = "sensorSignalRight", Type = Direction.OUT, DataType = "Real" }, new Connector { Name = "opticalReflectionRight", Type = Direction.IN, DataType = "Real" } }; // ---------------------------- var line = new Block { Name = "line", Connectors = lineConnectors, Position = new Point(580, 290), }; var controller = new Block { Name = "controller", Connectors = controllerConnectors, Position = new Point(60, 290), }; var body = new Block { Name = "body", Connectors = bodyConnectors, Position = new Point(450, 290), }; var leftMotor = new Block { Name = "motorLeft", Connectors = motorLeftConnectors, Position = new Point(190, 370), }; var leftEncoder = new Block { Name = "encoderLeft", Connectors = encoderLeftConnectors, Position = new Point(320, 530), }; var leftWheel = new Block { Name = "wheelLeft", Connectors = wheelLeftConnectors, Position = new Point(320, 370), }; var leftSensor = new Block { Name = "sensorLeft", Connectors = sensorLeftConnectors, Position = new Point(710, 370), }; // ---------------------------- var rightMotor = new Block { Name = "motorRight", Connectors = motorRightConnectors, Position = new Point(190, 210), }; var rightEncoder = new Block { Name = "encoderRight", Connectors = encoderRightConnectors, Position = new Point(320, 50), }; var rightWheel = new Block { Name = "wheelRight", Connectors = wheelRightConnectors, Position = new Point(320, 210), }; var rightSensor = new Block { Name = "sensorRight", Connectors = sensorRightConnectors, Position = new Point(710, 210), }; // ----------------------------- modelManager.CreateModel(line); modelManager.CreateModel(controller); modelManager.CreateModel(body); modelManager.CreateModel(leftMotor); modelManager.CreateModel(leftEncoder); modelManager.CreateModel(leftSensor); modelManager.CreateModel(leftWheel); modelManager.CreateModel(rightMotor); modelManager.CreateModel(rightEncoder); modelManager.CreateModel(rightSensor); modelManager.CreateModel(rightWheel); // ------------------------------ PropertyAdvisor.SetSelectedExternalToolParameter(controller.Parameters, selected); PropertyAdvisor.SetExternalToolParameter(controller.Parameters, "Overture", @"C:\Study\Overture\Overture.exe", @"C:\Users\Sam\Documents\Overture\workspace\RobotRT", "-import", string.Empty); PropertyAdvisor.SetExternalResultLocationParameter(controller.Parameters, selected, @"C:\Users\Sam\Desktop\data.csv"); PropertyAdvisor.SetSelectedExternalToolParameter(line.Parameters, selected); PropertyAdvisor.SetExternalToolParameter(line.Parameters, "Overture", @"C:\Study\Overture\Overture.exe", @"C:\Users\Sam\Documents\Overture\workspace\RobotRT", "-import", string.Empty); PropertyAdvisor.SetExternalResultLocationParameter(line.Parameters, selected, @"C:\Users\Sam\Desktop\data2.csv"); #endregion }; //TODO: bind to the model instead of the viewmodel of the connector }
public MessageRecorder <PropertyAdvisor> Create( string name, string phone, bool isManager, string projectNo) { var mr = new MessageRecorder <PropertyAdvisor>(); using (var conn = ConnectionManager.Open()) { var trans = conn.BeginTransaction(); var accountQuery = new Criteria <Account>() .Or(m => m.Phone, Op.Eq, phone) .Or(m => m.Phone2, Op.Eq, phone) .Or(m => m.Phone3, Op.Eq, phone); var account = conn.Get(accountQuery); if (account == null) { account = new Account { No = Guid.NewGuid().ToString("N").ToUpper(), Name = name, Phone = phone, CreatedBy = "SYSTEM", CreatedAt = DateTime.Now, Password = phone + "##", Status = AccountStatus.Type.Normal }; var effectedCount = conn.Insert(account, trans); if (effectedCount == -1) { trans.Rollback(); return(mr.Error("创建账户失败")); } } var q1 = new Criteria <AccountRoleRef>() .Where(m => m.AccountNo, Op.Eq, account.No) .And(m => m.BranchNo, Op.Eq, "420100") .And(m => m.RoleNo, Op.Eq, "PropertyStaff") .Limit(1); if (!conn.Exists(q1)) { var model2 = new AccountRoleRef { AccountNo = account.No, RoleNo = "PropertyStaff", BranchNo = "420100", CreatedAt = DateTime.Now, CreatedBy = "SYSTEM" }; var effectedCount1 = conn.Insert(model2, trans); if (effectedCount1 == -1) { trans.Rollback(); return(mr.Error("账户创建失败,请重试")); } } var query = new Criteria <PropertyAdvisor>() .Where(m => m.No, Op.Eq, account.No) .And(m => m.ProjectNo, Op.Eq, projectNo) .Desc(m => m.No); if (conn.Exists(query)) { trans.Rollback(); return(mr.Error("账户已经存在,不能重复创建")); } var model = new PropertyAdvisor { No = account.No, Name = account.Name, MobileNo = phone, ProjectNo = projectNo, Title = isManager ? "案场经理" : "案场顾问", CreatedBy = "SYSTEM", CreatedAt = DateTime.Now }; var effectedCount2 = conn.Insert(model, trans); if (effectedCount2 == -1) { trans.Rollback(); return(mr.Error("账户创建失败,请重试")); } trans.Commit(); mr.SetValue(model); } return(mr); }