Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed RunspaceConfiguration support #4942

Merged
merged 8 commits into from Oct 18, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -366,17 +366,13 @@ private void ProcessStrongTypeData()
else
{
// Update successfully, we add the TypeData into cache
if (Context.RunspaceConfiguration != null)
{
Context.RunspaceConfiguration.Types.Append(new TypeConfigurationEntry(type, false));
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
Context.InitialSessionState.Types.Add(new SessionStateTypeEntry(type, false));
}
else
{
Dbg.Assert(false, "Either RunspaceConfiguration or InitialSessionState must be non-null for Update-Typedata to work");
Dbg.Assert(false, "InitialSessionState must be non-null for Update-Typedata to work");
}
}
}
Expand Down Expand Up @@ -484,17 +480,13 @@ private void ProcessDynamicType()
else
{
// Update successfully, we add the TypeData into cache
if (Context.RunspaceConfiguration != null)
{
Context.RunspaceConfiguration.Types.Append(new TypeConfigurationEntry(type, false));
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
Context.InitialSessionState.Types.Add(new SessionStateTypeEntry(type, false));
}
else
{
Dbg.Assert(false, "Either RunspaceConfiguration or InitialSessionState must be non-null for Update-Typedata to work");
Dbg.Assert(false, "InitialSessionState must be non-null for Update-Typedata to work");
}
}
}
Expand Down Expand Up @@ -757,38 +749,7 @@ private void ProcessTypeFiles()
// filename is available
string target = UpdateDataStrings.UpdateTarget;

if (Context.RunspaceConfiguration != null)
{
for (int i = prependPathTotal.Count - 1; i >= 0; i--)
{
string formattedTarget = string.Format(CultureInfo.InvariantCulture, target, prependPathTotal[i]);

if (ShouldProcess(formattedTarget, action))
{
this.Context.RunspaceConfiguration.Types.Prepend(new TypeConfigurationEntry(prependPathTotal[i]));
}
}

foreach (string appendPathTotalItem in appendPathTotal)
{
string formattedTarget = string.Format(CultureInfo.InvariantCulture, target, appendPathTotalItem);

if (ShouldProcess(formattedTarget, action))
{
this.Context.RunspaceConfiguration.Types.Append(new TypeConfigurationEntry(appendPathTotalItem));
}
}

try
{
this.Context.CurrentRunspace.RunspaceConfiguration.Types.Update(true);
}
catch (RuntimeException e)
{
this.WriteError(new ErrorRecord(e, "TypesXmlUpdateException", ErrorCategory.InvalidOperation, null));
}
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
// This hashSet is to detect if there are duplicate type files
var fullFileNameHash = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase);
Expand Down Expand Up @@ -887,7 +848,7 @@ private void ProcessTypeFiles()
}
else
{
Dbg.Assert(false, "Either RunspaceConfiguration or InitialSessionState must be non-null for Update-Typedata to work");
Dbg.Assert(false, "InitialSessionState must be non-null for Update-Typedata to work");
}
}

Expand Down Expand Up @@ -931,38 +892,7 @@ protected override void ProcessRecord()
// filename is available
string target = UpdateDataStrings.UpdateTarget;

