Browse Source

zhao:修改上传

tags/录制修改前
耀 4 years ago
parent
commit
0474a500cf

+ 10
- 8
Common/system/FileToolsCommon.cs View File

300
         /// 获取一个文件的长度,单位为Byte  
300
         /// 获取一个文件的长度,单位为Byte  
301
         /// </summary>  
301
         /// </summary>  
302
         /// <param name="filePath">文件的绝对路径</param>          
302
         /// <param name="filePath">文件的绝对路径</param>          
303
-        public static int GetFileSize(string filePath)
303
+        public static long GetFileSize(string filePath)
304
         {
304
         {
305
             //创建一个文件对象  
305
             //创建一个文件对象  
306
             FileInfo fi = new FileInfo(filePath);
306
             FileInfo fi = new FileInfo(filePath);
307
 
307
 
308
             //获取文件的大小  
308
             //获取文件的大小  
309
-            return (int)fi.Length;
309
+            return fi.Length;
310
         }
310
         }
311
 
311
 
312
         /// <summary>  
312
         /// <summary>  
317
         {
317
         {
318
             //创建一个文件对象  
318
             //创建一个文件对象  
319
             FileInfo fi = new FileInfo(filePath);
319
             FileInfo fi = new FileInfo(filePath);
320
-            long size = fi.Length / 1024;
320
+            //double size = fi.Length / 1024;
321
+            double size = Math.Round(((double)fi.Length / 1024.0), 2, MidpointRounding.AwayFromZero);
321
             //获取文件的大小  
322
             //获取文件的大小  
322
-            return double.Parse(size.ToString());
323
+            return size;
323
         }
324
         }
324
 
325
 
325
         /// <summary>  
326
         /// <summary>  
330
         {
331
         {
331
             //创建一个文件对象  
332
             //创建一个文件对象  
332
             FileInfo fi = new FileInfo(filePath);
333
             FileInfo fi = new FileInfo(filePath);
333
-            long size = fi.Length / 1024 / 1024;
334
+            //double size = fi.Length / 1024 / 1024;
335
+            double size = Math.Round(((double)fi.Length / 1024.0 / 1024.0), 2, MidpointRounding.AwayFromZero);
334
             //获取文件的大小  
336
             //获取文件的大小  
335
-            return double.Parse(size.ToString());
337
+            return size;
336
         }
338
         }
337
         #endregion
339
         #endregion
338
 
340
 
536
         public static byte[] FileToBytes(string filePath)
538
         public static byte[] FileToBytes(string filePath)
