Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion docs/workflow/resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ We are using our own `Start-ResGen` to generate them.
Usually it's called as part of the regular build with

```
Start-PSBuild -ResGen
PS C:\> Start-PSBuild -ResGen
```

If you see compilation errors related to resources, try to call `Start-ResGen` explicitly.

```
PS C:\> Start-ResGen
```

## Editing resx files
Expand All @@ -20,3 +26,16 @@ It will try to create `.cs` files for you and you will get whole bunch of hard-t

To edit resource file, use any **plain text editor**.
Resource file is a simple xml, and it's easy to edit.


## Convert txt resource files into resx

`dotnet cli` doesn't support embeeding old-fashioned txt resource.
You can do a one-time convertion of `.txt` resources into `.resx` files with a helper function

```
# example, converting all .txt resources under src\Microsoft.WSMan.Management\resources
PS C:\> Convert-TxtResourceToXml -Path src\Microsoft.WSMan.Management\resources
```

`.resx` files would be placed next to `.txt` files.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*============================================================================
* Copyright (C) Microsoft Corporation, All rights reserved.
*============================================================================
*/

using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly:AssemblyFileVersionAttribute("1.0.0.0")]
[assembly:AssemblyVersion("1.0.0.0")]

[assembly:InternalsVisibleTo("Microsoft.Windows.DSC.CoreConfProviders,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly:InternalsVisibleTo("Microsoft.Management.Infrastructure.CimCmdlets.Test,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
//This is equal to Debuggable(true,true) which enables IsJITTracking and Disable Optimization. CoreCLR does not have constructor Debuggable(true,true)
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*============================================================================
* Copyright (C) Microsoft Corporation, All rights reserved.
*============================================================================
*/

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Management.Automation;

namespace Microsoft.Management.Infrastructure.CimCmdlets
{
public abstract class BinaryMiLogBase : PSCmdlet
{
internal const string Noun = "BinaryMiLog";

internal BinaryMiLogBase()
{
}

[Parameter(Mandatory = true, Position = 0)]
[ValidateNotNullOrEmpty]
public string Path { get; set; }

#region Path utilities copied from internal admin/monad/src/utils/PathUtils.cs

/* command.Context.ProviderNames.FileSystem is internal */
private const string FileSystemProviderName = "FileSystem";

private static string ResolveFilePath(string filePath, PSCmdlet command, bool isLiteralPath)
{
string path = null;

try
{
ProviderInfo provider = null;
PSDriveInfo drive = null;
List<string> filePaths = new List<string>();

if (isLiteralPath)
{
filePaths.Add(command.SessionState.Path.GetUnresolvedProviderPathFromPSPath(filePath, out provider, out drive));
}
else
{
filePaths.AddRange(command.SessionState.Path.GetResolvedProviderPathFromPSPath(filePath, out provider));
}

/* command.Context.ProviderNames.FileSystem is internal */
if (!provider.Name.Equals(FileSystemProviderName, StringComparison.OrdinalIgnoreCase))
{
ReportWrongProviderType(command, provider.Name);
}

if (filePaths.Count > 1)
{
ReportMultipleFilesNotSupported(command);
}
if (filePaths.Count == 0)
{
ReportWildcardingFailure(command, filePath);
}

path = filePaths[0];
}
catch (ItemNotFoundException)
{
if (!isLiteralPath)
{
return ResolveFilePath(filePath, command, isLiteralPath: true);
}
else
{
throw;
}
}
return path;
}

internal string GetVerifiedFilePath(FileAccess fileAccess)
{
string resolvedPath = ResolveFilePath(this.Path, this, isLiteralPath: false);

try
{
FileMode fileMode;
FileShare fileShare;
switch (fileAccess)
{
case FileAccess.Read:
fileMode = FileMode.Open;
fileShare = FileShare.Read;
break;
case FileAccess.Write:
fileMode = FileMode.Create;
fileShare = FileShare.None;
break;
default:
throw new ArgumentOutOfRangeException("fileAccess");
}

using (new FileStream(resolvedPath, fileMode, fileAccess, fileShare))
{
/* open and immediately close the file - to get exception in PowerShell style;
* obviously there is a race here - we can still get error from mibincodec.dll later on */
}
}
catch (ArgumentException e)
{
// NOTE: this call will throw
ReportFileOpenFailure(this, resolvedPath, e);
}
catch (IOException e)
{
// NOTE: this call will throw
ReportFileOpenFailure(this, resolvedPath, e);
}
catch (UnauthorizedAccessException e)
{
// NOTE: this call will throw
ReportFileOpenFailure(this, resolvedPath, e);
}
catch (NotSupportedException e)
{
// NOTE: this call will throw
ReportFileOpenFailure(this, resolvedPath, e);
}
catch (System.Security.SecurityException e)
{
// NOTE: this call will throw
ReportFileOpenFailure(this, resolvedPath, e);
}

return resolvedPath;
}

private static void ReportFileOpenFailure(Cmdlet cmdlet, string filePath, Exception e)
{
ErrorRecord errorRecord = new ErrorRecord(
e,
"FileOpenFailure",
ErrorCategory.OpenError,
null);

cmdlet.ThrowTerminatingError(errorRecord);
}


internal static void ReportWrongProviderType(Cmdlet cmdlet, string providerId)
{
string msg = string.Format(
CultureInfo.InvariantCulture, /* providerId is culture invariant */
Strings.ReadWriteFileNotFileSystemProvider,
providerId);

var errorRecord = new ErrorRecord (
new InvalidOperationException(msg),
"ReadWriteFileNotFileSystemProvider",
ErrorCategory.InvalidArgument,
null);

errorRecord.ErrorDetails = new ErrorDetails(msg);
cmdlet.ThrowTerminatingError(errorRecord);
}

internal static void ReportMultipleFilesNotSupported(Cmdlet cmdlet)
{
string msg = Strings.MultipleFilesNotSupported;

var errorRecord = new ErrorRecord (
new InvalidOperationException(msg),
"ReadWriteMultipleFilesNotSupported",
ErrorCategory.InvalidArgument,
null);

errorRecord.ErrorDetails = new ErrorDetails(msg);
cmdlet.ThrowTerminatingError(errorRecord);
}

internal static void ReportWildcardingFailure(Cmdlet cmdlet, string filePath)
{
string msg = string.Format(
CultureInfo.InvariantCulture, /* filePath is culture invariant */
Strings.DidNotResolveFile,
filePath);

var errorRecord = new ErrorRecord (
new FileNotFoundException(msg),
"FileOpenFailure",
ErrorCategory.OpenError,
filePath);

errorRecord.ErrorDetails = new ErrorDetails(msg);
cmdlet.ThrowTerminatingError(errorRecord);
}

#endregion

}
}
Loading