if (Context.RunspaceConfiguration != null)
{
for (int i = prependPathTotal.Count - 1; i >= 0; i--)
{
string formattedTarget = string.Format(CultureInfo.CurrentCulture, target, prependPathTotal[i]);

if (ShouldProcess(formattedTarget, action))
{
this.Context.RunspaceConfiguration.Formats.Prepend(new FormatConfigurationEntry(prependPathTotal[i]));
}
}

foreach (string appendPathTotalItem in appendPathTotal)
{
string formattedTarget = string.Format(CultureInfo.CurrentCulture, target, appendPathTotalItem);

if (ShouldProcess(formattedTarget, action))
{
this.Context.RunspaceConfiguration.Formats.Append(new FormatConfigurationEntry(appendPathTotalItem));
}
}

try
{
this.Context.CurrentRunspace.RunspaceConfiguration.Formats.Update(true);
}
catch (RuntimeException e)
{
this.WriteError(new ErrorRecord(e, "FormatXmlUpdateException", ErrorCategory.InvalidOperation, null));
}
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
if (Context.InitialSessionState.DisableFormatUpdates)
{
Expand Down Expand Up @@ -1055,12 +985,11 @@ protected override void ProcessRecord()
if (entries.Count > 0)
{
Context.FormatDBManager.UpdateDataBase(entries, this.Context.AuthorizationManager, this.Context.EngineHostInterface, false);
FormatAndTypeDataHelper.ThrowExceptionOnError(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this error processing removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

From the code, it appears that this helper is only used with RunspaceConfiguration processing Format and Type data.

Copy link
Member

Choose a reason for hiding this comment

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

I believe we still need this code. A test might look like:

"@
<Configuration>
  <ViewDefinitions>    
    <View>
      <Name>T2</Name>
    </View>   
  </ViewDefinitions>
</Configuration>
@" > test.format.ps1xml

{ Update-FormatData test.format.ps1xml } | Should Throw

In reply to: 142809956 [](ancestors = 142809956)

Copy link
Member Author

Choose a reason for hiding this comment

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

I misunderstood the relationship between the formatdata code and the runspace config code. Will put it back and add the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this (fixing the @" "@ here string) and it doesn't throw on Beta.8.

Copy link
Member

Choose a reason for hiding this comment

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

It does for me, Windows PowerShell and Beta 8 on Windows.

Copy link
Member Author

Choose a reason for hiding this comment

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

added back

Copy link
Member Author

Choose a reason for hiding this comment

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

repro'ing for me now, will add test

"ErrorsUpdatingFormats",
null,
entries,
RunspaceConfigurationCategory.Formats);
}
FormatAndTypeDataHelper.ThrowExceptionOnError( "ErrorsUpdatingFormats",
null,
entries,
RunspaceConfigurationCategory.Formats);
}
}
catch (RuntimeException e)
{
Expand All @@ -1069,7 +998,7 @@ protected override void ProcessRecord()
}
else
{
Dbg.Assert(false, "Either RunspaceConfiguration or InitialSessionState must be non-null for Update-FormatData to work");
Dbg.Assert(false, "InitialSessionState must be non-null for Update-FormatData to work");
}
}
}
Expand Down Expand Up @@ -1154,17 +1083,7 @@ protected override void ProcessRecord()
Dictionary<string, List<int>> fileToIndexMap = new Dictionary<string, List<int>>(StringComparer.OrdinalIgnoreCase);
List<int> indicesToRemove = new List<int>();

if (Context.RunspaceConfiguration != null)
{
for (int index = 0; index < Context.RunspaceConfiguration.Types.Count; index++)
{
string fileName = Context.RunspaceConfiguration.Types[index].FileName;
if (fileName == null) { continue; }

ConstructFileToIndexMap(fileName, index, fileToIndexMap);
}
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
for (int index = 0; index < Context.InitialSessionState.Types.Count; index++)
{
Expand Down Expand Up @@ -1200,23 +1119,15 @@ protected override void ProcessRecord()
indicesToRemove.Sort();
for (int i = indicesToRemove.Count - 1; i >= 0; i--)
{
if (Context.RunspaceConfiguration != null)
{
Context.RunspaceConfiguration.Types.RemoveItem(indicesToRemove[i]);
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
Context.InitialSessionState.Types.RemoveItem(indicesToRemove[i]);
}
}

try
{
if (Context.RunspaceConfiguration != null)
{
Context.RunspaceConfiguration.Types.Update();
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
bool oldRefreshTypeFormatSetting = Context.InitialSessionState.RefreshTypeAndFormatSetting;
try
Expand Down Expand Up @@ -1279,17 +1190,13 @@ protected override void ProcessRecord()
else
{
// Type is removed successfully, add it into the cache
if (Context.RunspaceConfiguration != null)
{
Context.RunspaceConfiguration.Types.Append(new TypeConfigurationEntry(type, true));
}
else if (Context.InitialSessionState != null)
if (Context.InitialSessionState != null)
{
Context.InitialSessionState.Types.Add(new SessionStateTypeEntry(type, true));
}
else
{
Dbg.Assert(false, "Either RunspaceConfiguration or InitialSessionState must be non-null for Remove-Typedata to work");
Dbg.Assert(false, "InitialSessionState must be non-null for Remove-Typedata to work");
}
}
}
Expand Down