Parcourir la source

Merge remote-tracking branch 'origin/zyy' into zhangxueyang

tags/录制修改前
zhangxueyang il y a 4 ans
Parent
révision
596e1e2cdd

+ 1
- 0
Common/Common.csproj Voir le fichier

@@ -117,6 +117,7 @@
117 117
   </ItemGroup>
118 118
   <ItemGroup>
119 119
     <Compile Include="Model\DownloadInfoModel.cs" />
120
+    <Compile Include="system\LatticeFileHelper.cs" />
120 121
     <Compile Include="system\PdfTrunImage.cs" />
121 122
     <Compile Include="system\BlackboardNew.cs" />
122 123
     <Compile Include="system\CameraHelper.cs" />

+ 266
- 0
Common/system/LatticeFileHelper.cs Voir le fichier

@@ -0,0 +1,266 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Diagnostics;
4
+using System.Drawing.Printing;
5
+using System.Linq;
6
+using System.Text;
7
+using System.Threading;
8
+using System.Threading.Tasks;
9
+
10
+namespace Common.system
11
+{
12
+    /// <summary>
13
+    /// 点阵文件制作打印
14
+    /// 创建时间:2020年9月1日
15
+    /// </summary>
16
+    public class LatticeFileHelper
17
+    {
18
+        /// <summary>
19
+        /// 打印进程
20
+        /// </summary>
21
+        public static Process PrintProcess = null;
22
+        /// <summary>
23
+        /// 输出日志文件地址  每个文件2MB左右
24
+        /// </summary>
25
+        static string LogPath = "";
26
+        /// <summary>
27
+        /// 运行配置 首次打开必须运行
28
+        /// </summary>
29
+        public static void RunPrintConfig()
30
+        {
31
+            string Path = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintConfig.exe");
32
+            Process myProcess = new Process();
33
+            LogPath = CreateLog();
34
+            myProcess.StartInfo.FileName = Path;   //绝对路径
35
+            //myProcess.StartInfo.Arguments = "";
36
+            myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
37
+            myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
38
+            myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
39
+            myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
40
+            //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
41
+            myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
42
+            myProcess.Start();                 //启动线程
43
+            myProcess.BeginErrorReadLine();    //开始异步读取
44
+            myProcess.WaitForExit();           //阻塞等待进程结束
45
+            myProcess.Close();                 //关闭进程
46
+            myProcess.Dispose();               //释放资源
47
+        }
48
+
49
+        /// <summary>
50
+        /// 生成点阵打印文件
51
+        /// </summary>
52
+        /// <param name="PDFPath">PDF文件位置</param>
53
+        /// <param name="SavePath">保存文件位置 TPF</param>
54
+        /// <param name="PrintResult">输出结果,非0为失败</param>
55
+        public static void GeneratingPDF(string PDFPath, string SavePath, out int PrintResult, int PointType = 0)
56
+        {
57
+            //XML点阵文件位置
58
+            string XmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
59
+            string ContentParameter = null;
60
+            ContentParameter = "-sMode=Generate \"-sPDF=" + PDFPath + "\" \"-sLIC=" + XmlFile + "\" \"-oTPF=" + SavePath + "\" \"-dType=" + PointType + "\" ";//[-dType=0] [-dPrint=0] [-pStart=0]
61
+            #region 制作点阵文件参数说明
62
+            //-sMode = Generate - sPDF = d:\l\e.pdf - sLIC = d:\l\a.xml - oPDF = d:\l\11210.pdf"
63
+            //当 - sMode = Generate,参数如下:
64
+            //PrintTool.exe - sMode = Generate - sPDF = -sLIC = < -oPDF =| -oTPF=> [dType=] [-dPrint] [-pStart =]
65
+            //- sPDF 原始 PDF 文件路径
66
+            //- sLIC 点阵资源文件路径
67
+            //- oPDF 生成的点阵 PDF 文件路径,-oPDF 与 - oTPF 至少设置一个。PDF 与 TPF 说明参见 2 生成文件类型说明
68
+            //- oTPF 生成的 TPF 文件,-oPDF 与 - oTPF 至少设置一个。PDF 与 TPF 说明参见 2 生成文件类型说明 
69
+            //- dType 0 为方点,1 为圆点;可选参数,默认 0。详细参数区别,参见 3.1 点阵形状
70
+            //- dPrint 0 为激光打印机,1 为印刷机;可选参数,默认 0。详细参数区别,参见 3.2 点阵 PDF 适用打印场景
71
+            //- pStart 整数,选择从哪页点阵资源开始制作点阵文件, 即起始点阵资源页序号;可选参数,默认0。关于 - pStart 的功能说明,参见 1.3.1.高级设置
72
+            #endregion
73
+            while (PrintProcess != null)
74
+            {
75
+                Thread.Sleep(100);
76
+            }
77
+            Process[] KillProcessArray = Process.GetProcessesByName("PrintTool");
78
+            foreach (var KillProcess in KillProcessArray)
79
+            {
80
+                KillProcess.Kill();
81
+            }
82
+            PrintProcess = new Process();
83
+            LogPath = CreateLog();
84
+            PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe");   //绝对路径
85
+            PrintProcess.StartInfo.Arguments = ContentParameter;
86
+            PrintProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
87
+            PrintProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
88
+            PrintProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
89
+            PrintProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
90
+            //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
91
+            PrintProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
92
+            PrintProcess.Start();                 //启动线程
93
+            PrintProcess.BeginErrorReadLine();    //开始异步读取
94
+            PrintProcess.WaitForExit();           //阻塞等待进程结束
95
+            PrintResult = PrintProcess.ExitCode;     //打印结果 非0则为打印失败
96
+            Output("【制作点阵文件】" + ContentParameter);//记录打印日志
97
+            PrintProcess.Close();                 //关闭进程
98
+            PrintProcess.Dispose();               //释放资源
99
+            #region 进程是否已经释放
100
+            bool IsRunning = true;
101
+            while (IsRunning)
102
+            {
103
+                IsRunning = false;
104
+                Process[] ProcessArray = Process.GetProcessesByName("PrintTool");
105
+                foreach (var KillProcess in ProcessArray)
106
+                {
107
+                    IsRunning = true;
108
+                    Thread.Sleep(100);
109
+                }
110
+            }
111
+            #endregion
112
+            PrintProcess = null;
113
+        }
114
+
115
+        /// <summary>
116
+        /// 获取打印机列表
117
+        /// </summary>
118
+        /// <param name="DefaultPrinter">默认打印机</param>
119
+        /// <returns>打印机列表</returns>
120
+        public static List<string> GetPrinterList(out string DefaultPrinter)
121
+        {
122
+            List<string> PrintersList = new List<string>();
123
+            DefaultPrinter = null;
124
+            try
125
+            {
126
+                PrintDocument print = new PrintDocument();
127
+                DefaultPrinter = print.PrinterSettings.PrinterName;//默认打印机名
128
+                foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
129
+                {
130
+                    PrintersList.Add(sPrint);
131
+                }
132
+            }
133
+            catch (Exception ex)
134
+            {
135
+
136
+            }
137
+            return PrintersList;
138
+        }
139
+
140
+        /// <summary>
141
+        /// 打印TPF点阵文件
142
+        /// </summary>
143
+        /// <param name="TPFPath">TPF路径</param>
144
+        /// <param name="PrinterNum">打印份数</param>
145
+        /// <param name="PrinterName">打印机名称</param>
146
+        /// <param name="PrintResult">输出结果,非0为失败</param>
147
+        public static void PrinterTPFFile(string TPFPath, int PrinterNum, string PrinterName, out int PrintResult)
148
+        {
149
+            //XML点阵文件位置
150
+            string XmlFile = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/print_license.xml");
151
+            string ContentParameter = null;
152
+            ContentParameter = "-sMode=Print \"-sTPF =" + TPFPath + "\" \"-dCopy= " + PrinterNum + "\" \"-dPaperSize=9\" \"-sPrinter=" + PrinterName + "\"";//[-dPaperSize =] 
153
+            #region 打印参数说明
154
+            //-sMode = Print,参数如下:
155
+            //PrintTool.exe - sMode = Print - sTPF = [-dCopy =][-dPaperSize =] - sPrinter =
156
+            //-sTPF 需要打印的 TPF 文件路径
157
+            //- dCopy 整数,可选参数,打印份数,默认 1 
158
+            //- dPaperSize 整数,可选参数,设置打印纸张尺寸。不设置此值,系统自动选择匹配纸张打印;A4:"-dPaperSize=9"  DMPAPER_A4	9	A4 210 x 297 mm   如
159
+            //  需要手动设置纸张尺寸,不同尺寸纸张对应值,参见 https://docs.microsoft.com/en-us/windows/win32/intl/paper-sizes
160
+            //- sPrinter 打印机名称
161
+            // 打印完成后,如果打印成功,PrintTool.exe 退出值为 0。
162
+            //如果打印失败,程序退出值为非 0。
163
+            #endregion
164
+            while (PrintProcess != null)
165
+            {
166
+                Thread.Sleep(100);
167
+            }
168
+            Process[] KillProcessArray = Process.GetProcessesByName("PrintTool");
169
+            foreach (var KillProcess in KillProcessArray)
170
+            {
171
+                KillProcess.Kill();
172
+            }
173
+            PrintProcess = new Process();
174
+            LogPath = CreateLog();
175
+            PrintProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath("/PrintTool/PrintTool.exe");   //绝对路径
176
+            PrintProcess.StartInfo.Arguments = ContentParameter;
177
+            PrintProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
178
+            PrintProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
179
+            PrintProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
180
+            PrintProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
181
+            //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
182
+            PrintProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
183
+            PrintProcess.Start();                 //启动线程
184
+            PrintProcess.BeginErrorReadLine();    //开始异步读取
185
+            PrintProcess.WaitForExit();           //阻塞等待进程结束
186
+            PrintResult = PrintProcess.ExitCode;     //打印结果 非0则为打印失败
187
+            Output("【打印TPF文件】" + ContentParameter);//记录打印日志
188
+            PrintProcess.Close();                 //关闭进程
189
+            PrintProcess.Dispose();               //释放资源
190
+            #region 进程是否已经释放
191
+            bool IsRunning = true;
192
+            while (IsRunning)
193
+            {
194
+                IsRunning = false;
195
+                Process[] ProcessArray = Process.GetProcessesByName("PrintTool");
196
+                foreach (var KillProcess in ProcessArray)
197
+                {
198
+                    IsRunning = true;
199
+                    Thread.Sleep(100);
200
+                }
201
+            }
202
+            #endregion
203
+            PrintProcess = null;
204
+        }
205
+
206
+        /// <summary>
207
+        /// 创建日志文件
208
+        /// </summary>
209
+        /// <returns></returns>
210
+        private static string CreateLog()
211
+        {
212
+            string LogFileName = DateTime.Now.ToString("yyyyMMdd");
213
+            string LogFilePath = FileToolsCommon.GetFileAbsolutePath("/Log/PrintLog/");
214
+            FileToolsCommon.CreateDirectory(LogFilePath);
215
+            string LogName = LogFilePath + LogFileName + ".log";
216
+            try
217
+            {
218
+                if (!FileToolsCommon.IsExistFile(LogName))
219
+                {
220
+                    FileToolsCommon.CreateFile(LogName);
221
+                    FileToolsCommon.AppendText(LogName, "\r\n****************************************************************************************************" +
222
+                        "****************************************************************************************************\r\n");
223
+                    return LogName;
224
+                }
225
+                else
226
+                {
227
+                    int num = 0;
228
+                    while (FileToolsCommon.GetFileSizeByMB(LogName) > 2)
229
+                    {
230
+                        num++;
231
+                        LogName = LogFilePath + LogFileName + "_" + num + ".log";
232
+                        FileToolsCommon.CreateFile(LogName);
233
+                    }
234
+                    FileToolsCommon.AppendText(LogName, "\r\n****************************************************************************************************" +
235
+                        "****************************************************************************************************\r\n");
236
+                    return LogName;
237
+                }
238
+            }
239
+            catch (Exception)
240
+            {
241
+                return LogName;
242
+            }
243
+        }
244
+
245
+        /// <summary>
246
+        /// 输出日志
247
+        /// </summary>
248
+        /// <param name="Message"></param>
249
+        private static void Output(string Message)
250
+        {
251
+            if (!String.IsNullOrEmpty(Message))
252
+            {
253
+                FileToolsCommon.AppendText(LogPath, Message + "\r\n");
254
+            }
255
+        }
256
+        /// <summary>
257
+        /// 输出结果
258
+        /// </summary>
259
+        /// <param name="sendProcess"></param>
260
+        /// <param name="output"></param>
261
+        private static void Output(object sendProcess, DataReceivedEventArgs output)
262
+        {
263
+            Output(output.Data);
264
+        }
265
+    }
266
+}

