示例#1
0
        private void ReadInf(string infFile, TitleReplacer titleReplacer)
        {
            InfFile = infFile;
            var infData = Data.CreateDataStorage();
            var ini     = new IniStorage(Encoding.GetEncoding("Unicode"));

            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;
            }
        }
示例#2
0
        /// <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 = Int32.Parse(data.GetValue(section + "SessionId"));
            }
            catch
            {
                sfi.SessionId = 0;
            }

            try
            {
                sfi.JobCounter = Int32.Parse(data.GetValue(section + "JobCounter"));
            }
            catch
            {
                sfi.JobCounter = 0;
            }

            try
            {
                sfi.JobId = Int32.Parse(data.GetValue(section + "JobId"));
            }
            catch
            {
                sfi.JobId = 0;
            }

            try
            {
                sfi.TotalPages = Int32.Parse(data.GetValue(section + "TotalPages"));
            }
            catch
            {
                sfi.TotalPages = 0;
            }

            try
            {
                sfi.Copies = Int32.Parse(data.GetValue(section + "Copies"));
            }
            catch
            {
                sfi.Copies = 0;
            }

            if (String.IsNullOrEmpty(sfi.Filename))
            {
                return(null);
            }

            return(sfi);
        }