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);
 }
        public CatalogueElementName(CatalogueName catalogueName, System.Enum element, string name)
        {
            const string method = ".ctor";

            // Check catalogue name.

            if (catalogueName == null)
            {
                throw new NullParameterException(typeof(CatalogueElementName), method, "catalogueName");
            }

            // Check element.

            if (!NameRegex.IsMatch(element.ToString()))
            {
                throw new InvalidParameterFormatException(typeof(CatalogueElementName), method, "element", element.ToString(), Constants.Validation.CompleteNamePattern);
            }

            // Check name.

            if (name == null)
            {
                throw new NullParameterException(typeof(CatalogueElementName), method, "name");
            }
            if (!NameRegex.IsMatch(name))
            {
                throw new InvalidParameterFormatException(typeof(CatalogueElementName), method, "name", name, Constants.Validation.CompleteNamePattern);
            }

            // Assign.

            m_catalogueName = catalogueName.Clone();
            m_element       = element.ToString();
            m_name          = name;
        }
Exemple #3
0
 /// <summary>
 /// Validates that the specified name meets minimum requirements.
 /// </summary>
 /// <param name="name">The desired name/alias.</param>
 /// <param name="result">Any error messages about the desired name.</param>
 /// <returns></returns>
 public virtual bool ValidateName(string name, ExecutionResults result)
 {
     if (!NameRegex.IsMatch(name) && !EmailRegex.IsMatch(name))
     {
         //if this message is changed, do the same anywhere else it is used
         result.AppendError(
             "The name contains invalid characters.  The name must be an email address OR contain only letters, numbers, dashes, underscores, and spaces, are allowed.");
         return(false);
     }
     return(true);
 }
        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);
        }
Exemple #5
0
 /// <summary>
 /// Verifies that a string is a valid hive name.
 /// </summary>
 /// <param name="name">The name being tested.</param>
 /// <returns><c>true</c> if the name is valid.</returns>
 public static bool IsValidName(string name)
 {
     return(name != null && NameRegex.IsMatch(name));
 }
