|
@@ -29,6 +29,10 @@ namespace GetEasy.Node.Printer
|
|
|
{
|
|
|
public class NodeReportDesigner
|
|
|
{
|
|
|
+ private static ManualResetEvent _nodeThread;
|
|
|
+ private static ManualResetEvent _formThread;
|
|
|
+ private static SaveObj _saveObj;
|
|
|
+
|
|
|
///// <summary>
|
|
|
///// 保存回调方法,防止被GC
|
|
|
///// </summary>
|
|
@@ -36,7 +40,7 @@ namespace GetEasy.Node.Printer
|
|
|
static NodeReportDesigner()
|
|
|
{
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
|
|
public delegate void SaveCallback([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]String template, SaveResultCallback resultCallback);
|
|
|
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
|
@@ -46,12 +50,12 @@ namespace GetEasy.Node.Printer
|
|
|
|
|
|
[DllExport(CallingConvention = CallingConvention.Winapi, ExportName = "designerReport")]
|
|
|
public static void DesignerReport([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]String template,
|
|
|
- [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]String templateData, SaveCallback saveCallback)
|
|
|
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]String templateData)
|
|
|
{
|
|
|
- ManualResetEvent manualResetEvent = new ManualResetEvent(false);
|
|
|
- ManualResetEvent formManualResetEvent = new ManualResetEvent(true);
|
|
|
+ _nodeThread = new ManualResetEvent(true);
|
|
|
+ _formThread = new ManualResetEvent(true);
|
|
|
+ _saveObj = new SaveObj();
|
|
|
|
|
|
- SaveObj obj = new SaveObj();
|
|
|
|
|
|
var thread = new Thread(() =>
|
|
|
{
|
|
@@ -73,10 +77,11 @@ namespace GetEasy.Node.Printer
|
|
|
if (!String.IsNullOrEmpty(templateData))
|
|
|
{
|
|
|
JsonDataSource dataSource = null;
|
|
|
- if(report.DataSource != null && report.DataSource is JsonDataSource)
|
|
|
+ if (report.DataSource != null && report.DataSource is JsonDataSource)
|
|
|
{
|
|
|
dataSource = report.DataSource as JsonDataSource;
|
|
|
- }else
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
dataSource = new JsonDataSource();
|
|
|
}
|
|
@@ -89,13 +94,13 @@ namespace GetEasy.Node.Printer
|
|
|
{
|
|
|
MemoryStream stream = new MemoryStream();
|
|
|
designPanel.Report.SaveLayoutToXml(stream);
|
|
|
- obj.SaveData = Encoding.UTF8.GetString(stream.ToArray());
|
|
|
+ _saveObj.SaveData = Encoding.UTF8.GetString(stream.ToArray());
|
|
|
|
|
|
- formManualResetEvent.Reset(); // 切换回主线程保存数据
|
|
|
- manualResetEvent.Set();
|
|
|
- formManualResetEvent.WaitOne();
|
|
|
+ _formThread.Reset(); // 切换回主线程保存数据
|
|
|
+ _nodeThread.Set();
|
|
|
+ _formThread.WaitOne();
|
|
|
|
|
|
- if (!obj.IsSaveSuccess)
|
|
|
+ if (!_saveObj.IsSaveSuccess)
|
|
|
{
|
|
|
MessageBox.Show("保存失败!", "提示");
|
|
|
}
|
|
@@ -114,36 +119,27 @@ namespace GetEasy.Node.Printer
|
|
|
{
|
|
|
Console.WriteLine(ex.Message);
|
|
|
}
|
|
|
- obj.SaveData = null; // 清空保存数据并且启动主线程
|
|
|
- manualResetEvent.Set();
|
|
|
+ _saveObj.SaveData = null; // 清空保存数据并且启动主线程
|
|
|
+ _nodeThread.Set();
|
|
|
});
|
|
|
thread.SetApartmentState(ApartmentState.STA);
|
|
|
thread.Start();
|
|
|
- WaitSaveOrClose(saveCallback, manualResetEvent, formManualResetEvent, obj);
|
|
|
}
|
|
|
|
|
|
- private static void WaitSaveOrClose(SaveCallback saveCallback, ManualResetEvent manualResetEvent, ManualResetEvent formManualResetEvent, SaveObj obj)
|
|
|
+ [DllExport(CallingConvention = CallingConvention.Winapi, ExportName = "waitSaveOrClose")]
|
|
|
+ public static void WaitSaveOrClose(SaveCallback saveCallback)
|
|
|
{
|
|
|
//RibbonControllerBase data;
|
|
|
- while(manualResetEvent.WaitOne())
|
|
|
+ _nodeThread.Reset();
|
|
|
+ _nodeThread.WaitOne();
|
|
|
+
|
|
|
+ saveCallback(_saveObj.SaveData, (result) =>
|
|
|
{
|
|
|
- //Guid resultKey = Guid.NewGuid();
|
|
|
- //SaveResultCallback resultCallback = (result) =>
|
|
|
- //{
|
|
|
- // obj.IsSaveSuccess = result;
|
|
|
-
|
|
|
- // //WaitSaveOrClose(saveCallback, manualResetEvent, formManualResetEvent, obj);
|
|
|
- // //dicResult.Remove(resultKey); // 删除回调,让系统GC
|
|
|
- //};
|
|
|
- //dicResult[resultKey] = resultCallback;
|
|
|
- saveCallback(obj.SaveData, (result)=> {
|
|
|
- obj.IsSaveSuccess = result;
|
|
|
- });
|
|
|
- formManualResetEvent.Set(); // 重新等待设计窗口信息
|
|
|
- manualResetEvent.Reset();
|
|
|
- }
|
|
|
+ _saveObj.IsSaveSuccess = result;
|
|
|
+ _formThread.Set(); // 重新等待设计窗口信息
|
|
|
+ });
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
[DllExport(CallingConvention = CallingConvention.Winapi, ExportName = "reportShowPreview")]
|
|
|
public static void ReportShowPreview([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]String fileName, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]String jsonData)
|
|
|
{
|