コード例 #1
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
        /// <summary>
        /// Writes text to a logg file
        /// <para>The logfile is called YYYMMDD_OARlog.txt, so a new one is created for every day.</para>
        /// </summary>
        /// <param name="textToLog">The text that should be logged.</param>
        /// <param name="dirPaths">The paths the program uses.</param>
        /// <returns>True upon completion of logging.</returns>
        internal bool Text(string textToLog, DirPaths dirPaths)
        {
            string logFile;

            logFile = Path.Combine(dirPaths.Log, DateTime.Now.ToString("yyyyMMdd"));
            logFile = string.Concat(logFile, @"_OARlog.txt");

            //Checks if there exists a file for todays date, otherwise it creats it.
            if (File.Exists(logFile))
            {
                Console.WriteLine(textToLog);

                using (StreamWriter writeString = File.AppendText(logFile))
                {
                    writeString.WriteLine(textToLog);
                }
            }

            else
            {
                Console.WriteLine(textToLog);

                using (StreamWriter writeString = File.CreateText(logFile))
                {
                    writeString.WriteLine(textToLog);
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
        /// <summary>
        /// Gets the values for fanOutX and rollPosition.
        /// </summary>
        /// <param name="Tower">Which tower the plate is in.</param>
        /// <param name="ElementInTower">"fanOutX" or "rollPosition"</param>
        /// <param name="dirPaths">Where the folders of the programs are located.</param>
        /// <returns>Value of the specified element.</returns>
        internal string GetValue(string Tower, string ElementInTower, DirPaths dirPaths)
        {
            XDocument doc = XDocument.Load(dirPaths.pressConfig);
            IEnumerable <XElement> childList =
                from x in doc.Root.Elements(Tower).Elements(ElementInTower)
                select x;

            return(childList.First().FirstAttribute.Value);
        }
コード例 #3
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
 internal Phase(Tuple <int, int> inTextPlacement, RegisterMarksCoordinates inRegMarkCoord, ParsingInformation inParsingInfo, DirPaths inDirPaths, int inDPI, Action <string> inLog, MoveFile inMoveFile)
 {
     this.textPlacement = inTextPlacement;
     this.regMarkCoord  = inRegMarkCoord;
     this.parsingInfo   = inParsingInfo;
     this.dirPaths      = inDirPaths;
     this.DPI           = inDPI;
     this.logg          = inLog;
     this.moveFile      = inMoveFile;
 }
コード例 #4
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
        /// <summary>
        /// Moves the register marks a certain amount up or down the image.
        /// </summary>
        /// <param name="inputImage">Image whose registermarks should be removed.</param>
        /// <param name="dirPaths">Paths of the program.</param>
        /// <param name="regMarkCoord">Coordinates of the register marks.</param>
        /// <returns>An image where the register marks have been removed.</returns>
        private BarebonesImage RemoveRegisterMarks(BarebonesImage inputImage, DirPaths dirPaths, RegisterMarksCoordinates regMarkCoord)
        {
            BarebonesImage blankRegMark = new BarebonesImage();

            string pathAndFile = Path.Combine(dirPaths.regMarks, dirPaths.blankRegMark);

            blankRegMark = blankRegMark.ReadATIFF(pathAndFile);

            //Cover the old register marks with white pixels.
            inputImage.Insert(blankRegMark, regMarkCoord.lead.Item1, regMarkCoord.lead.Item2);
            inputImage.Insert(blankRegMark, regMarkCoord.trail.Item1, regMarkCoord.trail.Item2);

            return(inputImage);
        }
コード例 #5
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
        /// <summary>
        /// Inserts register marks to their coordinates.
        /// </summary>
        /// <param name="inputImage">Image whose registermarks should be removed.</param>
        /// <param name="dirPaths">Paths of the program.</param>
        /// <param name="regMarkCoord">Coordinates of the register marks.</param>
        /// <returns>An image where the register marks have been inserted into their positions.</returns>
        private BarebonesImage InsertRegisterMarks(BarebonesImage inputImage, DirPaths dirPaths, RegisterMarksCoordinates regMarkCoord)
        {
            BarebonesImage leadRegMark  = new BarebonesImage();
            BarebonesImage trailRegMark = new BarebonesImage();

            string pathAndFile = Path.Combine(dirPaths.regMarks, dirPaths.leadRegMark);

            leadRegMark = leadRegMark.ReadATIFF(pathAndFile);

            pathAndFile  = Path.Combine(dirPaths.regMarks, dirPaths.trailRegMark);
            trailRegMark = trailRegMark.ReadATIFF(pathAndFile);

            //Insert the register mark.
            inputImage.Insert(leadRegMark, regMarkCoord.lead.Item1, regMarkCoord.lead.Item2);
            inputImage.Insert(trailRegMark, regMarkCoord.trail.Item1, regMarkCoord.trail.Item2);

            return(inputImage);
        }
コード例 #6
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
        static void Main()
        {
            #region Instantiation of classes, structs and stuff.
            Log        Logg       = new Log();
            ReadConfig readConfig = new ReadConfig();
            DirPaths   dirPaths   = new DirPaths(readConfig);
            MoveFile   fileMove   = new MoveFile();

            ParsingInformation       parsingInfo  = new ParsingInformation();
            Action <string>          logg         = (str) => Logg.Text(str, dirPaths);
            RegisterMarksCoordinates regMarkCoord = new RegisterMarksCoordinates();
            #endregion

            #region Load a bunch of parameters from the config file and instanciate a phase class.
            //Load registermark coordinates from the config file.
            regMarkCoord.lead  = new Tuple <int, int>(readConfig.ReadNumber("leadRegMarkX"), readConfig.ReadNumber("leadRegMarkY"));
            regMarkCoord.trail = new Tuple <int, int>(readConfig.ReadNumber("trailRegMarkX"), readConfig.ReadNumber("trailRegMarkY"));

            //Load the sleepTime from the config file.
            int sleepTime = readConfig.ReadNumber("sleepTime");

            //Load parsing information for the files names from the config file.
            parsingInfo.towerStart  = readConfig.ReadNumber("parseTowerStart");
            parsingInfo.towerStart -= 1;                                                         //C# starts to count at zero.
            parsingInfo.towerLength = readConfig.ReadNumber("parseTowerLength");

            parsingInfo.cylinderStart  = readConfig.ReadNumber("parseCylinderStart");
            parsingInfo.cylinderStart -= 1;
            parsingInfo.cylinderLength = readConfig.ReadNumber("parseCylinderLength");

            parsingInfo.sectionStart  = readConfig.ReadNumber("parseSectionStart");
            parsingInfo.sectionStart -= 1;
            parsingInfo.sectionLength = readConfig.ReadNumber("parseSectionLength");

            parsingInfo.halfStart  = readConfig.ReadNumber("parseHalfStart");
            parsingInfo.halfStart -= 1;
            parsingInfo.halfLength = readConfig.ReadNumber("parseHalfLength");

            int DPI = readConfig.ReadNumber("DPI");

            Tuple <int, int> readTextPlacement = new Tuple <int, int>(readConfig.ReadNumber("textPlacementX"), readConfig.ReadNumber("textPlacementY"));

            Phase phase = new Phase(readTextPlacement, regMarkCoord, parsingInfo, dirPaths, DPI, logg, fileMove);
            #endregion

            //Forever loop for now. Main loop of the program.
            string toExitOrNot = @"Never Exit";
            do
            {
                //Checks that all the folders are present and then moves any file from the source to middle.
                string fileToProcess = phase.Input();

                //If there is a file in the source folder the processing begins.
                if (fileToProcess != null)
                {
                    phase.Process(fileToProcess);
                }

                //Any file in the middle should have by this time undergone processing and so is outputed.
                phase.Output();

                //Let the CPU get some rest. ("sleepTime" is set in OARConfig.txt)
                System.Threading.Thread.Sleep(sleepTime);
            } while (!toExitOrNot.Equals("Exit"));
        }
コード例 #7
0
ファイル: Resizer.cs プロジェクト: johanpolson/OAResize
        /// <summary>
        /// Moves a file from source and middle to the next folder as long as the next folder is empty and there's only one in the first.
        /// </summary>
        /// <param name="folderPath">The folder to move the file from.</param>
        /// <param name="logg">The logging function.</param>
        /// <param name="dirPaths">Where the folders of the programs are located.</param>
        /// <returns>Name of the file that was moved or null if none was.</returns>
        internal string FromDir(string folderPath, Action <string> logg, DirPaths dirPaths)
        {
            //Moves any buffered file to the target so its journey may continue.
            string[] allFilesInDir = Directory.GetFiles(folderPath, "*.TIF");

            if (allFilesInDir.Length > 1)
            {
                logg("Warning - " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - More than one .TIF present in " + folderPath);
                Console.WriteLine(" Remove the files and press any key.");
                Console.ReadKey();
            }
            else if (allFilesInDir.Length == 0)
            {
                //If there are no files in the folder the program does nothing.
            }
            else
            {
                string fileName = Path.GetFileName(allFilesInDir[0]);

                //Files are moved differently from middle and from source.
                if (folderPath == dirPaths.source)
                {
                    //Check that there are no .TIF files in the dirPaths.target, only one file should be sent to the CTP at a time.
                    string[] allFilesInMiddle = Directory.GetFiles(dirPaths.middle, "*.TIF");

                    if (allFilesInMiddle.Length == 0)
                    {
                        //Get the full filenames for both files.
                        string sourceFile = Path.Combine(dirPaths.source, fileName);
                        string middleFile = Path.Combine(dirPaths.middle, fileName);

                        //Attempt to move the file a few times, catching the IOException.
                        int attempts = 0;
                        do
                        {
                            Thread.Sleep(100);
                            try{
                                File.Move(sourceFile, middleFile);
                                //If the above is successful the loop can exit immediately.
                                attempts = 9;
                            }
                            catch (IOException)
                            {
                                attempts++;
                            }
                        } while (attempts < 4);

                        //One final attempt for the road or we'll have to crash.
                        if (attempts != 9)
                        {
                            File.Move(sourceFile, middleFile);
                        }

                        Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - " + allFilesInDir[0] + " moved to buffer.");

                        return(fileName);
                    }

                    return(null);
                }
                else if (folderPath == dirPaths.middle)
                {
                    //Check that there are no .TIF files in the dirPaths.target, only one file should be sent to the CTP at a time.
                    string[] allFilesInTarget = Directory.GetFiles(dirPaths.target, "*.TIF");

                    if (allFilesInTarget.Length == 0)
                    {
                        //Get the full filenames for both files.
                        string middleFile = Path.Combine(dirPaths.middle, fileName);
                        string destFile   = Path.Combine(dirPaths.target, fileName);

                        //Move the file to a .tmp file and then "move" it again to rename it. The CTP wants it thus.
                        File.Move(middleFile, destFile + @".tmp");
                        File.Move(destFile + @".tmp", destFile);

                        Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " - " + allFilesInDir[0] + " moved to output.");

                        return(fileName);
                    }

                    return(null);
                }
            }

            return(null);
        }