Пример #1
0
 public bool CheckMatch(string name, Assembly assembly, ScopeType scope, BindingType binding, WeakReference weakInstance = null)
 {
     if (Scope != ScopeType.All && Scope != scope)
     {
         return(false);
     }
     if (Binding != BindingType.All && Binding != binding)
     {
         return(false);
     }
     if (NameRegex != null && name != null && !NameRegex.Match(name).Success)
     {
         return(false);
     }
     if (AssemblyRegex != null && assembly != null && !AssemblyRegex.Match(assembly.FullName).Success)
     {
         return(false);
     }
     if (this.weakInstance != null)
     {
         if (weakInstance == null)
         {
             return(false);
         }
         object target = null;
         weakInstance.TryGetTarget(out target);
         object target2 = null;
         this.weakInstance.TryGetTarget(out target2);
         if (target2 != target)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #2
0
        private static LogConfig ReadLogConfig()
        {
            var logConfig = new LogConfig();

            if (!File.Exists(LogConfigPath))
            {
                return(logConfig);
            }
            using (var sr = new StreamReader(LogConfigPath))
            {
                LogConfigItem current = null;
                string        line;
                while (!sr.EndOfStream && (line = sr.ReadLine()) != null)
                {
                    var match = NameRegex.Match(line);
                    if (match.Success)
                    {
                        current = new LogConfigItem(match.Groups["value"].Value);
                        logConfig.Items.Add(current);
                        continue;
                    }
                    if (current == null)
                    {
                        continue;
                    }
                    if (TryParseLine(line, LogLevelRegex, ref current.LogLevel))
                    {
                        continue;
                    }
                    if (TryParseLine(line, FilePrintingRegex, ref current.FilePrinting))
                    {
                        continue;
                    }
                    if (TryParseLine(line, ConsolePrintingRegex, ref current.ConsolePrinting))
                    {
                        continue;
                    }
                    if (TryParseLine(line, ScreenPrintingRegex, ref current.ScreenPrinting))
                    {
                        continue;
                    }
                    var verbose = false;
                    if (TryParseLine(line, VerboseRegex, ref verbose))
                    {
                        current.Verbose = verbose;
                    }
                }
            }
            return(logConfig);
        }
        public string GetFormattedName(string fileName, IEnumerable <FileTag> fileTagList)
        {
            string FileNewName = Format;

            fileTagList.DefaultIfEmpty(DefaultFileTagObject);
            try {
                System.Text.RegularExpressions.GroupCollection NameRegexMatchGroups = NameRegex.Match(fileName).Groups;
                Match FormatGroupsRegexMatch = FormatGroupsRegex.Match(FileNewName), FormatAttributesRegexMatch;
                while (FormatGroupsRegexMatch.Success)
                {
                    FileNewName = FileNewName.Replace(FormatGroupsRegexMatch.ToString(),
                                                      NameRegexMatchGroups[Convert.ToInt32(FormatGroupsRegexMatch.Groups[1].Value)].ToString());
                    FormatGroupsRegexMatch = FormatGroupsRegexMatch.NextMatch();
                }
                FormatAttributesRegexMatch = FormatAttributesRegex.Match(FileNewName);
                FileTag FileTagObject;
                while (FormatAttributesRegexMatch.Success)
                {
                    FileTagObject = fileTagList.FirstOrDefault(fO => fO.TagName == FormatAttributesRegexMatch.Groups[1].Value);
                    FileNewName   = FileNewName.Replace(FormatAttributesRegexMatch.ToString(), FileTagObject.TagValue);
                    FormatAttributesRegexMatch = FormatAttributesRegexMatch.NextMatch();
                }
            } catch (Exception ex) {
                Log.Write("Task::GetFormattedName() Error -> " + ex.Message);
                FileNewName = fileName;
            }
            return(FileNewName);
        }
Пример #4
0
        public static bool CopySeriesIntoShare(DirectoryInfo sourceDir, SearchOption searchOption, string targetDir, bool copy, string remoteDir, string namesDir, out List <EpisodeData> episodeList, out RecentFiles recentFiles)
        {
            var dateShows = Serializer <DateShows> .Deserialize(Path.Combine(namesDir, "DateShows.xml"));

            var dateShowShortNames = dateShows.ShortNameList ?? Enumerable.Empty <string>();

            ulong           bytes;
            bool            abort;
            List <FileInfo> fis;

            do
            {
                var mismatches = new Dictionary <string, bool>();

                fis = new List <FileInfo>(sourceDir.GetFiles("*.*", searchOption));

                for (var fileIndex = fis.Count - 1; fileIndex >= 0; fileIndex--)
                {
                    string name = fis[fileIndex].Name.ToLower();

                    if ((name == "thumbs.db") || (name.EndsWith(".lnk")) || (name.EndsWith(".title")))
                    {
                        fis.RemoveAt(fileIndex);

                        continue;
                    }
                }

                fis.Sort((left, right) => left.Name.CompareTo(right.Name));

                bytes = 0;

                abort = false;

                foreach (var fi in fis)
                {
                    bytes += (ulong)(fi.Length);

                    var match = NameRegex.Match(fi.Name);

                    if (match.Success)
                    {
                        var seriesName = match.Groups["SeriesName"].Value;

                        var seasonNumber = match.Groups["SeasonNumber"].Value;

                        if ((GetName(seriesName, namesDir, mismatches, out var name)) && (GetResolution(fi, out var resolution)))
                        {
                            CheckSeries(targetDir, name, seasonNumber, resolution, mismatches, fi.Name, ref abort);

                            CheckTitle(fi, match.Groups["EpisodeName"].Value, dateShowShortNames.Contains(name.ShortName), mismatches, ref abort);
                        }
                        else
                        {
                            abort = true;
                        }
                    }
                    else
                    {
                        var output = $"NameRegex fail: {fi.Name}";

                        if (mismatches.ContainsKey(output) == false)
                        {
                            mismatches.Add(output, true);

                            Console.WriteLine(output);
                        }

                        abort = true;
                    }
                }