コード例 #1
0
        internal static Dictionary<String, String> TransactionalApply(Boolean UseDistinctFolder, Boolean UseServerFilenames,
            String MaxDownloadThreads, String SavedFilesPath, String UserAgent, String FilenameTemplate)
        {
            Dictionary<String, String> output = new Dictionary<string, string>();
            if (UserAgent.HasAlphaNumericChars() == false)
            {
                output.Add(UserAgent.MemberName(_ => UserAgent), "User-Agent can not be empty");
            }
            if (SavedFilesPath.HasAlphaNumericChars() == false)
            {
                output.Add(SavedFilesPath.MemberName(_ => SavedFilesPath), "File path for saving files can not be empty");
            }
            else if (FilePathTools.IsValidFilePath(SavedFilesPath) == false)
            {
                output.Add(SavedFilesPath.MemberName(_ => SavedFilesPath), "File path is invalid");
            }
            Nullable<Byte> mdt = MaxDownloadThreads.TryParseNumber<Byte>(NumberStyles.None, CultureInfo.InvariantCulture);
            if (mdt == null)
            {
                output.Add(MaxDownloadThreads.MemberName(_ => MaxDownloadThreads), "Value '" + MaxDownloadThreads+"' is invalid");
            }
            Char[] intersects = FilenameTemplate.ToCharArray().Intersect(Path.GetInvalidFileNameChars()).ToArray();
            if (intersects.IsNullOrEmpty()==false)
            {
                output.Add(FilenameTemplate.MemberName(_ => FilenameTemplate)+"1",
                    "Filename template contains next invalid characters: "+intersects.ConcatToString(", ")+".");
            }
            if (FilenameTemplate.Contains(_TITLE_TOKEN, StringComparison.Ordinal) == false &&
                FilenameTemplate.Contains(_NUMBER_TOKEN, StringComparison.Ordinal) == false)
            {
                output.Add(FilenameTemplate.MemberName(_ => FilenameTemplate)+"2",
                    "Filename template must contain "+_TITLE_TOKEN+" or "+_NUMBER_TOKEN+" token");
            }

            if (output.Any() == true)
            {
                return output;
            }
            Byte value = mdt.Value > (Byte)99 ? (Byte)99 : mdt.Value;
            ProgramSettings._instance =
                new ProgramSettings(UseDistinctFolder, UseServerFilenames, value, SavedFilesPath.Trim(), UserAgent.Trim(), FilenameTemplate.Trim());
            return null;
        }
コード例 #2
0
 internal static Boolean SetDefault()
 {
     if (ProgramSettings._default.IsDefault == true) { return false; }
     ProgramSettings._instance = ProgramSettings._default;
     return true;
 }