537
         {
539
         {
538
             //获取文件的大小   
540
             //获取文件的大小   
539
-            int fileSize = GetFileSize(filePath);
541
+            long fileSize = GetFileSize(filePath);
540
 
542
 
541
             //创建一个临时缓冲区  
543
             //创建一个临时缓冲区  
542
             byte[] buffer = new byte[fileSize];
544
             byte[] buffer = new byte[fileSize];
548
             try
550
             try
549
             {
551
             {
550
                 //将文件流读入缓冲区  
552
                 //将文件流读入缓冲区  
551
-                fs.Read(buffer, 0, fileSize);
553
+                fs.Read(buffer, 0, (int)fileSize);
552
 
554
 
553
                 return buffer;
555
                 return buffer;
554
             }
556
             }

+ 53
- 8
XHWK.WKTool/App.cs View File

4
 using System;
4
 using System;
5
 using System.Collections.Generic;
5
 using System.Collections.Generic;
6
 using System.Diagnostics;
6
 using System.Diagnostics;
7
+using System.Reflection;
8
+using System.Security.Principal;
7
 using System.Security.RightsManagement;
9
 using System.Security.RightsManagement;
8
 using System.Threading;
10
 using System.Threading;
9
 using System.Windows;
11
 using System.Windows;
123
         [STAThread]
125
         [STAThread]
124
         private static void Main()
126
         private static void Main()
125
         {
127
         {
126
-            // 定义Application对象作为整个应用程序入口
127
-            Application app = new Application();
128
-            UserInfo = new Model_UserInfo();
129
-             WKDataList = new List<Model_WKData>();
130
-            WKData = new Model_WKData();
131
-            VideoList = new List<Model_Video>();
128
+            try
129
+            {
130
+                UserInfo = new Model_UserInfo();
131
+                WKDataList = new List<Model_WKData>();
132
+                WKData = new Model_WKData();
133
+                VideoList = new List<Model_Video>();
134
+                #region 强制以管理员方式运行 修改人:赵耀 修改时间:2020年9月7日
135
+                WindowsIdentity identity = WindowsIdentity.GetCurrent();
136
+                WindowsPrincipal principal = new WindowsPrincipal(identity);
137
+                //判断当前登录用户是否为管理员
138
+                if (principal.IsInRole(WindowsBuiltInRole.Administrator))
139
+                {
140
+                    //如果是管理员,则直接运行
141
+                    W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
142
+                    // 定义Application对象作为整个应用程序入口
143
+                    Application app = new Application();
144
+                    app.Run(W_CreateAMicroLessonWindow);
145
+                }
146
+                else
147
+                {
148
+                    //创建启动对象
149
+                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
150
+                    startInfo.UseShellExecute = true;
151
+                    startInfo.WorkingDirectory = Environment.CurrentDirectory;
152
+                    startInfo.FileName = Assembly.GetExecutingAssembly().Location;
153
+                    //设置启动动作,确保以管理员身份运行
154
+                    startInfo.Verb = "runas";
155
+                    try
156
+                    {
157
+                        System.Diagnostics.Process.Start(startInfo);
158
+                    }
159
+                    catch
160
+                    {
161
+                        return;
162
+                    }
163
+                    //退出
164
+                    Application.Current.Shutdown();
165
+
166
+                }
167
+                #endregion
168
+            }
169
+            catch (Exception ex)
170
+            {
171
+
172
+                string ErrMessage = "【进程】(Main):进程意外关闭。 " + ex.Message;
173
+                LogHelper.WriteErrLog(ErrMessage, ex);
174
+            }
175
+
132
             //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
176
             //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
133
-            W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
134
-            app.Run(W_CreateAMicroLessonWindow);
177
+            //Application app = new Application();
178
+            //W_CreateAMicroLessonWindow = new CreateAMicroLessonWindow();
179
+            //app.Run(W_CreateAMicroLessonWindow);
135
             //LogHelper.WriteInfoLog("启动项目");
180
             //LogHelper.WriteInfoLog("启动项目");
136
             StopSameProcess();
181
             StopSameProcess();
137
             Killffmpeg();
182
             Killffmpeg();

+ 1
- 1
XHWK.WKTool/CreateAMicroLessonWindow.xaml View File

7
         mc:Ignorable="d"
7
         mc:Ignorable="d"
8
         Title="MainWindow" Height="341" Width="454"   AllowsTransparency="True"
8
         Title="MainWindow" Height="341" Width="454"   AllowsTransparency="True"
9
     ShowInTaskbar="False"
9
     ShowInTaskbar="False"
10
-    WindowStartupLocation="CenterOwner"
10
+    WindowStartupLocation="CenterScreen"
11
     WindowStyle="None">
11
     WindowStyle="None">
12
     <Viewbox>
12
     <Viewbox>
13
         <Grid Height="341" Width="454" >
13
         <Grid Height="341" Width="454" >

+ 20
- 25
XHWK.WKTool/CreateAMicroLessonWindow.xaml.cs View File

84
                 System.Windows.MessageBox.Show("路径不可为空!");
84
                 System.Windows.MessageBox.Show("路径不可为空!");
85
                 return;
85
                 return;
86
             }
86
             }
87
-            APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/";
88
-            if (APP.UserInfo != null)
89
-            {
90
-                if (!string.IsNullOrWhiteSpace(APP.UserInfo.Username))
91
-                {
92
-                    //判断课程是否存在
93
-                    if (APP.WKDataList.Exists(x => x.WkName == APP.WKData.WkName))
94
-                    {
95
-                        MessageBoxResult dr = System.Windows.MessageBox.Show("此微课已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
96
-                        if (dr == MessageBoxResult.OK)
97
-                        {
98
-                            FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
99
-                            FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
100
-                            APP.WKDataList.RemoveAll(x => x.WkName == APP.WKData.WkName);
101
-                        }
102
-                        else
103
-                        {
104
-                            return;
105
-                        }
106
-                    }
107
-                    APP.WKData.WkPath += APP.UserInfo.Username + "/";
108
-                }
109
-            }
87
+            APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/"+APP.UserInfo.Username + "/";
110
             #endregion
88
             #endregion
111
             //创建文件夹
89
             //创建文件夹
112
             FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
90
             FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
114
             FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Text);
92
             FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Text);
115
             APP.WKData.WkName = txbExplainName.Text;
93
             APP.WKData.WkName = txbExplainName.Text;
116
             APP.WKData.WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
94
             APP.WKData.WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
95
+            //判断微课是否存在,存在则询问
96
+            if (APP.WKDataList != null&& APP.WKDataList.Count>0)
97
+            {
98
+                if (APP.WKDataList.Exists(x => x.WkName == APP.WKData.WkName))
99
+                {
100
+                    MessageBoxResult dr = System.Windows.MessageBox.Show("此微课已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
101
+                    if (dr == MessageBoxResult.OK)
102
+                    {
103
+                        FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
104
+                        FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
105
+                        APP.WKDataList.RemoveAll(x => x.WkName == APP.WKData.WkName);
106
+                    }
107
+                    else
108
+                    {
109
+                        return;
110
+                    }
111
+                }
112
+            }
117
             if (APP.W_XHMicroLessonSystemWindow == null)
113
             if (APP.W_XHMicroLessonSystemWindow == null)
118
             {
114
             {
119
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
115
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
120
                 //APP.W_XHMicroLessonSystemWindow .Topmost = true;
116
                 //APP.W_XHMicroLessonSystemWindow .Topmost = true;
121
             }
117
             }
122
-            this.Hide();
123
             APP.W_XHMicroLessonSystemWindow.Show();
118
             APP.W_XHMicroLessonSystemWindow.Show();
124
-          
119
+            this.Hide();
125
         }
120
         }
