/// <summary> /// Экспортировать таблицу базы конфигурации в файл формата DAT /// </summary> public static bool ExportTable(Tables.TableInfo srcTableInfo, string destFileName, int minID, int maxID, out string msg) { try { // проверка аргументов метода if (srcTableInfo == null) { throw new ArgumentNullException("srcTableInfo"); } if (string.IsNullOrWhiteSpace(destFileName)) { throw new ArgumentException(AppPhrases.ExportFileUndefied); } string dir = Path.GetDirectoryName(destFileName); if (string.IsNullOrWhiteSpace(dir)) { throw new DirectoryNotFoundException(AppPhrases.ExportDirUndefied); } if (!Directory.Exists(dir)) { throw new DirectoryNotFoundException(AppPhrases.ExportDirNotExists); } // получение таблицы DataTable srcTable = srcTableInfo.GetTable(); // ограничение диапазона идентификаторов if ((0 < minID || maxID < int.MaxValue) && srcTableInfo.IDColName != "") { srcTable.DefaultView.RowFilter = string.Format("{0} <= {2} and {2} <= {1}", minID, maxID, srcTableInfo.IDColName); } // сохранение таблицы в формате DAT BaseAdapter adapter = new BaseAdapter(); adapter.FileName = destFileName; adapter.Update(srcTable); msg = AppPhrases.ExportCompleted; return(true); } catch (Exception ex) { msg = AppPhrases.ExportError + ":\r\n" + ex.Message; return(false); } }
/// <summary> /// Передать базу конфигурации серверу, т.е конвертировать из формата SDF в DAT /// </summary> public static bool PassBase(List <Tables.TableInfo> srcTableInfoList, string baseDATDir, out string msg) { try { // проверка аргументов метода if (srcTableInfoList == null) { throw new ArgumentNullException("srcTableInfoList"); } if (!Directory.Exists(baseDATDir)) { throw new DirectoryNotFoundException(CommonPhrases.BaseDATDirNotExists); } // создание файла блокировки базы конфигурации string baseLockPath = baseDATDir + "baselock"; FileStream baseLockStream = new FileStream(baseLockPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); baseLockStream.Close(); try { // сохранение таблиц в формате DAT BaseAdapter adapter = new BaseAdapter(); foreach (Tables.TableInfo tableInfo in Tables.TableInfoList) { DataTable table = tableInfo.GetTable(); adapter.FileName = baseDATDir + tableInfo.FileName; adapter.Update(table); } } finally { // удаление файла блокировки базы конфигурации File.Delete(baseLockPath); } msg = AppPhrases.DbPassCompleted; return(true); } catch (Exception ex) { msg = AppPhrases.DbPassError + ":\r\n" + ex.Message; return(false); } }
private void miDbPassToServer_Click(object sender, EventArgs e) { // перевод базы конфигурации в формат DAT try { if (AppData.Connected) { string baseDatDir = settings.AppSett.BaseDATDir; if (Directory.Exists(baseDatDir)) { // создание файла блокировки базы конфигурации string baseLockPath = baseDatDir + "baselock"; FileStream baseLockStream = new FileStream(baseLockPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); baseLockStream.Close(); try { // сохранение таблиц базы конфигурации в формате DAT BaseAdapter adapter = new BaseAdapter(); foreach (Tables.TableInfo tableInfo in Tables.TablesInfo) { DataTable table = tableInfo.GetTable(); adapter.FileName = baseDatDir + tableInfo.FileName; adapter.Update(table); } } finally { // удаление файла блокировки базы конфигурации File.Delete(baseLockPath); } ScadaUtils.ShowInfo(AppPhrases.DbPassCompleted); } else { ScadaUtils.ShowError(CommonPhrases.BaseDATDirNotExists); } } } catch (Exception ex) { AppUtils.ProcError(AppPhrases.DbPassError + ":\r\n" + ex.Message); } }
private void btnExport_Click(object sender, EventArgs e) { // экспорт выбранной таблицы в формат DAT try { Tables.TableInfo tableInfo = cbTable.SelectedItem as Tables.TableInfo; if (tableInfo != null && AppData.Connected) { string fileName = txtFileName.Text.Trim(); string directory = fileName == "" ? "" : Path.GetDirectoryName(fileName); if (directory == "") { ScadaUtils.ShowError(AppPhrases.ExportDirUndefied); } else { if (Directory.Exists(directory)) { BaseAdapter adapter = new BaseAdapter(); DataTable table = tableInfo.GetTable(); adapter.FileName = fileName; adapter.Update(table); ScadaUtils.ShowInfo(AppPhrases.ExportCompleted); } else { ScadaUtils.ShowError(AppPhrases.ExportDirNotExists); } } } } catch (Exception ex) { AppUtils.ProcError(AppPhrases.ExportError + ":\r\n" + ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (dataTable == null) { ScadaUiUtils.ShowWarning("Table is not initialized."); } else { if (rbSnapshot.Checked) { var sa = new SrezAdapter { FileName = txtFileName.Text }; sa.Update(srezTable); } else if (rbEvent.Checked) { var ea = new EventAdapter { FileName = txtFileName.Text }; ea.Update(dataTable); } else // rbBase.Checked { var ba = new BaseAdapter { FileName = txtFileName.Text }; ba.Update(dataTable); } ScadaUiUtils.ShowInfo("Data saved successfully."); } } catch (Exception ex) { ScadaUiUtils.ShowError(ex.Message); } }
/// <summary> /// Exports the configuration to the specified archive. /// </summary> public void ExportToArchive(string destFileName, ScadaProject project, Instance instance, TransferSettings transferSettings) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (project == null) { throw new ArgumentNullException("project"); } if (instance == null) { throw new ArgumentNullException("instance"); } FileStream fileStream = null; ZipArchive zipArchive = null; try { fileStream = new FileStream(destFileName, FileMode.Create, FileAccess.Write, FileShare.Read); zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Create); bool ignoreRegKeys = transferSettings.IgnoreRegKeys; // add the configuration database to the archive if (transferSettings.IncludeBase) { foreach (IBaseTable srcTable in project.ConfigBase.AllTables) { string entryName = "BaseDAT/" + srcTable.Name.ToLowerInvariant() + ".dat"; var tableEntry = zipArchive.CreateEntry(entryName, CompressionLevel.Fastest); using (var entryStream = tableEntry.Open()) { // convert the table to DAT format BaseAdapter baseAdapter = new BaseAdapter() { Stream = entryStream }; baseAdapter.Update(srcTable); } } } // add the interface files to the archive if (transferSettings.IncludeInterface) { PackDirectory(zipArchive, project.Interface.InterfaceDir, DirectoryBuilder.GetDirectory(ConfigParts.Interface, '/'), ignoreRegKeys); } // add the Server settings to the archive if (transferSettings.IncludeServer && instance.ServerApp.Enabled) { PackDirectory(zipArchive, instance.ServerApp.AppDir, DirectoryBuilder.GetDirectory(ConfigParts.Server, '/'), ignoreRegKeys); } // add the Communicator settings to the archive if (transferSettings.IncludeServer && instance.ServerApp.Enabled) { PackDirectory(zipArchive, instance.CommApp.AppDir, DirectoryBuilder.GetDirectory(ConfigParts.Comm, '/'), ignoreRegKeys); } // add the Webstation settings to the archive if (transferSettings.IncludeServer && instance.ServerApp.Enabled) { PackDirectory(zipArchive, Path.Combine(instance.WebApp.AppDir, "config"), DirectoryBuilder.GetDirectory(ConfigParts.Web, AppFolder.Config, '/'), ignoreRegKeys); if (!transferSettings.IgnoreWebStorage) { PackDirectory(zipArchive, Path.Combine(instance.WebApp.AppDir, "storage"), DirectoryBuilder.GetDirectory(ConfigParts.Web, AppFolder.Storage, '/'), ignoreRegKeys); } } } catch (Exception ex) { throw new ScadaException(AdminPhrases.ExportToArchiveError, ex); } finally { zipArchive?.Dispose(); fileStream?.Dispose(); } }
/// <summary> /// Exports the configuration to the specified archive. /// </summary> public void ExportToArchive(string destFileName, ScadaProject project, Instance instance, UploadSettings uploadSettings) { if (destFileName == null) { throw new ArgumentNullException("destFileName"); } if (project == null) { throw new ArgumentNullException("project"); } if (instance == null) { throw new ArgumentNullException("instance"); } if (uploadSettings == null) { throw new ArgumentNullException("transferSettings"); } FileStream fileStream = null; ZipArchive zipArchive = null; try { fileStream = new FileStream(destFileName, FileMode.Create, FileAccess.Write, FileShare.Read); zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Create); List <int> objNums = uploadSettings.ObjNums; bool filterByObj = objNums.Count > 0; bool ignoreRegKeys = uploadSettings.IgnoreRegKeys; // add the configuration database to the archive if (uploadSettings.IncludeBase) { foreach (IBaseTable srcTable in project.ConfigBase.AllTables) { string entryName = "BaseDAT/" + srcTable.Name.ToLowerInvariant() + ".dat"; ZipArchiveEntry tableEntry = zipArchive.CreateEntry(entryName, CompressionLevel.Fastest); using (Stream entryStream = tableEntry.Open()) { // filter the source table by objects if needed IBaseTable baseTable = srcTable; if (filterByObj) { if (srcTable.ItemType == typeof(InCnl)) { baseTable = GetFilteredTable <InCnl>(srcTable, objNums); } else if (srcTable.ItemType == typeof(CtrlCnl)) { baseTable = GetFilteredTable <CtrlCnl>(srcTable, objNums); } else if (srcTable.ItemType == typeof(Interface)) { baseTable = GetFilteredTable <Interface>(srcTable, objNums); } } // convert the table to DAT format BaseAdapter baseAdapter = new BaseAdapter() { Stream = entryStream }; baseAdapter.Update(baseTable); } } } // add the interface files to the archive if (uploadSettings.IncludeInterface) { string interfaceDir = project.Interface.InterfaceDir; string entryPrefix = DirectoryBuilder.GetDirectory(ConfigParts.Interface, '/'); if (filterByObj) { PackFiles(zipArchive, interfaceDir, GetInterfaceFiles(project.ConfigBase.InterfaceTable, interfaceDir, objNums), entryPrefix); } else { PackDirectory(zipArchive, interfaceDir, entryPrefix, ignoreRegKeys); } } // add the Server settings to the archive if (uploadSettings.IncludeServer && instance.ServerApp.Enabled) { PackDirectory(zipArchive, instance.ServerApp.AppDir, DirectoryBuilder.GetDirectory(ConfigParts.Server, '/'), ignoreRegKeys); } // add the Communicator settings to the archive if (uploadSettings.IncludeComm && instance.CommApp.Enabled) { PackDirectory(zipArchive, instance.CommApp.AppDir, DirectoryBuilder.GetDirectory(ConfigParts.Comm, '/'), ignoreRegKeys); } // add the Webstation settings to the archive if (uploadSettings.IncludeWeb && instance.WebApp.Enabled) { PackDirectory(zipArchive, Path.Combine(instance.WebApp.AppDir, "config"), DirectoryBuilder.GetDirectory(ConfigParts.Web, AppFolder.Config, '/'), ignoreRegKeys); if (!uploadSettings.IgnoreWebStorage) { PackDirectory(zipArchive, Path.Combine(instance.WebApp.AppDir, "storage"), DirectoryBuilder.GetDirectory(ConfigParts.Web, AppFolder.Storage, '/'), ignoreRegKeys); } } // add an information entry to the archive using (Stream entryStream = zipArchive.CreateEntry(ProjectInfoEntryName, CompressionLevel.Fastest).Open()) { using (StreamWriter writer = new StreamWriter(entryStream, Encoding.UTF8)) { writer.Write(project.GetInfo()); } } } catch (Exception ex) { throw new ScadaException(AdminPhrases.ExportToArchiveError, ex); } finally { zipArchive?.Dispose(); fileStream?.Dispose(); } }
void Update() { adapter.Update(); }