private void OKButton_Click(object sender, System.Windows.RoutedEventArgs e) { String s = this.UserNameTextBox.Text; if ((System.Text.RegularExpressions.Regex.IsMatch(s, "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]+$")) & (s.Length == 8)) { PairCodeConfig.SetPairCode(s); DialogResult = true; } else { this.UserNameTextBox.Text = "配对码"; } }
//public class JoPaths //{ // public string getpath { get; set; } //} public async void handle(Object myClientSocket) { Socket ClientSocket = null; try { ClientSocket = (Socket)myClientSocket; Projection projection = new Projection(); WindowControl wc = new WindowControl(); Applacation app = new Applacation(); MediaFunction media = new MediaFunction(); Game game = new Game(); Response response = null; //test = windows.BackGroundWindow.Instance(); Console.WriteLine("name is:{0}", name); log.Info(string.Format("接收到手机发来的指令 name = {0},command = {1},param = {2}", name, command, param)); switch (name) { case CommandName.PC: if (command.Equals("AddDirsHTTP")) { string status = null; bool flag = true; Console.WriteLine("paths is:{0}", param["paths"]); String[] pathlist = param["paths"].Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries); //List<JoPaths> pathlist = JsonConvert.DeserializeObject<List<JoPaths>>(param["paths"]); //List<JoPaths> err_pathlist = new List<JoPaths>(); //String[] err_pathlist = null; List <string> err_pathlist = new List <string>(); foreach (string path in pathlist) { Console.WriteLine("path is:{0}" + path); string dirPath = path; if (File.Exists(dirPath) || Directory.Exists(dirPath)) { if (Directory.Exists(dirPath)) { DirectoryInfo Folder = new DirectoryInfo(dirPath); foreach (FileInfo file in Folder.GetFiles()) { if (File.Exists(file.FullName)) { Console.WriteLine("file fullname_1 is:{0}", file.FullName); Node node = new Node(file.FullName); NodeContainer.addNode(node); } } } else { FileInfo file = new FileInfo(dirPath); Console.WriteLine("file fullname_2 is:{0}", file.FullName); Node node = new Node(file.FullName); NodeContainer.addNode(node); } Console.WriteLine("status:200"); } else { flag = false; err_pathlist.Add(path); Console.WriteLine("status:404"); } } if (flag) { status = "200"; } else { status = "404"; } //string errpaths = "{\"errorPaths:\"" + "\"" + err_pathlist +"\"}"; response = new Response(status, "", CommandName.PC, err_pathlist); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("close")) { Environment.Exit(0); } else if (command.Equals("SEARCH")) { string key = param["key"]; List <MediaMengMeng> allmedia = util.config.MediaConfig.SearchAll(key); response = new Response("200", "", CommandName.PC, JsonConvert.SerializeObject(allmedia)); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.VIDEO: if (command.Equals("PLAY")) { PlayMedia(param["tvname"], param["path"]); media.AddRecentMeiaList(new MediaItem(param["path"])); response = new Response("200", "", CommandName.VIDEO, null); ////////////////////////////////////// ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETTOTALLIST")) { response = new Response("200", "", CommandName.VIDEO, JsonConvert.SerializeObject(media.getMediasByPath("VIDEO", param["folder"]))); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETRECENTLIST")) { response = new Response("200", "", CommandName.VIDEO, JsonConvert.SerializeObject(media.GetRecentVideoList())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("DELETE")) { if (media.DeletMyMediaLibrary("UserVideoConfig", param["folder"])) { response = new Response("200", "DELETE_SUCCESS", CommandName.VIDEO, null); } else { response = new Response("404", "DELETE_FAILED", CommandName.VIDEO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.AUDIO: if (command.Equals("PLAY")) { PlayMedia(param["tvname"], param["path"]); media.AddRecentMeiaList(new MediaItem(param["path"])); response = new Response("200", "", CommandName.AUDIO, null); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETTOTALLIST")) { response = new Response("200", "", CommandName.AUDIO, JsonConvert.SerializeObject(media.getMediasByPath("AUDIO", param["folder"]))); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETRECENTLIST")) { response = new Response("200", "", CommandName.AUDIO, JsonConvert.SerializeObject(media.GetRecentAudioList())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETSETS")) { response = new Response("200", "", CommandName.AUDIO, JsonConvert.SerializeObject(media.GetAudioSet())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("ADDSET")) { if (media.AddAudioSet(param["setname"])) { response = new Response("200", "", CommandName.AUDIO, null); } else { response = new Response("404", "", CommandName.AUDIO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("ADDFILESTOSET")) { string s = param["liststr"]; if (media.AddAudioSet(param["setname"], JsonConvert.DeserializeObject <List <MediaMengMeng> >(s))) { response = new Response("200", "", CommandName.AUDIO, null); } else { response = new Response("404", "", CommandName.AUDIO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("DELETESET")) { if (media.DeleteAudiSet(param["setname"])) { response = new Response("200", "", CommandName.AUDIO, null); } else { response = new Response("404", "", CommandName.AUDIO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("PLAYSET")) { bool re; //if (!param.ContainsKey("asBGM")) //{ // re = PlayMedias(param["tvname"], "audio", param["setname"]); //} //else //{ re = PlayMedias(param["tvname"], "audio", param["setname"]); //} if (re) { List <MediaMengMeng> list = media.GetAudioSet()[param["setname"]]; if (list.Count < 10) { foreach (MediaMengMeng m in list) { media.AddRecentAudioList(m); } } else { for (int i = list.Count - 10; i < list.Count; i++) { media.AddRecentAudioList(list[i]); } } response = new Response("200", "", CommandName.AUDIO, null); } else { response = new Response("404", "", CommandName.AUDIO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("PLAYSETASBGM")) { bool re; re = PlayMedias(param["tvname"], "audio", param["setname"], null); if (re) { List <MediaMengMeng> list = media.GetAudioSet()[param["setname"]]; if (list.Count < 10) { foreach (MediaMengMeng m in list) { media.AddRecentAudioList(m); } } else { for (int i = list.Count - 10; i < list.Count; i++) { media.AddRecentAudioList(list[i]); } } response = new Response("200", "", CommandName.AUDIO, null); } else { response = new Response("404", "", CommandName.AUDIO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("DELETE")) { if (media.DeletMyMediaLibrary("UserAudioConfig", param["folder"])) { response = new Response("200", "DELETE_SUCCESS", CommandName.AUDIO, null); } else { response = new Response("404", "DELETE_FAILED", CommandName.AUDIO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.IMAGE: if (command.Equals("PLAY")) { PlayMedia(param["tvname"], param["path"]); response = new Response("200", "", CommandName.IMAGE, null); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("PLAYALL")) { List <MediaMengMeng> l = media.getMediasByPath("IMAGE", param["folder"]); List <string> urls = new List <string>(); foreach (MediaMengMeng m in l) { info.media.MediaItem mi = new info.media.MediaItem(m.pathName); urls.Add(mi.url); } foreach (info.tv.TVInfo item in MyInfo.tvLibrary.value) { if (item.name.Equals(param["tvname"])) { function.tv.TVFunction.sendCommand(item.ip, info.tv.TVCommand.GetInstance("OPEN_HTTP_MEDIA", null, false, "", "image", urls, null)); } } //foreach (var ls in list) //{ // PlayMedia(param["tvname"], ls[""]); //} response = new Response("200", "", CommandName.IMAGE, null); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETTOTALLIST")) { List <MediaMengMeng> list = media.getMediasByPath("IMAGE", param["folder"]); response = new Response("200", "", CommandName.IMAGE, JsonConvert.SerializeObject(list)); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETSETS")) { response = new Response("200", "", CommandName.IMAGE, JsonConvert.SerializeObject(media.GetImageSet())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("ADDSET")) { if (media.AddImageSet(param["setname"])) { response = new Response("200", "", CommandName.IMAGE, null); } else { response = new Response("404", "", CommandName.IMAGE, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("ADDFILESTOSET")) { string s = param["liststr"]; if (media.AddImageSet(param["setname"], JsonConvert.DeserializeObject <List <MediaMengMeng> >(s))) { response = new Response("200", "", CommandName.IMAGE, null); } else { response = new Response("404", "", CommandName.IMAGE, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("DELETESET")) { if (media.DeleteImageSet(param["setname"])) { response = new Response("200", "", CommandName.IMAGE, null); } else { response = new Response("404", "", CommandName.IMAGE, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("PLAYSET")) { bool re = PlayMedias(param["tvname"], "image", param["setname"]); if (re) { List <MediaMengMeng> list = media.GetImageSet()[param["setname"]]; if (list.Count < 10) { foreach (MediaMengMeng m in list) { media.AddRecentImageList(m); } } else { for (int i = list.Count - 10; i < list.Count; i++) { media.AddRecentImageList(list[i]); } } response = new Response("200", "", CommandName.IMAGE, null); } else { response = new Response("404", "", CommandName.IMAGE, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("DELETE")) { if (media.DeletMyMediaLibrary("UserImageConfig", param["folder"])) { response = new Response("200", "DELETE_SUCCESS", CommandName.VIDEO, null); } else { response = new Response("404", "DELETE_FAILED", CommandName.VIDEO, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.APP: if (command.Equals("GETTOTALLIST")) { response = new Response("200", "", CommandName.APP, JsonConvert.SerializeObject(app.GetAppList())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("OPEN_RDP")) { if ((string)param["path"] == "back") { App.Current.Dispatcher.Invoke((Action)(() => { System.Windows.Window test = windows.BackGroundWindow.Instance(); test.Hide(); })); app.CloseAll(); Type oleType = Type.GetTypeFromProgID("Shell.Application"); object oleObject = System.Activator.CreateInstance(oleType); oleType.InvokeMember("ToggleDesktop", BindingFlags.InvokeMethod, null, oleObject, null); } else { App.Current.Dispatcher.Invoke((Action)(() => { System.Windows.Window test = windows.BackGroundWindow.Instance(); test.Show(); })); app.OpenApp((string)param["path"], ""); } } else if (command.Equals("OPEN_MIRACAST")) { //WindowControl.SetTaskBarState(0); if (!projection.IsConnection()) { app.CloseAll(); //projection.EnterQS(); //projection.ClosePopup(); } Process pro; pro = app.OpenApp((string)param["path"], ""); //Console.WriteLine(System.Windows.Forms.Screen.AllScreens.Last()); DeviceItem item = util.config.UserScreenConfig.GetScreen(param["tvname"]); if (item != null) { await projection.SelectProjectionDevice(item.screen); wc.MoveWindow(pro, System.Windows.Forms.Screen.AllScreens.Last(), true); response = new Response("200", "", CommandName.APP, null); } else { response = new Response("404", "don't have set miracast", CommandName.APP, null); } //projection.ClearMiracastPopup(); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.GAME: if (command.Equals("GETTOTALLIST")) { response = new Response("200", "", CommandName.GAME, JsonConvert.SerializeObject(game.GetGameList())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("OPEN")) { game.OpenGame(param["path"], ""); response = new Response("200", "", CommandName.GAME, null); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.SYS: if (command.Equals("GETINFOR")) { response = new Response("200", "", CommandName.SYS, JsonConvert.SerializeObject(function.pcapp.PCInformation.GetInstance())); ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } else if (command.Equals("GETSCREENSTATE")) { if (MyInfo.IsSreenLock) { response = new Response("404", "", CommandName.SYS, null); } else { response = new Response("200", "", CommandName.SYS, null); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; case CommandName.SECURITY: if (command.Equals("PAIR")) { string code = param["code"]; if (code.Equals(PairCodeConfig.GetPairCode())) { response = new Response("200", "", CommandName.SECURITY, "true"); } else { response = new Response("200", "", CommandName.SECURITY, "false"); } ClientSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(response))); } break; } log.InfoFormat("Command 接受到的命令: {0},返回的结果: {1}", JsonConvert.SerializeObject(this), JsonConvert.SerializeObject(response)); ClientSocket.Close(); } catch (Exception e) { if (ClientSocket != null) { ClientSocket.Close(); } log.Error("Comand 执行出错", e); } }
public MainWindow() { main = this; if (!System.IO.Directory.Exists(MyInfo.myDataPath)) { //Console.WriteLine(MyInfo.myDataPath); System.IO.Directory.CreateDirectory(MyInfo.myDataPath); //Console.WriteLine(MyInfo.iconFolder); System.IO.Directory.CreateDirectory(MyInfo.iconFolder); //Console.WriteLine(MyInfo.myDataPath + "\\MediaLibraryTemp"); System.IO.Directory.CreateDirectory(MyInfo.myDataPath + "\\MediaLibraryTemp"); System.IO.File.Copy(System.Windows.Forms.Application.StartupPath + "./AreaParty.exe.config", MyInfo.execonfig); } if (System.IO.File.Exists(MyInfo.execonfig)) { AppConfig.Change(MyInfo.execonfig); } if (String.IsNullOrEmpty(PairCodeConfig.GetPairCode())) { bool result = new PairCodeWindow().ShowDialog().Value; if (result == false) { System.Windows.Application.Current.Shutdown(); System.Windows.Forms.Application.Exit(); } } Thread t = new Thread(new ThreadStart(Run)); t.Name = "NoParameterThread"; t.IsBackground = true; t.Start(); if (ConfigUtil.GetValue("init").Equals("false")) { windows.InitSetting ist = new windows.InitSetting(); ist.ShowDialog(); AppScan.ScanAndUpdateMySoftware(); util.JAVAUtil.AddSourceToHTTP(info.MyInfo.iconFolder); ConfigUtil.SetValue("init", "true"); } function.webservice.WebOperation.ReportInfo(); function.webservice.WebOperation.GetUudateInfo(); InitializeComponent(); new Thread(new ThreadStart(delegate() { if (ConfigUtil.GetValue("longconnect").Equals("true")) { try { Thread.Sleep(1000 * 10); IPAddress ip = IPAddress.Parse("127.0.0.1"); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(ip, ConfigResource.HOLE_PORT)); string name = ConfigUtil.GetValue("username"); string password = ConfigUtil.GetValue("password"); Command c = CommandFactory.GetLoginCommand(name, password); socket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(c))); socket.Send(Encoding.UTF8.GetBytes("\r\n")); socket.Close(); App.Current.Dispatcher.Invoke((Action)(() => { this.Login_Label.Content = "长连接开启"; })); } catch (Exception e) { App.Current.Dispatcher.Invoke((Action)(() => { this.Login_Label.Content = "长连接失败"; })); Console.WriteLine(e); } } })).Start(); Icon(); //MessageBox.Show("" + ConfigUtil.IsExistsScreen("user")); }