+ 46
- 5
XHWK.WKTool/App.cs Voir le fichier

@@ -25,6 +25,10 @@ namespace XHWK.WKTool
25 25
         /// </summary>
26 26
         public static string ServerMsg=string.Empty;
27 27
         /// <summary>
28
+        /// 用户微课列表模型
29
+        /// </summary>
30
+        public static List<Model_WKData> WKDataList = null;
31
+        /// <summary>
28 32
         /// 微课模型
29 33
         /// </summary>
30 34
         public static Model_WKData WKData = null;
@@ -86,13 +90,15 @@ namespace XHWK.WKTool
86 90
             // 定义Application对象作为整个应用程序入口
87 91
             Application app = new Application();
88 92
             UserInfo = new Model_UserInfo();
89
-             WKData = new Model_WKData();
93
+             WKDataList = new List<Model_WKData>();
94
+            WKData = new Model_WKData();
90 95
             VideoList = new List<Model_Video>();
91 96
             //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
92 97
             CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
93 98
             app.Run(win);
94 99
             //LogHelper.WriteInfoLog("启动项目");
95 100
             StopSameProcess();
101
+            LatticeFileHelper.RunPrintConfig();
96 102
         }
97 103
         /// <summary>
98 104
         /// 结束已运行的程序
@@ -143,14 +149,49 @@ namespace XHWK.WKTool
143 149
             if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
