/// <summary> /// Determines the preselected profile for the printer that was used while creating the job /// </summary> /// <param name="jobInfo">The jobinfo used for the decision</param> /// <param name="settings">The settings used for the decision</param> /// <returns>The profile that is associated with the printer or the default profile</returns> private ConversionProfile PreselectedProfile(JobInfo jobInfo, PdfCreatorSettings settings) { foreach (var mapping in settings.ApplicationSettings.PrinterMappings) { if (mapping.PrinterName.Equals(jobInfo.SourceFiles[0].PrinterName, StringComparison.OrdinalIgnoreCase)) { var p = settings.GetProfileByGuid(mapping.ProfileGuid); if (p != null) { return(p); } break; } } var lastUsedProfile = settings.GetLastUsedProfile(); if (lastUsedProfile != null) { return(lastUsedProfile); } // try default profile var defaultProfile = GetDefaultProfile(settings.ConversionProfiles); if (defaultProfile != null) { return(defaultProfile); } // last resort: first profile from the list return(settings.ConversionProfiles[0]); }
/// <summary> /// Functions checks, if a default profile exists and adds one. /// </summary> private static void CheckAndAddMissingDefaultProfile(PdfCreatorSettings settings) { var defaultProfile = settings.GetProfileByGuid(ProfileGuids.DEFAULT_PROFILE_GUID); if (defaultProfile == null) { defaultProfile = new ConversionProfile(); defaultProfile.Name = "<Default Profile>"; defaultProfile.Guid = ProfileGuids.DEFAULT_PROFILE_GUID; settings.ConversionProfiles.Add(defaultProfile); } SetDefaultProperties(defaultProfile, false); }
/// <summary> /// Functions checks, if a default profile exists and adds one. /// </summary> private void CheckAndAddMissingDefaultProfile(PdfCreatorSettings settings, DefaultProfileBuilder profileBuilder) { var defaultProfile = settings.GetProfileByGuid(ProfileGuids.DEFAULT_PROFILE_GUID); if (defaultProfile == null) { defaultProfile = profileBuilder.CreateDefaultProfile(); settings.ConversionProfiles.Add(defaultProfile); } else { defaultProfile.Properties.Deletable = false; } }
public void GetProfileByGuid_WithNonexistantProfile_ReturnsProfile() { var settings = new PdfCreatorSettings(); var p1 = new ConversionProfile { Guid = "g1", Name = "p1" }; var p2 = new ConversionProfile { Guid = "g2", Name = "p2" }; settings.ConversionProfiles.Add(p1); settings.ConversionProfiles.Add(p2); Assert.IsNull(settings.GetProfileByGuid("g3")); }
public void GetProfileByGuid_WithExistingProfile_ReturnsProfile() { var settings = new PdfCreatorSettings(); var p1 = new ConversionProfile { Guid = "g1", Name = "p1" }; var p2 = new ConversionProfile { Guid = "g2", Name = "p2" }; settings.ConversionProfiles.Add(p1); settings.ConversionProfiles.Add(p2); Assert.AreSame(p2, settings.GetProfileByGuid("g2")); }
/// <summary> /// Determines the preselected profile for the printer that was used while creating the job /// </summary> /// <param name="jobInfo">The jobinfo used for the decision</param> /// <param name="settings">The settings used for the decision</param> /// <returns>The profile that is associated with the printer or the default profile</returns> private ConversionProfile PreselectedProfile(JobInfo jobInfo, PdfCreatorSettings settings) { // Check for a printer via Parameter var profile = settings.GetProfileByMappedPrinter(jobInfo.PrinterParameter); // Check for a profile via Parameter if (profile == null) { profile = settings.GetProfileByNameOrGuid(jobInfo.ProfileParameter); } // Check for a printer via Driver if (profile == null) { profile = settings.GetProfileByMappedPrinter(jobInfo.PrinterName); } // try profile from primary printer if (profile == null) { profile = settings.GetProfileByMappedPrinter(settings.CreatorAppSettings.PrimaryPrinter); } // try default profile if (profile == null) { profile = settings.GetProfileByGuid(ProfileGuids.DEFAULT_PROFILE_GUID); } // last resort: first profile from the list if (profile == null) { profile = settings.ConversionProfiles[0]; } return(profile); }
/// <summary> /// Determines the preselected profile for the printer that was used while creating the job /// </summary> /// <param name="jobInfo">The jobinfo used for the decision</param> /// <param name="settings">The settings used for the decision</param> /// <returns>The profile that is associated with the printer or the default profile</returns> private ConversionProfile PreselectedProfile(JobInfo jobInfo, PdfCreatorSettings settings) { ConversionProfile profile = null; foreach (var mapping in settings.ApplicationSettings.PrinterMappings) { if (mapping.PrinterName.Equals(jobInfo.SourceFiles[0].PrinterName, StringComparison.OrdinalIgnoreCase)) { profile = settings.GetProfileByGuid(mapping.ProfileGuid); if (mapping.ProfileGuid == ProfileGuids.LAST_USED_PROFILE_GUID) { profile = settings.GetLastUsedProfile(); } if (profile != null) { break; } } } //consider LastUsedProfile //todo: Do not relate to empty string and use own GUID to request LastUsedProfile (see above) if (jobInfo.SourceFiles.Count > 0 && string.IsNullOrEmpty(jobInfo.SourceFiles[0].PrinterName)) { var lastUsedProfile = settings.GetLastUsedProfile(); if (lastUsedProfile != null) { profile = lastUsedProfile; } } //Consider commandline paramaters if (_parametersManager.HasPredefinedParameters()) { var parameters = _parametersManager.GetAndResetParameters(); var profileParameter = parameters.Profile; if (!string.IsNullOrEmpty(profileParameter)) { profile = settings.GetProfileByName(profileParameter); if (profile == null) { profile = settings.GetProfileByGuid(profileParameter); } } var outputFile = parameters.Outputfile; if (outputFile != null) { jobInfo.OutputFileParameter = outputFile; } } if (profile != null) { return(profile); } // try default profile var defaultProfile = GetDefaultProfile(settings.ConversionProfiles); if (defaultProfile != null) { return(defaultProfile); } // last resort: first profile from the list return(settings.ConversionProfiles[0]); }
public static ConversionProfile GetDefaultProfile() { return(_settings.GetProfileByGuid(ProfileGuids.DEFAULT_PROFILE_GUID)); }