public static bool Save(String filePath, Profile profile) { StreamWriter writer; FileInfo info=new FileInfo(filePath); try { if (info.Exists) writer = new StreamWriter(filePath); else writer = info.CreateText(); writer.AutoFlush = false; writer.WriteLine(profile.Name); writer.WriteLine(profile.InstructionsCount); for (int i = 0; i < profile.InstructionsCount; ++i) writer.WriteLine(profile[i].phrase + FILE_DATASEPARATOR + (int)profile[i].commandType + FILE_DATASEPARATOR + profile[i].axis + FILE_DATASEPARATOR + profile[i].value + FILE_DATASEPARATOR + profile[i].control + FILE_DATASEPARATOR + profile[i].shift); writer.Flush(); writer.Close(); } catch (Exception) { return false; } return true; }
public static bool Load(String filePath,out Profile profile) { StreamReader reader; int instructionsCount; InstructionData instruction=new InstructionData(); String[] splittedLine; if (File.Exists(filePath)) { reader = new StreamReader(filePath); profile = new Profile(reader.ReadLine()); instructionsCount = Convert.ToInt32(reader.ReadLine()); for (int i = 0; i < instructionsCount; ++i) { profile.AddNewInstruction(); splittedLine = reader.ReadLine().Split(FILE_DATASEPARATOR); instruction.SetPhrase(splittedLine[0]); instruction.commandType = (InstructionData_CommandType)Convert.ToInt32(splittedLine[1]); instruction.axis = Convert.ToInt32(splittedLine[2]); instruction.value = Convert.ToInt32(splittedLine[3]); instruction.control = Convert.ToBoolean(splittedLine[4]); instruction.shift = Convert.ToBoolean(splittedLine[5]); profile[i] = instruction; } return true; } else { profile = null; return false; } }
private void nuevoPerfilToolStripMenuItem_Click(object sender, EventArgs e) { if (!saved) { switch (MessageBox.Show("El perfil '" + profile.Name + "' contiene cambios que no han sido guardados \n ¿Desea guardar antes de continuar?", "Prefil no guardado", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)) { case System.Windows.Forms.DialogResult.Yes: SaveProfile(); profile = new Profile(InputBox.Show("Introduce el nombre del perfil:", "KinectStick - Nuevo perfil", "Perfil " + DateTime.Now.ToShortDateString())); groupBox1.Visible = true; groupBox1.Text = profile.Name + " (Edición)"; FillProfileList(); break; case DialogResult.Cancel: break; case System.Windows.Forms.DialogResult.No: profile = new Profile(InputBox.Show("Introduce el nombre del perfil:", "KinectStick - Nuevo perfil", "Perfil " + DateTime.Now.ToShortDateString())); groupBox1.Visible = true; groupBox1.Text = profile.Name + " (Edición)"; FillProfileList(); break; } } }
private void LoadProfile(String name) { profile = new Profile(name); selectedIndex = -1; saved = true; profileFilePath = ""; profileCompilationFilePath = ""; }
public static CompiledProfile Compile(Profile profile) { return GenerateTree(PreCompile(profile)); }
public static PreCompiledProfile PreCompile(Profile profile) { List<String> phraseLibrary = new List<String>(); List<CompiledSpeechPhrase> generatedPhraseLibrary = new List<CompiledSpeechPhrase>(); List<PreCompiledInstruction> preInstructions = new List<PreCompiledInstruction>(); List<int> indices = new List<int>(); String[] splittedPhrase; int phraseIndex; for (int i = 0; i < profile.InstructionsCount; ++i) { splittedPhrase = profile[i].phrase.Split(PHRASESEPARATOR); indices.Clear(); foreach (String phrase in splittedPhrase) { phraseIndex = phraseLibrary.IndexOf(phrase); if (phraseIndex >= 0) indices.Add(phraseIndex); else { indices.Add(phraseLibrary.Count); phraseLibrary.Add(phrase); } } preInstructions.Add(new PreCompiledInstruction(indices.ToArray(), GenerateCommand(profile[i]))); } for (int i = 0; i < phraseLibrary.Count; ++i) generatedPhraseLibrary.Add(new CompiledSpeechPhrase(phraseLibrary[i], i)); return new PreCompiledProfile(preInstructions.ToArray(), generatedPhraseLibrary.ToArray()); }