/// <summary> /// Apply zip config on current system /// </summary> /// <param name="file"></param> /// <returns></returns> public IActionResult Import(IFormFile file) { if (file == null) { ModelState.AddModelError(string.Empty, "File not selected!"); return(View()); } if (file.ContentType != "application/x-zip-compressed") { ModelState.AddModelError(string.Empty, "File need to be in zip format!"); return(View()); } var memStream = new MemoryStream(); file.CopyTo(memStream); var response = ExportManager.Import(memStream); if (response.IsSuccess) { return(RedirectToAction("Index", "Home")); } ModelState.AddModelError(string.Empty, "Fail to import data"); return(View()); }
private void btnImport_Click(object sender, EventArgs e) { string file; using (OpenFileDialog dialog = new OpenFileDialog { AutoUpgradeEnabled = true, DereferenceLinks = true, Title = "Import " + Program.BrandName + " Settings", Filter = Program.BrandName + " Settings (*.tdsettings)|*.tdsettings" }){ if (dialog.ShowDialog() != DialogResult.OK) { return; } file = dialog.FileName; } ExportManager manager = new ExportManager(file, plugins); ExportFileFlags flags; using (DialogSettingsExport dialog = DialogSettingsExport.Import(manager.GetImportFlags())){ if (dialog.ShowDialog() != DialogResult.OK) { return; } flags = dialog.Flags; } if (manager.Import(flags)) { if (!manager.IsRestarting) { ((FormSettings)ParentForm).ReloadUI(); } } else { Program.Reporter.HandleException("Profile Import Error", "An exception happened while importing " + Program.BrandName + " settings.", true, manager.LastException); } }