126
         /// <summary>
121
         /// <summary>
127
         /// 窗体移动
122
         /// 窗体移动

+ 21
- 1
XHWK.WKTool/DAL/DAL_Upload.cs View File

120
             ErrMessage = "";
120
             ErrMessage = "";
121
             try
121
             try
122
             {
122
             {
123
-                Model_Video VideoInfo = APP.VideoList.Find(x => x.FileGuid == VideoGuid);
123
+                Model_Video VideoInfo = null;
124
+                foreach (Model_WKData Vdata in APP.WKDataList)
125
+                {
126
+                    if (Vdata.VideoList == null)
127
+                        continue;
128
+                    foreach (Model_Video videoinfo in Vdata.VideoList)
129
+                    {
130
+                        if(videoinfo.FileGuid== VideoGuid)
131
+                        {
132
+                            VideoInfo = videoinfo;
133
+                            break;
134
+                        }
135
+                    }
136
+                    if (VideoInfo != null)
137
+                        break;
138
+                }
139
+                if (VideoInfo==null)
140
+                {
141
+                    ErrMessage = "未找到课程!";
142
+                    return false;
143
+                }
124
                 string UploadUrl = FileRequestAddress + "/chunkdb/upchunk";
144
                 string UploadUrl = FileRequestAddress + "/chunkdb/upchunk";
125
                 if (VideoInfo.IsUpload)
145
                 if (VideoInfo.IsUpload)
126
                 {
146
                 {

+ 10
- 3
XHWK.WKTool/FileDirectoryWindow.xaml.cs View File

40
             LoadingVideoList();
40
             LoadingVideoList();
41
             int i = 1;
41
             int i = 1;
42
             bool isColour = true;
42
             bool isColour = true;
43
+            pageData.menuList.Clear();
43
             //显示视频
44
             //显示视频
44
             foreach (Model_Video videoinfo in model_VideoList)
45
             foreach (Model_Video videoinfo in model_VideoList)
45
             {
46
             {
74
                     vis= "Collapsed";
75
                     vis= "Collapsed";
75
                     cos= "Visible";
76
                     cos= "Visible";
76
                 }
77
                 }
77
-
78
                 pageData.menuList.Add(new FileDirectoryModel()
78
                 pageData.menuList.Add(new FileDirectoryModel()
79
                 {
79
                 {
80
                     SerialNumber = i,
80
                     SerialNumber = i,
141
                 if (buttons[i] == sender)
141
                 if (buttons[i] == sender)
142
                 {
142
                 {
143
                     DAL_Upload dAL_Upload = new DAL_Upload();
143
                     DAL_Upload dAL_Upload = new DAL_Upload();
144
-                    string msg = string.Empty;
145
-                    dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid,out msg);
144
+                    if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
145
+                    {
146
+                        MessageBox.Show("视频上传成功!");
147
+                    }
148
+                    else
149
+                    {
150
+                        MessageBox.Show(ErrMessage);
151
+                    }
152
+                    
146
                 }
153
                 }
147
             }
154
             }
148
         }
155
         }

+ 3
- 1
XHWK.WKTool/LoginWindow.xaml.cs View File

95
                         }
95
                         }
96
                         else
96
                         else
97
                         {
97
                         {
98
-                            APP.W_CreateAMicroLessonWindow.Show();
98
+                            APP.W_CreateAMicroLessonWindow.Owner = this;
99
+                            //APP.W_CreateAMicroLessonWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
100
+                            APP.W_CreateAMicroLessonWindow.ShowDialog();
99
                         }
101
                         }
100
                     }
