コード例 #1
0
 public void LoadStr(string contents, AbstractEasyParser parser, IContentExtractor extractor = null)
 {
     Parser = parser;
     if (extractor != null)
     {
         using (TextReader tr = new StringReader(contents))
         {
             TextReader extractedContents = extractor.GetTextReader(tr);
             contents = extractedContents.ReadToEnd();
         }
     }
     if (Parser != null)
     {
         Parser.OnRowAdd   += OnRowAdd;
         Parser.OnError    += OnError;
         Parser.OnProgress += OnProgress;
         Parser.LoadStr(contents, this);
         Parser.OnRowAdd   -= OnRowAdd;
         Parser.OnError    -= OnError;
         Parser.OnProgress -= OnProgress;
     }
     else
     {
         LoadXml(contents);
     }
     Transform();
 }
コード例 #2
0
 public void Load(TextReader txtReader, AbstractEasyParser parser, IContentExtractor extractor = null)
 {
     Parser = parser;
     if (extractor != null)
     {
         txtReader = extractor.GetTextReader(txtReader);
     }
     Load(txtReader);
 }
コード例 #3
0
 public void Load(Stream inStream, AbstractEasyParser parser, IContentExtractor extractor = null)
 {
     Parser = parser;
     if (extractor != null)
     {
         inStream = extractor.GetStream(inStream);
     }
     Load(inStream);
 }
コード例 #4
0
 public void Load(string filename, AbstractEasyParser parser, IContentExtractor extractor = null)
 {
     Parser = parser;
     if (extractor != null)
     {
         Stream inStream = extractor.GetStream(filename);
         Load(inStream);
     }
     else
     {
         Load(filename);
     }
 }
コード例 #5
0
        public void LoadDataToGridView()
        {
            if (stopWatch.IsRunning)
            {
                stopWatch.Stop();
            }
            if ((tabDataSource.SelectedTab == tabDatasourceText) && (txtTextContents.TextLength == 0))
            {
                return;
            }
            if ((tabDataSource.SelectedTab == tabDatasourceFile) && (txtFileName.TextLength == 0))
            {
                return;
            }
            if ((tabDataSource.SelectedTab == tabDatasourceDatabase) && (String.IsNullOrWhiteSpace(cmbDatasource.Text)))
            {
                return;
            }
            AbstractFileEasyEndpoint endpoint = null;

            if (tabDataSource.SelectedTab == tabDatasourceFile)
            {
                endpoint = GetEndpoint();
                if (endpoint == null)
                {
                    return;
                }
                if (endpoint.GetList(txtFileName.Text).Length == 0)
                {
                    return;
                }
            }
            stopWatch.Restart();
            intAutoNumber      = 0;
            this.UseWaitCursor = true;
            Application.DoEvents();
            lblRecordCount.Text   = "";
            txtRegexContents.Text = "";
            cmbTableName.Items.Clear();
            AbstractContentExtractor extractor = null;

            if ((chkUseTextExtractor.Checked) && (EasyETLEnvironment.Extractors.Find(e => e.DisplayName == cbTextExtractor.Text) != null))
            {
                extractor = (AbstractContentExtractor)Activator.CreateInstance(EasyETLEnvironment.Extractors.Find(e => e.DisplayName == cbTextExtractor.Text).Class);
            }
            try
            {
                EasyXmlDocument xDoc = new EasyXmlDocument();
                xDoc.OnProgress += xDoc_OnProgress;
                if (tabDataSource.SelectedTab == tabDatasourceDatabase)
                {
                    DatasourceEasyParser dbep = null;
                    if ((cmbDatasource.SelectedItem != null) && (ClientConfiguration.Datasources.Find(ds => ds.ActionName == cmbDatasource.SelectedItem.ToString()) != null))
                    {
                        dbep = ClientConfiguration.Datasources.Find(ds => ds.ActionName == cmbDatasource.SelectedItem.ToString()).CreateDatasource();
                        if (chkHasMaxRows.Checked)
                        {
                            dbep.MaxRecords = Convert.ToInt64(nudMaxRows.Value);
                        }
                        xDoc.LoadXml(dbep.Load(txtDatabaseQuery.Text).OuterXml);
                    }
                }
                else
                {
                    AbstractEasyParser ep = null;
                    if (ClientConfiguration.Parsers.Where(p => p.ActionName == cmbParserProfile.Text).Count() > 0)
                    {
                        ep = ClientConfiguration.Parsers.Find(p => p.ActionName == cmbParserProfile.Text).CreateParser();
                    }

                    if ((ep == null) && (EasyETLEnvironment.Parsers.Where(p => p.DisplayName == cmbParserProfile.Text).Count() > 0))
                    {
                        ClassMapping parserClassMapping = EasyETLEnvironment.Parsers.Where(p => p.DisplayName == cmbParserProfile.Text).First();
                        ep = (AbstractEasyParser)Activator.CreateInstance(parserClassMapping.Class);
                    }

                    if (ep != null)
                    {
                        ep.ProgressInterval = 100;
                        if (chkHasMaxRows.Checked)
                        {
                            ep.MaxRecords = Convert.ToInt64(nudMaxRows.Value);
                        }
                        if (!String.IsNullOrWhiteSpace(txtOnLoadContents.Text))
                        {
                            ep.OnLoadSettings = txtOnLoadContents.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                        }
                        if ((tabDataSource.SelectedTab == tabDatasourceFile))
                        {
                            Stream fileStream = endpoint.GetStream(txtFileName.Text);
                            if (extractor != null)
                            {
                                extractor.FileName = txtFileName.Text;
                            }
                            xDoc.Load(fileStream, ep, extractor);
                        }
                        else
                        {
                            xDoc.LoadStr(txtTextContents.Text, ep, extractor);
                        }
                        txtExceptions.Text = "";
                        if ((ep != null) && (ep.Exceptions.Count > 0))
                        {
                            MessageBox.Show("There were " + ep.Exceptions.Count + " Exceptions while loading the document");
                            foreach (MalformedLineException mep in ep.Exceptions)
                            {
                                txtExceptions.Text += String.Format("(Line {0} - {1}", mep.LineNumber, mep.Message) + Environment.NewLine;
                            }
                        }
                    }
                }
                ezDoc = xDoc;
                try
                {
                    TransformDataFromEzDoc();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Transforming document." + Environment.NewLine + ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading contents..." + Environment.NewLine + ex.Message);
            }
            endpoint           = null;
            this.UseWaitCursor = false;
        }