主要更新了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.Collections.Generic;
using System.IO;
using System.Linq;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Ramitta.lib
@@ -156,7 +152,7 @@ namespace Ramitta.lib
return Convert.ToBase64String(signature);
}
}
catch (Exception ex)
catch (Exception)
{
return null;
}
@@ -179,7 +175,7 @@ namespace Ramitta.lib
return Encoding.UTF8.GetString(decryptedBytes);
}
}
catch (Exception ex)
catch (Exception)
{
return null;
}
@@ -251,7 +247,7 @@ namespace Ramitta.lib
return Convert.ToBase64String(signature);
}
}
catch (Exception ex)
catch (Exception)
{
return null;
}

View File

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

View File

@@ -1,10 +1,5 @@
using Npgsql;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ramitta
{
@@ -145,7 +140,7 @@ namespace Ramitta
{
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];
if (parameters != null)

View File

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

View File

@@ -1,11 +1,6 @@
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ramitta.lib
{
@@ -85,8 +80,8 @@ namespace Ramitta.lib
}
public static Dictionary<string, List<string>> ReadExcelAsDictCol(
string filePath,
object sheetName = null,
string filePath,
object sheetName = null,
List<string> headerInit = null)
{
var result = new Dictionary<string, List<string>>();
@@ -166,23 +161,55 @@ namespace Ramitta.lib
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);
if (row == null) return null;
ICell cell = row.GetCell(cellIndex);
ICell cell = row.GetCell(actualCellIndex);
if (cell == null) return null;
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;
}
// 简短版本
// 简短版本
// 列名字转为列号
public static int ColToIndex(string col)
{
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.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -32,13 +25,13 @@ namespace Ramitta.lib
#endregion
#region
public static void DebugBar(Label obj, String? text, SolidColorBrush? color=null)
public static void DebugBar(Label obj, String? text, SolidColorBrush? color = null)
{
if (obj == null) return;
// 通过Dispatcher确保在UI线程执行
obj.Dispatcher.Invoke(() =>
{
if (text!=null)obj.Content = text;
if (text != null) obj.Content = text;
if (color != null) obj.Background = color;
@@ -122,37 +115,6 @@ namespace Ramitta.lib
}
#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
public static bool IsPathExist(string databasePath)
{
@@ -163,7 +125,7 @@ namespace Ramitta.lib
return Directory.Exists(databasePath);
}
public static void FileWrite(string outputPath, string outputText, bool createDirectories = true,bool fileAdd = false)
public static void FileWrite(string outputPath, string outputText, bool createDirectories = true, bool fileAdd = false)
{
string directory = Path.GetDirectoryName(outputPath);
if (createDirectories && !Directory.Exists(directory))
@@ -182,7 +144,7 @@ namespace Ramitta.lib
{
try
{
return File.ReadAllText(outputPath);
return File.ReadAllText(outputPath);
}
catch
{
@@ -262,7 +224,7 @@ namespace Ramitta.lib
#endregion
#region
public static async Task<int> RunExternalCommand(string? applicationPath = "explorer.exe", string arguments="", bool UseShellExecute = false, bool CreateNoWindow = false)
public static async Task<int> RunExternalCommand(string? applicationPath = "explorer.exe", string arguments = "", bool UseShellExecute = false, bool CreateNoWindow = false)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
@@ -289,7 +251,7 @@ namespace Ramitta.lib
}
catch (Exception ex)
catch (Exception)
{
throw;
}
@@ -335,7 +297,7 @@ namespace Ramitta.lib
return output; // 返回标准输出内容
}
}
catch (Exception ex)
catch (Exception)
{
// 可以记录或处理异常
throw; // 重新抛出异常以便调用者捕获

View File

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

View File

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

View File

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

View File

@@ -1,13 +1,10 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using static Ramitta.winDataGrid;
namespace Ramitta
{
@@ -20,7 +17,7 @@ namespace Ramitta
> Rows
{ get; private set; }
public Dictionary<string,object> ColumnsName=new();
public Dictionary<string, object> ColumnsName = new();
public winDataGrid()
{
@@ -59,7 +56,7 @@ namespace Ramitta
public void AddColumn(string columnName, ColumnType columnType)
{
DataGridTemplateColumn column = new DataGridTemplateColumn();
FrameworkElementFactory? elementFactory=null;
FrameworkElementFactory? elementFactory = null;
ColumnsName.Add(columnName, columnType);
switch (columnType)
@@ -90,21 +87,23 @@ namespace Ramitta
SetBindingToProperty(elementFactory, TextBox.BackgroundProperty, $"[{columnName}].Background");
break;
}
DataTemplate dataTemplate = new DataTemplate() { VisualTree=elementFactory};
DataTemplate dataTemplate = new DataTemplate() { VisualTree = elementFactory };
column.Header = columnName;
column.CellTemplate = dataTemplate;
column.CellEditingTemplate = dataTemplate;
xDataGrid.Columns.Add( column );
xDataGrid.Columns.Add(column);
}
public Dictionary<string, object> AddRow(){
public Dictionary<string, object> AddRow()
{
var keys = ColumnsName.Keys.ToList();
var row = new Dictionary<string, object> { };
foreach (var key in keys) {
foreach (var key in keys)
{
switch (ColumnsName[key])
{
@@ -118,7 +117,7 @@ namespace Ramitta
row.Add(key, new ComboBox());
break;
case ColumnType.TextBox:
row.Add(key, new TextBox());
row.Add(key, new TextBox());
break;
case ColumnType.Label:
row.Add(key, new Label());
@@ -130,7 +129,8 @@ namespace Ramitta
return row;
}
public void Clear() {
public void Clear()
{
Rows.Clear();
}

View File

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

View File

@@ -1,26 +1,10 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
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
{
@@ -104,9 +88,9 @@ namespace Ramitta
return node;
}
public RadioButtonTreeNode AddRadioButtonNode(string text, string? tag = null,string? GroupName = null, bool isChecked = false, TreeNode? parent = null)
public RadioButtonTreeNode AddRadioButtonNode(string text, string? tag = null, string? GroupName = null, bool isChecked = false, TreeNode? parent = null)
{
var RadioButton = new RadioButton()
{
Visibility = Visibility.Visible,
@@ -285,8 +269,7 @@ namespace Ramitta
// 清空现有数据
Clear();
if (string.IsNullOrWhiteSpace(jsonContent))
return;
if (string.IsNullOrWhiteSpace(jsonContent)) return;
try
{
@@ -320,7 +303,7 @@ namespace Ramitta
{
case nameof(LabelTreeNode):
newNode = CreateLabelTreeNode(nodeObject, text);
break;
case nameof(CheckboxTreeNode):
@@ -437,7 +420,7 @@ namespace Ramitta
ExpandNode(node);
}
}
public void CollapseAll(object? sender=null, RoutedEventArgs? e=null)
public void CollapseAll(object? sender = null, RoutedEventArgs? e = null)
{
foreach (var node in Nodes)
{
@@ -489,7 +472,7 @@ namespace Ramitta
parent.Children.Add(node);
}
}
private IEnumerable<TreeNode> GetAllNodes(IEnumerable<TreeNode>? nodes=null)
private IEnumerable<TreeNode> GetAllNodes(IEnumerable<TreeNode>? nodes = null)
{
if (nodes == null) nodes = null;
foreach (var node in nodes)