144 150
             {
145 151
                 WKData.VideoList = VideoList;
152
+                if (WKDataList != null)
153
+                {
154
+                    WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
155
+                }
156
+                else
157
+                {
158
+                    WKDataList = new List<Model_WKData>();
159
+                }
160
+                WKDataList.Add(WKData);
146 161
                 //string WkDateXmlStr = XmlUtilHelper.Serializer(typeof(Model_WKData), WKData);
147
-                string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKData);
162
+                string WkDateXmlStr = XmlUtilHelper.XmlSerialize(WKDataList);
148 163
                 string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
149 164
                 FileToolsCommon.CreateDirectory(SavePath);
150
-                
165
+                string SaveName = SavePath + "UserWkDate.d";
166
+                FileToolsCommon.DeleteFile(SaveName);
167
+                FileToolsCommon.WriteText(SaveName, WkDateXmlStr);
168
+            }
169
+        }
170
+
171
+        /// <summary>
172
+        /// 读取微课信息
173
+        /// </summary>
174
+        public static void ReadWkData()
175
+        {
176
+            if (UserInfo == null)
177
+            {
178
+                return;
179
+            }
180
+            if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
181
+            {
182
+                string SavePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/");
183
+                FileToolsCommon.CreateDirectory(SavePath);
184
+                string SaveName = SavePath + "UserWkDate.d";
185
+                if (FileToolsCommon.IsExistFile(SaveName))
186
+                {
187
+                    string WkDateXmlStr=FileToolsCommon.FileToString(SaveName);
188
+                    WKDataList = XmlUtilHelper.DESerializer<List<Model_WKData>>(WkDateXmlStr);
189
+                    if (WKDataList != null)
190
+                    {
191
+                        WKDataList.RemoveAll(x => x.WkName == WKData.WkName);
192
+                    }
193
+                }
151 194
             }
152
-            //if(APP.UserInfo)
153
-            //APP.UserInfo.Wkdata.Add(APP.WKData);
154 195
         }
