示例#1
0
        private async Task DiscoverDownloadsAsync()
        {
            activeDownloads = new List <DownloadOperation>();
            try
            {
                downloads = await BackgroundDownloader.GetCurrentDownloadsAsync();

                if (downloads.Count > 0)
                {
                    List <Task> tasks = new List <Task>();
                    foreach (DownloadOperation download in downloads)
                    {
                        HandleModel handModel = new HandleModel
                        {
                            Name         = download.ResultFile.Name,
                            DownOpration = download,
                            Size         = download.Progress.BytesReceived.ToString(),
                        };
                        if (download.Progress.TotalBytesToReceive > 0)
                        {
                            handModel.Progress = (download.Progress.BytesReceived / download.Progress.TotalBytesToReceive) * 100;
                        }
                        list_now.Items.Add(handModel);
                        tasks.Add(HandleDownloadAsync(handModel));
                    }
                    await Task.WhenAll(tasks);
                }
            }
            catch (Exception e)
            {
                await new ContentDialog {
                    Content = "错误:" + e.ToString(), IsSecondaryButtonEnabled = false, PrimaryButtonText = "确定"
                }.ShowAsync();
            }
        }
示例#2
0
 public static HandleModel MessageHandle(HandleModel handle, string str)
 {
     if (App.WinCommand.ContainsKey(str))
     {
         handle.Msg = App.WinCommand[str];
         handle.Typ = "Cmd";
         return(handle);
     }
     else if (App.Office.ContainsKey(str))
     {
         handle.Msg = App.Office[str];
         handle.Typ = "Office";
         return(handle);
     }
     else if (App.Web.ContainsKey(str))
     {
         handle.Msg = App.Web[str];
         handle.Typ = "Web";
         return(handle);
     }
     else if (App.Search.ContainsKey(str))
     {
         handle.Msg = App.Search[str];
         handle.Typ = "Search";
         return(handle);
     }
     else
     {
         handle.Msg = "";
         handle.Typ = "";
         return(handle);
     }
 }
示例#3
0
 private void DownLoadProgress(DownloadOperation download)
 {
     try
     {
         HandleModel test = null;
         foreach (HandleModel item in list_now.Items)
         {
             if (item.DownOpration.Guid == download.Guid)
             {
                 test = item;
             }
         }
         if (list_now.Items.Contains(test))
         {
             HandleModel item = (HandleModel)list_now.Items[list_now.Items.IndexOf(test)];
             item.Size     = download.Progress.BytesReceived.ToString();
             item.Status   = download.Progress.Status.ToString();
             item.Progress = ((double)download.Progress.BytesReceived / download.Progress.TotalBytesToReceive) * 100;
             if (item.Progress == 100 && download.Progress.BytesReceived > 0)
             {
                 //Sendtoast("下载完成", ((HandleModel)list_now.Items[list_now.Items.IndexOf(test)]).Name);
                 send("下载完成", ((HandleModel)list_now.Items[list_now.Items.IndexOf(test)]).Name);
                 list_now.Items.Remove(test);
             }
         }
     }
     catch (Exception)
     {
         return;
     }
 }
示例#4
0
        public void ProcessRequest(HttpContext context)
        {
            LogHelper.Write("----------------------分割线--------------------------");
            if (TokenModel.token == null)
            {
                LogHelper.Write("获取新的token");
                TokenModel.getAccesss_Token();
            }
            //Response.Write("<script>location.href='Test.html'</script>");
            if (flag)
            {
                createMenu();
                flag = false;
            }
            string postString = string.Empty;

            if (HttpContext.Current.Request.HttpMethod.ToUpper() == "POST")
            {
                using (Stream stream = HttpContext.Current.Request.InputStream)
                {
                    Byte[] postBytes = new Byte[stream.Length];
                    stream.Read(postBytes, 0, (Int32)stream.Length);
                    postString = Encoding.UTF8.GetString(postBytes);
                    HandleModel.Handle(postString);
                    LogHelper.Write(postString);
                }
            }
        }
示例#5
0
        public void ProcessRequest(HttpContext context)
        {
            LogHelper.Write("----------------------分割线111--------------------------");
            //接通测试
            //InterfaceTest();
            //事件响应
            string postString = response(context);

            HandleModel.Handle(postString);
        }
示例#6
0
        //参数为文档中的Operation
        public static void SendCmd(string str)
        {
            HandleModel handle = new HandleModel();

            handle = StringHandle.MessageHandle(handle, str);
            string  msg     = JsonConvert.SerializeObject(handle);
            Command command = new Command {
                Flag = "1", Msg = msg
            };

            //所发送的Msg,{"FullName":"我的电脑","FileTyp":null,"Name":"我的电脑","Lable":"我的电脑"}"}
            string message = JsonConvert.SerializeObject(command);

            App.SendData(message, App.socketCmd);
        }
