private void BackGround_BuildDataBase(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var bgw = sender as BackgroundWorker;
            String dir = checkBox_DbBUseOutputDir.Checked ? textBox_rgOutDir.Text : textBox_DbBRobotDir.Text;

            if (!Directory.Exists(dir)) {
                bgw.CancelAsync();
                e.Cancel = true;
                bgw.ReportProgress(0);
                MessageBox.Show(String.Format("ERROR: '{0}' doen't exist.", dir));
                return;
            }

            var dirFiles= Directory.GetFiles(dir, String.Format("*.{0}", RobotGenerator.FILEEXTENSION));
            _workingRobotDatabase = new RobotGenerationStorage(textBox_DbBName.Text, (uint)numericUpDown_DbBGeneration.Value);
            for (int i = 0; i < dirFiles.Length; i++) {
                //Console.WriteLine(dirFiles[i]);  // DEBUG
                bgw.ReportProgress((i * 99)/dirFiles.Length);
                RobotEntry re = new RobotEntry((uint)i, dirFiles[i]);  // TODO: Que el ID se coja del nombre del fichero ??? Robot.id.rxt ???
                _workingRobotDatabase.Robots.Add(re);
            }

            //Console.WriteLine(Serializers.Serialize(_workingRobotDatabase));  // DEBUG

            // textBox_DbBSaveAs.Text.IndexOf(@"\", textBox_DbBSaveAs.Text.Length)
            string pattern = @"^(.+){1}\\([^\\]+)$";
            string baseFullPath = Regex.Match(textBox_DbBSaveAs.Text, pattern).Groups[1].Value;
            baseFullPath = Directory.Exists(baseFullPath) ? textBox_DbBSaveAs.Text : textBox_DbBName.Text + '.' + RobotGenerationStorage.FILE_EXTENSION;
            File.WriteAllText(baseFullPath, Serializers.Serialize(_workingRobotDatabase));
            bgw.ReportProgress(100);
        }
예제 #2
0
 public static string Serialize(RobotEntry re)
 {
     XmlSerializer xs = null;
     try {
         xs = new XmlSerializer(typeof(RobotEntry));
     }catch (Exception e){
         Console.WriteLine("########## ERROR ##########");
         Console.WriteLine(e.HelpLink);
         Console.WriteLine(e.Source);
         Console.WriteLine(e.ToString());
         Console.WriteLine(e.StackTrace);
         Console.WriteLine("########## ERROR ##########");
     }
     string result = String.Empty;
     using (StringWriter sw = new StringWriter()) using (XmlTextWriter xw = new XmlTextWriter(sw) { Formatting = Formatting.Indented }) {
         xs.Serialize(xw, re);
         result = sw.ToString();
     }
     return result;
 }