예제 #1
0
 /// <summary>
 /// Grid pattern generation and writing to file
 /// </summary>
 /// <param name="options">parsed command line args</param>
 /// <returns>error code</returns>
 static int GeneratePattern(GenerateOptions options)
 {
     try
     {
         var settings  = PixelSettings.FromFile(options.PixelSettingsPath);
         var generator = new PatternGenerator(settings);
         var pattern   = generator.GeneratePattern(options.PatternWidth, options.PatternHeight);
         pattern.Save(options.OutputFileName);
     }
     catch (Exception e)
     {
         ConsoleLogger.WriteMessage(e.Message + "\n" + e.InnerException?.Message, MessageType.Error);
         if (e is FileNotFoundException)
         {
             return((int)ErrorCode.FileNotFound);
         }
         return((int)ErrorCode.UknownError);
     }
     return((int)ErrorCode.NoError);
 }
예제 #2
0
        /// <summary>
        /// Grid pattern generation and writing to file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>error code</returns>
        static ErrorCode GeneratePattern(GenerateOptions options)
        {
            try
            {
                if (options.ExcessValue != null)
                {
                    return(ErrorCode.ArgumentsMismatch);
                }

                Settings        = PixelSettings.FromFile(options.PixelSettingsPath);
                _outputFileName = options.OutputFileName;

                var    generator  = new PatternGenerator(Settings);
                byte[] sampleData = null;
                if (options.InputFileName != null)
                {
                    sampleData = ParseDataFile(options.InputFileName);
                }
                var pattern = generator.GeneratePattern(options.PatternWidth,
                                                        options.PatternHeight, options.EnumerationStyle, sampleData);
                pattern.Save(options.OutputFileName);
            }
            catch (Exception e)
            {
                switch (e)
                {
                case PixelProcessingException _:
                    ConsoleLogger.WriteMessage(e.Message, MessageType.Error);
                    return(ErrorCode.FileParsingError);

                case FileNotFoundException _:
                    return(ErrorCode.FileNotFound);

                default:
                    return(ErrorCode.UknownError);
                }
            }
            return(ErrorCode.NoError);
        }
예제 #3
0
        /// <summary>
        /// Grid pattern generation and writing to file
        /// </summary>
        /// <param name="options">parsed command line args</param>
        /// <returns>always returns null</returns>
        static object GeneratePattern(GenerateOptions options)
        {
            if (options.ExcessValue != null)
            {
                throw new ArgumentException("Argument mismatch!");
            }

            Settings        = PixelSettings.FromFile(options.PixelSettingsPath);
            _outputFileName = options.OutputFileName;

            var generator = new PatternGenerator(Settings);

            byte[] sampleData = null;
            if (options.InputFileName != null)
            {
                sampleData = ParseDataFile(options.InputFileName);
            }
            var pattern = generator.GeneratePattern(options.PatternWidth,
                                                    options.PatternHeight, options.EnumerationStyle, sampleData);

            pattern.Save(options.OutputFileName);

            return(null);
        }