主要更新了http相关的内容

This commit is contained in:
2025-11-18 19:54:13 +08:00
parent bf464b04a6
commit 5762b6daf4
13 changed files with 155 additions and 136 deletions

View File

@@ -1,10 +1,6 @@
using System; using System.IO;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
namespace Ramitta.lib namespace Ramitta.lib
@@ -156,7 +152,7 @@ namespace Ramitta.lib
return Convert.ToBase64String(signature); return Convert.ToBase64String(signature);
} }
} }
catch (Exception ex) catch (Exception)
{ {
return null; return null;
} }
@@ -179,7 +175,7 @@ namespace Ramitta.lib
return Encoding.UTF8.GetString(decryptedBytes); return Encoding.UTF8.GetString(decryptedBytes);
} }
} }
catch (Exception ex) catch (Exception)
{ {
return null; return null;
} }
@@ -251,7 +247,7 @@ namespace Ramitta.lib
return Convert.ToBase64String(signature); return Convert.ToBase64String(signature);
} }
} }
catch (Exception ex) catch (Exception)
{ {
return null; return null;
} }

View File

@@ -1,10 +1,4 @@
using Neo4j.Driver; using Neo4j.Driver;
using NPOI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
namespace Ramitta namespace Ramitta
{ {
@@ -58,7 +52,8 @@ namespace Ramitta
string nodeType2, Dictionary<string, string> nodeProperties2, // 使用字典替代单独的参数 string nodeType2, Dictionary<string, string> nodeProperties2, // 使用字典替代单独的参数
ArrowDirection arrow = ArrowDirection.Right, ArrowDirection arrow = ArrowDirection.Right,
Dictionary<string, string> relationshipProperties = null // 可选字典参数 Dictionary<string, string> relationshipProperties = null // 可选字典参数
){ )
{
using (var session = _driver.AsyncSession()) using (var session = _driver.AsyncSession())
{ {
// 构建查询的 MATCH 部分,动态地使用字典中的键值对来构造节点的属性 // 构建查询的 MATCH 部分,动态地使用字典中的键值对来构造节点的属性

View File

@@ -1,10 +1,5 @@
using Npgsql; using Npgsql;
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ramitta namespace Ramitta
{ {
@@ -145,7 +140,7 @@ namespace Ramitta
{ {
for (int i = 0; i < queries.Count; i++) for (int i = 0; i < queries.Count; i++)
{ {
using (var cmd = new NpgsqlCommand(queries[i], conn, (NpgsqlTransaction)transaction)) using (var cmd = new NpgsqlCommand(queries[i], conn, transaction))
{ {
var parameters = parametersList[i]; var parameters = parametersList[i];
if (parameters != null) if (parameters != null)

View File

@@ -1,6 +1,4 @@
using System; using System.Data;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite; using System.Data.SQLite;
namespace Ramitta namespace Ramitta

View File

@@ -1,11 +1,6 @@
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ramitta.lib namespace Ramitta.lib
{ {
@@ -166,23 +161,55 @@ namespace Ramitta.lib
return true; return true;
} }
public static ICell? getRowCell(ISheet sheet, int rowIndex, int cellIndex) public static ICell? getRowCell(ISheet sheet, int rowIndex, object cellIndex)
{ {
int actualCellIndex = 0;
if (cellIndex is int intIndex)
{
// 如果输入是数字,直接使用
actualCellIndex = intIndex;
}
else if (cellIndex is string strIndex)
{
actualCellIndex = ColToIndex(strIndex);
}
else
{
return null;
}
IRow row = sheet.GetRow(rowIndex); IRow row = sheet.GetRow(rowIndex);
if (row == null) return null; if (row == null) return null;
ICell cell = row.GetCell(cellIndex); ICell cell = row.GetCell(actualCellIndex);
if (cell == null) return null; if (cell == null) return null;
return cell; return cell;
} }
public static String? getRowCellStr(ISheet sheet, int rowIndex, int cellIndex)
public static String? getRowCellStr(ISheet sheet, int rowIndex, object cellIndex)
{ {
var cellValue = getRowCell(sheet, rowIndex, cellIndex)?.ToString(); int actualCellIndex = 0;
if (cellIndex is int intIndex)
{
// 如果输入是数字,直接使用
actualCellIndex = intIndex;
}
else if (cellIndex is string strIndex)
{
actualCellIndex = ColToIndex(strIndex);
}
else
{
return null;
}
var cellValue = getRowCell(sheet, rowIndex, actualCellIndex)?.ToString();
return string.IsNullOrWhiteSpace(cellValue) ? null : cellValue; return string.IsNullOrWhiteSpace(cellValue) ? null : cellValue;
} }
// 简短版本 // 简短版本
// 列名字转为列号
public static int ColToIndex(string col) public static int ColToIndex(string col)
{ {
return col.ToUpper().Aggregate(0, (cur, ch) => cur * 26 + (ch - 'A')); return col.ToUpper().Aggregate(0, (cur, ch) => cur * 26 + (ch - 'A'));

77
Ramitta/HttpHelper.cs Normal file
View File

@@ -0,0 +1,77 @@
using System.IO;
using System.Net;
using System.Text;
namespace Ramitta.lib
{
public static class HttpHelper
{
// 异步发送HTTP GET请求
public static async Task<string> SendHttpGetAsync(string url, int timeout = 10000)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.Timeout = timeout;
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36";
using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
return await reader.ReadToEndAsync();
}
}
catch (Exception ex)
{
throw new Exception($"GET请求失败: {ex.Message}");
}
}
public static async Task<string> SendHttpPostAsync(string url, string jsonData, int timeout = 10000)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Timeout = timeout;
request.ContentType = "application/json";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
byte[] data = Encoding.UTF8.GetBytes(jsonData);
request.ContentLength = data.Length;
using (Stream requestStream = await request.GetRequestStreamAsync())
{
await requestStream.WriteAsync(data, 0, data.Length);
}
using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
{
return await reader.ReadToEndAsync();
}
}
catch (WebException ex)
{
WebResponse errorResponse = ex.Response;
if (errorResponse is HttpWebResponse httpErrorResponse)
{
using (Stream errorStream = httpErrorResponse.GetResponseStream())
using (StreamReader errorReader = new StreamReader(errorStream, Encoding.UTF8))
{
string errorContent = await errorReader.ReadToEndAsync();
throw new Exception($"HTTP错误 {(int)httpErrorResponse.StatusCode} ({httpErrorResponse.StatusCode}): {errorContent}");
}
}
throw new Exception("网络错误: " + ex.Message);
}
catch (Exception ex)
{
throw new Exception("POST请求失败: " + ex.Message);
}
}
}
}

View File

@@ -1,16 +1,9 @@
using Microsoft.VisualBasic;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
@@ -122,37 +115,6 @@ namespace Ramitta.lib
} }
#endregion #endregion
#region
public static Dictionary<string, string>? Startupe;
public static Dictionary<string, string> ParseCommandLineArgs(string[] args)
{
var arguments = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < args.Length; i++)
{
string arg = args[i];
// 检查是否是参数名(以-或/开头)
if (arg.StartsWith("-") || arg.StartsWith("/"))
{
string key = arg.TrimStart('-', '/');
string value = "true"; // 默认值为true表示开关存在
// 检查下一个参数是否是值(不以-或/开头)
if (i + 1 < args.Length && !args[i + 1].StartsWith("-") && !args[i + 1].StartsWith("/"))
{
value = args[i + 1];
i++; // 跳过下一个参数,因为已经被用作值
}
arguments[key] = value;
}
}
return arguments;
}
#endregion
#region #region
public static bool IsPathExist(string databasePath) public static bool IsPathExist(string databasePath)
{ {
@@ -289,7 +251,7 @@ namespace Ramitta.lib
} }
catch (Exception ex) catch (Exception)
{ {
throw; throw;
} }
@@ -335,7 +297,7 @@ namespace Ramitta.lib
return output; // 返回标准输出内容 return output; // 返回标准输出内容
} }
} }
catch (Exception ex) catch (Exception)
{ {
// 可以记录或处理异常 // 可以记录或处理异常
throw; // 重新抛出异常以便调用者捕获 throw; // 重新抛出异常以便调用者捕获

View File

@@ -1,6 +1,4 @@
using System; using System.IO.Ports;
using System.IO.Ports;
using System.Threading;
namespace Ramitta.lib namespace Ramitta.lib

View File

@@ -1,9 +1,4 @@
using System; using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Ramitta.Utils namespace Ramitta.Utils
{ {

View File

@@ -1,9 +1,4 @@
using System; using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input; using System.Windows.Input;
namespace Ramitta.Utils namespace Ramitta.Utils
@@ -47,7 +42,6 @@ namespace Ramitta.Utils
Window win = Window.GetWindow(this); Window win = Window.GetWindow(this);
ResizePosition ResPosition = ResizePosition.None; ResizePosition ResPosition = ResizePosition.None;
int Resizer = 10; int Resizer = 10;
int ResizerSpeed = 10;
win.MouseMove += new MouseEventHandler( win.MouseMove += new MouseEventHandler(
delegate (object target, MouseEventArgs args) delegate (object target, MouseEventArgs args)
{ {

View File

@@ -1,13 +1,10 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Media; using System.Windows.Media;
using static Ramitta.winDataGrid;
namespace Ramitta namespace Ramitta
{ {
@@ -100,11 +97,13 @@ namespace Ramitta
public Dictionary<string, object> AddRow(){ public Dictionary<string, object> AddRow()
{
var keys = ColumnsName.Keys.ToList(); var keys = ColumnsName.Keys.ToList();
var row = new Dictionary<string, object> { }; var row = new Dictionary<string, object> { };
foreach (var key in keys) { foreach (var key in keys)
{
switch (ColumnsName[key]) switch (ColumnsName[key])
{ {
@@ -130,7 +129,8 @@ namespace Ramitta
return row; return row;
} }
public void Clear() { public void Clear()
{
Rows.Clear(); Rows.Clear();
} }

View File

@@ -1,5 +1,4 @@
using System; using System.Windows;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;

View File

@@ -1,26 +1,10 @@
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Ramitta namespace Ramitta
{ {
@@ -285,8 +269,7 @@ namespace Ramitta
// 清空现有数据 // 清空现有数据
Clear(); Clear();
if (string.IsNullOrWhiteSpace(jsonContent)) if (string.IsNullOrWhiteSpace(jsonContent)) return;
return;
try try
{ {