104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Services;
|
|
using System.Data.SqlClient;
|
|
using System.Web.Script.Services;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.IO.Compression;
|
|
|
|
|
|
namespace BackupService
|
|
{
|
|
/// <summary>
|
|
///BackupService 的摘要描述
|
|
/// </summary>
|
|
[WebService(Namespace = "https://thinkyustaff.com/")]
|
|
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
|
[System.ComponentModel.ToolboxItem(false)]
|
|
[System.Web.Script.Services.ScriptService]
|
|
public class BackupService : System.Web.Services.WebService
|
|
{
|
|
|
|
[WebMethod]
|
|
public string BackupTable()
|
|
{
|
|
string filePath = Server.MapPath("~/SQL");
|
|
Directory.CreateDirectory(filePath);
|
|
BackupWorker worker = new BackupWorker();
|
|
worker.DataPath = filePath;
|
|
worker.Begin();
|
|
|
|
return "OK";
|
|
}
|
|
|
|
[WebMethod]
|
|
public string BackupOneTable(string tableName)
|
|
{
|
|
string filePath = Server.MapPath("~/SQL");
|
|
Directory.CreateDirectory(filePath);
|
|
BackupWorker worker = new BackupWorker();
|
|
worker.DataPath = filePath;
|
|
worker.BackupOneTable(tableName);
|
|
|
|
return "OK";
|
|
}
|
|
|
|
[WebMethod]
|
|
[ScriptMethod]
|
|
public List<FileList> GetFileList(string path)
|
|
{
|
|
var result = new List<FileList>();
|
|
ListFiles(path, result);
|
|
return result;
|
|
}
|
|
|
|
|
|
private void ListFiles(string path, List<FileList> fileLists)
|
|
{
|
|
var newPath = new FileList();
|
|
newPath.Path = path;
|
|
foreach (var file in Directory.GetFiles(path))
|
|
{
|
|
newPath.FileNames.Add(Path.GetFileName(file));
|
|
}
|
|
fileLists.Add(newPath);
|
|
|
|
foreach (var dir in Directory.GetDirectories(path))
|
|
{
|
|
ListFiles(dir, fileLists);
|
|
}
|
|
}
|
|
|
|
|
|
[WebMethod]
|
|
[ScriptMethod]
|
|
public string GetFile(string path)
|
|
{
|
|
return Convert.ToBase64String(File.ReadAllBytes(path));
|
|
}
|
|
|
|
[Serializable]
|
|
public class FileList
|
|
{
|
|
public string Path { get; set; }
|
|
public List<string> FileNames { get; set; }
|
|
|
|
public FileList()
|
|
{
|
|
FileNames = new List<string>();
|
|
}
|
|
}
|
|
|
|
public class TableItem
|
|
{
|
|
public string TableName { get; set; }
|
|
public bool HasIdentity { get; set; }
|
|
}
|
|
}
|
|
}
|