Exemple #6
0
        /// <summary>
        /// 指定したResSetを
        /// 設定されているスキンを使用して文字列形式に変換
        /// </summary>
        /// <param name="resSet"></param>
        /// <returns></returns>
        public override string Convert(ResSet resSet)
        {
            if (!resSet.Visible)
            {
                return(String.Empty);
            }

            if (resSet.DateString == "透明あぼーん")
            {
                return(String.Empty);
            }

            /*
             * if (resSet.IsABone) {
             *      resSet = ResSet.ABone(resSet, ABoneType.NG, "");
             *      resSet.Email = String.Empty;
             * }*/

            // 使用するスキン
            string skinhtml = resSet.IsNew ? newResSkin : resSkin;
            string dateonly, body;

            // 本分からtagを取り除く
            body = resSet.Body;
            body = Regex.Replace(body, "<a[^>]+>(?<uri>[^<]*)</a>", "${uri}", RegexOptions.IgnoreCase);
            body = Regex.Replace(body, "<(?!br|hr)[^>]+>", "");

            buffer.Append(body);
            buffer.Replace("<br>", "\r\n");
            buffer.Replace("<hr>", "\r\n ————————————————————\r\n");
            buffer.Replace("&gt;", ">");
            buffer.Replace("&lt;", "<");
            body = buffer.ToString();
            buffer.Remove(0, buffer.Length);

            #region 日付とIDを作成
            dateonly = resSet.DateString;
            Match m = Regex.Match(resSet.DateString, "( ID:)|(\\[)");

            if (m.Success)
            {
                dateonly = resSet.DateString.Substring(0, m.Index);
            }
            #endregion

#if REGEX_REPLACE
            skinhtml = PlainNumberRegex.Replace(skinhtml, resSet.Index.ToString());
            skinhtml = IDRegex.Replace(skinhtml, resSet.ID);
            skinhtml = NameRegex.Replace(skinhtml, resSet.Name);
            skinhtml = EmailRegex.Replace(skinhtml, resSet.Email);
            skinhtml = DateRegex.Replace(skinhtml, resSet.DateString);
            skinhtml = DateOnlyRegex.Replace(skinhtml, dateonly);
            skinhtml = BodyRegex.Replace(skinhtml, body);
#else
            buffer.Append(skinhtml);
            buffer.Replace("<PLAINNUMBER/>", resSet.Index.ToString());
            buffer.Replace("<ID/>", resSet.ID);
            buffer.Replace("<NAME/>", HtmlTextUtility.RemoveTag(resSet.Name));
            buffer.Replace("<MAIL/>", resSet.Email);
            buffer.Replace("<DATE/>", resSet.DateString);
            buffer.Replace("<DATEONLY/>", dateonly);
            buffer.Replace("<MESSAGE/>", body);
            skinhtml = buffer.ToString();
            buffer.Remove(0, buffer.Length);
#endif

            return(skinhtml);
        }
 public override bool Matches(UserMarkerLocation uml)
 {
     return(PathRegex.IsMatch(uml.m_path) && NameRegex.IsMatch(uml.m_name));
 }
        public void PerformTask(TaskDetail taskDetail, UIOption Verbose = UIOption.OnlyErrorDialogs)
        {
            try {
                int    TotalCount = 0, CurrentCount = 0;
                string FileName, FileExtension, FileNewName;
                taskDetail(-1, 0, "", "", ""); // Loading...
                List <FileInfo> FileInfoList = new List <FileInfo>(Source.GetFiles());
                FileInfoList = FileInfoList.FindAll(delegate(FileInfo fileInfoObject) {
                    return(ExtensionRegex.IsMatch(fileInfoObject.Extension.ToLower()) &&
                           NameRegex.IsMatch(Path.GetFileNameWithoutExtension(fileInfoObject.Name)));
                });
                TotalCount = FileInfoList.Count;
                List <Tuple <FileInfo, IEnumerable <FileTag> > > FileList = new List <Tuple <FileInfo, IEnumerable <FileTag> > >();
                if (AttributeMatchList != null)
                {
                    IEnumerable <FileTag> FileTagInfoList, FileTagInfoListIntersected;
                    foreach (FileInfo FileInfoObject in FileInfoList)
                    {
                        FileTagInfoList            = GenerateFileInfo.GetFileTag(FileInfoObject.FullName);
                        FileTagInfoListIntersected = FileTagInfoList;
                        FileTagInfoListIntersected = FileTagInfoListIntersected.Intersect(AttributeMatchList);
                        if (FileTagInfoListIntersected.Count() > 0)
                        {
                            FileList.Add(new Tuple <FileInfo, IEnumerable <FileTag> >(FileInfoObject, FileTagInfoList));
                        }
                    }
                }
                else
                {
                    foreach (FileInfo FileInfoObject in FileInfoList)
                    {
                        FileList.Add(new Tuple <FileInfo, IEnumerable <FileTag> >(FileInfoObject, GenerateFileInfo.GetFileTag(FileInfoObject.FullName)));
                    }
                }
                TotalCount   = FileList.Count;
                CurrentCount = 0;
                taskDetail(TotalCount, 0, "", "", ""); // Loading Done...
                foreach (Tuple <FileInfo, IEnumerable <FileTag> > FileListObject in FileList)
                {
                    FileName      = Path.GetFileNameWithoutExtension(FileListObject.Item1.Name);
                    FileExtension = Path.GetExtension(FileListObject.Item1.Name);
                    FileNewName   = GetFormattedName(FileName, FileListObject.Item2);
                    taskDetail(TotalCount, CurrentCount, FileName, FileExtension, FileNewName);
                    switch (PerformType)
                    {
                    case PerformTaskType.Copy:
                        FileSystem.CopyFile(FileListObject.Item1.FullName, Destination + "/" + FileNewName + FileExtension, Verbose);
                        break;

                    case PerformTaskType.Move:
                        FileSystem.MoveFile(FileListObject.Item1.FullName, Destination + "/" + FileNewName + FileExtension, Verbose);
                        break;

                    case PerformTaskType.Rename:
                        FileSystem.RenameFile(FileListObject.Item1.FullName, FileNewName + FileExtension);
                        break;

                    case PerformTaskType.Delete:
                        FileSystem.DeleteFile(FileListObject.Item1.FullName, Verbose, RecycleOption.SendToRecycleBin);
                        break;

                    default:
                        Log.Write("PerformTask() Warning -> Invalid PerformType Given In " + Name);
                        break;
                    }
                    taskDetail(TotalCount, ++CurrentCount, FileName, FileExtension, FileNewName);
                }
            } catch (Exception ex) {
                Log.Write("Task::PerformTask() Error -> Task - " + Name + " [" + ex.Message + "]");
            }
        }
        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);
        }
Exemple #10
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;
                    }
                }