星火直播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 31KB

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