コード例 #1
0
        private void loadEditFileTypeWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (ConfigurationDatabase != null)
            {
                try
                {
                    FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase);

                    FileType = fileTypeDAO.GetFileType(FileTypeID);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("Failed to get File Type data. " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (FileType != null)
                {
                    fileTypeIDTextBox.Invoke(new Action(() => fileTypeIDTextBox.Text           = FileType.FileTypeID.ToString()));
                    nameTextBox.Invoke(new Action(() => nameTextBox.Text                       = FileType.Name));
                    delimiterTextBox.Invoke(new Action(() => delimiterTextBox.Text             = FileType.Delimiter.ToString()));
                    storedProcedureTextBox.Invoke(new Action(() => storedProcedureTextBox.Text = FileType.DatabaseStoredProcedureName));

                    headerGroupBox.Invoke(new Action(() => headerGroupBox.Enabled     = true));
                    footerGroupBox.Invoke(new Action(() => footerGroupBox.Enabled     = true));
                    columnGroupBox.Invoke(new Action(() => columnGroupBox.Enabled     = true));
                    settingsGroupBox.Invoke(new Action(() => settingsGroupBox.Enabled = true));

                    try
                    {
                        SettingsDAO settingsDAO = new SettingsDAO(ConfigurationDatabase);
                        Settings = settingsDAO.GetSettingsByFileTypeID(FileTypeID);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("Failed to get Settings data. " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (Settings != null)
                    {
                        useFileNameCheckBox.Invoke(new Action(() => useFileNameCheckBox.Checked                            = Settings.UseFileName));
                        useFileExtensionCheckBox.Invoke(new Action(() => useFileExtensionCheckBox.Checked                  = Settings.UseFileExtension));
                        textToIgnoreFileNameTextBox.Invoke(new Action(() => textToIgnoreFileNameTextBox.Text               = Settings.TextToIgnoreFileName));
                        dateTimeFormatFileNameTextBox.Invoke(new Action(() => dateTimeFormatFileNameTextBox.Text           = Settings.DateTimeFormatFileName));
                        textToIgnoreFileExtensionTextBox.Invoke(new Action(() => textToIgnoreFileExtensionTextBox.Text     = Settings.TextToIgnoreFileExtension));
                        dateTimeFormatFileExtensionTextBox.Invoke(new Action(() => dateTimeFormatFileExtensionTextBox.Text = Settings.DateTimeFormatFileExtension));
                        linkDateTimeCheckBox.Invoke(new Action(() => linkDateTimeCheckBox.Checked                          = Settings.LinkDateTime));
                        dateTimeColumnTextBox.Invoke(new Action(() => dateTimeColumnTextBox.Text                           = Settings.DateTimeColumn));
                        dateTimeFormatLinkDateTextBox.Invoke(new Action(() => dateTimeFormatLinkDateTextBox.Text           = Settings.DateTimeFormatLinkDate));
                        truncateTableCheckBox.Invoke(new Action(() => truncateTableCheckBox.Checked                        = Settings.TruncateTable));
                    }

                    try
                    {
                        HeaderDAO headerDAO = new HeaderDAO(ConfigurationDatabase);
                        Headers = headerDAO.GetHeadersByFileTypeID(FileTypeID);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("Failed to get Header data. " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (Headers != null)
                    {
                        foreach (Header header in Headers)
                        {
                            headerDataGridView.Invoke(new Action(() => headerDataGridView.Rows.Add(header.HeaderNumber.ToString(), header.HeaderName)));
                        }
                    }

                    try
                    {
                        ColumnDAO columnDAO = new ColumnDAO(ConfigurationDatabase);
                        Columns = columnDAO.Read(FileTypeID);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("Failed to get Column data. " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (Columns != null)
                    {
                        foreach (Column column in Columns)
                        {
                            columnDataGridView.Invoke(new Action(() => columnDataGridView.Rows.Add(column.ColumnNumber.ToString(), column.ColumnName, column.DatabaseColumnName, column.Ignore, column.NotInFile)));
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void Start()
        {
            try
            {
                if (!EventLog.SourceExists(Name))
                {
                    EventLog.CreateEventSource(Name, "File Reader Service");
                }

                eventLog = new EventLog();

                eventLog.Log    = "File Reader Service";
                eventLog.Source = Name;
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed to setup event viewer logging. " + exception.Message);
            }

            try
            {
                if (ConfigurationDatabase != null)
                {
                    FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase);
                    FileType = fileTypeDAO.GetFileType(FileTypeID);

                    SettingsDAO settingsDAO = new SettingsDAO(ConfigurationDatabase);
                    FileType.Settings = settingsDAO.GetSettingsByFileTypeID(FileTypeID);

                    ColumnDAO columnDAO = new ColumnDAO(ConfigurationDatabase);
                    FileType.Columns = columnDAO.Read(FileTypeID);

                    HeaderDAO headerDAO = new HeaderDAO(ConfigurationDatabase);
                    FileType.Headers = headerDAO.GetHeadersByFileTypeID(FileTypeID);

                    FooterDAO footerDAO = new FooterDAO(ConfigurationDatabase);
                    FileType.Footers = footerDAO.GetFootersByFileTypeID(FileTypeID);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed to get file type information from configuration database. " + exception.Message);

                if (eventLog != null)
                {
                    eventLog.WriteEntry("Failed to get file type information from configuration database. " + exception.Message, EventLogEntryType.Error);
                }
            }

            try
            {
                FileSystemWatcher                     = new FileSystemWatcher(Directory, "*.*");
                FileSystemWatcher.Changed            += new FileSystemEventHandler(OnChanged);
                FileSystemWatcher.NotifyFilter        = NotifyFilters.LastWrite;
                FileSystemWatcher.EnableRaisingEvents = true;
            }
            catch (Exception exception)
            {
                Console.WriteLine("Failed to setup file system watcher. " + exception.Message);

                if (eventLog != null)
                {
                    eventLog.WriteEntry("Failed to setup file system watcher. " + exception.Message, EventLogEntryType.Error);
                }
            }
        }