Skip to content
13 changes: 13 additions & 0 deletions src/Microsoft.PowerShell.Commands.Diagnostics/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Reflection;
using System.Resources;

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

[assembly:AssemblyCulture("")]
[assembly:NeutralResourcesLanguage("en-US")]

#if !CORECLR
[assembly:AssemblyKeyFileAttribute(@"..\signing\visualstudiopublic.snk")]
[assembly:AssemblyDelaySignAttribute(true)]
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no AssemblyInfo.cs or AssemblyInfo.cst in SD. sergei (@vors) are we supposed to create such file in this case?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dongbo Wang (@daxian-dbw) yes, in windows build they are generated from templates by build scripts. We need them for FullCLR at least, because we want to deploy assemlbies in GAC and it requires signing. #739 for that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sergei (@vors) Dongbo Wang (@daxian-dbw) You bring up a good point, for the assembly info files that are auto-generated... I'm wondering if the updated schema can handle all of this now. Here are the available build options. At least the key file and delayed attribute can be set through this (probably for both frameworks, not just FullCLR). I'm not sure about the version of culture values though. If we still need an assembly info source file, I imagine we could share it among the libraries.

122 changes: 122 additions & 0 deletions src/Microsoft.PowerShell.Commands.Diagnostics/CommonUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong SD changeset to import these files from. These must be copied from the latest tag, i.e. SD changeset 709776.

We cannot maintain the sync if the sources are imported from random changesets.

using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;


