Skip to content

Commit

Permalink
More code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishamm committed May 11, 2021
1 parent 43b99fb commit 3f5e049
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 1,187 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,7 @@ src/Documentation/api
!src/Documentation/api/toc.yml
src/Documentation/obj
Makefile.local

# XML documentation
src/DuetAPI/DuetAPI.xml
src/DuetAPIClient/DuetAPIClient.xml
1 change: 0 additions & 1 deletion src/CodeStream/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.IO;
using System.Net.Sockets;
using System.Text.Json;
using System.Threading.Tasks;

namespace CodeStream
Expand Down
1 change: 0 additions & 1 deletion src/DuetAPI/Commands/Packages/InstallSystemPackage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DuetAPI.Utility;
using System;

namespace DuetAPI.Commands
{
Expand Down
1,152 changes: 0 additions & 1,152 deletions src/DuetAPIClient/DuetAPIClient.xml

This file was deleted.

46 changes: 19 additions & 27 deletions src/DuetControlServer/Files/ImageProcessing/IconImageParser.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using DuetAPI.Commands;
using DuetAPI.ObjectModel;
using DuetControlServer.Files.ImageProcessing;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SixLabors.ImageSharp;
Expand All @@ -26,7 +22,7 @@ public static class IconImageParser
public static async Task ProcessAsync(StreamReader reader, CodeParserBuffer codeParserBuffer, ParsedFileInfo parsedFileInfo, Code code)
{
_logger.Info($"Processing Image {parsedFileInfo.FileName}");
StringBuilder imageBuffer = new StringBuilder();
StringBuilder imageBuffer = new();
code.Reset();

//Keep reading the data from the file
Expand Down Expand Up @@ -65,32 +61,28 @@ public static async Task ProcessAsync(StreamReader reader, CodeParserBuffer code

private static ParsedThumbnail ReadImage(string imageBuffer)
{
ParsedThumbnail thumbnail = new ParsedThumbnail();
ParsedThumbnail thumbnail = new();
//Convert the string into a usable format
var finalString = imageBuffer.Replace("Icon: ", String.Empty).Replace(";", string.Empty).Replace(" ", string.Empty).Replace("\r\n", string.Empty);

using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(finalString)))
using (MemoryStream bitmapSource = new MemoryStream())
using MemoryStream ms = new(Convert.FromBase64String(finalString));
using MemoryStream bitmapSource = new();
_logger.Debug("Encoding Image");
try
{
_logger.Debug("Encoding Image");
try
{
var image = BinaryToImage(ms, out int width, out int height);
thumbnail.EncodedImage = image.ToBase64String(PngFormat.Instance);
_logger.Debug(thumbnail.EncodedImage);
thumbnail.Width = width;
thumbnail.Height = height;
image?.Dispose(); //Clean up image after getting data from it.
return thumbnail;
}
catch (Exception ex)
{
var imageProcessingException = new ImageProcessingException("Error processing Icon image", ex);
_logger.Error(imageProcessingException);
throw imageProcessingException;
}
return null;

var image = BinaryToImage(ms, out int width, out int height);
thumbnail.EncodedImage = image.ToBase64String(PngFormat.Instance);
_logger.Debug(thumbnail.EncodedImage);
thumbnail.Width = width;
thumbnail.Height = height;
image?.Dispose(); //Clean up image after getting data from it.
return thumbnail;
}
catch (Exception ex)
{
var imageProcessingException = new ImageProcessingException("Error processing Icon image", ex);
_logger.Error(imageProcessingException);
throw imageProcessingException;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DuetControlServer.Files.ImageProcessing
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using DuetAPI.Commands;
using DuetAPI.ObjectModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

Expand Down

0 comments on commit 3f5e049

Please sign in to comment.