static void Main(string[] args) { FileNameFactory.Initialize(); Color transparentColorKey = Color.FromArgb(255, 0, 255, 255); // Enumerate the current directory if (args.Length == 0) { var files = Directory.EnumerateFiles(".\\sources", "*.png", SearchOption.AllDirectories); foreach (var file in files) { try { DoOneImage(file, transparentColorKey); } catch (Exception ex) { Console.WriteLine($"{Path.GetFileNameWithoutExtension(file)}: ERROR: {ex.Message}"); } } } else { try { DoOneImage(args[0], transparentColorKey); } catch (Exception ex) { Console.WriteLine($"{Path.GetFileNameWithoutExtension(args[0])}: ERROR: {ex.Message}"); } } }
private void WriteFileCustom(byte[] body, bool request, string logPath) { logPath = Path.Combine(logPath, "GetForecastByLocation"); var fileNameFactory = new FileNameFactory(); try { var message = SoapMessage.Parse(body, request); fileNameFactory.AddSegment(message.GetOperationName()); fileNameFactory.AddSegment(message.GetNodeValue("body", "GetForecastByLocation", "Location")); fileNameFactory.AddSegment(message.GetNodeValue("body", "GetForecastByLocationResponse", "GetForecastByLocationResult", "WeatherReport", "Location")); fileNameFactory.AddSegment(message.GetNodeValue("body", "GetForecastByLocationResponse", "GetForecastByLocationResult", "WeatherReport", "Temperature")); fileNameFactory.AddDirection(request); string indentedXml = message.GetIndentedXml(); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), indentedXml, null, logPath); } catch (FileSystemAcccesDeniedException) { throw; } catch (Exception ex) { fileNameFactory.AddSegment("ERROR"); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), null, body, logPath); fileNameFactory.AddSegment("exception"); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), ex.ToString(), null, logPath); } }
public void CreateFileName() { var fileName = FileNameFactory.DefaultFileName(); Assert.Equal(FileNameFactory.DefaultName, fileName.Name); Assert.Equal(FileNameFactory.DefaultExtension, fileName.Extension); Assert.Equal(FileNameFactory.DefaultName + "." + FileNameFactory.DefaultExtension, fileName.ToString()); }
static void DoOneImage(string filename, Color transparentColorKey) { using (Bitmap bmp = Bitmap.FromFile(filename) as Bitmap) { #if DEBUG bmp.Save(FileNameFactory.MakePreviewFilename(filename, "Original")); #endif float minError = float.MaxValue; string bestEntry = string.Empty; Bitmap bestBmp = null; // try no dither first -- error must be zero { Bitmap tmpBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb); float error = DitherOneImage(bmp, tmpBmp, NoDither, transparentColorKey); if (error == 0) { bestEntry = "NoDither"; bestBmp = tmpBmp; minError = 0; } } Console.WriteLine($"{Path.GetFileNameWithoutExtension(filename)}:"); foreach (var ditherEntry in DitherPatterns) { if (minError == 0) // Can't do any better than no error! { continue; } Bitmap tmpBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb); float error = DitherOneImage(bmp, tmpBmp, ditherEntry.Value, transparentColorKey); Console.WriteLine($" .. {error} MSQ {ditherEntry.Key}"); #if DEBUG tmpBmp.Save(FileNameFactory.MakePreviewFilename(filename, $"Preview ({ditherEntry.Key})")); #endif // If this is the best one, save it if (error < minError) { bestBmp = tmpBmp; bestEntry = ditherEntry.Key; minError = error; } } Assert(bestBmp != null); bestBmp.Save(FileNameFactory.MakeFinalFilename(filename)); #if DEBUG bestBmp.Save(FileNameFactory.MakePreviewFilename(filename, $"Final ({bestEntry})")); #endif } }
// this custom handling method looks for 'GetForecastByLocation' only private void WriteFileCustom(byte[] body, bool request, string logPath) { const string operationNameToLog = "GetForecastByLocation"; logPath = Path.Combine(logPath, operationNameToLog); var fileNameFactory = new FileNameFactory(); try { var message = SoapMessage.Parse(body, request); string operationName = message.GetOperationName(); if (operationName != operationNameToLog) { return; } // _dbLoggingTest.LogToDatabase(message, request); // uncomment to see simple DB logging fileNameFactory.AddSegment(message.GetNodeValue("Body / GetForecastByLocation / Location")); fileNameFactory.AddSegment(message.GetNodeValue("Body / GetForecastByLocationResponse / GetForecastByLocationResult / WeatherReport / Location")); fileNameFactory.AddSegment(message.GetNodeValue("Body / GetForecastByLocationResponse / GetForecastByLocationResult / WeatherReport / Temperature")); fileNameFactory.AddDirection(request); string indentedXml = message.GetIndentedXml(); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), indentedXml, null, logPath); } catch (FileSystemAcccesDeniedException) { throw; } catch (Exception ex) { fileNameFactory.AddSegment("ERROR"); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), null, body, logPath); fileNameFactory.AddSegment("exception"); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), ex.ToString(), null, logPath); } }
private void WriteFileCustom(byte[] body, bool request, string logPath) { const string operationNameToLog = "GetLastReportByLocation"; logPath = Path.Combine(logPath, operationNameToLog); var fileNameFactory = new FileNameFactory(); try { var message = SoapMessage.Parse(body, request); string operationName = message.GetOperationName(); if (operationName != operationNameToLog) { return; } fileNameFactory.AddSegment(operationName); fileNameFactory.AddSegment(message.GetNodeValue("Body", "GetLastReportByLocation", "Location")); // fileNameFactory.AddSegment(message.GetNodeValue("Body", "SendReport", "report", "location")); // fileNameFactory.AddSegment(message.GetNodeValue("Body", "GetForecastByLocation", "location")); fileNameFactory.AddDirection(request); string indentedXml = message.GetIndentedXml(); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), indentedXml, null, logPath); } catch (FileSystemAcccesDeniedException) { throw; } catch (Exception ex) { fileNameFactory.AddSegment("ERROR"); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), null, body, logPath); fileNameFactory.AddSegment("exception"); SoapLoggerTools.WriteFile(fileNameFactory.GetFileName(), ex.ToString(), null, logPath); } }