namespace Microsoft.PowerShell.Commands.Diagnostics.Common
{

internal class CommonUtilities
{
//
// No-op private ctor to prevent the default ctor from getting generated.
// This class is intended to only have static members.
//
private CommonUtilities() {}

//
// StringArrayToString helper converts a string array into a comma-separated string.
// Note this has only limited use, individual strings cannot have commas.
//
public static string StringArrayToString (IEnumerable input)
{
string ret = "";
foreach (string element in input)
{
ret += element + ", ";
}

ret = ret.TrimEnd();
ret = ret.TrimEnd(',');

return ret;
}


const uint FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
const uint FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
const uint FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
const uint FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
uint dwMessageId, uint dwLanguageId,
[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder lpBuffer,
uint nSize, IntPtr Arguments);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibraryEx(
[MarshalAs(UnmanagedType.LPWStr)] string lpFileName,
IntPtr hFile,
uint dwFlags
);

[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr hModule);


[DllImport("kernel32.dll", EntryPoint = "GetUserDefaultLangID", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
private static extern ushort GetUserDefaultLangID();


public static uint FormatMessageFromModule(uint lastError, string moduleName, out String msg)
{
Debug.Assert (!string.IsNullOrEmpty(moduleName));

uint formatError = 0;
msg = String.Empty;
IntPtr moduleHandle = IntPtr.Zero;

moduleHandle = LoadLibraryEx(moduleName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
if (moduleHandle == IntPtr.Zero)
{
return (uint)Marshal.GetLastWin32Error();
}

try
{
uint dwFormatFlags = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE;
uint LANGID = (uint)GetUserDefaultLangID();
uint langError = (uint)Marshal.GetLastWin32Error();
if (langError != 0)
{
LANGID = 0; // neutral
}

StringBuilder outStringBuilder = new StringBuilder(1024);
uint nChars = FormatMessage(dwFormatFlags,
moduleHandle,
lastError,
LANGID,
outStringBuilder,
(uint)outStringBuilder.Capacity,
IntPtr.Zero);

if (nChars == 0)
{
formatError = (uint)Marshal.GetLastWin32Error();
//Console.WriteLine("Win32FormatMessage", String.Format(null, "Error formatting message: {0}", formatError));
}
else
{
msg = outStringBuilder.ToString();
if (msg.EndsWith(Environment.NewLine, StringComparison.Ordinal))
{
msg = msg.Substring(0, msg.Length - 2);
}
}
}
finally
{
FreeLibrary(moduleHandle);
}
return formatError;
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;

namespace Microsoft.PowerShell.Commands.GetCounter
{


public class CounterFileInfo
{
internal CounterFileInfo(DateTime oldestRecord,
DateTime newestRecord,
UInt32 sampleCount)
{

_oldestRecord = oldestRecord;
_newestRecord = newestRecord;
_sampleCount = sampleCount;
}

internal CounterFileInfo(){}

public DateTime OldestRecord
{
get
{
return _oldestRecord;
}
}
private DateTime _oldestRecord = DateTime.MinValue;

public DateTime NewestRecord
{
get
{
return _newestRecord;
}
}
private DateTime _newestRecord = DateTime.MaxValue;

public UInt32 SampleCount
{
get
{
return _sampleCount;
}
}
private UInt32 _sampleCount = 0;

}

}

180 changes: 180 additions & 0 deletions src/Microsoft.PowerShell.Commands.Diagnostics/CounterSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
//
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//


using System;
using System.Reflection;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Resources;
using Microsoft.Powershell.Commands.GetCounter.PdhNative;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;


namespace Microsoft.PowerShell.Commands.GetCounter
{

public class PerformanceCounterSample
{
internal PerformanceCounterSample()
{
}

internal PerformanceCounterSample(string path,
string instanceName,
double cookedValue,
UInt64 rawValue,
UInt64 secondValue,
uint multiCount,
PerformanceCounterType counterType,
UInt32 defaultScale,
UInt64 timeBase,
DateTime timeStamp,
UInt64 timeStamp100nSec,
UInt32 status)
{
_path = path;
_instanceName = instanceName;
_cookedValue = cookedValue;
_rawValue = rawValue;
_secondValue = secondValue;
_multiCount = multiCount;
_counterType = counterType;
_defaultScale = defaultScale;
_timeBase = timeBase;
_timeStamp = timeStamp;
_timeStamp100nSec = timeStamp100nSec;
_status = status;
}

public string Path
{
get {return _path;}
set {_path = value;}
}
private string _path = "";


public string InstanceName
{
get {return _instanceName;}
set {_instanceName = value;}
}
private string _instanceName = "";


public double CookedValue
{
get {return _cookedValue;}
set {_cookedValue = value;}
}
private double _cookedValue = 0;

public UInt64 RawValue
{
get {return _rawValue;}
set {_rawValue = value;}
}
private UInt64 _rawValue = 0;

public UInt64 SecondValue
{
get {return _secondValue;}
set {_secondValue = value;}
}
private UInt64 _secondValue = 0;

public uint MultipleCount
{
get {return _multiCount;}
set {_multiCount = value;}
}
private uint _multiCount = 0;

public PerformanceCounterType CounterType
{
get {return _counterType;}
set {_counterType = value;}
}
private PerformanceCounterType _counterType = 0;

public DateTime Timestamp
{
get {return _timeStamp;}
set {_timeStamp = value;}
}
private DateTime _timeStamp = DateTime.MinValue;


public UInt64 Timestamp100NSec
{
get {return _timeStamp100nSec;}
set {_timeStamp100nSec = value;}
}
private UInt64 _timeStamp100nSec = 0;

public UInt32 Status
{
get {return _status;}
set {_status = value;}
}
private UInt32 _status = 0;

public UInt32 DefaultScale
{
get {return _defaultScale;}
set {_defaultScale = value;}
}
private UInt32 _defaultScale = 0;

public UInt64 TimeBase
{
get {return _timeBase;}
set {_timeBase = value;}
}
private UInt64 _timeBase = 0;



}

public class PerformanceCounterSampleSet
{
internal PerformanceCounterSampleSet()
{
_resourceMgr = new ResourceManager("GetEventResources", Assembly.GetExecutingAssembly());
}

internal PerformanceCounterSampleSet (DateTime timeStamp,
PerformanceCounterSample[] counterSamples,
bool firstSet) : this()
{
_timeStamp = timeStamp;
_counterSamples = counterSamples;
}

public DateTime Timestamp
{
get {return _timeStamp;}
set {_timeStamp = value;}
}
private DateTime _timeStamp = DateTime.MinValue;

[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
Scope = "member",
Target = "Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample.CounterSamples",
Justification="A string[] is required here because that is the type Powershell supports")]
public PerformanceCounterSample[] CounterSamples
{
get {return _counterSamples;}
set {_counterSamples = value;}
}
private PerformanceCounterSample[] _counterSamples = null;

private ResourceManager _resourceMgr = null;

}
}
Loading