コード例 #1
0
 private void ParseDirectoryRecursive(object path)
 {
     try
     {
         do
         {
             FileInfoDataList ss = ShowSharefile.ReceiveShare();
             if (ss.Name == "")
             {
                 break;
             }
             int    asdf = ss.Name.LastIndexOf(@"\");
             string a    = ss.Name.Substring(0, asdf + 1);
             if (Directory != a)
             {
                 continue;
             }
             ss.Name = ss.Name.Substring(asdf + 1, ss.Name.Length - asdf - 1);
             Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate
             {
                 FileInfoDataList si = ShowSharefile.GetInfo(ss);
                 if (si != null)
                 {
                     FileItemInfo.Add(si);
                 }
                 Thread.Sleep(5);
             });
         } while (true);
     }
     catch (Exception)
     {
         ;
     }
 }
コード例 #2
0
        private void ParseDirectoryThread(object p)//使用后台线程获取文件信息
        {
            /////////////_client.RequestOpenShareFolder(string.Empty, 0);

            string _directory = "";

            if (p != null && p is string)
            {
                _directory = (string)p;
            }
            if (_directory == "")
            {
                return;
            }
            ShowSharefile.SendDirectoryName(_directory);
            try
            {
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate
                {
                    FileItemInfo.Clear();
                });
                t = new Thread(new ParameterizedThreadStart(ParseDirectoryRecursive)); //在后台线程中调用ParseDirectoryRecursive方法
                t.IsBackground = true;                                                 //指定为后台线程
                t.Priority     = ThreadPriority.BelowNormal;                           //指定线程优先级别
                t.Start(_directory);                                                   //为线程方法传入文件夹路径
            }
            catch (Exception)                                                          //如果产生异常
            {                                                                          //调用自定义的异常信息窗口
                throw;
                // ExceptionManagement.Manage("Catalog:ParseDirectoryThread", err);
            }
        }
コード例 #3
0
ファイル: SharePage.cs プロジェクト: amos402/ShareWare
        private void Show_Root(ObservableCollection <FileInfoDataList> list, bool first_execution)
        {
            FileInfoDataList sh = new FileInfoDataList();

            foreach (var item in _sh.SharePath.Keys)
            {
                Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate
                {
                    sh.Name     = item;
                    sh.IsFolder = true;
                    sh.Size     = null;
                    sh          = ShowSharefile.GetInfo(sh);
                    if (first_execution)
                    {
                        Root_Name.Add(item);
                    }
                    list.Add(sh);
                });
            }
        }
コード例 #4
0
ファイル: SharePage.cs プロジェクト: amos402/ShareWare
        private void GetDirList(string strBaseDir, ObservableCollection <FileInfoDataList> list)
        {
            try
            {
                DirectoryInfo   di    = new DirectoryInfo(strBaseDir);
                DirectoryInfo[] diA   = di.GetDirectories();
                FileInfo[]      files = di.GetFiles();

                foreach (var item in files)
                {
                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate
                    {
                        FileInfoDataList sh = new FileInfoDataList();
                        sh.Name             = item.Name;
                        sh.IsFolder         = false;
                        sh.Size             = null;
                        sh = ShowSharefile.GetInfo(sh);
                        list.Add(sh);
                    });
                }
                foreach (var item in diA)
                {
                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate
                    {
                        FileInfoDataList sh = new FileInfoDataList();
                        sh.Name             = item.Name;
                        sh.IsFolder         = true;
                        sh.Size             = null;
                        sh = ShowSharefile.GetInfo(sh);
                        list.Add(sh);
                    });
                }
            }
            catch (Exception)
            {
                ;
            }
        }
コード例 #5
0
        private void OnSearch(object obj)
        {
            Islist = false;

            if (_preSearchTime == null)
            {
                _preSearchTime = DateTime.Now;
            }
            else
            {
                var now      = DateTime.Now;
                var spanTime = now - _preSearchTime;
                if (spanTime < _elapsedTime)
                {
                    MessageBox.Show(string.Format("每次搜索间隔不能超过{0}秒", _elapsedTime.Seconds.ToString()));
                    return;
                }
                else
                {
                    _preSearchTime = DateTime.Now;
                }
            }
            IsBusy_Main = true;
            try
            {
                List <string> nameList = FileName.Split(' ').ToList();
                nameList.RemoveAll(new Predicate <string>(T => T == string.Empty));

                Task <List <FileInfoData> > task = _client.SearchFileAsync(nameList, true);
                FileItemInfo.Clear();
                if (_ctsSearch != null)
                {
                    if (!_ctsSearch.Token.CanBeCanceled)
                    {
                        _ctsSearch.Cancel();
                    }
                }
                task.ContinueWith(T =>
                {
                    ThreadPool.QueueUserWorkItem(delegate
                    {
                        IsBusy_Main = false;
                        if (T.Result != null)
                        {
                            _ctsSearch    = new CancellationTokenSource();
                            Task listTask = new Task(() =>
                            {
                                foreach (var item in T.Result)
                                {
                                    try
                                    {
                                        Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                                              (ThreadStart) delegate
                                        {
                                            FileInfoDataList f = new FileInfoDataList(item);
                                            f = ShowSharefile.GetInfo(f);
                                            if (item != null)
                                            {
                                                FileItemInfo.Add(f);
                                            }
                                            Thread.Sleep(30);
                                        });
                                    }
                                    catch (Exception)
                                    {
                                        //throw;
                                    }
                                }
                            }, _ctsSearch.Token);
                            listTask.Start();
                        }
                    });
                });
            }
            catch (Exception e)
            {
                if (ErrorOccur != null)
                {
                    ErrorOccur(this, new ModelEventArgs(ModelEventType.Exception)
                    {
                        ModelException = e
                    });
                }
            }
        }
コード例 #6
0
        public int LoadItems(object p)
        {
            if (t != null)
            {
                if (t.IsAlive)
                {
                    t.Abort();
                }
            }
            string D = "";
            string a = ((string)p);

            //if (a.Length == 36 && Directory.IndexOf("\\") == -1)
            //{
            //}
            //else
            {
                if (a != null && a is string)
                {
                    D         = directory + a + "\\";
                    Directory = Directory + a + "\\";
                    string[] split = Directory.Split(new Char[] { '\\' });
                    if ((split.Length == 2 || split.Length == 1) && ShowSharefile.NewSock != null)
                    {
                        ShowSharefile.NewSock.Close();
                        ShowSharefile.NewSock = null;
                    }
                }
                else
                {
                    if (Directory.IndexOf("\\") == -1 || Directory.LastIndexOf("\\") != Directory.Length - 1)
                    {
                        Directory = Directory + "\\";
                    }
                    if (LoadIDName != "")
                    {
                        string Lname = "";
                        if (Directory.IndexOf("\\") == -1)
                        {
                            Lname = Directory;
                        }
                        else
                        {
                            Lname = Directory.Substring(Directory.IndexOf("\\"));
                        }
                        if (LoadIDName.CompareTo(Lname) != 0)
                        {
                            ShowSharefile.NewSock.Close();
                            ShowSharefile.NewSock = null;
                        }
                    }
                    D = Directory;
                }
            }
            if (ShowSharefile.NewSock == null)
            {
                ShowSharefile.CreatSocket(D);
                _client.RequestOpenShareFolder((string)p, ShowSharefile.Port);
            }
            else
            {
                ParseDirectoryThread(D);
            }
            return(ShowSharefile.Port);
        }