Skip to content

Commit

Permalink
#180 Add IShSession.OpenApiAM10Service proxy similar to IShSession.Op…
Browse files Browse the repository at this point in the history
…enApiISH30Service proxy... Cleaning up (platform) compilation warnings and info entries
  • Loading branch information
ddemeyer committed Apr 7, 2024
1 parent 6728fef commit f61bf56
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ public InfoShareOpenApiWithOpenIdConnectConnection(ILogger logger, HttpClient ht
_logger.WriteDebug($"InfoShareOpenApiWithOpenIdConnectConnection reusing AccessToken[{ _connectionParameters.Tokens.AccessToken}] AccessTokenExpiration[{ _connectionParameters.Tokens.AccessTokenExpiration}]");
}
_logger.WriteDebug($"InfoShareOpenApiWithOpenIdConnectConnection OpenApiISH30Client using infoShareWSBaseUri[{infoShareWSUrlForOpenApi}]");
_openApiISH30Client = new OpenApiISH30Client(_httpClient);
_openApiISH30Client.BaseUrl = new Uri(infoShareWSUrlForOpenApi, "api").ToString();
_openApiISH30Client = new OpenApiISH30Client(_httpClient)
{
BaseUrl = new Uri(infoShareWSUrlForOpenApi, "api").ToString()
};
_logger.WriteDebug($"InfoShareOpenApiWithOpenIdConnectConnection OpenApiAM10Client using IssuerUrl[{_connectionParameters.IssuerUrl}]");
_openApiAM10Client = new OpenApiAM10Client(_httpClient);
_openApiAM10Client.BaseUrl = _connectionParameters.IssuerUrl.ToString();
_openApiAM10Client = new OpenApiAM10Client(_httpClient)
{
BaseUrl = _connectionParameters.IssuerUrl.ToString()
};
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ internal static void Redirect()
internal static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
var name = new AssemblyName(args.Name).Name;
Assembly outAssembly = null;
_forcedLoadedAssemblies.TryGetValue(name, out outAssembly);
_forcedLoadedAssemblies.TryGetValue(name, out Assembly outAssembly);
return outAssembly;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@ public class AppDomainModuleAssemblyInitializer : IModuleAssemblyInitializer
/// </summary>
private static readonly ConcurrentDictionary<string, Assembly> _forcedLoadedAssemblies = new ConcurrentDictionary<string, Assembly>();

private static string binaryFolderPath = Path.GetFullPath(
Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
".."));

private static string binaryCommonAssembliesFolderPath = Path.Combine(binaryFolderPath, "Common");

#if NET48
private static string binaryNetFrameworkAssembliesPath = Path.Combine(binaryFolderPath, "net48");
#else
private static string binaryNetCoreAssembliesPath = Path.Join(binaryFolderPath, "net6.0");
#endif

