星火直播PC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ToolbarWindow.xaml.cs 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Shapes;
  15. using XHZB.Model;
  16. using Common.ZB;
  17. using XHZB.Desktop.Utils;
  18. using Common.system;
  19. using System.Windows.Media.Animation;
  20. using System.Threading;
  21. using XHZB.Desktop.WebSocket;
  22. namespace XHZB.Desktop
  23. {
  24. /// <summary>
  25. /// ToolbarWindow.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class ToolbarWindow : Window
  28. {
  29. #region 字段
  30. /// <summary>
  31. /// 屏幕宽
  32. /// </summary>
  33. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  34. /// <summary>
  35. /// 屏幕高
  36. /// </summary>
  37. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  38. /// <summary>
  39. /// 工具栏数据
  40. /// </summary>
  41. internal ToolbarModel pageData = new ToolbarModel();
  42. /// <summary>
  43. /// 是否已打开课堂工具二级列表
  44. /// </summary>
  45. private bool heibanshow = false;
  46. private bool isTool = true;
  47. #region 当前已打开页面
  48. /// <summary>
  49. /// 是否已打开个人空间
  50. /// </summary>
  51. public static bool IsOpenUserCenterWindow = false;
  52. /// <summary>
  53. /// 是否已打开课堂点名
  54. /// </summary>
  55. public static bool IsOpenRollCallWindow = false;
  56. /// <summary>
  57. /// 是否已打开考勤页面
  58. /// </summary>
  59. public static bool IsOpenAttendanceWindow = false;
  60. #endregion 当前已打开页面
  61. #endregion
  62. #region 初始化
  63. public ToolbarWindow()
  64. {
  65. InitializeComponent();
  66. txbName.Text = APP.LoginUser.username;
  67. heiban_btn.Click += Heiban_btn_Click;
  68. pizhu_btn.Click += Pizhu_btn_Click;
  69. Topmost = true;
  70. Left = pwidth - 300;
  71. Top = (pHeight - 568) / 2;
  72. pageData.menuList.Add(new ToolbarMenu()
  73. {
  74. Name = "个人空间",
  75. Pic = "../Images/ToolBar/我的备课@2x.png"
  76. });
  77. pageData.menuList.Add(new ToolbarMenu()
  78. {
  79. Name = "开始直播",
  80. Pic = "../Images/ToolBar/直播@2x.png"
  81. });
  82. pageData.menuList.Add(new ToolbarMenu()
  83. {
  84. Name = "抢答点名",
  85. Pic = "../Images/ToolBar/抢答@2x.png"
  86. });
  87. pageData.menuList.Add(new ToolbarMenu()
  88. {
  89. Name = "课堂工具",
  90. Pic = "../Images/ToolBar/黑板01@2x.png"
  91. });
  92. pageData.menuList.Add(new ToolbarMenu()
  93. {
  94. Name = "本节考勤",
  95. Pic = "../Images/ToolBar/本节考勤01@2x.png"
  96. });
  97. pageData.menuList.Add(new ToolbarMenu()
  98. {
  99. Name = "结束直播",
  100. Pic = "../Images/ToolBar/下课@2x.png"
  101. });
  102. DataContext = pageData;
  103. Thread t = new Thread(new ThreadStart(startSocket))
  104. {
  105. IsBackground = true
  106. };
  107. t.Start();
  108. }
  109. #endregion
  110. #region 事件
  111. /// <summary>
  112. /// 模块点击
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void toolbar_item_Click(object sender, RoutedEventArgs e)
  117. {
  118. int clickindex = 0;
  119. List<Button> buttons = VTHelper.FindChilds<Button>(toolbar_list, "toolbar_item");
  120. for (int i = 0; i < buttons.Count; i++)
  121. {
  122. if (buttons[i] == sender)
  123. {
  124. clickindex = i;
  125. break;
  126. }
  127. }
  128. ToolbarMenu item = pageData.menuList[clickindex];
  129. if (clickindex == 0)//个人空间
  130. {
  131. #region 关闭冲突页面
  132. if (IsOpenUserCenterWindow)
  133. {
  134. if (APP.W_UserCenterWindow != null && !APP.W_UserCenterWindow.IsFocused)
  135. {
  136. APP.W_UserCenterWindow.Focus();
  137. }
  138. return;
  139. }
  140. else
  141. {
  142. CloseOrHideWindowPage();
  143. }
  144. #endregion 关闭冲突页面
  145. try
  146. {
  147. HideLevel2();
  148. if (APP.W_UserCenterWindow != null && !APP.W_UserCenterWindow.IsFocused)
  149. {
  150. APP.W_UserCenterWindow.Focus();
  151. }
  152. else
  153. {
  154. APP.W_UserCenterWindow = new UserCenterWindow();
  155. APP.W_UserCenterWindow.Show();
  156. APP.W_UserCenterWindow.Closed += UserCenterWindow_Closed;
  157. }
  158. IsOpenUserCenterWindow = true;
  159. }
  160. catch (Exception ex)
  161. {
  162. IsOpenUserCenterWindow = false;
  163. APP.W_UserCenterWindow = null;
  164. LogHelper.WriteErrLog("【个人空间(toolbar_item_Click)" + ex.Message, ex);
  165. }
  166. }
  167. else if (clickindex == 1)//直播
  168. {
  169. if (!pageData.tongping)
  170. {
  171. HideLevel2();
  172. pageData.tongping = !pageData.tongping;
  173. if (pageData.tongping && isTool)
  174. {
  175. isTool = false;
  176. if (StartLive(out string ErrMessage))
  177. {
  178. pageData.menuList[1].Pic = "../Images/ToolBar/img_shared_1.gif";
  179. pageData.menuList[1].Name = "正在直播";
  180. if (APP.W_CameraWindow == null)
  181. {
  182. APP.W_CameraWindow = new CameraWindow();
  183. APP.W_CameraWindow.Topmost = true;
  184. APP.W_CameraWindow.Left = pwidth - 320;
  185. APP.W_CameraWindow.Top = 0;
  186. }
  187. APP.W_CameraWindow.Show();
  188. }
  189. else
  190. {
  191. pageData.tongping = !pageData.tongping;
  192. MessageWindow.Show(ErrMessage);
  193. }
  194. }
  195. }
  196. }
  197. else if (clickindex == 2)//抢答点名
  198. {
  199. HideLevel2();
  200. try
  201. {
  202. #region 关闭冲突页面
  203. if (IsOpenRollCallWindow)
  204. {
  205. return;
  206. }
  207. else
  208. {
  209. CloseOrHideWindowPage();
  210. }
  211. #endregion 关闭冲突页面
  212. if (APP.W_RollCallWindow == null)
  213. {
  214. APP.W_RollCallWindow = new RollCallWindow();
  215. APP.W_RollCallWindow.click_closeClick += RollCallWindow_click_closeClick;
  216. }
  217. else
  218. {
  219. APP.W_RollCallWindow.Initialize();
  220. }
  221. APP.W_RollCallWindow.Owner = this;
  222. //ZSocketServer.getInstance().addWin(rollCallWindow);
  223. IsOpenRollCallWindow = true;
  224. APP.W_RollCallWindow.Show();
  225. }
  226. catch (Exception ex)
  227. {
  228. IsOpenRollCallWindow = false;
  229. APP.W_RollCallWindow = null;
  230. LogHelper.WriteErrLog("【抢答点名(toolbar_item_Click)" + ex.Message, ex);
  231. }
  232. }
  233. else if (clickindex == 3)//课堂工具。
  234. {
  235. try
  236. {
  237. heibanshow = !heibanshow;
  238. List<DependencyObject> list = new List<DependencyObject>
  239. {
  240. heiban_btn,
  241. pizhu_btn
  242. };
  243. hideOrShow(heibanshow, ketangTool, list);
  244. }
  245. catch (Exception ex)
  246. {
  247. LogHelper.WriteErrLog("【课堂工具(toolbar_item_Click)" + ex.Message, ex);
  248. }
  249. }
  250. else if (clickindex == 4)//本节考勤
  251. {
  252. HideLevel2();
  253. try
  254. {
  255. showKaoqin();
  256. }
  257. catch (Exception ex)
  258. {
  259. LogHelper.WriteErrLog("【考勤(toolbar_item_Click)" + ex.Message, ex);
  260. }
  261. }
  262. else if (clickindex == 5)//结束课堂。
  263. {
  264. if (MessageWindow.Show("是否结束直播?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
  265. {
  266. closeAction();
  267. }
  268. }
  269. }
  270. /// <summary>
  271. /// 个人空间关闭
  272. /// </summary>
  273. /// <param name="sender"></param>
  274. /// <param name="e"></param>
  275. private void UserCenterWindow_Closed(object sender, EventArgs e)
  276. {
  277. APP.W_UserCenterWindow = null;
  278. IsOpenUserCenterWindow = false;
  279. }
  280. /// <summary>
  281. /// 课堂点名关闭
  282. /// </summary>
  283. private void RollCallWindow_click_closeClick()
  284. {
  285. IsOpenRollCallWindow = false;
  286. APP.W_RollCallWindow = null;
  287. }
  288. /// <summary>
  289. /// 考勤关闭
  290. /// </summary>
  291. /// <param name="sender"></param>
  292. /// <param name="e"></param>
  293. private void AttendanceWindow_Closed(object sender, EventArgs e)
  294. {
  295. IsOpenAttendanceWindow = false;
  296. APP.W_AttendanceWindow = null;
  297. }
  298. /// <summary>
  299. /// 考勤
  300. /// </summary>
  301. private void showKaoqin()
  302. {
  303. try
  304. {
  305. #region 关闭冲突页面
  306. if (IsOpenAttendanceWindow)
  307. {
  308. return;
  309. }
  310. else
  311. {
  312. CloseOrHideWindowPage();
  313. }
  314. #endregion 关闭冲突页面
  315. if (APP.W_AttendanceWindow == null)
  316. {
  317. APP.W_AttendanceWindow = new AttendanceWindow
  318. {
  319. Owner = this
  320. };
  321. APP.W_AttendanceWindow.Closed += AttendanceWindow_Closed;
  322. }
  323. else
  324. {
  325. APP.W_AttendanceWindow.Initialize();
  326. }
  327. IsOpenAttendanceWindow = true;
  328. APP.W_AttendanceWindow.Show();
  329. }
  330. catch (Exception ex)
  331. {
  332. IsOpenAttendanceWindow = false;
  333. APP.W_AttendanceWindow = null;
  334. LogHelper.WriteErrLog("【考勤(toolbar_item_Click)" + ex.Message, ex);
  335. }
  336. //}
  337. }
  338. /// <summary>
  339. /// 黑板
  340. /// </summary>
  341. /// <param name="sender"></param>
  342. /// <param name="e"></param>
  343. private void Heiban_btn_Click(object sender, RoutedEventArgs e)
  344. {
  345. try
  346. {
  347. heibanshow = !heibanshow;
  348. #region 关闭冲突页面
  349. CloseOrHideWindowPage();
  350. #endregion 关闭冲突页面
  351. List<DependencyObject> list = new List<DependencyObject>
  352. {
  353. heiban_btn,
  354. pizhu_btn
  355. };
  356. hideOrShow(heibanshow, ketangTool, list);
  357. if (APP.W_ZBlackboardWindow == null)
  358. {
  359. APP.W_ZBlackboardWindow = new ZBlackboardWindow
  360. {
  361. Topmost = true,
  362. Width = pwidth,
  363. Height = pHeight,
  364. Left = 0,
  365. Top = 0,
  366. Owner = this
  367. };
  368. //APP.W_ZBlackboardWindow.click_closeClick += BlackboardWin2_click_closeClick;
  369. }
  370. //ZSocketServer.getInstance().addWin(blackboardWin2);
  371. APP.W_ZBlackboardWindow.ShowDialog();
  372. }
  373. catch (Exception ex)
  374. {
  375. LogHelper.WriteErrLog("【黑板(Heiban_btn_Click)" + ex.Message, ex);
  376. }
  377. }
  378. /// <summary>
  379. /// 批注
  380. /// </summary>
  381. /// <param name="sender"></param>
  382. /// <param name="e"></param>
  383. private void Pizhu_btn_Click(object sender, RoutedEventArgs e)
  384. {
  385. try
  386. {
  387. heibanshow = !heibanshow;
  388. #region 关闭冲突页面
  389. //CloseOrHideWindowPage();
  390. #endregion 关闭冲突页面
  391. List<DependencyObject> list = new List<DependencyObject>
  392. {
  393. heiban_btn,
  394. pizhu_btn
  395. };
  396. hideOrShow(heibanshow, ketangTool, list);
  397. if (APP.W_PracticeWindow == null)
  398. {
  399. APP.W_PracticeWindow = new PracticeWindow();
  400. APP.W_PracticeWindow.click_closeClick += PracticeWin_click_closeClick;
  401. APP.W_PracticeWindow.Topmost = true;//zhangxueyang
  402. APP.W_PracticeWindow.Width = pwidth;
  403. APP.W_PracticeWindow.Height = pHeight;
  404. APP.W_PracticeWindow.Left = 0;
  405. APP.W_PracticeWindow.Top = 0;
  406. APP.W_PracticeWindow.Unloaded += PracticeWin_Unloaded;
  407. }
  408. APP.W_PracticeWindow.Owner = this;//zhangxueyang
  409. Hide();
  410. addimage();
  411. //ZSocketServer.getInstance().addWin(practiceWin);
  412. APP.W_PracticeWindow.ShowDialog();
  413. }
  414. catch (Exception ex)
  415. {
  416. LogHelper.WriteErrLog("【批注(Pizhu_btn_Click)" + ex.Message, ex);
  417. }
  418. }
  419. /// <summary>
  420. /// 添加截图到批注
  421. /// </summary>
  422. private void addimage()
  423. {
  424. string ImagePath = ImageHelper.GetTempImagePath();
  425. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), ImagePath,false,out BitmapImage bitmapImage,-1);
  426. APP.W_PracticeWindow.addImage(ImagePath);
  427. }
  428. /// <summary>
  429. /// 批注关闭
  430. /// </summary>
  431. private void PracticeWin_click_closeClick()
  432. {
  433. APP.W_PracticeWindow = null;
  434. }
  435. /// <summary>
  436. /// 批注关闭时显示工具栏
  437. /// </summary>
  438. /// <param name="sender"></param>
  439. /// <param name="e"></param>
  440. private void PracticeWin_Unloaded(object sender, RoutedEventArgs e)
  441. {
  442. Show();
  443. }
  444. /// <summary>
  445. /// 结束课堂
  446. /// </summary>
  447. private void closeAction()
  448. {
  449. //MyApp.myloading.Show();//加载等待
  450. try
  451. {
  452. //#region 加载通知栏图标
  453. //System.Windows.Forms.NotifyIcon ico = new System.Windows.Forms.NotifyIcon
  454. //{
  455. // Icon = new System.Drawing.Icon(FileToolsCommon.GetFileAbsolutePath("favicon256.ico")),
  456. // //this.Icon.DoubleClick += Icon_DoubleClick;//双击恢复 暂无
  457. // Visible = true
  458. //};
  459. //#endregion 加载通知栏图标
  460. //WindowState = WindowState.Minimized;
  461. //#region 关闭已打开窗口
  462. //pageData.tongping = !pageData.tongping;
  463. ////停止屏幕共享
  464. //if (pageData.tongping)
  465. //{
  466. // tongpingEnd();
  467. // pageData.menuList[1].Pic = "../Images/MainInterface/屏幕共享@2x.png";
  468. // pageData.menuList[1].Name = "屏幕共享";
  469. // gridAnimated.Visibility = Visibility.Collapsed;
  470. //}
  471. //if (blackboardWin2 != null)
  472. //{
  473. // blackboardWin2.Close();
  474. //}
  475. //if (rollCallWindow != null)
  476. //{
  477. // rollCallWindow.Close();
  478. //}
  479. //if (classroomExamWindow != null)
  480. //{
  481. // classroomExamWindow.Close();
  482. //}
  483. //if (classReportWindow != null)
  484. //{
  485. // classReportWindow.Close();
  486. //}
  487. //if (practiceWin != null)
  488. //{
  489. // practiceWin.Close();
  490. //}
  491. //if (classroomQuestionsWindow != null)
  492. //{
  493. // classroomQuestionsWindow.Close();
  494. //}
  495. //if (jietuWindow != null)
  496. //{
  497. // jietuWindow.Close();
  498. //}
  499. //if (attendanceWindow != null)
  500. //{
  501. // attendanceWindow.Close();
  502. //}
  503. //if (userCenterWindow != null)
  504. //{
  505. // userCenterWindow.Close();
  506. //}
  507. //#endregion 关闭已打开窗口
  508. //new Thread(o =>
  509. //{
  510. // StopNginx();
  511. // string msg = ZSocketMsgManger.classEnd();
  512. // ZSocketServer.getInstance().SendMessage(msg);
  513. // #region 清除没有上线人数的课堂数据
  514. // /*
  515. // * 上传本地数据库数据
  516. // * 判断该节课是否有人上线 若没人在线删除本节课数据。
  517. // * 可能存在多节课 1.多节课都没人上线,删除所有数据不上传。 2.多节课有上线的有没上线的情况,删除没有上线人数课的数据,将其余数据上传。
  518. // *
  519. // *
  520. // *
  521. // */
  522. // List<ClassData> classDataList = new List<ClassData>();
  523. // classDataList = ZSqliteManger.queryClassData();//取所有数据
  524. // if (classDataList.Count > 0)
  525. // {
  526. // for (int i = 0; i < classDataList.Count; i++)
  527. // {
  528. // if ("startclass".Equals(classDataList[i].api))//获取每节课的课堂id
  529. // {
  530. // List<ClassData> classroomidDataList = new List<ClassData>();
  531. // classroomidDataList = ZSqliteManger.queryClassRoomidData(classDataList[i].roomid);//取该节课的所有数据
  532. // for (int j = 0; j < classroomidDataList.Count; j++)
  533. // {
  534. // if ("sign".Equals(classroomidDataList[j].api))//若存在上线学生跳出循环
  535. // {
  536. // break;
  537. // }
  538. // if (j + 1 == classroomidDataList.Count)//若遍历完所有数据仍没有上线学生,删除该课堂id下所有数据
  539. // {
  540. // ZSqliteManger.clearClassData(classroomidDataList[j].roomid);
  541. // if (classroomidDataList[j].roomid == ZCommonData.roomid)
  542. // {
  543. // try
  544. // {
  545. // string path = ZConfig.classRoomImagePath();
  546. // if (Directory.Exists(path))
  547. // {
  548. // Directory.Delete(path, true);
  549. // }
  550. // }
  551. // catch (Exception ex)
  552. // {
  553. // LogHelper.WriteErrLog("ToolbarWindow(删除无效课堂文件夹报错:)" + ex.Message, ex);
  554. // }
  555. // }
  556. // }
  557. // }
  558. // }
  559. // }
  560. // classDataList = new List<ClassData>();
  561. // classDataList = ZSqliteManger.queryClassData();//取所有数据
  562. // }
  563. // #endregion
  564. // if (classDataList.Count > 0)
  565. // {
  566. // bool isRoomid = false;
  567. // for (int i = 0; i < classDataList.Count; i++)
  568. // {
  569. // if (classDataList[i].roomid == ZCommonData.roomid)
  570. // {
  571. // isRoomid = true;
  572. // }
  573. // }
  574. // if (isRoomid)
  575. // {
  576. // Dictionary<string, object> stopclass = new Dictionary<string, object>
  577. // {
  578. // { "roomid", ZCommonData.roomid },
  579. // { "endtime", ZNumUtil.unixTime() }
  580. // };
  581. // ZCommonData.askid = ZNumUtil.randomNum();
  582. // ZSqliteManger.insertClassData(new ClassData()
  583. // {
  584. // unix = ZNumUtil.unixTime(),
  585. // roomid = ZCommonData.roomid,
  586. // api = "stopclass",
  587. // json = ZJsonHelper.ToJson(stopclass),
  588. // askid = ZCommonData.askid
  589. // });
  590. // }
  591. // }
  592. // ZSocketServer.getInstance().Dispose();
  593. // if (classDataList.Count > 0)
  594. // {
  595. // MyApp.ZipFile();
  596. // }
  597. //else
  598. //{
  599. EndLive();
  600. //}
  601. WSocketClient.getInstance().SendMessage(SocketMsgManger.NolineMsg());
  602. Dispatcher.Invoke(new Action(() =>
  603. {
  604. System.Environment.Exit(0);
  605. }));
  606. }
  607. catch (Exception ex)
  608. {
  609. LogHelper.WriteErrLog("【ToolbarWindow】(closeAction)" + ex.Message, ex);
  610. }
  611. }
  612. /// <summary>
  613. /// 二级工具栏打开隐藏
  614. /// </summary>
  615. /// <param name="toolShow"></param>
  616. /// <param name="target"></param>
  617. /// <param name="contentList"></param>
  618. private void hideOrShow(bool toolShow, DependencyObject target, List<DependencyObject> contentList)
  619. {
  620. Storyboard story = new Storyboard();
  621. DoubleAnimation da = new DoubleAnimation();
  622. if (toolShow)
  623. {
  624. da.From = 0;
  625. da.To = 173;
  626. }
  627. else
  628. {
  629. da.From = 173.0;
  630. da.To = 0.0;
  631. }
  632. //可选属性:是否往返播放
  633. da.AutoReverse = false;
  634. //da.RepeatBehavior = RepeatBehavior.Forever;
  635. //da.RepeatBehavior = new RepeatBehavior(2);
  636. da.Duration = new Duration(TimeSpan.FromSeconds(0.3));
  637. Storyboard.SetTarget(da, target);
  638. Storyboard.SetTargetProperty(da, new PropertyPath("Width"));
  639. story.Children.Add(da);
  640. foreach (DependencyObject item in contentList)
  641. {
  642. DoubleAnimation da2 = new DoubleAnimation();
  643. if (toolShow)
  644. {
  645. da2.From = 0;
  646. da2.To = 1.0;
  647. }
  648. else
  649. {
  650. da2.From = 1.0;
  651. da2.To = 0.0;
  652. }
  653. da2.Duration = new Duration(TimeSpan.FromSeconds(0.1));
  654. Storyboard.SetTarget(da2, item);
  655. Storyboard.SetTargetProperty(da2, new PropertyPath("Opacity"));
  656. story.Children.Add(da2);
  657. }
  658. story.Begin();
  659. }
  660. /// <summary>
  661. /// 工具栏打开与缩放
  662. /// </summary>
  663. /// <param name="toolShow"></param>
  664. /// <param name="target"></param>
  665. /// <param name="contentList"></param>
  666. private void hideOrShowToolbar(bool toolShow, DependencyObject target, List<DependencyObject> contentList)
  667. {
  668. if (txbName.Visibility == Visibility.Visible)
  669. {
  670. txbName.Visibility = Visibility.Collapsed;
  671. }
  672. else
  673. {
  674. txbName.Visibility = Visibility.Visible;
  675. }
  676. Storyboard story = new Storyboard();
  677. DoubleAnimation da = new DoubleAnimation();
  678. if (toolShow)
  679. {
  680. da.From = 0;
  681. da.To = 450;
  682. }
  683. else
  684. {
  685. da.From = 450;
  686. da.To = 0.0;
  687. }
  688. //可选属性:是否往返播放
  689. da.AutoReverse = false;
  690. //da.RepeatBehavior = RepeatBehavior.Forever;
  691. //da.RepeatBehavior = new RepeatBehavior(2);
  692. da.Duration = new Duration(TimeSpan.FromSeconds(0.3));
  693. Storyboard.SetTarget(da, target);
  694. Storyboard.SetTargetProperty(da, new PropertyPath("Height"));
  695. story.Children.Add(da);
  696. foreach (DependencyObject item in contentList)
  697. {
  698. DoubleAnimation da2 = new DoubleAnimation();
  699. if (toolShow)
  700. {
  701. da2.From = 0;
  702. da2.To = 1.0;
  703. }
  704. else
  705. {
  706. da2.From = 1.0;
  707. da2.To = 0.0;
  708. }
  709. da2.Duration = new Duration(TimeSpan.FromSeconds(0.1));
  710. Storyboard.SetTarget(da2, item);
  711. Storyboard.SetTargetProperty(da2, new PropertyPath("Opacity"));
  712. story.Children.Add(da2);
  713. }
  714. story.Begin();
  715. }
  716. private void toolbar_win_Closed(object sender, EventArgs e)
  717. {
  718. }
  719. private void toolbar_win_ContentRendered(object sender, EventArgs e)
  720. {
  721. }
  722. private void toolbar_win_Loaded(object sender, RoutedEventArgs e)
  723. {
  724. }
  725. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  726. {
  727. time = NumUtil.unixTime();
  728. }
  729. private int time = NumUtil.unixTime();
  730. private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  731. {
  732. int temptime = NumUtil.unixTime();
  733. if (temptime - time < 1)
  734. {
  735. pageData.IsOpen = !pageData.IsOpen;
  736. List<DependencyObject> list = new List<DependencyObject>
  737. {
  738. toolbar_list
  739. };
  740. hideOrShowToolbar(pageData.IsOpen, toolbar, list);
  741. if (!pageData.IsOpen)
  742. {
  743. if (heibanshow)
  744. {
  745. List<DependencyObject> list3 = new List<DependencyObject>();
  746. heibanshow = false;
  747. list3.Add(heiban_btn);
  748. list3.Add(pizhu_btn);
  749. hideOrShow(heibanshow, ketangTool, list3);
  750. }
  751. }
  752. }
  753. }
  754. /// <summary>
  755. /// 工具栏移动事件
  756. /// </summary>
  757. /// <param name="sender"></param>
  758. /// <param name="e"></param>
  759. private void Rectangle_MouseMove(object sender, MouseEventArgs e)
  760. {
  761. if (e.LeftButton == MouseButtonState.Pressed)
  762. {
  763. DragMove();
  764. }
  765. }
  766. #endregion
  767. #region 方法
  768. /// <summary>
  769. /// 启动WS
  770. /// </summary>
  771. private void startSocket()
  772. {
  773. WSocketClient.getInstance().StartWsClient();
  774. }
  775. /// <summary>
  776. /// 关闭或隐藏页面
  777. /// </summary>
  778. private void CloseOrHideWindowPage()
  779. {
  780. if (IsOpenUserCenterWindow)
  781. {
  782. IsOpenUserCenterWindow = false;
  783. APP.W_UserCenterWindow.Close();
  784. }
  785. if (IsOpenRollCallWindow)
  786. {
  787. IsOpenRollCallWindow = false;
  788. APP.W_RollCallWindow.Hide();
  789. }
  790. if (IsOpenAttendanceWindow)
  791. {
  792. IsOpenAttendanceWindow = false;
  793. APP.W_AttendanceWindow.Hide();
  794. }
  795. }
  796. /// <summary>
  797. /// 隐藏二级菜单
  798. /// </summary>
  799. private void HideLevel2()
  800. {
  801. try
  802. {
  803. if (heibanshow)
  804. {
  805. heibanshow = !heibanshow;
  806. List<DependencyObject> lists = new List<DependencyObject>
  807. {
  808. heiban_btn,
  809. pizhu_btn
  810. };
  811. hideOrShow(heibanshow, ketangTool, lists);
  812. }
  813. }
  814. catch (Exception ex)
  815. {
  816. LogHelper.WriteErrLog("【工具栏(ToolbarWindow)" + ex.Message, ex);
  817. }
  818. }
  819. #endregion
  820. #region 直播
  821. /// <summary>
  822. /// 直播间节点和房号
  823. /// </summary>
  824. string NodeKey = "live/test";
  825. /// <summary>
  826. /// 开始直播
  827. /// </summary>
  828. public bool StartLive(out string ErrMessage)
  829. {
  830. try
  831. {
  832. WSocketClient.getInstance().SendMessage(SocketMsgManger.GetIntoMsg());
  833. NodeKey = "live/"+APP.ClassroomAdd.ToString();
  834. System.Drawing.Size DesktopSize = PrimaryScreen.DESKTOP;
  835. //开始直播
  836. if(APP.FFmpeg.StartLiveRecordingVideo(APP.RTMPServerPath, NodeKey, DesktopSize,out ErrMessage))
  837. {
  838. return true;
  839. }
  840. else
  841. {
  842. return false;
  843. }
  844. }
  845. catch (Exception ex)
  846. {
  847. ErrMessage = "无法开始直播:" + ex.Message;
  848. LogHelper.WriteErrLog(ErrMessage, ex);
  849. return false;
  850. }
  851. }
  852. /// <summary>
  853. /// 结束直播
  854. /// </summary>
  855. public void EndLive()
  856. {
  857. APP.FFmpeg.StopLive();
  858. }
  859. #endregion
  860. }
  861. /// <summary>
  862. /// 工具栏模型
  863. /// </summary>
  864. public class ToolbarModel : NotifyModel
  865. {
  866. public ObservableCollection<ToolbarMenu> menuList { get; set; }
  867. internal bool _tongping = false;
  868. public bool tongping
  869. {
  870. get => _tongping;
  871. set { _tongping = value; OnPropertyChanged("tongping"); }
  872. }
  873. internal bool _IsOpen = true;
  874. public bool IsOpen
  875. {
  876. get => _IsOpen;
  877. set { _IsOpen = value; OnPropertyChanged("IsOpen"); }
  878. }
  879. public ToolbarModel()
  880. {
  881. menuList = new ObservableCollection<ToolbarMenu>();
  882. }
  883. }
  884. /// <summary>
  885. /// 工具栏菜单模型
  886. /// </summary>
  887. public class ToolbarMenu : NotifyModel
  888. {
  889. internal string _name;
  890. public string Name
  891. {
  892. get => _name;
  893. set { _name = value; OnPropertyChanged("Name"); }
  894. }
  895. internal string _Pic;
  896. public string Pic
  897. {
  898. get => _Pic;
  899. set { _Pic = value; OnPropertyChanged("Pic"); }
  900. }
  901. }
  902. }