public async Task <bool> Create(FileType FileType) { FileTypeDAO FileTypeDAO = new FileTypeDAO(); FileTypeDAO.Id = FileType.Id; FileTypeDAO.Code = FileType.Code; FileTypeDAO.Name = FileType.Name; DataContext.FileType.Add(FileTypeDAO); await DataContext.SaveChangesAsync(); FileType.Id = FileTypeDAO.Id; await SaveReference(FileType); return(true); }
private void removeFileTypeButton_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure you want to delete this File Type?", "Remove File Type", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { int fileTypeID; DataGridViewRow fileTypeRow; if (fileTypeGridView.Rows.Count > 0) { fileTypeRow = fileTypeGridView.CurrentRow; fileTypeID = Convert.ToInt32(fileTypeRow.Cells["fileTypeID"].Value); try { FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase); fileTypeDAO.Delete(fileTypeID); SettingsDAO settingsDAO = new SettingsDAO(ConfigurationDatabase); settingsDAO.Delete(fileTypeID); ColumnDAO columnDAO = new ColumnDAO(ConfigurationDatabase); columnDAO.DeleteAll(fileTypeID); HeaderDAO headerDAO = new HeaderDAO(ConfigurationDatabase); headerDAO.DeleteAll(fileTypeID); FooterDAO footerDAO = new FooterDAO(ConfigurationDatabase); footerDAO.DeleteAll(fileTypeID); FileTypes = fileTypeDAO.GetAllFileTypes(); if (FileTypes != null) { fileTypeGridView.Rows.Remove(fileTypeRow); fileTypeGridView.Refresh(); } } catch (Exception exception) { MessageBox.Show("Failed to remove File Source. " + exception.Message, "File Source Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public async Task <bool> BulkMerge(List <FileType> FileTypes) { List <FileTypeDAO> FileTypeDAOs = new List <FileTypeDAO>(); foreach (FileType FileType in FileTypes) { FileTypeDAO FileTypeDAO = new FileTypeDAO(); FileTypeDAO.Id = FileType.Id; FileTypeDAO.Code = FileType.Code; FileTypeDAO.Name = FileType.Name; FileTypeDAOs.Add(FileTypeDAO); } await DataContext.BulkMergeAsync(FileTypeDAOs); return(true); }
public async Task <bool> Update(FileType FileType) { FileTypeDAO FileTypeDAO = DataContext.FileType.Where(x => x.Id == FileType.Id).FirstOrDefault(); if (FileTypeDAO == null) { return(false); } FileTypeDAO.Id = FileType.Id; FileTypeDAO.Code = FileType.Code; FileTypeDAO.Name = FileType.Name; await DataContext.SaveChangesAsync(); await SaveReference(FileType); return(true); }
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))); } } } } }
private void loadConfigurationWorker_DoWork(object sender, DoWorkEventArgs e) { if (!EventLog.SourceExists("File Reader Tool")) { EventLog.CreateEventSource("File Reader Tool", "File Reader Service"); } eventLog = new EventLog(); eventLog.Log = "File Reader Service"; eventLog.Source = "File Reader Tool"; try { ConfigurationDatabase = LocalConfigurationDatabase.GetConfigurationDatabase(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Configuration Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (ConfigurationDatabase != null) { try { CollectionDatabaseConfiguration collectionDatabaseConfiguration = new CollectionDatabaseConfiguration(ConfigurationDatabase); CollectionDatabase = collectionDatabaseConfiguration.GetCollectionDatabase(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Collection Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (CollectionDatabase != null) { try { CollectionDatabase.CreateOpenConnection(); connectedLabel.Invoke(new Action(() => connectedLabel.Text = "Connected")); } catch (Exception exception) { MessageBox.Show(exception.Message, "Collection Database", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (CollectionDatabase != null) { databaseTypeTextBox.Invoke(new Action(() => databaseTypeTextBox.Text = CollectionDatabase.DatabaseType.ToString())); dataSourceTextBox.Invoke(new Action(() => dataSourceTextBox.Text = CollectionDatabase.DataSource)); hostTextBox.Invoke(new Action(() => hostTextBox.Text = CollectionDatabase.Host)); portTextBox.Invoke(new Action(() => portTextBox.Text = CollectionDatabase.Port.ToString())); usernameTextBox.Invoke(new Action(() => usernameTextBox.Text = CollectionDatabase.Username)); passwordTextBox.Invoke(new Action(() => passwordTextBox.Text = CollectionDatabase.Password)); } try { FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase); FileTypes = fileTypeDAO.GetAllFileTypes(); } catch (Exception exception) { MessageBox.Show("Failed to get File Type Configuration. " + exception.Message, "File Type Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (FileTypes != null) { try { foreach (FileType fileType in FileTypes) { fileTypeGridView.Invoke(new Action(() => fileTypeGridView.Rows.Add(fileType.FileTypeID.ToString(), fileType.Name, fileType.Delimiter, fileType.DatabaseStoredProcedureName))); } } catch (Exception exception) { } } try { FileSourceDAO fileSourceDAO = new FileSourceDAO(ConfigurationDatabase); FileSources = fileSourceDAO.GetAllFileSources(); } catch (Exception exception) { MessageBox.Show("Failed to get File Source Configuration. " + exception.Message, "File Source Configuration", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (FileSources != null) { try { foreach (FileSource fileSource in FileSources) { fileSourceGridView.Invoke(new Action(() => fileSourceGridView.Rows.Add(fileSource.FileTypeID.ToString(), fileSource.Name.ToString(), fileSource.Directory.ToString()))); } } catch (Exception exception) { } } } }
private void createFileTypeButton_Click(object sender, EventArgs e) { FileType = new FileType(); if (nameTextBox.Text != "") { FileType.Name = nameTextBox.Text; } else { MessageBox.Show("File Type name cannot be an empty string.", "Enter Name", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (delimiterTextBox.Text != "") { try { FileType.Delimiter = delimiterTextBox.Text; } catch (Exception exception) { MessageBox.Show("Delimiter must be a single character. " + exception.Message, "Delimiter", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Delimiter cannot be an empty string.", "Enter Delimiter", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (storedProcedureTextBox.Text != "") { FileType.DatabaseStoredProcedureName = storedProcedureTextBox.Text; } else { MessageBox.Show("Procedure cannot be an empty string.", "Enter Procedure", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (ConfigurationDatabase != null) { try { FileTypeDAO fileTypeDAO = new FileTypeDAO(ConfigurationDatabase); int result = fileTypeDAO.CreateFileType(FileType); if (result == 0) { MessageBox.Show("Failed to create the file type. Make sure to use a unique name and check the configuration database connection.", "Failed To Create File Type", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { FileType.FileTypeID = result; fileTypeIDTextBox.Text = result.ToString(); headerGroupBox.Enabled = true; footerGroupBox.Enabled = true; columnGroupBox.Enabled = true; settingsGroupBox.Enabled = true; FileTypeID = result; DataGridView.Invoke(new Action(() => DataGridView.Rows.Add(FileType.FileTypeID, FileType.Name, FileType.Delimiter, FileType.DatabaseStoredProcedureName))); } } catch (Exception exception) { MessageBox.Show("Failed to create new file type. " + exception.Message, "Create New File Type", MessageBoxButtons.OK, MessageBoxIcon.Error); FileType = null; } } }
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); } } }