Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
更改备份方式
修复代码上传存在的问题
修复数据库无法使用
  • Loading branch information
Coloryr committed Nov 27, 2021
1 parent f824d23 commit c55f6c4
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 69 deletions.
48 changes: 21 additions & 27 deletions CodeTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
using ColoryrServer.Core.FileSystem;
using ICSharpCode.SharpZipLib.Zip;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

Stopwatch stopwatch = new();
stopwatch.Start();
var Conn = new MySqlConnection("SslMode=none;Server=127.0.0.1;Port=3306;User ID=root;Password=123456;Charset=utf8;Pooling=false;");
Conn.Open();
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed);

MySqlCommand Sql = new MySqlCommand("select * from citypipeerror");

Sql.Connection = Conn;
Sql.Connection.ChangeDatabase("citypipe");
MySqlDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
var readlist1 = new List<Dictionary<string, dynamic>>();
while (reader.Read())
var dir = AppContext.BaseDirectory + "test\\";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
ZipFile zip;
if (!File.Exists(dir + "backup.zip"))
{
var item = new List<dynamic>();
var item1 = new Dictionary<string, dynamic>();
var data = reader.GetSchemaTable();
for (int b = 0; b < reader.FieldCount; b++)
{
item1.Add(data.Rows[b][0] as string, reader[b]);
item.Add(reader[b]);
}
readlist1.Add(item1);
readlist.Add(item);
ZipOutputStream s = new(File.Create(dir + "backup.zip"));
s.Close();
}
reader.Close();
Sql.Connection.Close();
zip = new ZipFile(dir + "backup.zip");
var dir1 = AppContext.BaseDirectory + "test\\test\\";
zip.BeginUpdate();
foreach (var item in new DirectoryInfo(dir1).GetFiles())
{
zip.Add(item.FullName, item.Name);
}
zip.CommitUpdate();
zip.Close();


2 changes: 2 additions & 0 deletions ColoryrBuild/ColoryrBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<MinimumPlatformVersion>7.0</MinimumPlatformVersion>
<AssemblyVersion>1.1.0</AssemblyVersion>
<FileVersion>1.1.0</FileVersion>
<DebugType>embedded</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -24,6 +25,7 @@
<PackageReference Include="DiffPlex.Wpf" Version="1.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NotifyIconWpf" Version="1.0.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
</ItemGroup>

<ItemGroup>
Expand Down
47 changes: 32 additions & 15 deletions ColoryrBuild/Windows/EditWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ private async void OnChanged(object source, FileSystemEventArgs e)
Write = true;
if(type is CodeType.Web)
{
obj1.Code = CodeSave.Load(Local + e.Name);
obj3.Codes[e.Name] = CodeSave.Load(Local + e.Name).Replace("\r", "");
await Dispatcher.InvokeAsync(() =>
{
Model = App.StartContrast(obj1, old);
textEditor.Text = obj1.Code;
Model = App.StartContrast(type, obj3.UUID, obj3.Codes[e.Name], old);
textEditor.Text = obj3.Codes[e.Name];
});
}
else if (type is not CodeType.App and not CodeType.Web)
{
if (e.Name == "main.cs")
{
obj1.Code = CodeSave.Load(Local + "main.cs");
obj1.Code = CodeSave.Load(Local + "main.cs").Replace("\r", "");
await Dispatcher.InvokeAsync(() =>
{
Model = App.StartContrast(obj1, old);
Expand Down Expand Up @@ -114,18 +114,22 @@ public async void GetCode()
else
obj1 = data;

obj1.Code = obj1.Code;

textEditor.Text = obj1.Code;
old = obj1.Code;
Text.Text = obj1.Text;
if (File.Exists(Local + "main.cs"))
{
string time = string.Format("{0:s}", DateTime.Now).Replace(":", "_");
var newLocal = Local + "backup/";
if (!Directory.Exists(newLocal))
try
{
ZIPUtils.Pack(Local, Local + "main.cs", time + ".cs");
}
catch
{
Directory.CreateDirectory(newLocal);
MessageBox.Show("备份失败");
}
File.Move(Local + "main.cs", newLocal + time + ".cs");
}
CodeSave.Save(Local + "main.cs", obj1.Code);
App.LogShow("获取代码", $"代码{obj1.Type}[{obj1.UUID}]获取成功");
Expand All @@ -145,11 +149,13 @@ public async void GetCode()
FileList.Items.Clear();

string time = string.Format("{0:s}", DateTime.Now).Replace(":", "_");
var newLocal = Local + $"backup_{time}/";
if (!Directory.Exists(newLocal))

var newLocal = Local + $"backup/";
if (Directory.Exists(newLocal))
{
Directory.CreateDirectory(newLocal);
Directory.Delete(newLocal, true);
}
Directory.CreateDirectory(newLocal);

foreach (var item in obj3.Codes)
{
Expand All @@ -160,6 +166,17 @@ public async void GetCode()
CodeSave.Save(Local + item.Key, item.Value);
FileList.Items.Add(item.Key);
}

try
{
ZIPUtils.Pack1(Local, newLocal, $"backup_{time}");
}
catch
{
MessageBox.Show("备份失败");
}
Directory.Delete(newLocal, true);

foreach (var item in obj3.Files)
{
FileList.Items.Add(item.Key);
Expand Down Expand Up @@ -244,13 +261,13 @@ private async Task UpdateTask()
if (thisfile.EndsWith(".cs"))
{
string temp = thisfile.Replace(".cs", "");
obj2.Codes[temp] = textEditor.Text;
obj2.Codes[temp] = textEditor.Text.Replace("\r", "");
Model = App.StartContrast(type, obj2.UUID, obj2.Codes[temp], old);
}
else if (thisfile.EndsWith(".xaml"))
{
string temp = thisfile.Replace(".xaml", "");
obj2.Codes[temp] = textEditor.Text;
obj2.Codes[temp] = textEditor.Text.Replace("\r", "");
Model = App.StartContrast(type, obj2.UUID, obj2.Xamls[temp], old);
}
else
Expand All @@ -265,7 +282,7 @@ private async Task UpdateTask()
|| thisfile.EndsWith(".js") || thisfile.EndsWith(".json")
|| thisfile.EndsWith(".txt"))
{
obj3.Codes[thisfile] = textEditor.Text;
obj3.Codes[thisfile] = textEditor.Text.Replace("\r", "");
Model = App.StartContrast(type, obj3.UUID, obj3.Codes[thisfile], old);
}
else
Expand All @@ -276,7 +293,7 @@ private async Task UpdateTask()
else
{
obj1.Text = Text.Text;
obj1.Code = textEditor.Text;
obj1.Code = textEditor.Text.Replace("\r", "");
await Dispatcher.InvokeAsync(() =>
{
Model = App.StartContrast(obj1, old);
Expand Down
47 changes: 47 additions & 0 deletions ColoryrBuild/ZIPUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using ICSharpCode.SharpZipLib.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ColoryrBuild
{
internal class ZIPUtils
{
public static void Pack(string dir, string file, string name)
{
ZipFile zip;
if (!File.Exists(dir + "backup.zip"))
{
ZipOutputStream s = new(File.Create(dir + "backup.zip"));
s.Close();
}
zip = new ZipFile(dir + "backup.zip");
zip.BeginUpdate();
zip.Add(file, name);
zip.CommitUpdate();
zip.Close();
}

public static void Pack1(string dir, string dir1, string name)
{
ZipFile zip;
if (!File.Exists(dir + "backup.zip"))
{
ZipOutputStream s = new(File.Create(dir + "backup.zip"));
s.Close();
}
zip = new ZipFile(dir + "backup.zip");
zip.BeginUpdate();
zip.AddDirectory(name);
foreach (var item in new DirectoryInfo(dir1).GetFiles())
{
zip.Add(item.FullName, name + "/" + item.Name);
}
zip.CommitUpdate();
zip.Close();
}
}
}
7 changes: 1 addition & 6 deletions ColoryrServer/ASP/ASPConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public override void Start()
Port = 3306,
User = "root",
Password = "MTIzNDU2",
ConnCount = 50,
TimeOut = 1000,
Conn = "SslMode=none;Server={0};Port={1};User ID={2};Password={3};Charset=utf8;"
}
Expand All @@ -115,7 +114,6 @@ public override void Start()
IP = "127.0.0.1",
User = "root",
Password = "MTIzNDU2",
ConnCount = 50,
TimeOut = 1000,
Conn = "Server={0};UID={1};PWD={2};"
}
Expand All @@ -127,9 +125,7 @@ public override void Start()
Enable = false,
IP = "127.0.0.1",
Port = 6379,
TimeOut = 1000,
Conn = "{0}:{1}",
ConnCount = 20
Conn = "{0}:{1}"
}
},
Oracle = new()
Expand All @@ -140,7 +136,6 @@ public override void Start()
IP = "127.0.0.1",
User = "root",
Password = "MTIzNDU2",
ConnCount = 20,
TimeOut = 1000,
Conn = "User Id={2};Password={3};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVICE_NAME=test)))"
}
Expand Down
2 changes: 2 additions & 0 deletions ColoryrServer/Core/DataBase/MSCon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static SqlRes MSsqlSqlRes(SqlCommand Sql, string Database, int id)
try
{
Sql.Connection = new SqlConnection(ConnectStr[id]);
Sql.Connection.Open();
Sql.Connection.ChangeDatabase(Database);
SqlDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
Expand Down Expand Up @@ -184,6 +185,7 @@ public static List<List<dynamic>> MSsqlSql(SqlCommand Sql, string Database, int
try
{
Sql.Connection = new SqlConnection(ConnectStr[id]);
Sql.Connection.Open();
Sql.Connection.ChangeDatabase(Database);
SqlDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
Expand Down
2 changes: 2 additions & 0 deletions ColoryrServer/Core/DataBase/MysqlCon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static SqlRes MysqlSqlRes(MySqlCommand Sql, string Database, int id)
try
{
Sql.Connection = new MySqlConnection(ConnectStr[id]);
Sql.Connection.Open();
Sql.Connection.ChangeDatabase(Database);
MySqlDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
Expand Down Expand Up @@ -184,6 +185,7 @@ public static List<List<dynamic>> MysqlSql(MySqlCommand Sql, string Database, in
try
{
Sql.Connection = new MySqlConnection(ConnectStr[id]);
Sql.Connection.Open();
Sql.Connection.ChangeDatabase(Database);
MySqlDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
Expand Down
2 changes: 2 additions & 0 deletions ColoryrServer/Core/DataBase/OracleCon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public static SqlRes OracleSqlRes(OracleCommand Sql, string Database, int id)
try
{
Sql.Connection = new OracleConnection(ConnectStr[id]);
Sql.Connection.Open();
Sql.Connection.ChangeDatabase(Database);
OracleDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
Expand Down Expand Up @@ -183,6 +184,7 @@ public static List<List<dynamic>> OracleSql(OracleCommand Sql, string Database,
try
{
Sql.Connection = new OracleConnection(ConnectStr[id]);
Sql.Connection.Open();
Sql.Connection.ChangeDatabase(Database);
OracleDataReader reader = Sql.ExecuteReader();
var readlist = new List<List<dynamic>>();
Expand Down
21 changes: 9 additions & 12 deletions ColoryrServer/Core/DataBase/RedisCon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,16 @@ public static void Start()
continue;
string ConnectString = string.Format(config.Conn, config.IP, config.Port);
State.Add(a, false);
for (int b = 0; b < config.ConnCount; b++)
var Conn = ConnectionMultiplexer.Connect(ConnectString);
if (Test(Conn))
{
var Conn = ConnectionMultiplexer.Connect(ConnectString);
if (Test(Conn))
{
ConnectStr.Add(a, ConnectString);
State[a] = true;
ServerMain.LogOut($"Redis数据库{a}已连接");
}
else
{
ServerMain.LogError($"Redis数据库{a}连接失败");
}
ConnectStr.Add(a, ConnectString);
State[a] = true;
ServerMain.LogOut($"Redis数据库{a}已连接");
}
else
{
ServerMain.LogError($"Redis数据库{a}连接失败");
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions ColoryrServer/Core/FileSystem/ConfigUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@ public record RedisConfig
/// </summary>
public short Port { get; set; }
/// <summary>
/// 连接数
/// </summary>
public int ConnCount { get; set; }
/// <summary>
/// 连接超时
/// </summary>
public int TimeOut { get; set; }
/// <summary>
/// 连接字符串
/// </summary>
public string Conn { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion ColoryrServer/Core/FileSystem/FileEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class FileEdit
{
public static string StartEdit(string old, List<CodeEditObj> editText)
{
var temp = old.Split("\n");
var temp = old.Replace("\r", "").Split("\n");
int arg = 0;
var list = new List<string>(temp);
foreach (var item in editText)
Expand Down
2 changes: 2 additions & 0 deletions ColoryrServer/Core/ServerMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -119,6 +120,7 @@ public static void Start()
bitmap.Dispose();
Stream zip = ZipOutputStream.Null;
Stream zip1 = ZipInputStream.Null;
NameValueCollection nameValue = new();

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Expand Down

0 comments on commit c55f6c4

Please sign in to comment.