155 196
 
156 197
         #region 内存处理 -创建人:赵耀 -创建时间:2020年8月12日

+ 2
- 0
XHWK.WKTool/LoginWindow.xaml.cs Voir le fichier

@@ -76,6 +76,8 @@ namespace XHWK.WKTool
76 76
                 APP.IsLoginType = true;
77 77
                 txbAccountNumber.Text = string.Empty;
78 78
                 pobPassword.Password = string.Empty;
79
+                //读取微课数据
80
+                APP.ReadWkData();
79 81
                 this.Hide();
80 82
             }
81 83
             else

+ 2
- 0
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Voir le fichier

@@ -194,6 +194,8 @@ namespace XHWK.WKTool
194 194
                         VideoInfo.ThumbnailPath = ThumbnailPathName;
195 195
                         APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
196 196
                         APP.VideoList.Add(VideoInfo);
197
+                        //保存数据
198
+                        APP.SaveWkData();
197 199
                     }))).Start();
198 200
                 }
199 201
                 catch (Exception ex)

+ 3
- 0
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Voir le fichier

@@ -193,6 +193,7 @@ namespace XHWK.WKTool
193 193
         /// <param name="e"></param>
194 194
         private void BtnDown_Click(object sender, RoutedEventArgs e)
195 195
         {
196
+            APP.SaveWkData();
196 197
             System.Environment.Exit(0);
197 198
         }
198 199
         /// <summary>
@@ -903,6 +904,8 @@ namespace XHWK.WKTool
903 904
                         VideoInfo.ThumbnailPath = ThumbnailPathName;
904 905
                         APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
905 906
                         APP.VideoList.Add(VideoInfo);
907
+                        //保存数据
908
+                        APP.SaveWkData();
906 909
                     }))).Start();
907 910
                     //List<Model_Video> VideoList
908 911
                 }

Chargement…
Annuler
Enregistrer