public DatabaseFileInfo GetFileInfo(int conStrId) { DatabaseFileInfo model = new DatabaseFileInfo(); var strModel = new ConStrDao().GetModel(conStrId); SqlConnection conn = new SqlConnection(strModel.ConStrContent); //数据库名称 string databaseName = conn.Database; model.Name = databaseName; string strRestoreSql = "select database_id,name,physical_name AS CurrentLocation,state_desc,size,type_desc,[type] from sys.master_files where database_id = db_id(N'" + databaseName + "'); "; DataTable dt = SqlHelper.GetDataTable(strModel.ConStrContent, CommandType.Text, strRestoreSql, null); foreach (DataRow r in dt.Rows) { if (r["type"].ToString() == "0") { model.MDFFilePath = r["CurrentLocation"].ToString(); model.MDFName = r["name"].ToString(); } if (r["type"].ToString() == "1") { model.LogFilePath = r["CurrentLocation"].ToString(); model.LogName = r["name"].ToString(); } } return(model); }
/// <summary> /// 获取备份文件的文件信息 /// </summary> /// <param name="conStrId"></param> /// <returns></returns> public DatabaseFileInfo GetBackupFileInfo(int conStrId, string backupFilePath) { DatabaseFileInfo model = new DatabaseFileInfo(); var strModel = new ConStrDao().GetModel(conStrId); SqlConnection conn = new SqlConnection(strModel.ConStrContent); //数据库名称 string databaseName = conn.Database; model.Name = databaseName; string strRestoreSql = "restore filelistonly from disk=N'" + backupFilePath + "' "; DataTable dt = SqlHelper.GetDataTable(strModel.ConStrContent, CommandType.Text, strRestoreSql, null); foreach (DataRow r in dt.Rows) { if (r["Type"].ToString() == "D") { model.MDFFilePath = r["PhysicalName"].ToString(); model.MDFName = r["LogicalName"].ToString(); } if (r["Type"].ToString() == "L") { model.LogFilePath = r["PhysicalName"].ToString(); model.LogName = r["LogicalName"].ToString(); } } return(model); }
public void DatabaseFileInfoShouldReturnNullGivenEmptyProperties() { LocalizedPropertyInfo[] properties = new LocalizedPropertyInfo[] { }; var fileInfo = new DatabaseFileInfo(properties); Assert.True(string.IsNullOrEmpty(fileInfo.Id)); Assert.True(string.IsNullOrEmpty(fileInfo.GetPropertyValueAsString(BackupSetInfo.BackupComponentPropertyName))); }
private async Task VerifyRestoreMultipleBackupSets(string[] backupFiles, int backupSetIndexToDelete, int[] expectedSelectedIndexes, TaskExecutionModeFlag executionMode = TaskExecutionModeFlag.ExecuteAndScript) { var testDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "RestoreTest"); try { string targetDbName = testDb.DatabaseName; bool canRestore = true; var response = await VerifyRestore(backupFiles, null, canRestore, TaskExecutionModeFlag.None, targetDbName, null, null); Assert.True(response.BackupSetsToRestore.Count() >= 2); var allIds = response.BackupSetsToRestore.Select(x => x.Id).ToList(); if (backupSetIndexToDelete >= 0) { allIds.RemoveAt(backupSetIndexToDelete); } string[] selectedIds = allIds.ToArray(); Dictionary <string, object> options = new Dictionary <string, object>(); options.Add(RestoreOptionsHelper.ReplaceDatabase, true); response = await VerifyRestore(backupFiles, null, canRestore, executionMode, targetDbName, selectedIds, options, (database) => { if (executionMode.HasFlag(TaskExecutionModeFlag.Execute)) { bool tablesFound = true; for (int i = 0; i < tableNames.Length; i++) { string tableName = tableNames[i]; if (!database.Tables.Contains(tableName, "test") && expectedSelectedIndexes.Contains(i)) { tablesFound = false; break; } } bool numberOfTableCreatedIsCorrect = database.Tables.Count == expectedSelectedIndexes.Length; return(numberOfTableCreatedIsCorrect && tablesFound); } return(true); }); for (int i = 0; i < response.BackupSetsToRestore.Count(); i++) { DatabaseFileInfo databaseInfo = response.BackupSetsToRestore[i]; Assert.Equal(databaseInfo.IsSelected, expectedSelectedIndexes.Contains(i)); } } finally { if (testDb != null) { testDb.Cleanup(); } } }
/// <summary> /// Handles the choosing of a database. /// </summary> /// <param name="sender"> /// A <see cref="System.Object"/> /// </param> /// <param name="args"> /// A <see cref="EventArgs"/> /// </param> private void OnOptionRBClicked(object sender, EventArgs args) { RadioButton clickedRB = (RadioButton)sender; if (clickedRB == newRB) { choosenDatabase = null; } else { choosenDatabase = databaseHash[clickedRB.Label]; } }
protected override void FindFileInfo(HttpContextBase httpContext) { HttpRequestBase request = httpContext.Request; string physicalPath = request.PhysicalPath; string fileName = Path.GetFileName(physicalPath); // TODO: Throws if file does not exists dynamic databaseFileInfo = SqlHelper.FindFile(fileName).RecordToExpando(); _fileId = databaseFileInfo.Id; RequestFileInfo = new DatabaseFileInfo(databaseFileInfo.Name, databaseFileInfo.Length, databaseFileInfo.DateModified); }
/// <summary> /// List of selected backupsets /// </summary> public DatabaseFileInfo[] GetSelectedBakupSets() { List <DatabaseFileInfo> result = new List <DatabaseFileInfo>(); IEnumerable <BackupSetInfo> backupSetInfos = GetBackupSetInfo(); foreach (var backupSetInfo in backupSetInfos) { var item = new DatabaseFileInfo(backupSetInfo.ConvertPropertiesToArray()); Guid backupSetGuid; if (!Guid.TryParse(item.Id, out backupSetGuid)) { backupSetGuid = Guid.Empty; } item.IsSelected = this.backupSetsFilterInfo.IsBackupSetSelected(backupSetGuid); result.Add(item); } return(result.ToArray()); }
public void DatabaseFileInfoShouldReturnValuesGivenValidProperties() { LocalizedPropertyInfo[] properties = new LocalizedPropertyInfo[] { new LocalizedPropertyInfo { PropertyName = "name", PropertyValue = 1 }, new LocalizedPropertyInfo { PropertyName = DatabaseFileInfo.IdPropertyName, PropertyValue = "id" } }; var fileInfo = new DatabaseFileInfo(properties); Assert.Equal(fileInfo.Id, "id"); Assert.Equal(fileInfo.GetPropertyValueAsString("name"), "1"); }
/// <summary> /// Handles the click on the "learn image" treeview's context menu item. /// </summary> /// <param name="sender"> /// A <see cref="System.Object"/> /// </param> /// <param name="args"> /// A <see cref="EventArgs"/> /// </param> private void OnLearnImageItemActivate(object sender, EventArgs args) { // We ask for confirmation ResponseType res = ConfirmDialog.Show(MainRecognizerWindow.Window, "¿Realmente quieres añadir el símbolo «{0}» a una base de datos?", selectedNode.Name); if (res == ResponseType.Yes) { // We let the user select the database to be modified. LearnSymbolDatabaseChooserDialog databaseDialog = new LearnSymbolDatabaseChooserDialog(MainRecognizerWindow.Window, Config.RecognizerConfig.Instance.DatabaseFilesInfo); res = databaseDialog.Show(); databaseDialog.Destroy(); if (res == ResponseType.Ok) { DatabaseFileInfo selectedDatabase = databaseDialog.ChoosenDatabase; MathTextDatabase database = null; string databasePath = ""; if (selectedDatabase != null) { database = selectedDatabase.Database; databasePath = selectedDatabase.Path; } new MainLearnerWindow(this.MainRecognizerWindow.Window, database, databasePath, selectedNode.MathTextBitmap.Pixbuf, selectedNode.Name); } } }
public IFileInfo GetFileInfo(string subpath) { var result = new DatabaseFileInfo(_serviceProvider, subpath); return(result.Exists ? result as IFileInfo : new NotFoundFileInfo(subpath)); }
public Microsoft.Extensions.FileProviders.IFileInfo GetFileInfo(string subpath) { var result = new DatabaseFileInfo(this.m_factory, subpath); return(result.Exists ? result as Microsoft.Extensions.FileProviders.IFileInfo : new Microsoft.Extensions.FileProviders.NotFoundFileInfo(subpath)); }
public IFileInfo GetFileInfo(string subpath) { var result = new DatabaseFileInfo(_context, subpath); return(result.Exists ? result as IFileInfo : new NotFoundFileInfo(subpath)); }