Skip to content

Commit

Permalink
use interpolated strings in ReachFramework and PresentationUI
Browse files Browse the repository at this point in the history
  • Loading branch information
halgab committed Jan 28, 2024
1 parent be3b317 commit 22c1e96
Show file tree
Hide file tree
Showing 61 changed files with 521 additions and 610 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private void EnsureNotDisposed()
private void EnsureState(State requiredState)
{
if (InitializationState != requiredState)
throw new InvalidOperationException("InitializationState != " + requiredState.ToString());
throw new InvalidOperationException($"InitializationState != {requiredState}");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ namespace MS.Internal.Documents.Application
/// Responsibility:
/// The class must hide the location and implemenation complexity of
/// performing simple logical operations needed by the system.
///
///
/// Design Comments:
/// The need for this is primarly driven from two factors:
///
///
/// - Package which does not allow use to discard changes
///
/// - RightsManagement where key changes make it impossible to edit a
///
/// - RightsManagement where key changes make it impossible to edit a
/// document in place
/// </remarks>
internal sealed class DocumentStream : StreamProxy, IDisposable
Expand Down Expand Up @@ -155,7 +155,7 @@ internal DocumentStream Copy(CriticalFileToken copiesToken)
}
}
// Since we have already closed the original file, we need to reopen it if we
// fail to copy the file or open the new file. After doing so, we rethrow the
// fail to copy the file or open the new file. After doing so, we rethrow the
// original exception so it can be handled at a higher level.
#pragma warning suppress 56500 // suppress PreSharp Warning 56500: Avoid `swallowing errors by catching non-specific exceptions..
catch
Expand Down Expand Up @@ -220,7 +220,7 @@ internal DocumentStream Copy(CriticalFileToken copiesToken)
/// <remarks>
/// We prefer to create the temporary file in the same location as the
/// source to inherit the folders attributes and security.
///
///
/// If we can not we will use a system generated file.
/// </remarks>
/// <param name="copyoriginal">When true we will copy the source file if
Expand Down Expand Up @@ -262,7 +262,7 @@ internal DocumentStream CreateTemporary(bool copyOriginal)
// Copy Data
if (copyOriginal)
{
// We use a native File.Copy if possible because this is
// We use a native File.Copy if possible because this is
// most performant. This is only possible if the source is file
// based.
if (isFileSource)
Expand Down Expand Up @@ -499,9 +499,9 @@ internal bool ReOpenWriteable()
/// <returns>False if the operation failed.</returns>
/// <remarks>
/// This method is inplace to work around issues with re-publishing
/// XpsDocuments into the same file. The intended use for the method is
/// XpsDocuments into the same file. The intended use for the method is
/// to logically allow in place editing for the user.
///
///
/// After use this object is unusable and should be disposed as the
/// temporary file is gone; it has become the original. In the event of an
/// error while swapping the file, the file no longer becomes the original,
Expand Down Expand Up @@ -588,7 +588,7 @@ internal bool SwapWithOriginal()
#pragma warning suppress 56500 // suppress PreSharp Warning 56500: Avoid `swallowing errors by catching non-specific exceptions..
catch
{
// TODO: 1603621 back out changes in case of failure
// TODO: 1603621 back out changes in case of failure
Trace.SafeWrite(
Trace.File,
"File attributes or permissions could not be set.");
Expand Down Expand Up @@ -666,7 +666,7 @@ internal bool DeleteOnClose
void IDisposable.Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
GC.SuppressFinalize(this);
}


Expand Down Expand Up @@ -735,7 +735,7 @@ protected override void Dispose(bool disposing)
/// <param name="temporary">The stream for the temporary file.</param>
/// <param name="tempToken">The file token for the temporary file.</param>
private void MakeTempFile(
bool inSameFolder,
bool inSameFolder,
out FileStream temporary,
out CriticalFileToken tempToken)
{
Expand Down Expand Up @@ -803,8 +803,10 @@ protected override void Dispose(bool disposing)
#if DEBUG
Invariant.Assert(
((i != 3) || (temporary != null) || (inSameFolder)),
"Unable to create a temp file.\n"
+ "Unless IE Cache is read-only we have a defect.");
"""
Unable to create a temp file.
Unless IE Cache is read-only we have a defect.
""");
#endif
}
}
Expand Down Expand Up @@ -842,19 +844,19 @@ private Uri MakeTemporaryFileName(bool inSameFolder, int generation)
/// <remarks>
/// Design is simple Source needs to be moved to Target ensuring
/// no data loss on errror.
///
///
/// If Source exists rename it (creating Backup)
/// Move Source to Target
/// If error occurs Move Backup to Source (resore from Backup)
/// If all was good (delete Backup)
///
///
/// This design incures trival I/O costs by using moves.
/// </remarks>
private void RobustFileMove()
{
string sourceFile = _xpsFileToken.Location.LocalPath;
string targetFile = _original._xpsFileToken.Location.LocalPath;
string backupFile = targetFile + ".bak";
string backupFile = $"{targetFile}.bak";

bool backupExists = false;
FileAttributes targetAttributes = FileAttributes.Normal;
Expand All @@ -881,7 +883,7 @@ private void RobustFileMove()
// Save the original file attributes so we can restore them if
// the temp file copy fails.
targetAttributes = File.GetAttributes(targetFile);
File.Move(targetFile, backupFile);
File.Move(targetFile, backupFile);

Trace.SafeWrite(
Trace.File,
Expand All @@ -903,7 +905,7 @@ private void RobustFileMove()
Trace.File,
"Moved(Saved) {0} as {1}.",
sourceFile,
targetFile);
targetFile);
}
catch
{
Expand All @@ -913,7 +915,7 @@ private void RobustFileMove()
if (backupExists)
{
// restore original on failure
File.Move(backupFile, targetFile);
File.Move(backupFile, targetFile);
Trace.SafeWrite(
Trace.File,
"Restored {0} from {1}, due to exception.",
Expand All @@ -930,8 +932,8 @@ private void RobustFileMove()
{
// Try to delete the backup file
if (backupExists)
{
File.Delete(backupFile);
{
File.Delete(backupFile);
backupExists = false;
Trace.SafeWrite(
Trace.File,
Expand All @@ -948,7 +950,7 @@ private void RobustFileMove()
"Unable to remove backup {0}.\n{1}",
backupFile,
e);
}
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static bool ShowSaveFileDialog(ref CriticalFileToken fileToken)
string extension = SR.FileManagementSaveExt;

Trace.SafeWrite(Trace.File, "Showing SafeFileDialog.");

bool result = false;

SaveFileDialog save = new SaveFileDialog();
Expand Down Expand Up @@ -85,10 +85,10 @@ internal static bool ShowSaveFileDialog(ref CriticalFileToken fileToken)
// gets up to homework.386, then the dialog would just pass it through as
// is, requiring us to append the extension here.
if (!extension.Equals(
Path.GetExtension(filePath),
Path.GetExtension(filePath),
StringComparison.OrdinalIgnoreCase))
{
filePath = filePath + extension;
filePath += extension;
}

Uri file = new Uri(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private RightsManagementResourceHelper()
internal static DocumentStatusResources GetDocumentLevelResources(RightsManagementStatus status)
{
DocumentStatusResources docStatusResources = new DocumentStatusResources();

// Set appropriate Text and ToolTip values.
switch (status)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ internal static string GetCredentialManagementResources(RightsManagementUser use
case (AuthenticationType.Windows):
accountName = String.Format(
CultureInfo.CurrentCulture,
SR.RMCredManagementWindowsAccount,
SR.RMCredManagementWindowsAccount,
user.Name);
break;
case (AuthenticationType.Passport):
Expand Down Expand Up @@ -137,9 +137,7 @@ private static DrawingBrush GetDrawingBrushFromStatus(RightsManagementStatus sta
if (_brushResources[index] == null)
{
// Determine resource name.
string resourceName = "PUIRMStatus"
+ Enum.GetName(typeof(RightsManagementStatus), status)
+ "BrushKey";
string resourceName = $"PUIRMStatus{Enum.GetName(status)}BrushKey";

// Acquire reference to the brush.
object resource = _frameworkElement.FindResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

// Description:
// Description:
// SignatureResourceHelper is a helper class used to get resources.
using System;
using System.Collections;
Expand Down Expand Up @@ -53,7 +53,7 @@ internal static class SignatureResourceHelper
case SignatureStatus.NotSigned:
docSigStatusResources.Text = String.Empty;
docSigStatusResources.ToolTip = SR.DocumentSignatureManagerDefaultToolTip;
break;
break;
default: // SignatureStatus.Unknown or SignatureStatus.Undetermined
// In this case signatures have been applied to the document, but
// the validity of the signatures is not yet known.
Expand All @@ -72,7 +72,7 @@ internal static class SignatureResourceHelper
/// </summary>
/// <param name="sigStatus">Requested signature status</param>
/// <param name="certStatus">Requested certificate status</param>
/// <returns>A Image on success (valid status, DrawingBrush found), null
/// <returns>A Image on success (valid status, DrawingBrush found), null
/// otherwise.</returns>
internal static Drawing.Image GetImageFromStatus(
int height,
Expand Down Expand Up @@ -108,9 +108,9 @@ internal static SignatureResources GetResources(DigitalSignature signature, Cert

resources._displayImage = GetImageFromStatus(
defaultHeight, defaultWidth, signature.SignatureState, certStatus);
resources._location =
resources._location =
string.IsNullOrEmpty(signature.Location) ? none : signature.Location;
resources._reason =
resources._reason =
string.IsNullOrEmpty(signature.Reason) ? none : signature.Reason;
resources._signBy = GetFormattedDate(signature.SignedOn);
resources._subjectName = signature.SubjectName;
Expand All @@ -131,7 +131,7 @@ internal static SignatureResources GetResources(DigitalSignature signature, Cert
/// Get the DrawingBrush icon for the status.
/// </summary>
/// <param name="status">Requested status</param>
/// <returns>A DrawingBrush on success (valid status, DrawingBrush found), null
/// <returns>A DrawingBrush on success (valid status, DrawingBrush found), null
/// otherwise.</returns>
private static DrawingBrush GetDrawingBrushFromStatus(SignatureStatus sigStatus)
{
Expand Down Expand Up @@ -159,9 +159,7 @@ private static DrawingBrush GetDrawingBrushFromStatus(SignatureStatus sigStatus)
if (_brushResources[index] == null)
{
// Determine resource name.
string resourceName = "PUISignatureStatus"
+ Enum.GetName(typeof(SignatureStatus), sigStatus)
+ "BrushKey";
string resourceName = $"PUISignatureStatus{Enum.GetName(sigStatus)}BrushKey";

// Acquire reference to the brush.
object resource = _frameworkElement.FindResource(
Expand Down Expand Up @@ -238,7 +236,7 @@ private static string GetSummaryMessage(DigitalSignature signature, CertificateP
signature.SubjectName,
GetFormattedDate(signature.SignedOn),
location);
break;
break;
}

return result;
Expand Down Expand Up @@ -302,7 +300,7 @@ private static string GetSignatureSummaryMessage(SignatureStatus sigStatus, Cert
else if (sigStatus == SignatureStatus.Unverifiable)
{
message = SR.SignatureResourceHelperSignatureStatusUnverifiable;
}
}
else
{
message = SR.SignatureResourceHelperSignatureStatusInvalid;
Expand Down Expand Up @@ -356,11 +354,11 @@ public override string ToString()
{
return String.Format(
CultureInfo.CurrentCulture,
SR.SignatureResourcesFormatForAccessibility,
_summaryMessage,
_subjectName,
_reason,
_location,
SR.SignatureResourcesFormatForAccessibility,
_summaryMessage,
_subjectName,
_reason,
_location,
_signBy);
}
}
Expand Down

0 comments on commit 22c1e96

Please sign in to comment.