Пример #1
0
 private void Image_Add_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         System.Windows.Forms.FolderBrowserDialog fbr = new System.Windows.Forms.FolderBrowserDialog();
         if (fbr.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             string   path = fbr.SelectedPath;
             FileInfo fi   = new FileInfo(path);
             if (!this.dictImage.ContainsKey(fi.Name))
             {
                 this.dictImage.Add(fi.Name, path);
                 ObservableCollection <ListBoxMediaItem> test = this.listbox2.ItemsSource as ObservableCollection <ListBoxMediaItem>;
                 test.Add(new ListBoxMediaItem {
                     Name = fi.Name, ImagePath = "/styles/skin/item/item_image.png"
                 });
                 //MediaConfig.AddMediaLibrary(path);
                 MediaConfig.AddMyImageLibrary(path);
                 //JAVAUtil.AddSourceToHTTP(path);
                 //new Thread(new ThreadStart(delegate ()
                 //{
                 new function.media.MediaFunction().GetThumbnail(path);
                 util.JAVAUtil.AddAlltoHttp(path);
                 //})).Start();
             }
         }
     }catch (Exception error)
     {
         log.Info(string.Format("图片添加失败:{0}:", error.Message));
     }
 }
Пример #2
0
        public static void StartService()
        {
            string sharedFilePathFile = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\AreaParty\sharedFilePathInfor.audio";

            transferinformation.Action.readSharedFileAndParse(ref sharedFilePathFile, ref sharedFileList);


            System.Threading.Thread thread = new System.Threading.Thread(MonitoringSys);
            thread.IsBackground = true;
            thread.Start();

            System.Threading.Thread thread1 = new System.Threading.Thread(MonitoringProcesses);
            thread1.IsBackground = true;
            thread1.Start();

            System.Threading.Thread thread2 = new System.Threading.Thread(TransferMonitorData);
            thread2.IsBackground = true;
            thread2.Start();

            //bool run = false;
            //while (!run)
            //{
            //    System.Threading.Thread thread2 = new System.Threading.Thread(TransferMonitorData);
            //    thread2.IsBackground = true;
            //    try
            //    {
            //        thread2.Start();
            //        run = true;
            //    }
            //    catch (SocketException e)
            //    {
            //        thread2.Abort();
            //        AreaParty.function.pcapp.PCApp.Close("127.0.0.1", 7777);
            //        //thread2.Start();
            //    }
            //}



            IPEndPoint  localIP  = new IPEndPoint(IPAddress.Any, ConfigResource.PCINFO_PORT);
            TcpListener listener = new TcpListener(localIP);

            //try
            //{
            listener.Start();
            //}
            //catch (SocketException)
            //{
            //    //listener.
            //    //localIP = new IPEndPoint(IPAddress.Any, ConfigResource.PCINFO_PORT);
            //    //listener = new TcpListener(localIP);
            //    //listener.
            //}



            Console.WriteLine("Action Server is listening...");
            while (isRun)
            {
                TcpClient remoteClient = listener.AcceptTcpClient();
                Console.WriteLine("Action Server is connected...");

                int    RecvBytes  = 0;
                byte[] RecvBuf    = new byte[1024];
                string messageGet = null;
                try
                {
                    RecvBytes = remoteClient.Client.Receive(RecvBuf);
                    if (RecvBytes <= 0)
                    {
                        Console.WriteLine("Action socket 被动关闭");
                        continue;
                    }
                    messageGet = Encoding.UTF8.GetString(RecvBuf, 0, RecvBytes);
                    Console.WriteLine("Action Message: {0}", messageGet);

                    RequestMessageFormat request       = JsonHelper.DeserializeJsonToObject <RequestMessageFormat>(messageGet);
                    ReturnMessageFormat  returnMessage = new ReturnMessageFormat();
                    switch (request.name)
                    {
                    case Order.get_areaparty_path:
                        returnMessage.data    = null;
                        returnMessage.message = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\AreaParty\\";
                        returnMessage.status  = 200;
                        break;

                    case Order.ownProgressAction_name:
                        if (request.command == Order.ownProgressAction_Close)
                        {
                            StopService();
                        }
                        //transferinformation.Action.CloseProcess(System.Diagnostics.Process.GetCurrentProcess().Id);
                        break;

                    case Order.processAction_name:
                        if (request.command == Order.processAction_command)
                        {
                            returnMessage = transferinformation.Action.CloseProcess(int.Parse(request.param));
                        }
                        break;

                    case Order.computerAction_name:
                        if (request.command == Order.computerAction_command_reboot)
                        {
                            transferinformation.Action.RebootComputer();
                        }
                        else if (request.command == Order.computerAction_command_shutdown)
                        {
                            transferinformation.Action.shutdownComputer();
                        }
                        break;

                    case Order.fileAction_name:
                        switch (request.command)
                        {
                        case Order.fileAction_share_command:
                            SharedFilePathFormat sharedFile = JsonHelper.DeserializeJsonToObject <SharedFilePathFormat>(request.param);
                            returnMessage = transferinformation.Action.AddSharedFile(ref sharedFile, ref sharedFileList, ref sharedFilePathFile);
                            break;

                        case Order.fileAction_open_command:
                        {
                            // 此处是打开文件代码
                        }
                        break;

                        case Order.fileOrFolderAction_delete_command:
                        {
                            // 此处是删除文件的代码
                            returnMessage = transferinformation.Action.DeleteFile(request.param);
                        }
                        break;

                        case Order.fileOrFolderAction_rename_command:
                        {
                            // 此处是重命名文件的代码
                            string[] temp = System.Text.RegularExpressions.Regex.Split(request.param, "-PATH-",
                                                                                       System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            returnMessage = transferinformation.Action.RenameFile(temp[1], temp[2]);
                        }
                        break;

                        case Order.fileOrFolderAction_copy_command:
                        {
                            string[] temp = System.Text.RegularExpressions.Regex.Split(request.param, "-PATH-",
                                                                                       System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            returnMessage = transferinformation.Action.CopyFile(temp[2], temp[1]);
                        }
                        break;

                        case Order.fileOrFolderAction_cut_command:
                        {
                            string[] temp = System.Text.RegularExpressions.Regex.Split(request.param, "-PATH-",
                                                                                       System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            returnMessage = transferinformation.Action.CutFile(temp[2] + @"\", temp[1]);
                        }
                        break;
                        }
                        break;

                    case Order.folderAction_name:
                        switch (request.command)
                        {
                        case Order.nasAction_add:
                            returnMessage = NasFunction.addNasFolder(request.param);
                            break;

                        case Order.nasAction_delete:
                            returnMessage = NasFunction.deleteNasFolder(request.param);
                            break;

                        case Order.folderAction_addtohttp_command:
                            ReturnMessageFormat message = new ReturnMessageFormat();
                            string method = request.param.Substring(0, 5);   //request.param = "VIDIO/AUDIO/IMAGE" + uri
                            string path   = request.param.Remove(0, 5);      //request.param = uri
                            //FileInfo Info = new FileInfo(path);
                            try
                            {
                                switch (method)
                                {
                                case AreaParty.pages.ListName.VIDIO:
                                    MediaConfig.AddMyVideoLibrary(path);
                                    //MediaPage.videoList.Add(new MediaPage.ListBoxMediaItem { Name = Info.Name, ImagePath = "/styles/skin/item/item_video.png" });
                                    //MediaPage.dictVideo.Add(Info.Name, path);
                                    //MediaPage..Add(new ListBoxMediaItem { Name = Info.Name, ImagePath = "/styles/skin/item/item_video.png" });
                                    break;

                                case AreaParty.pages.ListName.AUDIO:
                                    MediaConfig.AddMyAudioLibrary(path);
                                    break;

                                case AreaParty.pages.ListName.IMAGE:
                                    MediaConfig.AddMyImageLibrary(path);
                                    break;
                                }
                                new AreaParty.function.media.MediaFunction().GetThumbnail(path);
                                AreaParty.util.JAVAUtil.AddAlltoHttp(path);
                                message.status  = Order.success;
                                message.message = "";
                                message.data    = null;
                            }
                            catch (Exception e)
                            {
                                message.status  = Order.failure;
                                message.message = e.Message;
                                message.data    = null;
                            }
                            returnMessage = message;
                            break;

                        case Order.folderAction_open_command:
                        {
                            // 此处是打开文件夹代码
                            if (request.param != Order.folderAction_open_more_param)
                            {
                                NodeFormat root = new NodeFormat();
                                root.path     = request.param;
                                folderContent = transferinformation.Action.OpenFolder(root);
                            }
                            returnMessage = folderContent[0];
                            folderContent.RemoveAt(0);
                        }
                        break;

                        case Order.fileOrFolderAction_delete_command:
                        {
                            // 此处是删除文件夹的代码
                            returnMessage = transferinformation.Action.DeleteFolder(request.param);
                        }
                        break;

                        case Order.fileOrFolderAction_rename_command:
                        {
                            // 此处是重命名文件夹的代码
                            string[] temp = System.Text.RegularExpressions.Regex.Split(request.param, "-PATH-",
                                                                                       System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            returnMessage = transferinformation.Action.RenameFolder(temp[1], temp[2]);
                        }
                        break;

                        case Order.folderAction_add_command:
                        {
                            returnMessage = transferinformation.Action.CreateFolder(request.param);
                        }
                        break;

                        case Order.fileOrFolderAction_copy_command:
                        {
                            string[] temp = System.Text.RegularExpressions.Regex.Split(request.param, "-PATH-",
                                                                                       System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            returnMessage = transferinformation.Action.CopyFolder(temp[1], temp[2]);
                        }
                        break;

                        case Order.fileOrFolderAction_cut_command:
                        {
                            string[] temp = System.Text.RegularExpressions.Regex.Split(request.param, "-PATH-",
                                                                                       System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                            returnMessage = transferinformation.Action.CutFolder(temp[2], temp[1]);
                        }
                        break;
                        }
                        break;

                    case Order.diskAction_name:
                        switch (request.command)
                        {
                        case Order.diskAction_get_command:
                            returnMessage = transferinformation.Action.GetDiskList();
                            break;
                        }
                        break;

                    case Order.appAction_name:
                        switch (request.command)
                        {
                        case Order.appAction_get_command:
                            if (request.param != Order.appAction_get_more_param)
                            {
                                exeContent = transferinformation.Action.GetApplicationList();
                            }
                            returnMessage = exeContent[0];
                            exeContent.RemoveAt(0);
                            break;
                        }
                        break;
                    }

                    byte[] messageToSend = Encoding.UTF8.GetBytes(JsonHelper.SerializeObject(returnMessage));
                    int    i             = remoteClient.Client.Send(messageToSend);
                    Console.WriteLine("send Message: {0} ", JsonHelper.SerializeObject(returnMessage));
                }
                catch (Exception e)
                {
                    Console.WriteLine("Action socket 被动关闭" + e.Message);
                }
                remoteClient.Close();
            }

            Console.ReadLine();
        }