chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<%@ WebService Language="C#" CodeBehind="BackupService.asmx.cs" Class="BackupService.BackupService" %>
|
||||
@@ -0,0 +1,103 @@
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>
|
||||
</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{A42DA595-C6E4-4658-8790-F6364DF91F84}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BackupService</RootNamespace>
|
||||
<AssemblyName>BackupService</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<Use64BitIISExpress />
|
||||
<IISExpressSSLPort />
|
||||
<IISExpressAnonymousAuthentication />
|
||||
<IISExpressWindowsAuthentication />
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
<UseGlobalApplicationHostFile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.EnterpriseServices" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
<None Include="Web.Release.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="BackupService.asmx" />
|
||||
<Content Include="Global.asax" />
|
||||
<Content Include="Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BackupService.asmx.cs">
|
||||
<DependentUpon>BackupService.asmx</DependentUpon>
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="BackupWorker.cs" />
|
||||
<Compile Include="ErrorLogger.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<UseIIS>True</UseIIS>
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>49336</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:49336/</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Timers;
|
||||
using System.IO;
|
||||
using System.Data.SqlClient;
|
||||
using static BackupService.BackupService;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace BackupService
|
||||
{
|
||||
public class BackupWorker
|
||||
{
|
||||
private string dataPath = null;
|
||||
private Timer timer = null;
|
||||
private string fromTable = null;
|
||||
|
||||
public BackupWorker()
|
||||
{
|
||||
timer = new Timer();
|
||||
timer.AutoReset = false;
|
||||
timer.Interval = 1000;
|
||||
timer.Enabled = false;
|
||||
timer.Elapsed += new ElapsedEventHandler(DoWork);
|
||||
}
|
||||
|
||||
public string DataPath
|
||||
{
|
||||
get { return dataPath; }
|
||||
set { dataPath = value; }
|
||||
}
|
||||
|
||||
public void Begin(string fromTable = null)
|
||||
{
|
||||
this.fromTable = fromTable;
|
||||
timer.Start();
|
||||
}
|
||||
|
||||
public void BackupOneTable(string tableName)
|
||||
{
|
||||
var nowtime = DateTime.UtcNow.AddHours(8);
|
||||
|
||||
try
|
||||
{
|
||||
using (var conn = new SqlConnection("Data Source=sql5060.site4now.net;Initial Catalog=DB_A48A46_thinkyu;Persist Security Info=True;User ID=DB_A48A46_thinkyu_admin;Password=VUPm4ej03xu3"))
|
||||
{
|
||||
conn.Open();
|
||||
var cmd = new SqlCommand();
|
||||
var da = new SqlDataAdapter();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = @"SELECT INFORMATION_SCHEMA.TABLES.TABLE_NAME, Count(sys.identity_columns.Column_ID) as HAS_IDENTITY
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
LEFT JOIN sys.identity_columns on OBJECT_NAME(object_id) = INFORMATION_SCHEMA.TABLES.TABLE_NAME
|
||||
WHERE TABLE_TYPE <> 'VIEW' and INFORMATION_SCHEMA.TABLES.TABLE_NAME = @TABLE_NAME
|
||||
GROUP BY INFORMATION_SCHEMA.TABLES.TABLE_NAME";
|
||||
cmd.Parameters.AddWithValue("TABLE_NAME", tableName);
|
||||
|
||||
var tableList = new List<TableItem>();
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
tableList.Add(new TableItem() { TableName = Convert.ToString(reader["TABLE_NAME"]), HasIdentity = Convert.ToInt32(reader["HAS_IDENTITY"]) == 1 });
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var table in tableList)
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
var columnnames = new List<string>();
|
||||
cmd.CommandText = "select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=@TABLE_NAME order by ORDINAL_POSITION ";
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.AddWithValue("TABLE_NAME", table.TableName);
|
||||
da.SelectCommand = cmd;
|
||||
var columns = new DataTable();
|
||||
da.Fill(columns);
|
||||
foreach (DataRow row in columns.Rows)
|
||||
{
|
||||
columnnames.Add(string.Format("[{0}]", row["COLUMN_NAME"]));
|
||||
}
|
||||
var columnlist = string.Join(", ", columnnames.ToArray());
|
||||
|
||||
output.AppendFormat("-- BACKUP DATE {0:yyyy/MM/dd HH:mm}\r\n", nowtime);
|
||||
output.AppendFormat("-- TABLE [{0}]\r\n", table.TableName);
|
||||
|
||||
if (table.HasIdentity)
|
||||
output.AppendFormat("set identity_insert [{0}] on;\r\n", table.TableName);
|
||||
|
||||
cmd.CommandText = string.Format("select * from [{0}]", table.TableName);
|
||||
cmd.CreateParameter();
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var sql = string.Format("insert into [{0}] ({1}) values (", table.TableName, columnlist);
|
||||
var values = new List<string>();
|
||||
foreach (DataRow col in columns.Rows)
|
||||
{
|
||||
var colname = Convert.ToString(col["COLUMN_NAME"]);
|
||||
var datatype = Convert.ToString(col["DATA_TYPE"]).ToLower();
|
||||
var value = reader[colname];
|
||||
|
||||
if (value == DBNull.Value)
|
||||
values.Add("null");
|
||||
else if (datatype == "char" || datatype == "varchar")
|
||||
values.Add(string.Format("'{0}'", value));
|
||||
else if (datatype == "nvarchar" || datatype == "nchar")
|
||||
values.Add(string.Format("N'{0}'", value));
|
||||
else if (datatype == "nvarchar" || datatype == "datetime")
|
||||
values.Add(string.Format("'{0:yyyy/MM/dd HH:mm:ss.fff}'", value));
|
||||
else if (datatype == "bit")
|
||||
values.Add(string.Format("{0}", value));
|
||||
else
|
||||
values.Add(string.Format("{0}", value));
|
||||
}
|
||||
sql += string.Join(", ", values.ToArray()) + ");";
|
||||
output.AppendLine(sql);
|
||||
}
|
||||
}
|
||||
|
||||
if (table.HasIdentity)
|
||||
output.AppendFormat("set identity_insert [{0}] off;\r\n", table.TableName);
|
||||
|
||||
var buffer = Encoding.UTF8.GetBytes(output.ToString());
|
||||
|
||||
using (FileStream stream = new FileStream(string.Format("{0}/{1}.gz", dataPath, table.TableName), FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
using (GZipStream gZip = new GZipStream(stream, CompressionMode.Compress))
|
||||
{
|
||||
gZip.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorLogger.WriteException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoWork(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
var nowtime = DateTime.UtcNow.AddHours(8);
|
||||
|
||||
try
|
||||
{
|
||||
using (var conn = new SqlConnection("Data Source=sql5060.site4now.net;Initial Catalog=DB_A48A46_thinkyu;Persist Security Info=True;User ID=DB_A48A46_thinkyu_admin;Password=VUPm4ej03xu3"))
|
||||
{
|
||||
conn.Open();
|
||||
var cmd = new SqlCommand();
|
||||
var da = new SqlDataAdapter();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = @"SELECT INFORMATION_SCHEMA.TABLES.TABLE_NAME, Count(sys.identity_columns.Column_ID) as HAS_IDENTITY
|
||||
FROM INFORMATION_SCHEMA.TABLES
|
||||
LEFT JOIN sys.identity_columns on OBJECT_NAME(object_id) = INFORMATION_SCHEMA.TABLES.TABLE_NAME
|
||||
WHERE TABLE_TYPE <> 'VIEW'
|
||||
GROUP BY INFORMATION_SCHEMA.TABLES.TABLE_NAME";
|
||||
|
||||
var tableList = new List<TableItem>();
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
string tableName = Convert.ToString(reader["TABLE_NAME"]);
|
||||
bool hasIdentity = Convert.ToInt32(reader["HAS_IDENTITY"]) == 1;
|
||||
|
||||
if (string.IsNullOrEmpty(this.fromTable) || tableName.CompareTo(this.fromTable) >= 0) {
|
||||
tableList.Add(new TableItem() { TableName = tableName, HasIdentity = hasIdentity });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var table in tableList)
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
var columnnames = new List<string>();
|
||||
cmd.CommandText = "select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=@TABLE_NAME order by ORDINAL_POSITION ";
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.AddWithValue("TABLE_NAME", table.TableName);
|
||||
da.SelectCommand = cmd;
|
||||
var columns = new DataTable();
|
||||
da.Fill(columns);
|
||||
foreach (DataRow row in columns.Rows)
|
||||
{
|
||||
columnnames.Add(string.Format("[{0}]", row["COLUMN_NAME"]));
|
||||
}
|
||||
var columnlist = string.Join(", ", columnnames.ToArray());
|
||||
|
||||
output.AppendFormat("-- BACKUP DATE {0:yyyy/MM/dd HH:mm}\r\n", nowtime);
|
||||
output.AppendFormat("-- TABLE [{0}]\r\n", table.TableName);
|
||||
|
||||
if (table.HasIdentity)
|
||||
output.AppendFormat("set identity_insert [{0}] on;\r\n", table.TableName);
|
||||
|
||||
cmd.CommandText = string.Format("select * from [{0}]", table.TableName);
|
||||
cmd.CreateParameter();
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
var sql = string.Format("insert into [{0}] ({1}) values (", table.TableName, columnlist);
|
||||
var values = new List<string>();
|
||||
foreach (DataRow col in columns.Rows)
|
||||
{
|
||||
var colname = Convert.ToString(col["COLUMN_NAME"]);
|
||||
var datatype = Convert.ToString(col["DATA_TYPE"]).ToLower();
|
||||
var value = reader[colname];
|
||||
|
||||
if (value == DBNull.Value)
|
||||
values.Add("null");
|
||||
else if (datatype == "char" || datatype == "varchar")
|
||||
values.Add(string.Format("'{0}'", value));
|
||||
else if (datatype == "nvarchar" || datatype == "nchar")
|
||||
values.Add(string.Format("N'{0}'", value));
|
||||
else if (datatype == "nvarchar" || datatype == "datetime")
|
||||
values.Add(string.Format("'{0:yyyy/MM/dd HH:mm:ss.fff}'", value));
|
||||
else if (datatype == "bit")
|
||||
values.Add(string.Format("{0}", value));
|
||||
else
|
||||
values.Add(string.Format("{0}", value));
|
||||
}
|
||||
sql += string.Join(", ", values.ToArray()) + ");";
|
||||
output.AppendLine(sql);
|
||||
}
|
||||
}
|
||||
|
||||
if (table.HasIdentity)
|
||||
output.AppendFormat("set identity_insert [{0}] off;\r\n", table.TableName);
|
||||
|
||||
var buffer = Encoding.UTF8.GetBytes(output.ToString());
|
||||
|
||||
using (FileStream stream = new FileStream(string.Format("{0}/{1}.gz", dataPath, table.TableName), FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
using (GZipStream gZip = new GZipStream(stream, CompressionMode.Compress))
|
||||
{
|
||||
gZip.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ErrorLogger.WriteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace BackupService
|
||||
{
|
||||
public class ErrorLogger
|
||||
{
|
||||
private const string Message1 = @"錯誤類別:{0}
|
||||
錯誤來源:{1}
|
||||
錯誤訊息:{2}
|
||||
堆疊內容:
|
||||
{3}
|
||||
|
||||
";
|
||||
|
||||
private const string Message2 = @"以上的錯誤發生的原因是:
|
||||
錯誤類別:{0}
|
||||
錯誤來源:{1}
|
||||
錯誤訊息:{2}
|
||||
堆疊內容:
|
||||
{3}
|
||||
|
||||
";
|
||||
|
||||
private static string logPath = null;
|
||||
|
||||
public static string LogPath
|
||||
{
|
||||
get { return ErrorLogger.logPath; }
|
||||
set { ErrorLogger.logPath = value; }
|
||||
}
|
||||
|
||||
|
||||
public static void WriteException(Exception ex)
|
||||
{
|
||||
// 發生未處理錯誤時執行的程式碼
|
||||
string Message = "";
|
||||
|
||||
Message += String.Format(ErrorLogger.Message1,
|
||||
ex.GetType().FullName,
|
||||
ex.Source,
|
||||
ex.Message,
|
||||
ex.StackTrace);
|
||||
|
||||
ex = ex.InnerException;
|
||||
while (ex != null)
|
||||
{
|
||||
Message += String.Format(ErrorLogger.Message2,
|
||||
ex.GetType().FullName,
|
||||
ex.Source,
|
||||
ex.Message,
|
||||
ex.StackTrace);
|
||||
ex = ex.InnerException;
|
||||
}
|
||||
|
||||
//寫入文字檔
|
||||
string fileName = DateTime.UtcNow.AddHours(8).ToString("yyyyMMdd_HHmmss");
|
||||
System.IO.File.AppendAllText(string.Format(@"{0}/{1}.txt", ErrorLogger.logPath, fileName), Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<%@ Application Codebehind="Global.asax.cs" Inherits="BackupService.Global" Language="C#" %>
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.SessionState;
|
||||
|
||||
namespace BackupService
|
||||
{
|
||||
public class Global : System.Web.HttpApplication
|
||||
{
|
||||
|
||||
protected void Application_Start(object sender, EventArgs e)
|
||||
{
|
||||
string logPath = Server.MapPath("~/LOG");
|
||||
Directory.CreateDirectory(logPath);
|
||||
ErrorLogger.LogPath = logPath;
|
||||
}
|
||||
|
||||
protected void Session_Start(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Application_BeginRequest(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Application_AuthenticateRequest(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void Application_Error(object sender, EventArgs e)
|
||||
{
|
||||
ErrorLogger.WriteException(Server.GetLastError());
|
||||
Server.ClearError();
|
||||
}
|
||||
|
||||
protected void Session_End(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Application_End(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 組件的一般資訊是由下列的屬性集
|
||||
// 控制。變更這些屬性值可修改與組件關聯的
|
||||
// 資訊。
|
||||
[assembly: AssemblyTitle("BackupService")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("BackupService")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 將 ComVisible 設定為 false 會使得這個組件中的型別
|
||||
// 對 COM 元件而言為不可見。如果您需要從 COM 存取此組件中
|
||||
// 的型別,請在該型別上將 ComVisible 屬性設定為 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 下列 GUID 為專案公開 (Expose) 至 COM 時所要使用的 typelib ID
|
||||
[assembly: Guid("a42da595-c6e4-4658-8790-f6364df91f84")]
|
||||
|
||||
// 組件的版本資訊是由下列四項值構成:
|
||||
//
|
||||
// 主要版本
|
||||
// 次要版本
|
||||
// 組建編號
|
||||
// 修訂編號
|
||||
//
|
||||
// 您可以指定所有的值,也可以依照以下的方式,使用 '*' 將修訂和組建編號
|
||||
// 指定為預設值:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
此檔案由您的 Web 專案發佈/封裝處理序使用。您可以藉由編輯此 MSBuild 檔案,
|
||||
自訂此處理序的行為。若要深入了解,請前往 https://go.microsoft.com/fwlink/?LinkID=208121。
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||
<PublishProvider>FileSystem</PublishProvider>
|
||||
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||
<SiteUrlToLaunchAfterPublish />
|
||||
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
|
||||
<ExcludeApp_Data>False</ExcludeApp_Data>
|
||||
<publishUrl>D:\VS.NET\Thinkyu\BackupServiceRelease</publishUrl>
|
||||
<DeleteExistingFiles>False</DeleteExistingFiles>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 如需使用 web.config 轉換的詳細資訊,請前往 https://go.microsoft.com/fwlink/?LinkId=125889 -->
|
||||
|
||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||
<!--
|
||||
在下面的範例中,"SetAttributes" 轉換只會在 "Match" 定位程式找到
|
||||
值為 "MyDB" 的屬性 "name" 時,才將 "connectionString" 的值變
|
||||
更為使用 "ReleaseSQLServer"。
|
||||
|
||||
<connectionStrings>
|
||||
<add name="MyDB"
|
||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||
</connectionStrings>
|
||||
-->
|
||||
<system.web>
|
||||
<!--
|
||||
|
||||
在下面的範例中,"Replace" 轉換將會取代 web.config 檔案
|
||||
的整個 <customErrors> 區段。
|
||||
請注意,因為在 <system.web> 節點之下
|
||||
只有一個 customErrors 區段,所以不需要使用 "xdt:Locator" 屬性。
|
||||
|
||||
<customErrors defaultRedirect="GenericError.htm"
|
||||
mode="RemoteOnly" xdt:Transform="Replace">
|
||||
<error statusCode="500" redirect="InternalError.htm"/>
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!-- 如需使用 web.config 轉換的詳細資訊,請前往 https://go.microsoft.com/fwlink/?LinkId=125889 -->
|
||||
|
||||
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||
<!--
|
||||
在下面的範例中,"SetAttributes" 轉換只會在 "Match" 定位程式找到
|
||||
值為 "MyDB" 的屬性 "name" 時,才將 "connectionString" 的值變
|
||||
更為使用 "ReleaseSQLServer"。
|
||||
|
||||
<connectionStrings>
|
||||
<add name="MyDB"
|
||||
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||
</connectionStrings>
|
||||
-->
|
||||
<system.web>
|
||||
<compilation xdt:Transform="RemoveAttributes(debug)" />
|
||||
<!--
|
||||
|
||||
在下面的範例中,"Replace" 轉換將會取代 web.config 檔案
|
||||
的整個 <customErrors> 區段。
|
||||
請注意,因為在 <system.web> 節點之下
|
||||
只有一個 customErrors 區段,所以不需要使用 "xdt:Locator" 屬性。
|
||||
|
||||
<customErrors defaultRedirect="GenericError.htm"
|
||||
mode="RemoteOnly" xdt:Transform="Replace">
|
||||
<error statusCode="500" redirect="InternalError.htm"/>
|
||||
</customErrors>
|
||||
-->
|
||||
</system.web>
|
||||
</configuration>
|
||||
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
|
||||
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
|
||||
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
|
||||
</sectionGroup>
|
||||
</sectionGroup>
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<appSettings/>
|
||||
<connectionStrings/>
|
||||
<system.web>
|
||||
<compilation debug="true">
|
||||
<assemblies>
|
||||
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
|
||||
</assemblies>
|
||||
</compilation>
|
||||
<!--
|
||||
<authentication> 區段可讓您設定
|
||||
ASP.NET 用來識別連入使用者的
|
||||
安全性驗證模式。
|
||||
-->
|
||||
<authentication mode="Windows"/>
|
||||
<!--
|
||||
<customErrors> 區段可讓您設定
|
||||
當執行要求期間發生無法處理
|
||||
之錯誤時的處理方式。更明確地說,
|
||||
開發人員可以利用它設定要顯示的
|
||||
html 錯誤頁面,以取代錯誤堆疊追蹤。
|
||||
|
||||
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
|
||||
<error statusCode="403" redirect="NoAccess.htm" />
|
||||
<error statusCode="404" redirect="FileNotFound.htm" />
|
||||
</customErrors>
|
||||
-->
|
||||
<pages>
|
||||
<controls>
|
||||
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</controls>
|
||||
</pages>
|
||||
<httpRuntime executionTimeout="600"/>
|
||||
<httpHandlers>
|
||||
<remove verb="*" path="*.asmx"/>
|
||||
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
|
||||
</httpHandlers>
|
||||
<httpModules>
|
||||
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</httpModules>
|
||||
</system.web>
|
||||
<system.codedom>
|
||||
<compilers>
|
||||
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<providerOption name="CompilerVersion" value="v3.5"/>
|
||||
<providerOption name="WarnAsError" value="false"/>
|
||||
</compiler>
|
||||
</compilers>
|
||||
</system.codedom>
|
||||
<!--
|
||||
在 Internet Information Services 7.0 下,需要有 system.webServer 區段才能執行
|
||||
ASP.NET AJAX。在舊版 IIS 下則不需要。
|
||||
-->
|
||||
<system.webServer>
|
||||
<validation validateIntegratedModeConfiguration="false"/>
|
||||
<modules>
|
||||
<remove name="ScriptModule"/>
|
||||
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</modules>
|
||||
<handlers>
|
||||
<remove name="WebServiceHandlerFactory-Integrated"/>
|
||||
<remove name="ScriptHandlerFactory"/>
|
||||
<remove name="ScriptHandlerFactoryAppServices"/>
|
||||
<remove name="ScriptResource"/>
|
||||
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
<system.web.extensions>
|
||||
<scripting>
|
||||
<webServices>
|
||||
<jsonSerialization maxJsonLength="1048576000"/>
|
||||
</webServices>
|
||||
</scripting>
|
||||
</system.web.extensions>
|
||||
<runtime>
|
||||
<assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user