コード例 #1
0
        public CanadaGooseModel LoadAdhocDate(string adhocFile)
        {
            CanadaGooseModel newCGFile = new CanadaGooseModel();

            using (StringReader reader = new StringReader(adhocFile))
            {
                string line;
                int    i = 0;
                while ((line = reader.ReadLine()) != null)
                {
                    if (i == 1)
                    {
                        CanadaGooseHeader header = CanadaGooseHeader.FromCsv(line);
                        //DoSomething(line); or //save line into List<string>
                        newCGFile.CGHeader.Add(header);
                    }

                    if (i > 2)
                    {
                        CanadaGooseSingleLine newLine = CanadaGooseSingleLine.FromCsv(line);
                        newCGFile.AllCGLines.Add(newLine);
                    }

                    i++;
                }
            }

            return(newCGFile);
        }
コード例 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string fileName = null;
            //SELECT FILE

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title            = "Select Canada Goose File";
            openFileDialog1.Multiselect      = false;
            openFileDialog1.CheckFileExists  = true;
            openFileDialog1.CheckPathExists  = true;
            openFileDialog1.DefaultExt       = "txt";
            openFileDialog1.Filter           = "TXT files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.ReadOnlyChecked  = true;
            openFileDialog1.ShowReadOnly     = true;

            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                foreach (string filename in openFileDialog1.FileNames)
                {
                    fileName = filename;
                }
            }

            string content = System.IO.File.ReadAllText(fileName);

            //FIX LINE ENDINGS
            content = Regex.Replace(content, @"\n", "");
            content = Regex.Replace(content, @"\r", "\r\n");

            var invalidPathChars = content.Where(Path.GetInvalidPathChars().Contains).ToArray();

            if (invalidPathChars.Length > 0)
            {
                Console.WriteLine("invalid path chars: " + string.Join(string.Empty, invalidPathChars));
            }

            //Load data from the file
            newCGFile = LoadAdhocDate(content);

            //TODO: Add verification of the data to ensure the current process doesnt blow up
            //TODO: Auto-augment the data for known data issues?

            DataTable table = new DataTable();

            table = ToDataTable <CanadaGooseHeader>(newCGFile.CGHeader);
            HeaderDG.ItemsSource = newCGFile.CGHeader;

            DataTable table2 = new DataTable();

            table2             = ToDataTable <CanadaGooseSingleLine>(newCGFile.AllCGLines);
            LineDG.ItemsSource = newCGFile.AllCGLines;
        }
コード例 #3
0
        public CanadaGooseAugmentWindow(CanadaGooseModel currentCGData, DataGrid headerGrid, DataGrid lineGrid)
        {
            cgData   = currentCGData;
            headerDG = headerGrid;
            lineDG   = lineGrid;

            InitializeComponent();

            CanadaGooseFunction newCGFunction = new CanadaGooseFunction();

            augmentFilePath = newCGFunction.GetAugmentFilePath();

            allAugments.AllAugments = newCGFunction.LoadAugments(augmentFilePath);
        }