Exemplo n.º 1
0
        public Visualiser()
        {
            InitializeComponent();

            //sourceFile = "../../Resources/salestable.xml";
            //tvvm = new TreeViewViewModel(sourceFile);
            //ModelTreeView.DataContext = tvvm;
            myToolbox = new Toolbox();
            //string elementsFile = DirectoryHelper.getFilePath("Resources\\ToolBoxItems.xml");
            //loadToolboxes(elementsFile);

            suggestions = new ObservableCollection<Suggestion>();
            suggestionsListBox.ItemsSource = suggestions;

            //initiate the scheduling canvas
            initiateSchedulingCanvas();

            prettyPrinter = new XmlPrettyPrinter();

            ShowSample = false;//set popup for sample to false

            popupTimer = new System.Windows.Threading.DispatcherTimer();
            popupTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            popupTimer.Interval = new TimeSpan(0, 0, 2);

            logger = new Logger("VisualiserLogger");
            logsTab.Content = logger;
        }
Exemplo n.º 2
0
        public void ConvertToXML(string CSVFile, string XMLoutputFile)
        {
            //Read CSV file
            using (CsvReader csvReader = new CsvReader(new StreamReader(CSVFile), true))
            {
                int fieldCount = csvReader.FieldCount;

                //MessageBox.Show("Field count : " + fieldCount.ToString());

                //read headers
                string[] headers = csvReader.GetFieldHeaders();

                XmlWriter writer = XmlWriter.Create(XMLoutputFile);

                try
                {
                    using (writer)
                    {

                        writer.WriteStartDocument();

                        writer.WriteStartElement("Root");

                        //read the rest of the file
                        while (csvReader.ReadNextRecord())
                        {
                            //create data element
                            writer.WriteStartElement("Data");

                            //reade each row
                            for (int i = 0; i < fieldCount; i++)
                            {
                                //check the value for illigal XML characters
                                StringBuilder buffer = new StringBuilder(csvReader[i].Length);
                                foreach (char c in csvReader[i])
                                {
                                    if (IsLegalXmlChar(c))
                                    {
                                        buffer.Append(c);
                                    }
                                }

                                writer.WriteElementString(headers[i], buffer.ToString());

                            }

                            //write end data element
                            writer.WriteEndElement();
                        }

                        //write end root element
                        writer.WriteEndElement();

                        //write end document
                        writer.WriteEndDocument();
                    }
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                        XmlPrettyPrinter printer = new XmlPrettyPrinter();
                        printer.PrintXmlFile(XMLoutputFile);
                    }
                }
            }

            //return csvDoc;
        }