Files
UVtools/UVtools.Core/Network/RemotePrinterRequest.cs
T
Tiago Conceição 9f7722d369 v3.7.0
- **File formats:**
   - (Add) `TransitionLayerCount` modifier to: Chitubox Zip, CWS, JXS, OSLA, PW*, UVJ, ZCodex, ZCode
   - (Add) Utility methods for transition layers calculation/parse
   - (Improvement) Calculate and set `TransitionLayerCount` property in file decode based on layer exposure time configuration
- **GCode:**
   - (Improvement) GCode: Able to parse layer image file with appended numbers on the filename (Afecting CWS) (#577)
   - (Fix) Bad parsing of the file when it comes from Lychee or NovaMaker slicer (Afecting CWS)
   - (Fix) Incorrect parse of "Wait time before cure" from layers when printer require wait sync moves (Afecting CWS)
- **Tools:**
   - (Add) External tests: The Complete Resin 3D Printing Settings Guide for Beginners
   - (Add) External tests: 9 settings for faster printing
   - (Improvement) Fade exposure time: Set `TransitionLayerCount` property with the affected layer count
- **Suggestions:**
   - (Add) Transition layers: If you are printing flat on the build plate your model will print better when using a smooth transition exposure time instead of a harsh variation, resulting in reduced layer line effect and avoid possible problems due the large exposure difference.
                              This is not so important when your model print raised under a raft/supports unaffected by the bottom exposure, in that case, it's fine to ignore this.
   - (Add) Model position: Printing on a corner will reduce the FEP stretch forces when detaching from the model during a lift sequence, benefits are: Reduced lift height and faster printing, less stretch, less FEP marks, better FEP lifespan, easier to peel, less prone to failure and use the screen pixels more evenly.
                           If the model is too large to fit within the margin(s) on the screen, it will attempt to center it on that same axis to avoid touching on screen edge(s) and to give a sane margin from it.
- **Status bar:**
   - (Add) Transition layers: 0/-0.00s
   - (Improvement) Change "Layer Height: 0.000mm" to "Layers: count @ 0.000mm"
   - (Improvement) Change "Bottom layers: 0" to "Bottom layers: 0/0.000mm"
- (Change) Show user informative message about CTB Encrypted file format once per ten file loads
- (Upgrade) .NET from 6.0.9 to 6.0.10
- (Fix) Windows MSI installation not upgrading well when downgrade libraries
2022-10-12 01:16:34 +01:00

192 lines
4.9 KiB
C#

/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.ComponentModel;
using System.Net.Http;
using System.Threading.Tasks;
using UVtools.Core.Extensions;
using UVtools.Core.Objects;
using UVtools.Core.Operations;
namespace UVtools.Core.Network;
public class RemotePrinterRequest : BindableBase
{
#region Enums
public enum RequestMethod : byte
{
[Description("GET")]
GET,
[Description("POST")]
POST,
[Description("PUT")]
PUT
}
public enum RequestType : byte
{
UploadFile,
PrintFile,
DeleteFile,
PausePrint,
ResumePrint,
StopPrint,
GetFiles,
PrintStatus,
PrinterInfo,
}
#endregion
#region Members
private RequestType _type;
private RequestMethod _method;
private string _path = string.Empty;
#endregion
#region Properties
/// <summary>
/// Gets or sets this request type
/// </summary>
public RequestType Type
{
get => _type;
set => RaiseAndSetIfChanged(ref _type, value);
}
/// <summary>
/// Gets or sets this request method
/// </summary>
public RequestMethod Method
{
get => _method;
set => RaiseAndSetIfChanged(ref _method, value);
}
/// <summary>
/// Gets or sets the request path, eg: print/file/{0}
/// </summary>
public string Path
{
get => _path;
set
{
if (!string.IsNullOrWhiteSpace(value))
{
value = value.Trim();
if (value[0] == '/') value = value.Remove(0, 1);
if(value[^1] == '/') value = value.Remove(value.Length-1, 1);
}
if(!RaiseAndSetIfChanged(ref _path, value)) return;
RaisePropertyChanged(nameof(IsValid));
}
}
public bool IsValid => !string.IsNullOrWhiteSpace(_path);
#endregion
#region Constructors
public RemotePrinterRequest() { }
public RemotePrinterRequest(RequestType type, RequestMethod method, string path = "")
{
_type = type;
_method = method;
Path = path;
}
#endregion
#region Methods
/// <summary>
/// Gets the path with formatted arguments
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
public string GetFormattedPath(params object?[] parameters) => string.Format(_path, parameters);
public async Task<HttpResponseMessage> SendRequest(string host, ushort port = 0, OperationProgress? progress = null, string? param1 = null, HttpContent? content = null)
{
string url = $"http://{host}";
if (port > 0) url += $":{port}";
progress ??= new();
progress.Title = $"Sending {_method} request to: {url}";
progress.ItemName = "Megabyte(s)";
progress.CanCancel = true;
if (!string.IsNullOrWhiteSpace(_path)) url += $"/{GetFormattedPath(param1)}";
switch (_method)
{
case RequestMethod.GET:
{
using var response = await NetworkExtensions.HttpClient.GetAsync(url, progress.Token);
return response;
}
case RequestMethod.POST:
{
using var response = await NetworkExtensions.HttpClient.PostAsync(url, content, progress.Token);
return response;
}
case RequestMethod.PUT:
{
using var response = await NetworkExtensions.HttpClient.PutAsync(url, content, progress.Token);
return response;
}
default:
throw new ArgumentOutOfRangeException(nameof(Method));
}
}
public async Task<HttpResponseMessage> SendRequest(RemotePrinter remotePrinter,
OperationProgress? progress = null, string? param1 = null, HttpContent? content = null)
=> await SendRequest(remotePrinter.Host, remotePrinter.Port, progress, param1, content);
public RemotePrinterRequest Clone()
{
return (MemberwiseClone() as RemotePrinterRequest)!;
}
public override string ToString()
{
return _path;
}
protected bool Equals(RemotePrinterRequest other)
{
return _path == other._path;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((RemotePrinterRequest)obj);
}
public override int GetHashCode()
{
return (_path != null ? _path.GetHashCode() : 0);
}
#endregion
}