示例#7
0
        private async Task HandleDownloadAsync(HandleModel model)
        {
            var download = model.DownOpration;

            try
            {
                DownLoadProgress(download);
                Progress <DownloadOperation> progressCallback = new Progress <DownloadOperation>(DownLoadProgress);
                await download.AttachAsync().AsTask(cts.Token, progressCallback);
            }
            catch (TaskCanceledException)
            {
                // messagepop.Show("取消: " + download.Guid);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#8
0
 public IActionResult CurrentPage(HandleModel model)
 {
     return(CurrentPage());
 }
示例#9
0
        public static void Command(HandleModel handle)
        {
            if (handle.Typ == "Cmd")
            {
                //dicCmd命令
                foreach (KeyValuePair <string, string> s in App.dicCmd)
                {
                    if (s.Key.Equals(handle.Msg))
                    {
                        if (handle.Msg.Equals("DisConnect"))
                        {
                            InfoHandle.DisConnectClient();

                            OnStartUp();
                        }
                        else if (handle.Msg.Equals("Win_Desktop"))
                        {
                            string t = "C:\\Users\\" + Environment.UserName + "\\Desktop";
                            Process.Start(@t);
                        }
                        else if (handle.Msg.Equals("Win_VolumeUp"))
                        {
                            SetVolUp();
                        }
                        else if (handle.Msg.Equals("Win_VolumeDown"))
                        {
                            SetVolDown();
                        }
                        else if (handle.Msg.Equals("Win_VolumeMute"))
                        {
                            SetVolMute();
                        }

                        //请求截屏
                        else if (handle.Msg.Equals("Win_Screenshot"))
                        {
                            Screen scr     = Screen.PrimaryScreen;
                            int    iWidth  = scr.Bounds.Width;
                            int    iHeight = scr.Bounds.Height;
                            System.Drawing.Image myImage = new Bitmap(iWidth, iHeight);
                            Graphics             g       = Graphics.FromImage(myImage);
                            g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), new System.Drawing.Size(iWidth, iHeight));

                            //保存文件流到stream
                            stream = new MemoryStream();
                            myImage.Save(stream, ImageFormat.Png);

                            byte[] filebuffer = new byte[stream.Length];
                            stream.Seek(0, SeekOrigin.Begin);
                            stream.Read(filebuffer, 0, filebuffer.Length);
                            // 设置当前流的位置为流的开始


                            //ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
                            //imgscreen.Source = (ImageSource)imageSourceConverter.ConvertFrom(stream);

                            //向客户端发送截图的文件
                            App.SendScreen(filebuffer, App.serverSocketCmd);
                            //系统截屏

                            /*
                             * keybd_event(0x2C, 0, 0, 0);
                             * keybd_event(0x2C, 0, 0x2, 0);
                             * System.Diagnostics.Process.Start(@"C:\\WINDOWS\\system32\\mspaint.exe");//打开文件和文件夹
                             * Thread.Sleep(1000);
                             * keybd_event(17, 0, 0, 0);
                             * keybd_event(86, 0, 0, 0);
                             * keybd_event(86, 0, 0x2, 0);
                             * keybd_event(17, 0, 0x2, 0);*/
                        }

                        else if (handle.Msg.Equals("Win_Logoff"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Equals("Win_Sleep"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Equals("Win_Reset"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Equals("Win_Shutdown_Immediately"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Equals("Win_Shutdown_HalfAfterHour"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Equals("Win_Shutdown_AfterOneHour"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Equals("Win_Shutdown_Cancel"))
                        {
                            Process.Start("shutdown.exe", s.Value);
                        }
                        else if (handle.Msg.Contains("Close"))
                        {
                            string suffix = "";
                            int    flag   = 0;
                            windows = new Dictionary <IntPtr, string>();
                            EnumWindows(PrintWindow, IntPtr.Zero);
                            if (handle.Msg.Equals("Close_mspaint"))
                            {
                                suffix = "画图";
                            }
                            else if (handle.Msg.Equals("Close_calc"))
                            {
                                suffix = "计算器";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_notepad"))
                            {
                                suffix = "记事本";
                            }
                            else if (handle.Msg.Equals("Close_cmd"))
                            {
                                suffix = @"\system32\cmd.exe";
                            }
                            else if (handle.Msg.Equals("Close_write"))
                            {
                                suffix = "写字板";
                            }
                            else if (handle.Msg.Equals("Close_mstsc"))
                            {
                                suffix = "远程桌面连接";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_taskmgr"))
                            {
                                suffix = "任务管理器";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_explorer"))
                            {
                                suffix = "文件资源管理器";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_devmgmt.msc"))
                            {
                                suffix = "设备管理器";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_iexplore.exe"))
                            {
                                suffix = "Internet Explorer";
                            }
                            else if (handle.Msg.Equals("Close_control"))
                            {
                                suffix = "控制面板";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_narrator"))
                            {
                                suffix = "\"讲述人\"设置";
                                flag   = 1;
                            }
                            else if (handle.Msg.Equals("Close_winword"))
                            {
                                suffix = "Word";
                            }
                            else if (handle.Msg.Equals("Close_powerpnt"))
                            {
                                suffix = "PowerPoint";
                            }
                            else if (handle.Msg.Equals("Close_exce"))
                            {
                                suffix = "Excel";
                            }
                            if (flag == 0)
                            {
                                CloseWindow(suffix, suffix.Length);
                            }
                            else if (flag == 1)
                            {
                                CloseWindow(suffix);
                            }
                        }
                        else if (handle.Msg.Contains("Video"))
                        {
                            if (handle.Msg.Equals("Video_Stop"))
                            {
                                keybd_event(0x11, 0, 0, 0);
                                keybd_event(83, 0, 0, 0);
                                keybd_event(83, 0, 0x2, 0);
                                keybd_event(0x11, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Pause"))
                            {
                                keybd_event(32, 0, 0, 0);
                                keybd_event(32, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Play"))
                            {
                                keybd_event(32, 0, 0, 0);
                                keybd_event(32, 0, 0x2, 0);
                            }

                            else if (handle.Msg.Equals("Video_Forward"))
                            {
                                keybd_event(39, 0, 0, 0);
                                keybd_event(39, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Backward"))
                            {
                                keybd_event(37, 0, 0, 0);
                                keybd_event(37, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Brightincrease"))
                            {
                                keybd_event(107, 0, 0, 0);
                                keybd_event(107, 0, 0x2, 0);
                                keybd_event(107, 0, 0, 0);
                                keybd_event(107, 0, 0x2, 0);
                                keybd_event(107, 0, 0, 0);
                                keybd_event(107, 0, 0x2, 0);
                                keybd_event(107, 0, 0, 0);
                                keybd_event(107, 0, 0x2, 0);
                                keybd_event(107, 0, 0, 0);
                                keybd_event(107, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Brightreduce"))
                            {
                                keybd_event(109, 0, 0, 0);
                                keybd_event(109, 0, 0x2, 0);
                                keybd_event(109, 0, 0, 0);
                                keybd_event(109, 0, 0x2, 0);
                                keybd_event(109, 0, 0, 0);
                                keybd_event(109, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_PageDown"))
                            {
                                keybd_event(34, 0, 0, 0);
                                keybd_event(34, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_PageUp"))
                            {
                                keybd_event(33, 0, 0, 0);
                                keybd_event(33, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_AllScreen"))
                            {
                                keybd_event(111, 0, 0, 0);
                                keybd_event(111, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Volumnreduce"))
                            {
                                keybd_event(40, 0, 0, 0);
                                keybd_event(40, 0, 0x2, 0);
                                keybd_event(40, 0, 0, 0);
                                keybd_event(40, 0, 0x2, 0);
                                keybd_event(40, 0, 0, 0);
                                keybd_event(40, 0, 0x2, 0);
                            }
                            else if (handle.Msg.Equals("Video_Volumnincrease"))
                            {
                                keybd_event(38, 0, 0, 0);
                                keybd_event(38, 0, 0x2, 0);
                                keybd_event(38, 0, 0, 0);
                                keybd_event(38, 0, 0x2, 0);
                                keybd_event(38, 0, 0, 0);
                                keybd_event(38, 0, 0x2, 0);
                            }
                        }
                        else
                        {
                            string[] com = s.Value.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                            if (com.Length == 1)
                            {
                                Process.Start(@s.Value);
                            }
                        }
                    }
                }
            }
            else if (handle.Typ == "Office")
            {
                //dicOffice命令
                foreach (KeyValuePair <string, string> s in App.dicOffice)
                {
                    if (s.Key.Equals(handle.Msg))
                    {
                        if (s.Value == "DownPPt")
                        {
                            PPT.Down();
                        }
                        else if (s.Value == "UpPPt")
                        {
                            PPT.Up();
                        }
                        else if (s.Value == "FirstPPt")
                        {
                            PPT.First();
                        }
                        else if (s.Value == "LastPPt")
                        {
                            PPT.Last();
                        }
                        else if (s.Value == "ClosePPt")
                        {
                            PPT.Close();
                        }
                        else if (s.Value == "Play_powerpnt")
                        {
                            PPT.Play();
                        }
                        else
                        {
                            PPT.Open(s.Value);
                        }
                    }
                }
            }
            else if (handle.Typ == "Web")
            {
                //dicWeb命令
                foreach (KeyValuePair <string, string> s in App.dicWeb)
                {
                    if (s.Key.Equals(handle.Msg))
                    {
                        System.Diagnostics.Process.Start(s.Value);
                    }
                }
            }
            else if (handle.Typ == "Search")
            {
                System.Diagnostics.Process.Start(handle.Msg);
            }
        }
示例#10
0
        public static void ReceiveCmd(object obj)
        {
            Socket s = obj as Socket;

            byte[] buffer = null;
            while (true)
            {
                try
                {
                    buffer = new byte[200];
                    s.Receive(buffer);
                }
                catch (ArgumentNullException)
                {
                    //MessageBox.Show("发送的东西为空");
                    // s.Dispose();
                    //InfoHandle.threadDisk.Abort();
                    return;
                }
                catch (SocketException)
                {
                    //MessageBox.Show("访问套接字失败");
                    return;
                }
                catch (ObjectDisposedException)
                {
                    Debug.WriteLine("连接已断开");
                    //MessageBox.Show("连接已断开");
                    //DisConnect();
                    //Cmd.OnStartUp();
                    return;
                }
                string info = Encoding.UTF8.GetString(buffer);
                info = Msg.HandleRcvMsg(info);
                //考虑是否有#
                try
                {
                    if (info.Contains("XiYou#"))
                    {
                        HandleRcvMsg(ref info);
                        Debug.WriteLine("SocketCmd接收的信息:" + info);
                        Command command = JsonConvert.DeserializeObject <Command>(info);
                        if (command.Flag == "1")
                        {
                            HandleModel handle = JsonConvert.DeserializeObject <HandleModel>(command.Msg);
                            Cmd.Command(handle);
                        }
                        else if (command.Flag == "2")
                        {
                            //json反序列为类
                            DiskFolder folder = JsonConvert.DeserializeObject <DiskFolder>(command.Msg);
                            DiskHandle(folder);
                        }
                        else if (command.Flag == "3")
                        {
                            string[] offset = Regex.Split(command.Msg, ",");
                            if (offset.Length >= 2 && offset.Length < 5)
                            {
                                var sgl1 = new Signal1();
                                sgl1.x    = Convert.ToDouble(offset[0]);
                                sgl1.y    = Convert.ToDouble(offset[1]);
                                sgl1.mode = Msg.HandleRcvMsg(offset[2]);
                                Signal1.DoMouseEvent(sgl1);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
        }
示例#11
0
        private async void Voice(object sender, RoutedEventArgs e)
        {
            voice.IsEnabled = false;
            using (SpeechRecognizer speechRecognizer = new SpeechRecognizer())
            {
                try
                {
                    //编译所有语法协定
                    SpeechRecognitionCompilationResult compilationResult = await speechRecognizer.CompileConstraintsAsync();

                    if (compilationResult.Status == SpeechRecognitionResultStatus.Success)
                    {
                        //开始语音识别
                        var recogResult = await speechRecognizer.RecognizeWithUIAsync();

                        if (recogResult.Status == SpeechRecognitionResultStatus.Success)
                        {
                            info = recogResult.Text;
                            HandleModel handle = new HandleModel();
                            handle = StringHandle.MessageHandle(handle, info);
                            string msg = JsonConvert.SerializeObject(handle);

                            Command command = new Command {
                                Flag = "1", Msg = msg
                            };
                            if (handle.Typ != "")
                            {
                                string sendMsg = JsonConvert.SerializeObject(command);
                                Debug.WriteLine("语音发送的命令:" + sendMsg);
                                TextToSpeech("正在为你" + info);
                                App.SendData(sendMsg, App.socketCmd);
                                voice.IsEnabled = true;
                            }
                            else
                            {
                                handle.Typ = "Search";
                                //handle.Msg = speechContent.Text;

                                string uriMsg = string.Format("{0}{1}", App.Search["百度"], System.Net.WebUtility.UrlEncode(info));
                                Uri    uri    = new Uri(uriMsg);
                                handle.Msg = uriMsg;
                                string msg1 = JsonConvert.SerializeObject(handle);
                                command.Msg = msg1;
                                string sendMsg = JsonConvert.SerializeObject(command);
                                Debug.WriteLine("语音发送的命令:" + sendMsg);
                                webView.Visibility = Visibility.Visible;
                                webView.Navigate(uri);
                                TextToSpeech("指令无效即将使用百度搜索");

                                App.SendData(sendMsg, App.socketCmd);
                                voice.IsEnabled = true;
                            }
                        }
                        //语音识别失败
                        if (recogResult.Status != 0)
                        {
                            voice.IsEnabled = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("语音异常:" + ex.Message);
                    //await new MessageDialog("语音异常:" + ex.Message).ShowAsync();
                }
            }
        }