private void importToolStripButton_Click(object sender, EventArgs e) { using (var dialog = new ExportOpenFileDialog(_directory, "Open STB Device Export File", ImportExportType.Printer)) { if (dialog.ShowDialog() == DialogResult.OK) { var file = dialog.Base.FileName; _directory = Path.GetDirectoryName(file); using (AssetInventoryContext context = DbConnect.AssetInventoryContext()) { var contracts = LegacySerializer.DeserializeDataContract <AssetContractCollection <PrinterContract> >(File.ReadAllText(file)); foreach (var contract in contracts) { var printer = ContractFactory.Create(contract, context); AddPrinter(printer); } } } } }
private void importToolStripButton_Click(object sender, EventArgs e) { try { using (var dialog = new ExportOpenFileDialog(_directory, "Open Test Document Export File", ImportExportType.Document)) { if (dialog.ShowDialog() == DialogResult.OK) { var file = dialog.Base.FileName; _directory = Path.GetDirectoryName(file); var contracts = LegacySerializer.DeserializeDataContract <DocumentContractCollection>(File.ReadAllText(file)); foreach (var contract in contracts) { if (!_context.TestDocuments.Any(x => x.FileName.Equals(contract.FileName, StringComparison.OrdinalIgnoreCase))) { var document = ContractFactory.Create(_context, contract); _importedDocumentData.Add(document.TestDocumentId, contract.Data); AddDocument(document); } else { // Log an error for the current file, but keep going TraceFactory.Logger.Debug("Document already exists: {0}".FormatWith(contract.FileName)); } } MessageBox.Show("Documents have been imported", "Import Documents", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { TraceFactory.Logger.Error(ex); MessageBox.Show("Error importing document: {0}. Check log file for more details.".FormatWith(ex.Message)); } }
private void importButton_Click(object sender, EventArgs e) { var file = string.Empty; using (var dialog = new ExportOpenFileDialog(_directory, "Open Software Installer Export File", ImportExportType.Installer)) { if (dialog.ShowDialog() == DialogResult.OK) { file = dialog.Base.FileName; _directory = Path.GetDirectoryName(file); } } if (string.IsNullOrEmpty(file)) { return; } var contract = LegacySerializer.DeserializeDataContract <MetadataTypeInstallerContract>(File.ReadAllText(file)); using (var context = new EnterpriseTestContext()) { var metadataType = context.MetadataTypes.FirstOrDefault(x => x.Name.Equals(contract.Name)); if (metadataType == null) { MessageBox.Show("The plugin activity ({0}) dependent on this software installer does not exist in this system.".FormatWith(contract.Name)); return; } try { Cursor = Cursors.WaitCursor; var currentPackages = context.SoftwareInstallerPackages .Where(x => x.MetadataTypes.Any(y => y.Name.Equals(contract.Name))) .Select(x => x.Description); if (currentPackages != null && currentPackages.Count() > 0) { var packageNames = string.Join(Environment.NewLine, currentPackages.ToArray()); StringBuilder builder = new StringBuilder(); builder.Append("The following packages are already associated with the {0} plugin.".FormatWith(contract.Name)); builder.AppendLine(" Do you want to continue with the import?"); builder.AppendLine(); builder.AppendLine(packageNames); var result = MessageBox.Show(builder.ToString(), "Installers Already Exist for {0}".FormatWith(contract.Name), MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { return; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor = Cursors.Default; } try { Cursor = Cursors.WaitCursor; contract.Import(context); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { Cursor = Cursors.Default; } } LoadGrids(); MessageBox.Show("The software installer was successfully imported", "Import Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); }