Beispiel #1
0
 public void Watch(string path)
 {
     Dispatcher.BackgroundThread(() =>
     {
         while (true)
         {
             Thread.Sleep(500);
             var cmdOut = AdbClient.Instance.ExecuteRemoteCommandSync(slave.Device, $"test -e {path} && echo '1';");
             if (cmdOut.Contains("1"))
             {
                 // 存在
                 var content = AdbClient.Instance.ExecuteRemoteCommandSync(slave.Device, $"su -c 'cat {path}'");
                 AdbClient.Instance.ExecuteRemoteCommandSync(slave.Device, $"su -c 'rm -f {path}'");
                 if (!string.IsNullOrEmpty(content))
                 {
                     FileDetected?.Invoke(slave, content);
                 }
             }
             else
             {
                 continue;
             }
         }
     });
 }
        internal void OnFileDetected(SVR_ImportFolder folder, FileInfo file)
        {
            var path = file.FullName.Replace(folder.ImportFolderLocation, "");

            if (!path.StartsWith("/"))
            {
                path = "/" + path;
            }
            FileDetected?.Invoke(null, new FileDetectedEventArgs
            {
                FileInfo     = file,
                ImportFolder = folder,
                RelativePath = path,
            });
        }
Beispiel #3
0
        private void ObjectDetected(object source, FileSystemEventArgs e)
        {
            if (File.Exists(e.FullPath))
            {
                FileDetected?.Invoke(e.FullPath);

                //string destinationDir = _defaultDestinationDir;
                string destinationDir = _config.DefaultDestinationDir.Dir;
                bool   isAddNumber    = true;
                bool   isAddMoveDate  = false;

                //foreach (var rule in _rules)
                //    if (Regex.IsMatch(e.Name, rule.Key))
                //        destinationDir = rule.Value;
                foreach (RuleElement rule in _config.Rules)
                {
                    if (Regex.IsMatch(e.Name, rule.Rule))
                    {
                        destinationDir = rule.TargetFolder;
                        isAddNumber    = rule.IsAddNumber;
                        isAddMoveDate  = rule.IsAddMoveDate;
                    }
                }

                if (destinationDir.Equals(_config.DefaultDestinationDir.Dir))
                {
                    RuleFound?.Invoke(false, e.Name);
                }
                else
                {
                    RuleFound?.Invoke(true, e.Name);
                }

                string targetFileName = e.Name;

                if (isAddMoveDate)
                {
                    string fileExtension    = "";
                    int    fileExtensionIdx = -1;
                    Match  match            = Regex.Match(e.Name, @"\.[а-я|А-Я|a-z|A-z|0-9]*$");
                    if (match.Success)
                    {
                        fileExtension    = match.Value;
                        fileExtensionIdx = match.Index;
                    }

                    targetFileName = string.Format("{0} {1}{2}", e.Name.Substring(0, fileExtensionIdx), DateTime.Today.ToString("yyyyMMdd"), fileExtension);
                }

                string destinationFile = destinationDir + "\\" + targetFileName;

                if (!File.Exists(destinationFile))
                {
                    File.Move(e.FullPath, destinationFile);
                    FileMoved?.Invoke(true, e.FullPath, destinationFile);
                }
                else if (isAddNumber)
                {
                    string fileExtension    = "";
                    int    fileExtensionIdx = -1;
                    Match  match            = Regex.Match(destinationFile, @"\.[а-я|А-Я|a-z|A-z|0-9]*$");
                    if (match.Success)
                    {
                        fileExtension    = match.Value;
                        fileExtensionIdx = match.Index;
                    }

                    int    fileIdx    = 0;
                    int    fileIdxIdx = fileExtensionIdx;
                    string pattern    = @"\(\d*\)$";
                    if (fileExtensionIdx > 0)
                    {
                        match = Regex.Match(destinationFile.Substring(0, fileExtensionIdx), pattern);
                    }
                    else
                    {
                        match = Regex.Match(destinationFile, pattern);
                    }

                    if (match.Success)
                    {
                        fileIdx    = Convert.ToInt32(Regex.Replace(match.Value, @"[^\d]+", "")) + 1;
                        fileIdxIdx = match.Index;
                    }

                    while (true)
                    {
                        destinationFile = string.Format("{0} ({1}){2}", destinationFile.Substring(0, fileIdxIdx), fileIdx, fileExtension);
                        if (!File.Exists(destinationFile))
                        {
                            File.Move(e.FullPath, destinationFile);
                            FileMoved?.Invoke(true, e.FullPath, destinationFile);
                            break;
                        }
                        fileIdx++;
                    }
                }
                else
                {
                    FileMoved?.Invoke(false, e.FullPath, "");
                }
            }
        }