/// <summary>
/// Early registration of my AssemblyResolve call.
/// </summary>
Expand Down Expand Up @@ -130,8 +117,7 @@ public void OnImport()
private static Assembly ResolveAssembly_NetFramework(object sender, ResolveEventArgs args)
{
var name = new AssemblyName(args.Name).Name;
Assembly outAssembly = null;
_forcedLoadedAssemblies.TryGetValue(name, out outAssembly);
_forcedLoadedAssemblies.TryGetValue(name, out Assembly outAssembly);
return outAssembly;

/*
Expand Down Expand Up @@ -171,8 +157,7 @@ private static Assembly ResolveAssembly_NetCore(
AssemblyName assemblyName)
{
var name = assemblyName.Name;
Assembly outAssembly = null;
_forcedLoadedAssemblies.TryGetValue(name, out outAssembly);
_forcedLoadedAssemblies.TryGetValue(name, out Assembly outAssembly);
return outAssembly;

/*
Expand Down
91 changes: 45 additions & 46 deletions Source/ISHRemote/Trisoft.ISHRemote/HelperClasses/IshObfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ public static class IshObfuscator
/// <summary>
/// To replace words up to 20 characters with a fixed replacement word
/// </summary>
private static string[] _shortWordSubstitutions = { "", "a", "be", "the", "easy", "would", "summer", "healthy", "zucchini", "breakfast", "chimpanzee",
private static readonly string[] _shortWordSubstitutions = { "", "a", "be", "the", "easy", "would", "summer", "healthy", "zucchini", "breakfast", "chimpanzee",
"alternative", "professional", "extraordinary", "representative", "confidentiality", "extraterrestrial", "telecommunication",
"bioinstrumentation", "psychophysiological", "internationalization" };
/// <summary>
/// To replace words > 20 chars .. a part of this very long word can be taken
/// </summary>
private static string _longWordSubstitution = string.Concat(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 100000));
private static readonly string _longWordSubstitution = string.Concat(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 100000));

#endregion

#region Public xml obfuscation methods

/// <summary>
/// Obfuscates the given xml file.
/// When the obfuscation succeeds a file is created at the location given in outputFileLocation
Expand Down Expand Up @@ -148,46 +146,6 @@ public static void ObfuscateXml(string inputFileLocation, string outputFileLocat
}
}

/// <summary>
/// Obfuscates the given image file.
/// For that, a new image is created with the same format, width and height and a yellow background (and the filename in text in the image if it is wide enough to put it there).
/// When the obfuscation succeeds a file is created at the location given in outputFileLocation
/// </summary>
/// <param name="inputFileLocation">The location of the input file</param>
/// <param name="outputFileLocation">The location for the output file</param>
public static void ObfuscateImage(string inputFileLocation, string outputFileLocation)
{
#if NET6_0_OR_GREATER
if (!OperatingSystem.IsWindows())
{
throw new PlatformNotSupportedException($"Obfuscate Image is only supported on Windows platform (through NET6+ extension), obfuscating image inputFile[{inputFileLocation}] is skipped. [OS:{Environment.OSVersion}]");
}
#endif
int width;
int height;
ImageFormat format;
PixelFormat pixelFormat;
var fileInfo = new FileInfo(inputFileLocation);
using (Stream stream = File.OpenRead(inputFileLocation))
{
using (Image sourceImage = Image.FromStream(stream, false, false))
{
width = sourceImage.Width;
height = sourceImage.Height;
format = sourceImage.RawFormat;
pixelFormat = sourceImage.PixelFormat;
}
}
// Creating the image with the pixelformat gives an error, so not passing it to CreateImageWithText, which means color depth will be different
var newImage = CreateImageWithText(fileInfo.Name, width, height);
newImage.Save(outputFileLocation, format);
}

#endregion


#region Private methods

/// <summary>
/// Writes an xml declaration with the correct encoding
/// </summary>
Expand Down Expand Up @@ -288,6 +246,45 @@ private static string ObfuscateWord(string word)
}
}

// Overall build should treat warnings as errors, hence:
// Disabling warning regarding 'This call site is reachable on Windows all versions.'
#pragma warning disable CA1416

/// <summary>
/// Obfuscates the given image file.
/// For that, a new image is created with the same format, width and height and a yellow background (and the filename in text in the image if it is wide enough to put it there).
/// When the obfuscation succeeds a file is created at the location given in outputFileLocation
/// </summary>
/// <param name="inputFileLocation">The location of the input file</param>
/// <param name="outputFileLocation">The location for the output file</param>
public static void ObfuscateImage(string inputFileLocation, string outputFileLocation)
{
#if NET6_0_OR_GREATER
if (!OperatingSystem.IsWindows())
{
throw new PlatformNotSupportedException($"Obfuscate Image is only supported on Windows platform (through NET6+ extension), obfuscating image inputFile[{inputFileLocation}] is skipped. [OS:{Environment.OSVersion}]");
}
#endif
int width;
int height;
ImageFormat format;
PixelFormat pixelFormat;
var fileInfo = new FileInfo(inputFileLocation);
using (Stream stream = File.OpenRead(inputFileLocation))
{
using (Image sourceImage = Image.FromStream(stream, false, false))
{
width = sourceImage.Width;
height = sourceImage.Height;
format = sourceImage.RawFormat;
pixelFormat = sourceImage.PixelFormat;
}
}
// Creating the image with the pixelformat gives an error, so not passing it to CreateImageWithText, which means color depth will be different
var newImage = CreateImageWithText(fileInfo.Name, width, height);
newImage.Save(outputFileLocation, format);
}

/// <summary>
/// Creates an image with the given width and height and having the given text
/// </summary>
Expand Down Expand Up @@ -338,9 +335,11 @@ private static Image CreateImageWithText(String text, int width, int height)
drawing.Dispose();

return img;

}
#endregion

// Restoring warning regarding 'This call site is reachable on Windows all versions.'
#pragma warning restore CA1416

}
}

27 changes: 11 additions & 16 deletions Source/ISHRemote/Trisoft.ISHRemote/Objects/Public/IshSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ public IshSession(ILogger logger, string webServicesBaseUrl, string ishUserName,
}
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
handler.SslProtocols = (System.Security.Authentication.SslProtocols)(SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13);
_httpClient = new HttpClient(handler);
_httpClient.Timeout = _timeout;
_httpClient = new HttpClient(handler)
{
Timeout = _timeout
};
// webServicesBaseUrl should have trailing slash, otherwise .NET throws unhandy "Reference to undeclared entity 'raquo'." error
_webServicesBaseUri = (webServicesBaseUrl.EndsWith("/")) ? new Uri(webServicesBaseUrl) : new Uri(webServicesBaseUrl + "/");
_ishUserName = ishUserName == null ? Environment.UserName : ishUserName;
Expand Down Expand Up @@ -302,8 +304,10 @@ internal IshTypeFieldSetup IshTypeFieldSetup
{
_logger.WriteDebug($"Loading TriDKXmlSetupFullExport_12_00_01...");
var triDKXmlSetupHelper = new TriDKXmlSetupHelper(_logger, Properties.Resouces.ISHTypeFieldSetup.TriDKXmlSetupFullExport_12_00_01);
_ishTypeFieldSetup = new IshTypeFieldSetup(_logger, triDKXmlSetupHelper.IshTypeFieldDefinition);
_ishTypeFieldSetup.StrictMetadataPreference = Enumerations.StrictMetadataPreference.Off; // Otherwise custom metadata fields are always removed as they are unknown for the default TriDKXmlSetup Resource
_ishTypeFieldSetup = new IshTypeFieldSetup(_logger, triDKXmlSetupHelper.IshTypeFieldDefinition)
{
StrictMetadataPreference = Enumerations.StrictMetadataPreference.Off // Otherwise custom metadata fields are always removed as they are unknown for the default TriDKXmlSetup Resource
};
}

if (_serverVersion.MajorVersion == 13 || (_serverVersion.MajorVersion == 14 && _serverVersion.RevisionVersion < 4))
Expand Down Expand Up @@ -1174,18 +1178,9 @@ private void VerifyConnectionValidity()

public void Dispose()
{
if (_infoShareWcfSoapWithWsTrustConnection != null)
{
_infoShareWcfSoapWithWsTrustConnection.Dispose();
}
if (_infoShareWcfSoapWithOpenIdConnectConnection != null)
{
_infoShareWcfSoapWithOpenIdConnectConnection.Dispose( );
}
if (_infoShareOpenApiWithOpenIdConnectConnection != null)
{
_infoShareOpenApiWithOpenIdConnectConnection.Dispose( );
}
_infoShareWcfSoapWithWsTrustConnection?.Dispose();
_infoShareWcfSoapWithOpenIdConnectConnection?.Dispose( );
_infoShareOpenApiWithOpenIdConnectConnection?.Dispose( );
}
public void Close()
{
Expand Down

0 comments on commit f61bf56

Please sign in to comment.