private void ReadInf(string infFile, TitleReplacer titleReplacer) { InfFile = infFile; var infData = Data.CreateDataStorage(); var ini = new IniStorage(Helper.EncodingHelper.GetEncoding(infFile)); ini.SetData(infData); ini.ReadData(infFile); foreach (var section in infData.GetSections()) { var sfi = SourceFileInfo.ReadSourceFileInfo(infFile, infData, section); if (sfi != null) { SourceFiles.Add(sfi); } } Metadata = new Metadata(); if (SourceFiles.Count > 0) { Metadata.PrintJobAuthor = SourceFiles[0].Author; Metadata.PrintJobName = titleReplacer.Replace(SourceFiles[0].DocumentTitle); Metadata.Title = ""; //Set to avoid null exception when replacing tokens Metadata.Author = ""; JobType = SourceFiles[0].Type; } }
private void AddSourceFileTokens(SourceFileInfo sourceFileInfo) { _tokenReplacer.AddStringToken("ClientComputer", sourceFileInfo.ClientComputer); _tokenReplacer.AddNumberToken("Counter", sourceFileInfo.JobCounter); _tokenReplacer.AddNumberToken("JobId", sourceFileInfo.JobId); _tokenReplacer.AddStringToken("PrinterName", sourceFileInfo.PrinterName); _tokenReplacer.AddNumberToken("SessionId", sourceFileInfo.SessionId); }
private void AddTokensForDocumentTitle(SourceFileInfo sfi, Metadata metadata) { var titleFilename = ""; var titleFolder = ""; if (FileUtil.Instance.IsValidRootedPath(sfi.DocumentTitle)) { titleFilename = _pathWrapSafe.GetFileNameWithoutExtension(sfi.DocumentTitle); titleFolder = _pathWrapSafe.GetDirectoryName(sfi.DocumentTitle); } else { titleFilename = metadata.PrintJobName; } _tokenReplacer.AddStringToken("InputFilename", titleFilename); _tokenReplacer.AddStringToken("InputFilePath", titleFolder); }
/// <summary> /// Read a single SourceFileInfo record from the given data section /// </summary> /// <param name="infFilename">full path to the inf file to read</param> /// <param name="data">Data set to use</param> /// <param name="section">Name of the section to process</param> /// <returns>A filled SourceFileInfo or null, if the data is invalid (i.e. no filename)</returns> internal static SourceFileInfo ReadSourceFileInfo(string infFilename, Data data, string section) { if (infFilename == null) { throw new ArgumentNullException("infFilename"); } var sfi = new SourceFileInfo(); sfi.DocumentTitle = data.GetValue(section + "DocumentTitle"); sfi.WinStation = data.GetValue(section + "WinStation"); sfi.Author = data.GetValue(section + "Username"); sfi.ClientComputer = data.GetValue(section + "ClientComputer"); sfi.Filename = data.GetValue(section + "SpoolFileName"); var type = data.GetValue(section + "SourceFileType"); sfi.Type = type.Equals("xps", StringComparison.OrdinalIgnoreCase) ? JobType.XpsJob : JobType.PsJob; if (!Path.IsPathRooted(sfi.Filename)) { sfi.Filename = Path.Combine(Path.GetDirectoryName(infFilename) ?? "", sfi.Filename); } sfi.PrinterName = data.GetValue(section + "PrinterName"); try { sfi.SessionId = int.Parse(data.GetValue(section + "SessionId")); } catch { sfi.SessionId = 0; } try { sfi.JobCounter = int.Parse(data.GetValue(section + "JobCounter")); } catch { sfi.JobCounter = 0; } try { sfi.JobId = int.Parse(data.GetValue(section + "JobId")); } catch { sfi.JobId = 0; } try { sfi.TotalPages = int.Parse(data.GetValue(section + "TotalPages")); } catch { sfi.TotalPages = 0; } try { sfi.Copies = int.Parse(data.GetValue(section + "Copies")); } catch { sfi.Copies = 0; } if (string.IsNullOrEmpty(sfi.Filename)) { return(null); } return(sfi); }