102
                     }
101
                 }
103
                 }

+ 38
- 34
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

302
             if(APP.fileDirectoryWindow==null)
302
             if(APP.fileDirectoryWindow==null)
303
             {
303
             {
304
                 APP.fileDirectoryWindow = new FileDirectoryWindow();
304
                 APP.fileDirectoryWindow = new FileDirectoryWindow();
305
-                APP.fileDirectoryWindow.Topmost = true;
305
+                //APP.fileDirectoryWindow.Topmost = true;
306
                 APP.fileDirectoryWindow.Owner = this;
306
                 APP.fileDirectoryWindow.Owner = this;
307
             }
307
             }
308
             else
308
             else
309
             {
309
             {
310
-                Initialize();
310
+                APP.fileDirectoryWindow.Initialize();
311
             }
311
             }
312
-            APP.fileDirectoryWindow.Show();
312
+            APP.fileDirectoryWindow.ShowDialog();
313
         }
313
         }
314
         /// <summary>
314
         /// <summary>
315
         /// 关闭事件
315
         /// 关闭事件
1042
         {
1042
         {
1043
             if (IsSuspendR)
1043
             if (IsSuspendR)
1044
             {
1044
             {
1045
-                ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
1046
-                ImgPrintTwo.Visibility = Visibility.Visible;
1047
-                btnPrint.IsEnabled = false;
1048
-
1049
-                ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
1050
-                ImgScreenshotTwo.Visibility = Visibility.Visible;
1051
-                btnScreenshot.IsEnabled = false;
1052
-
1053
-                ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
1054
-                ImgImportTwo.Visibility = Visibility.Visible;
1055
-                btnImport.IsEnabled = false;
1056
-
1057
-                ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
1058
-                ImgScreenRecordingTwo.Visibility = Visibility.Visible;
1059
-                btnScreenRecording.IsEnabled = false;
1060
-
1061
-                ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
1062
-                ImgUploadTwo.Visibility = Visibility.Visible;
1063
-                btnUpload.IsEnabled = false;
1064
-
1065
-                ImgMyMine.Visibility = Visibility.Collapsed;//录制中不可点击我的
1066
-                ImgMyMineTwo.Visibility = Visibility.Visible;
1067
-                btnMyMine.IsEnabled = false;
1068
-
1069
-                ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
1070
-                ImgSetUpTwo.Visibility = Visibility.Visible;
1071
-                btnSetUp.IsEnabled = false;
1072
-
1073
-                btnLoginType.IsEnabled = false;
1074
-
1075
                 if (IsFirstR)//是否第一次录制  初始化录制
1045
                 if (IsFirstR)//是否第一次录制  初始化录制
1076
                 {
1046
                 {
1077
                     VideoInfo = new Model_Video();
1047
                     VideoInfo = new Model_Video();
1107
                             return;
1077
                             return;
1108
                         }
1078
                         }
1109
                     }
1079
                     }
1080
+
1081
+                    #region 禁用按钮
1082
+                    ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
1083
+                    ImgPrintTwo.Visibility = Visibility.Visible;
1084
+                    btnPrint.IsEnabled = false;
1085
+
1086
+                    ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
1087
+                    ImgScreenshotTwo.Visibility = Visibility.Visible;
1088
+                    btnScreenshot.IsEnabled = false;
1089
+
1090
+                    ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
1091
+                    ImgImportTwo.Visibility = Visibility.Visible;
1092
+                    btnImport.IsEnabled = false;
1093
+
1094
+                    ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
1095
+                    ImgScreenRecordingTwo.Visibility = Visibility.Visible;
1096
+                    btnScreenRecording.IsEnabled = false;
1097
+
1098
+                    ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
1099
+                    ImgUploadTwo.Visibility = Visibility.Visible;
1100
+                    btnUpload.IsEnabled = false;
1101
+
1102
+                    ImgMyMine.Visibility = Visibility.Collapsed;//录制中不可点击我的
1103
+                    ImgMyMineTwo.Visibility = Visibility.Visible;
1104
+                    btnMyMine.IsEnabled = false;
1105
+
1106
+                    ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
1107
+                    ImgSetUpTwo.Visibility = Visibility.Visible;
1108
+                    btnSetUp.IsEnabled = false;
1109
+
1110
+                    btnLoginType.IsEnabled = false;
1111
+                    #endregion
1112
+
1110
                     IsFirstR = false;
1113
                     IsFirstR = false;
1111
                     RsImgName = new List<string>();
1114
                     RsImgName = new List<string>();
1112
                     timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
1115
                     timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
1273
                             Thread.Sleep(100);
1276
                             Thread.Sleep(100);
1274
                         }
1277
                         }
1275
                         FileToolsCommon.DeleteFile(ThumbnailPathName);
1278
                         FileToolsCommon.DeleteFile(ThumbnailPathName);
1276
-                        VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
1277
                         VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1279
                         VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
1278
                         VideoInfo.VideoPath = VideoSavePathName;
1280
                         VideoInfo.VideoPath = VideoSavePathName;
1279
                         VideoInfo.ThumbnailPath = ThumbnailPathName;
1281
                         VideoInfo.ThumbnailPath = ThumbnailPathName;
1282
+                        Thread.Sleep(500);
1283
+                        VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
1280
                         APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
1284
                         APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
1281
                         VideoInfo.FileGuid = Guid.NewGuid().ToString();
1285
                         VideoInfo.FileGuid = Guid.NewGuid().ToString();
1282
                         VideoInfo.IsUpload = false;
1286
                         VideoInfo.IsUpload = false;

Loading…
Cancel
Save