private void OnSaveButtonClick(object sender, RoutedEventArgs e) { bool isSuccess = false; progressWindow = new SaveProgressWindow(); bw = new BackgroundWorker(); //var fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CognitiveLoop", "roboData.xml"); bw.WorkerReportsProgress = true; bw.DoWork += bw_DoWork; bw.ProgressChanged += bw_ProgressChanged; bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.RunWorkerAsync(); //Progress Bar Window progressWindow.Show(); RoboViewModel robo = ((MainViewModel)this.DataContext).RoboViewModel; XmlSerializer serializer = new XmlSerializer(robo.GetType(), App.types); using (XmlTextWriter writer = new XmlTextWriter(App.xmlSource, System.Text.Encoding.UTF8)) { serializer.Serialize(writer, robo); } }
public MainViewModel() { this.Title = $"Cognitive Loop {GetVersionText()}"; this.Zoom = 1.0; this.BoundSpinnerValue = 1; this.IsCheckedToggleButton3 = true; this.ColorViewModel = new ColorViewModel(); this.FontsViewModel = new FontsViewModel(); this.GalleryViewModel = new GalleryViewModel(); this.IssueReprosViewModel = new IssueReprosViewModel(); this.PreviewCommand = new RelayCommand <GalleryItem>(Preview); this.CancelPreviewCommand = new RelayCommand <GalleryItem>(CancelPreview); this.GroupByAdvancedSample = x => ((GallerySampleDataItemViewModel)x).Text.Substring(0, 1); this.memoryTimer = new Timer(TimeSpan.FromSeconds(5).TotalMilliseconds); this.memoryTimer.Elapsed += this.HandleMemoryTimer_Elapsed; this.memoryTimer.Start(); this._RoboViewModel = RoboViewModel.GetInstance(); ////string.Format("{0:##,000}", this.UsedMemory) }
private void AppendNodeRobo(Type[] types, RoboViewModel robo) { PropertyInfo[] listProperties = robo.GetType().GetProperties(); foreach (var property in listProperties) { string nodeName = property.Name; writer.WriteStartElement(nodeName); var valueObj = property.GetValue(robo); if (valueObj != null) { Type returnType = property.GetValue(robo).GetType(); foreach (Type type in types) { if (type == returnType) { var castedObject = Convert.ChangeType(valueObj, type); Type list = this.isEnumerableType(type); if (list != null) { IEnumerable enumerable = (IEnumerable)castedObject; foreach (object item in enumerable) { string className = item.GetType().Name; writer.WriteStartElement(className); AppendNodeSuits(types, item); writer.WriteEndElement(); } } } } } else { string value = ""; //XMLElement element = CreateXMLNode(nodeName, value, null); } writer.WriteEndElement(); } }
public bool Serialize(XmlTextWriter w, RoboViewModel robo) { this.writer = w; Type suitCollectionType = new ObservableCollection <TestSuitViewModel>().GetType(); Type sequenceCollectionType = new ObservableCollection <TestSequenceViewModel>().GetType(); Type stepCollectionType = new ObservableCollection <TestStepViewModel>().GetType(); Type appsCollectionType = new ObservableCollection <AppsViewModel>().GetType(); Type dataSourceCollectionType = new ObservableCollection <DataSourceViewModel>().GetType(); Type variableCollectionType = new ObservableCollection <VariableViewModel>().GetType(); Type stringType = string.Empty.GetType(); Type boolType = bool.TrueString.GetType(); Type intType = int.MinValue.GetType(); Type doubleType = double.MinValue.GetType(); Type suitType = new TestSuitViewModel().GetType(); Type seqType = new TestSequenceViewModel().GetType(); Type stepType = new TestStepViewModel().GetType(); Type appType = new AppsViewModel().GetType(); Type dsType = new DataSourceViewModel().GetType(); Type varType = new VariableViewModel().GetType(); Type[] types = { suitCollectionType, sequenceCollectionType, stepCollectionType, appsCollectionType, dataSourceCollectionType, variableCollectionType, stringType, boolType, intType, doubleType, suitType, seqType, stepType, appType, dsType, varType }; writer.WriteStartDocument(true); writer.Formatting = Formatting.Indented; writer.Indentation = 2; writer.WriteStartElement("Suits"); AppendNodeRobo(types, robo); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); return(true); }
public IActionResult Index(int id = 0) { ResultadoViewModel dados = new ResultadoViewModel(); switch (id) { case 0: //Buscar dados robo dados = new RoboController(_robo).Get().Value; break; #region Cabeça case 1: //Inclinar cabeça para baixo dados = new CabecaController(_robo).InclinarParaBaixo().Value; break; case 2: //Inclinar cabeça para cima dados = new CabecaController(_robo).InclinarParaCima().Value; break; case 3: //Rotação positiva cabeça dados = new CabecaController(_robo).RotacionarCabecaPositivo().Value; break; case 4: //Rotação negavita cabeça dados = new CabecaController(_robo).RotacionarCabecaNegativo().Value; break; #endregion Cabeça #region Braço Esquerdo case 5: //Contrair cotovelo esquerdo dados = new BracoEsquerdoController(_robo).ContrairCotovelo().Value; break; case 6: //Descontrair cotovelo esquerdo dados = new BracoEsquerdoController(_robo).DescontrairCotovelo().Value; break; case 7: //Rotação positiva pulso esquerdo dados = new BracoEsquerdoController(_robo).RotacionarPulsoPositivo().Value; break; case 8: //Rotação negativa pulso esquerdo dados = new BracoEsquerdoController(_robo).RotacionarPulsoNegativo().Value; break; #endregion Braço Esquerdo #region Braço Direito case 9: //Contrair cotovelo esquerdo dados = new BracoDireitoController(_robo).ContrairCotovelo().Value; break; case 10: //Descontrair cotovelo esquerdo dados = new BracoDireitoController(_robo).DescontrairCotovelo().Value; break; case 11: //Rotação positiva pulso esquerdo dados = new BracoDireitoController(_robo).RotacionarPulsoPositivo().Value; break; case 12: //Rotação negativa pulso esquerdo dados = new BracoDireitoController(_robo).RotacionarPulsoNegativo().Value; break; #endregion Braço Direito } RoboViewModel comandosRobo = (RoboViewModel)dados; return(View(comandosRobo)); }