Beispiel #1
0
        public JsonResult Restore(string file)
        {
            try
            {
                var result = new JsonOperationResponse();
                try
                {
                    var backupFile = string.Empty;
                    if (Settings.BackupPath.StartsWith("~"))
                    {
                        backupFile = Server.MapPath(Settings.BackupPath + file);
                    }
                    else
                    {
                        backupFile = Settings.BackupPath + file;
                    }

                    if (System.IO.File.Exists(backupFile))
                    {
                        var connectionString       = ConfigurationManager.ConnectionStrings["KbVaultEntities"].ConnectionString;
                        var entityConnectionString = new EntityConnectionStringBuilder(connectionString);
                        var builder = new System.Data.SqlClient.SqlConnectionStringBuilder(entityConnectionString.ProviderConnectionString);

                        IVaultBackup backup = new VaultMsSqlBackup();
                        backup.Connect(entityConnectionString.ProviderConnectionString);
                        result.Successful = backup.Restore(builder.InitialCatalog, backupFile);
                        if (result.Successful)
                        {
                            result.ErrorMessage = UIResources.BackupRestoreSuccessfull;
                        }
                    }
                    else
                    {
                        throw new FileNotFoundException(file);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    result.ErrorMessage = ex.Message;
                }

                return(Json(result, JsonRequestBehavior.DenyGet));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
Beispiel #2
0
        public JsonResult Restore(string file)
        {
            try
            {
                var foundSettings = _context.Settings.FirstOrDefault(s => true);
                var result        = new JsonOperationResponse();
                try
                {
                    var backupFile = string.Empty;
                    if (foundSettings.BackupPath.StartsWith("~"))
                    {
                        var webroot = _env.WebRootPath;
                        backupFile = System.IO.Path.Combine(webroot, foundSettings.BackupPath + file);
                        //backupFile = Server.MapPath(Settings.BackupPath + file);
                    }
                    else
                    {
                        backupFile = foundSettings.BackupPath + file;
                    }

                    if (System.IO.File.Exists(backupFile))
                    {
                        var connectionString = ConfigurationManager.ConnectionStrings["KnowledgeBaseContextBackup"].ConnectionString;
                        //https://docs.microsoft.com/en-us/dotnet/api/system.data.entity.core.entityclient?view=entity-framework-6.2.0
                        var entityConnectionString = ConfigurationManager.ConnectionStrings["KnowledgeBaseContextBackup"].ConnectionString;
                        var builder = new System.Data.SqlClient.SqlConnectionStringBuilder(entityConnectionString);

                        //var entityConnectionString = new EntityConnectionStringBuilder(connectionString);
                        //var entityConnectionString = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(connectionString);
                        //var builder = new System.Data.SqlClient.SqlConnectionStringBuilder(entityConnectionString.ProviderConnectionString);


                        //var builder = new System.Data.Common.DbConnectionStringBuilder.SqlConnectionStringBuilder(entityConnectionString.ProviderConnectionString);
                        //System.Data.Entity.Core.EntityClient.
                        //System.Data.Common.DbConnectionStringBuilder.

                        IVaultBackup backup = new VaultMsSqlBackup();
                        //backup.Connect(entityConnectionString.ProviderConnectionString);
                        backup.Connect(entityConnectionString);

                        result.Successful = backup.Restore(builder.InitialCatalog, backupFile);
                        if (result.Successful)
                        {
                            result.ErrorMessage = "BackupRestoreSuccessfull"; // Resources.UIResources.BackupRestoreSuccessfull;
                        }
                    }
                    else
                    {
                        throw new FileNotFoundException(file);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    result.ErrorMessage = ex.Message;
                }

                return(Json(result));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }