Skip to content

Commit c55f6c4

Browse files
committed
up
更改备份方式 修复代码上传存在的问题 修复数据库无法使用
1 parent f824d23 commit c55f6c4

12 files changed

Lines changed: 121 additions & 69 deletions

File tree

CodeTest/Program.cs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
using ColoryrServer.Core.FileSystem;
2+
using ICSharpCode.SharpZipLib.Zip;
23
using MySql.Data.MySqlClient;
34
using System;
45
using System.Collections.Generic;
56
using System.Diagnostics;
7+
using System.IO;
68

7-
Stopwatch stopwatch = new();
8-
stopwatch.Start();
9-
var Conn = new MySqlConnection("SslMode=none;Server=127.0.0.1;Port=3306;User ID=root;Password=123456;Charset=utf8;Pooling=false;");
10-
Conn.Open();
11-
stopwatch.Stop();
12-
Console.WriteLine(stopwatch.Elapsed);
13-
14-
MySqlCommand Sql = new MySqlCommand("select * from citypipeerror");
15-
16-
Sql.Connection = Conn;
17-
Sql.Connection.ChangeDatabase("citypipe");
18-
MySqlDataReader reader = Sql.ExecuteReader();
19-
var readlist = new List<List<dynamic>>();
20-
var readlist1 = new List<Dictionary<string, dynamic>>();
21-
while (reader.Read())
9+
var dir = AppContext.BaseDirectory + "test\\";
10+
if (!Directory.Exists(dir))
11+
{
12+
Directory.CreateDirectory(dir);
13+
}
14+
ZipFile zip;
15+
if (!File.Exists(dir + "backup.zip"))
2216
{
23-
var item = new List<dynamic>();
24-
var item1 = new Dictionary<string, dynamic>();
25-
var data = reader.GetSchemaTable();
26-
for (int b = 0; b < reader.FieldCount; b++)
27-
{
28-
item1.Add(data.Rows[b][0] as string, reader[b]);
29-
item.Add(reader[b]);
30-
}
31-
readlist1.Add(item1);
32-
readlist.Add(item);
17+
ZipOutputStream s = new(File.Create(dir + "backup.zip"));
18+
s.Close();
3319
}
34-
reader.Close();
35-
Sql.Connection.Close();
20+
zip = new ZipFile(dir + "backup.zip");
21+
var dir1 = AppContext.BaseDirectory + "test\\test\\";
22+
zip.BeginUpdate();
23+
foreach (var item in new DirectoryInfo(dir1).GetFiles())
24+
{
25+
zip.Add(item.FullName, item.Name);
26+
}
27+
zip.CommitUpdate();
28+
zip.Close();
29+
3630

ColoryrBuild/ColoryrBuild.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<MinimumPlatformVersion>7.0</MinimumPlatformVersion>
99
<AssemblyVersion>1.1.0</AssemblyVersion>
1010
<FileVersion>1.1.0</FileVersion>
11+
<DebugType>embedded</DebugType>
1112
</PropertyGroup>
1213

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

2931
<ItemGroup>

ColoryrBuild/Windows/EditWindow.xaml.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,18 @@ private async void OnChanged(object source, FileSystemEventArgs e)
7171
Write = true;
7272
if(type is CodeType.Web)
7373
{
74-
obj1.Code = CodeSave.Load(Local + e.Name);
74+
obj3.Codes[e.Name] = CodeSave.Load(Local + e.Name).Replace("\r", "");
7575
await Dispatcher.InvokeAsync(() =>
7676
{
77-
Model = App.StartContrast(obj1, old);
78-
textEditor.Text = obj1.Code;
77+
Model = App.StartContrast(type, obj3.UUID, obj3.Codes[e.Name], old);
78+
textEditor.Text = obj3.Codes[e.Name];
7979
});
8080
}
8181
else if (type is not CodeType.App and not CodeType.Web)
8282
{
8383
if (e.Name == "main.cs")
8484
{
85-
obj1.Code = CodeSave.Load(Local + "main.cs");
85+
obj1.Code = CodeSave.Load(Local + "main.cs").Replace("\r", "");
8686
await Dispatcher.InvokeAsync(() =>
8787
{
8888
Model = App.StartContrast(obj1, old);
@@ -114,18 +114,22 @@ public async void GetCode()
114114
else
115115
obj1 = data;
116116

117+
obj1.Code = obj1.Code;
118+
117119
textEditor.Text = obj1.Code;
118120
old = obj1.Code;
119121
Text.Text = obj1.Text;
120122
if (File.Exists(Local + "main.cs"))
121123
{
122124
string time = string.Format("{0:s}", DateTime.Now).Replace(":", "_");
123-
var newLocal = Local + "backup/";
124-
if (!Directory.Exists(newLocal))
125+
try
126+
{
127+
ZIPUtils.Pack(Local, Local + "main.cs", time + ".cs");
128+
}
129+
catch
125130
{
126-
Directory.CreateDirectory(newLocal);
131+
MessageBox.Show("备份失败");
127132
}
128-
File.Move(Local + "main.cs", newLocal + time + ".cs");
129133
}
130134
CodeSave.Save(Local + "main.cs", obj1.Code);
131135
App.LogShow("获取代码", $"代码{obj1.Type}[{obj1.UUID}]获取成功");
@@ -145,11 +149,13 @@ public async void GetCode()
145149
FileList.Items.Clear();
146150

147151
string time = string.Format("{0:s}", DateTime.Now).Replace(":", "_");
148-
var newLocal = Local + $"backup_{time}/";
149-
if (!Directory.Exists(newLocal))
152+
153+
var newLocal = Local + $"backup/";
154+
if (Directory.Exists(newLocal))
150155
{
151-
Directory.CreateDirectory(newLocal);
156+
Directory.Delete(newLocal, true);
152157
}
158+
Directory.CreateDirectory(newLocal);
153159

154160
foreach (var item in obj3.Codes)
155161
{
@@ -160,6 +166,17 @@ public async void GetCode()
160166
CodeSave.Save(Local + item.Key, item.Value);
161167
FileList.Items.Add(item.Key);
162168
}
169+
170+
try
171+
{
172+
ZIPUtils.Pack1(Local, newLocal, $"backup_{time}");
173+
}
174+
catch
175+
{
176+
MessageBox.Show("备份失败");
177+
}
178+
Directory.Delete(newLocal, true);
179+
163180
foreach (var item in obj3.Files)
164181
{
165182
FileList.Items.Add(item.Key);
@@ -244,13 +261,13 @@ private async Task UpdateTask()
244261
if (thisfile.EndsWith(".cs"))
245262
{
246263
string temp = thisfile.Replace(".cs", "");
247-
obj2.Codes[temp] = textEditor.Text;
264+
obj2.Codes[temp] = textEditor.Text.Replace("\r", "");
248265
Model = App.StartContrast(type, obj2.UUID, obj2.Codes[temp], old);
249266
}
250267
else if (thisfile.EndsWith(".xaml"))
251268
{
252269
string temp = thisfile.Replace(".xaml", "");
253-
obj2.Codes[temp] = textEditor.Text;
270+
obj2.Codes[temp] = textEditor.Text.Replace("\r", "");
254271
Model = App.StartContrast(type, obj2.UUID, obj2.Xamls[temp], old);
255272
}
256273
else
@@ -265,7 +282,7 @@ private async Task UpdateTask()
265282
|| thisfile.EndsWith(".js") || thisfile.EndsWith(".json")
266283
|| thisfile.EndsWith(".txt"))
267284
{
268-
obj3.Codes[thisfile] = textEditor.Text;
285+
obj3.Codes[thisfile] = textEditor.Text.Replace("\r", "");
269286
Model = App.StartContrast(type, obj3.UUID, obj3.Codes[thisfile], old);
270287
}
271288
else
@@ -276,7 +293,7 @@ private async Task UpdateTask()
276293
else
277294
{
278295
obj1.Text = Text.Text;
279-
obj1.Code = textEditor.Text;
296+
obj1.Code = textEditor.Text.Replace("\r", "");
280297
await Dispatcher.InvokeAsync(() =>
281298
{
282299
Model = App.StartContrast(obj1, old);

ColoryrBuild/ZIPUtils.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using ICSharpCode.SharpZipLib.Zip;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ColoryrBuild
10+
{
11+
internal class ZIPUtils
12+
{
13+
public static void Pack(string dir, string file, string name)
14+
{
15+
ZipFile zip;
16+
if (!File.Exists(dir + "backup.zip"))
17+
{
18+
ZipOutputStream s = new(File.Create(dir + "backup.zip"));
19+
s.Close();
20+
}
21+
zip = new ZipFile(dir + "backup.zip");
22+
zip.BeginUpdate();
23+
zip.Add(file, name);
24+
zip.CommitUpdate();
25+
zip.Close();
26+
}
27+
28+
public static void Pack1(string dir, string dir1, string name)
29+
{
30+
ZipFile zip;
31+
if (!File.Exists(dir + "backup.zip"))
32+
{
33+
ZipOutputStream s = new(File.Create(dir + "backup.zip"));
34+
s.Close();
35+
}
36+
zip = new ZipFile(dir + "backup.zip");
37+
zip.BeginUpdate();
38+
zip.AddDirectory(name);
39+
foreach (var item in new DirectoryInfo(dir1).GetFiles())
40+
{
41+
zip.Add(item.FullName, name + "/" + item.Name);
42+
}
43+
zip.CommitUpdate();
44+
zip.Close();
45+
}
46+
}
47+
}

ColoryrServer/ASP/ASPConfig.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public override void Start()
102102
Port = 3306,
103103
User = "root",
104104
Password = "MTIzNDU2",
105-
ConnCount = 50,
106105
TimeOut = 1000,
107106
Conn = "SslMode=none;Server={0};Port={1};User ID={2};Password={3};Charset=utf8;"
108107
}
@@ -115,7 +114,6 @@ public override void Start()
115114
IP = "127.0.0.1",
116115
User = "root",
117116
Password = "MTIzNDU2",
118-
ConnCount = 50,
119117
TimeOut = 1000,
120118
Conn = "Server={0};UID={1};PWD={2};"
121119
}
@@ -127,9 +125,7 @@ public override void Start()
127125
Enable = false,
128126
IP = "127.0.0.1",
129127
Port = 6379,
130-
TimeOut = 1000,
131-
Conn = "{0}:{1}",
132-
ConnCount = 20
128+
Conn = "{0}:{1}"
133129
}
134130
},
135131
Oracle = new()
@@ -140,7 +136,6 @@ public override void Start()
140136
IP = "127.0.0.1",
141137
User = "root",
142138
Password = "MTIzNDU2",
143-
ConnCount = 20,
144139
TimeOut = 1000,
145140
Conn = "User Id={2};Password={3};Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVICE_NAME=test)))"
146141
}

ColoryrServer/Core/DataBase/MSCon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static SqlRes MSsqlSqlRes(SqlCommand Sql, string Database, int id)
142142
try
143143
{
144144
Sql.Connection = new SqlConnection(ConnectStr[id]);
145+
Sql.Connection.Open();
145146
Sql.Connection.ChangeDatabase(Database);
146147
SqlDataReader reader = Sql.ExecuteReader();
147148
var readlist = new List<List<dynamic>>();
@@ -184,6 +185,7 @@ public static List<List<dynamic>> MSsqlSql(SqlCommand Sql, string Database, int
184185
try
185186
{
186187
Sql.Connection = new SqlConnection(ConnectStr[id]);
188+
Sql.Connection.Open();
187189
Sql.Connection.ChangeDatabase(Database);
188190
SqlDataReader reader = Sql.ExecuteReader();
189191
var readlist = new List<List<dynamic>>();

ColoryrServer/Core/DataBase/MysqlCon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static SqlRes MysqlSqlRes(MySqlCommand Sql, string Database, int id)
142142
try
143143
{
144144
Sql.Connection = new MySqlConnection(ConnectStr[id]);
145+
Sql.Connection.Open();
145146
Sql.Connection.ChangeDatabase(Database);
146147
MySqlDataReader reader = Sql.ExecuteReader();
147148
var readlist = new List<List<dynamic>>();
@@ -184,6 +185,7 @@ public static List<List<dynamic>> MysqlSql(MySqlCommand Sql, string Database, in
184185
try
185186
{
186187
Sql.Connection = new MySqlConnection(ConnectStr[id]);
188+
Sql.Connection.Open();
187189
Sql.Connection.ChangeDatabase(Database);
188190
MySqlDataReader reader = Sql.ExecuteReader();
189191
var readlist = new List<List<dynamic>>();

ColoryrServer/Core/DataBase/OracleCon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public static SqlRes OracleSqlRes(OracleCommand Sql, string Database, int id)
141141
try
142142
{
143143
Sql.Connection = new OracleConnection(ConnectStr[id]);
144+
Sql.Connection.Open();
144145
Sql.Connection.ChangeDatabase(Database);
145146
OracleDataReader reader = Sql.ExecuteReader();
146147
var readlist = new List<List<dynamic>>();
@@ -183,6 +184,7 @@ public static List<List<dynamic>> OracleSql(OracleCommand Sql, string Database,
183184
try
184185
{
185186
Sql.Connection = new OracleConnection(ConnectStr[id]);
187+
Sql.Connection.Open();
186188
Sql.Connection.ChangeDatabase(Database);
187189
OracleDataReader reader = Sql.ExecuteReader();
188190
var readlist = new List<List<dynamic>>();

ColoryrServer/Core/DataBase/RedisCon.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,16 @@ public static void Start()
5959
continue;
6060
string ConnectString = string.Format(config.Conn, config.IP, config.Port);
6161
State.Add(a, false);
62-
for (int b = 0; b < config.ConnCount; b++)
62+
var Conn = ConnectionMultiplexer.Connect(ConnectString);
63+
if (Test(Conn))
6364
{
64-
var Conn = ConnectionMultiplexer.Connect(ConnectString);
65-
if (Test(Conn))
66-
{
67-
ConnectStr.Add(a, ConnectString);
68-
State[a] = true;
69-
ServerMain.LogOut($"Redis数据库{a}已连接");
70-
}
71-
else
72-
{
73-
ServerMain.LogError($"Redis数据库{a}连接失败");
74-
}
65+
ConnectStr.Add(a, ConnectString);
66+
State[a] = true;
67+
ServerMain.LogOut($"Redis数据库{a}已连接");
68+
}
69+
else
70+
{
71+
ServerMain.LogError($"Redis数据库{a}连接失败");
7572
}
7673
}
7774
}

ColoryrServer/Core/FileSystem/ConfigUtil.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,6 @@ public record RedisConfig
190190
/// </summary>
191191
public short Port { get; set; }
192192
/// <summary>
193-
/// 连接数
194-
/// </summary>
195-
public int ConnCount { get; set; }
196-
/// <summary>
197-
/// 连接超时
198-
/// </summary>
199-
public int TimeOut { get; set; }
200-
/// <summary>
201193
/// 连接字符串
202194
/// </summary>
203195
public string Conn { get; set; }

0 commit comments

Comments
 (0)