MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Collections.ObjectModel;5using System.Management.Automation.Provider;6 7using Dbg = System.Management.Automation;8 9#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings10#pragma warning disable 5650011 12namespace System.Management.Automation13{14 /// <summary>15 /// Holds the state of a Monad Shell session.16 /// </summary>17 internal sealed partial class SessionStateInternal18 {19 #region IPropertyCmdletProvider accessors20 21 #region GetProperty22 23 /// <summary>24 /// Gets the specified properties from the specified item.25 /// </summary>26 /// <param name="paths">27 /// The path(s) to the item(s) to get the properties from.28 /// </param>29 /// <param name="providerSpecificPickList">30 /// A list of the properties that the provider should return.31 /// </param>32 /// <param name="literalPath">33 /// If true, globbing is not done on paths.34 /// </param>35 /// <returns>36 /// A property table container the properties and their values.37 /// </returns>38 /// <exception cref="ArgumentNullException">39 /// If <paramref name="path"/> is null.40 /// </exception>41 /// <exception cref="ProviderNotFoundException">42 /// If the <paramref name="path"/> refers to a provider that could not be found.43 /// </exception>44 /// <exception cref="DriveNotFoundException">45 /// If the <paramref name="path"/> refers to a drive that could not be found.46 /// </exception>47 /// <exception cref="NotSupportedException">48 /// If the provider that the <paramref name="path"/> refers to does49 /// not support this operation.50 /// </exception>51 /// <exception cref="ProviderInvocationException">52 /// If the provider threw an exception.53 /// </exception>54 internal Collection<PSObject> GetProperty(55 string[] paths,56 Collection<string> providerSpecificPickList,57 bool literalPath)58 {59 if (paths == null)60 {61 throw PSTraceSource.NewArgumentNullException("path");62 }63 64 CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);65 context.SuppressWildcardExpansion = literalPath;66 67 GetProperty(paths, providerSpecificPickList, context);68 69 context.ThrowFirstErrorOrDoNothing();70 71 Collection<PSObject> results = context.GetAccumulatedObjects();72 73 return results;74 }75 76 /// <summary>77 /// Gets the specified properties from the specified item.78 /// </summary>79 /// <param name="paths">80 /// The path(s) to the item(s) to get the properties from.81 /// </param>82 /// <param name="providerSpecificPickList">83 /// A list of the properties that the provider should return.84 /// </param>85 /// <param name="context">86 /// The context which the core command is running.87 /// </param>88 /// <returns>89 /// Nothing. A PSObject representing the properties should be written to the90 /// context.91 /// </returns>92 /// <exception cref="ArgumentNullException">93 /// If <paramref name="path"/> is null.94 /// </exception>95 /// <exception cref="ProviderNotFoundException">96 /// If the <paramref name="path"/> refers to a provider that could not be found.97 /// </exception>98 /// <exception cref="DriveNotFoundException">99 /// If the <paramref name="path"/> refers to a drive that could not be found.100 /// </exception>101 /// <exception cref="NotSupportedException">102 /// If the provider that the <paramref name="path"/> refers to does103 /// not support this operation.104 /// </exception>105 /// <exception cref="ProviderInvocationException">106 /// If the provider threw an exception.107 /// </exception>108 /// <exception cref="ItemNotFoundException">109 /// If <paramref name="path"/> does not contain glob characters and110 /// could not be found.111 /// </exception>112 internal void GetProperty(113 string[] paths,114 Collection<string> providerSpecificPickList,115 CmdletProviderContext context)116 {117 if (paths == null)118 {119 throw PSTraceSource.NewArgumentNullException(nameof(paths));120 }121 122 foreach (string path in paths)123 {124 if (path == null)125 {126 throw PSTraceSource.NewArgumentNullException(nameof(paths));127 }128 129 ProviderInfo provider = null;130 CmdletProvider providerInstance = null;131 132 Collection<string> providerPaths =133 Globber.GetGlobbedProviderPathsFromMonadPath(134 path,135 false,136 context,137 out provider,138 out providerInstance);139 140 foreach (string providerPath in providerPaths)141 {142 GetPropertyPrivate(143 providerInstance,144 providerPath,145 providerSpecificPickList,146 context);147 }148 }149 }150 151 /// <summary>152 /// Gets the property from the item at the specified path.153 /// </summary>154 /// <param name="providerInstance">155 /// The provider instance to use.156 /// </param>157 /// <param name="path">158 /// The path to the item if it was specified on the command line.159 /// </param>160 /// <param name="providerSpecificPickList">161 /// The names of the properties to get.162 /// </param>163 /// <param name="context">164 /// The context which the core command is running.165 /// </param>166 /// <exception cref="NotSupportedException">167 /// If the <paramref name="providerInstance"/> does not support this operation.168 /// </exception>169 /// <exception cref="PipelineStoppedException">170 /// If the pipeline is being stopped while executing the command.171 /// </exception>172 /// <exception cref="ProviderInvocationException">173 /// If the provider threw an exception.174 /// </exception>175 private void GetPropertyPrivate(176 CmdletProvider providerInstance,177 string path,178 Collection<string> providerSpecificPickList,179 CmdletProviderContext context)180 {181 // All parameters should have been validated by caller182 Dbg.Diagnostics.Assert(183 providerInstance != null,184 "Caller should validate providerInstance before calling this method");185 186 Dbg.Diagnostics.Assert(187 path != null,188 "Caller should validate path before calling this method");189 190 Dbg.Diagnostics.Assert(191 context != null,192 "Caller should validate context before calling this method");193 194 try195 {196 providerInstance.GetProperty(path, providerSpecificPickList, context);197 }198 catch (NotSupportedException)199 {200 throw;201 }202 catch (LoopFlowException)203 {204 throw;205 }206 catch (ActionPreferenceStopException)207 {208 throw;209 }210 catch (PipelineStoppedException)211 {212 throw;213 }214 catch (Exception e) // Catch-all OK, 3rd party callout.215 {216 throw NewProviderInvocationException(217 "GetPropertyProviderException",218 SessionStateStrings.GetPropertyProviderException,219 providerInstance.ProviderInfo,220 path,221 e);222 }223 }224 225 /// <summary>226 /// Gets the dynamic parameters for the get-itemproperty cmdlet.227 /// </summary>228 /// <param name="path">229 /// The path to the item if it was specified on the command line.230 /// </param>231 /// <param name="providerSpecificPickList">232 /// A list of the properties that the provider should return.233 /// </param>234 /// <param name="context">235 /// The context which the core command is running.236 /// </param>237 /// <returns>238 /// An object that has properties and fields decorated with239 /// parsing attributes similar to a cmdlet class.240 /// </returns>241 /// <exception cref="ProviderNotFoundException">242 /// If the <paramref name="path"/> refers to a provider that could not be found.243 /// </exception>244 /// <exception cref="DriveNotFoundException">245 /// If the <paramref name="path"/> refers to a drive that could not be found.246 /// </exception>247 /// <exception cref="NotSupportedException">248 /// If the provider that the <paramref name="path"/> refers to does249 /// not support this operation.250 /// </exception>251 /// <exception cref="ProviderInvocationException">252 /// If the provider threw an exception.253 /// </exception>254 /// <exception cref="ItemNotFoundException">255 /// If <paramref name="path"/> does not contain glob characters and256 /// could not be found.257 /// </exception>258 internal object GetPropertyDynamicParameters(259 string path,260 Collection<string> providerSpecificPickList,261 CmdletProviderContext context)262 {263 if (path == null)264 {265 return null;266 }267 268 ProviderInfo provider = null;269 CmdletProvider providerInstance = null;270 271 CmdletProviderContext newContext =272 new CmdletProviderContext(context);273 newContext.SetFilters(274 new Collection<string>(),275 new Collection<string>(),276 null);277 278 Collection<string> providerPaths =279 Globber.GetGlobbedProviderPathsFromMonadPath(280 path,281 true,282 newContext,283 out provider,284 out providerInstance);285 286 if (providerPaths.Count > 0)287 {288 // Get the dynamic parameters for the first resolved path289 290 return GetPropertyDynamicParameters(providerInstance, providerPaths[0], providerSpecificPickList, newContext);291 }292 293 return null;294 }295 296 /// <summary>297 /// Gets the dynamic parameters for the get-itemproperty cmdlet.298 /// </summary>299 /// <param name="path">300 /// The path to the item if it was specified on the command line.301 /// </param>302 /// <param name="providerSpecificPickList">303 /// The names of the properties to get.304 /// </param>305 /// <param name="providerInstance">306 /// The instance of the provider to use.307 /// </param>308 /// <param name="context">309 /// The context which the core command is running.310 /// </param>311 /// <returns>312 /// An object that has properties and fields decorated with313 /// parsing attributes similar to a cmdlet class.314 /// </returns>315 /// <exception cref="NotSupportedException">316 /// If the <paramref name="providerInstance"/> does not support this operation.317 /// </exception>318 /// <exception cref="PipelineStoppedException">319 /// If the pipeline is being stopped while executing the command.320 /// </exception>321 /// <exception cref="ProviderInvocationException">322 /// If the provider threw an exception.323 /// </exception>324 private object GetPropertyDynamicParameters(325 CmdletProvider providerInstance,326 string path,327 Collection<string> providerSpecificPickList,328 CmdletProviderContext context)329 {330 // All parameters should have been validated by caller331 Dbg.Diagnostics.Assert(332 providerInstance != null,333 "Caller should validate providerInstance before calling this method");334 335 Dbg.Diagnostics.Assert(336 path != null,337 "Caller should validate path before calling this method");338 339 Dbg.Diagnostics.Assert(340 context != null,341 "Caller should validate context before calling this method");342 343 object result = null;344 try345 {346 result = providerInstance.GetPropertyDynamicParameters(path, providerSpecificPickList, context);347 }348 catch (NotSupportedException)349 {350 throw;351 }352 catch (LoopFlowException)353 {354 throw;355 }356 catch (PipelineStoppedException)357 {358 throw;359 }360 catch (ActionPreferenceStopException)361 {362 throw;363 }364 catch (Exception e) // Catch-all OK, 3rd party callout.365 {366 throw NewProviderInvocationException(367 "GetPropertyDynamicParametersProviderException",368 SessionStateStrings.GetPropertyDynamicParametersProviderException,369 providerInstance.ProviderInfo,370 path,371 e);372 }373 374 return result;375 }376 377 #endregion GetProperty378 379 #region SetProperty380 381 /// <summary>382 /// Sets the specified properties on the specified item.383 /// </summary>384 /// <param name="paths">385 /// The path(s) to the item(s) to set the properties on.386 /// </param>387 /// <param name="property">388 /// A PSObject containing the properties to be changed.389 /// </param>390 /// <param name="force">391 /// Passed on to providers to force operations.392 /// </param>393 /// <param name="literalPath">394 /// If true, globbing is not done on paths.395 /// </param>396 /// <returns>397 /// An array of PSObjects representing the properties that were set on each item.398 /// </returns>399 /// <exception cref="ArgumentNullException">400 /// If <paramref name="path"/> or <paramref name="property"/> is null.401 /// </exception>402 /// <exception cref="ProviderNotFoundException">403 /// If the <paramref name="path"/> refers to a provider that could not be found.404 /// </exception>405 /// <exception cref="DriveNotFoundException">406 /// If the <paramref name="path"/> refers to a drive that could not be found.407 /// </exception>408 /// <exception cref="NotSupportedException">409 /// If the provider that the <paramref name="path"/> refers to does410 /// not support this operation.411 /// </exception>412 /// <exception cref="ProviderInvocationException">413 /// If the provider threw an exception.414 /// </exception>415 internal Collection<PSObject> SetProperty(string[] paths, PSObject property, bool force, bool literalPath)416 {417 if (paths == null)418 {419 throw PSTraceSource.NewArgumentNullException(nameof(paths));420 }421 422 if (property == null)423 {424 throw PSTraceSource.NewArgumentNullException("properties");425 }426 427 CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);428 context.Force = force;429 context.SuppressWildcardExpansion = literalPath;430 431 SetProperty(paths, property, context);432 433 context.ThrowFirstErrorOrDoNothing();434 435 Collection<PSObject> results = context.GetAccumulatedObjects();436 437 return results;438 }439 440 /// <summary>441 /// Sets the specified properties on specified item.442 /// </summary>443 /// <param name="paths">444 /// The path(s) to the item(s) to set the properties on.445 /// </param>446 /// <param name="property">447 /// A property table containing the properties and values to be set on the object.448 /// </param>449 /// <param name="context">450 /// The context which the core command is running.451 /// </param>452 /// <returns>453 /// Nothing. A PSObject is passed to the context for the properties on each item454 /// that were modified.455 /// </returns>456 /// <exception cref="ArgumentNullException">457 /// If <paramref name="path"/> or <paramref name="property"/> is null.458 /// </exception>459 /// <exception cref="ProviderNotFoundException">460 /// If the <paramref name="path"/> refers to a provider that could not be found.461 /// </exception>462 /// <exception cref="DriveNotFoundException">463 /// If the <paramref name="path"/> refers to a drive that could not be found.464 /// </exception>465 /// <exception cref="NotSupportedException">466 /// If the provider that the <paramref name="path"/> refers to does467 /// not support this operation.468 /// </exception>469 /// <exception cref="ProviderInvocationException">470 /// If the provider threw an exception.471 /// </exception>472 /// <exception cref="ItemNotFoundException">473 /// If <paramref name="path"/> does not contain glob characters and474 /// could not be found.475 /// </exception>476 internal void SetProperty(477 string[] paths,478 PSObject property,479 CmdletProviderContext context)480 {481 if (paths == null)482 {483 throw PSTraceSource.NewArgumentNullException(nameof(paths));484 }485 486 if (property == null)487 {488 throw PSTraceSource.NewArgumentNullException(nameof(property));489 }490 491 foreach (string path in paths)492 {493 if (path == null)494 {495 throw PSTraceSource.NewArgumentNullException(nameof(paths));496 }497 498 ProviderInfo provider = null;499 CmdletProvider providerInstance = null;500 501 Collection<string> providerPaths =502 Globber.GetGlobbedProviderPathsFromMonadPath(503 path,504 false,505 context,506 out provider,507 out providerInstance);508 509 if (providerPaths != null)510 {511 foreach (string providerPath in providerPaths)512 {513 SetPropertyPrivate(providerInstance, providerPath, property, context);514 }515 }516 }517 }518 519 /// <summary>520 /// Sets the property of the item at the specified path.521 /// </summary>522 /// <param name="providerInstance">523 /// The provider instance to use.524 /// </param>525 /// <param name="path">526 /// The path to the item if it was specified on the command line.527 /// </param>528 /// <param name="property">529 /// The name of the property to set.530 /// </param>531 /// <param name="context">532 /// The context which the core command is running.533 /// </param>534 /// <exception cref="NotSupportedException">535 /// If the <paramref name="providerInstance"/> does not support this operation.536 /// </exception>537 /// <exception cref="PipelineStoppedException">538 /// If the pipeline is being stopped while executing the command.539 /// </exception>540 /// <exception cref="ProviderInvocationException">541 /// If the provider threw an exception.542 /// </exception>543 private void SetPropertyPrivate(544 CmdletProvider providerInstance,545 string path,546 PSObject property,547 CmdletProviderContext context)548 {549 // All parameters should have been validated by caller550 Dbg.Diagnostics.Assert(551 providerInstance != null,552 "Caller should validate providerInstance before calling this method");553 554 Dbg.Diagnostics.Assert(555 path != null,556 "Caller should validate path before calling this method");557 558 Dbg.Diagnostics.Assert(559 property != null,560 "Caller should validate properties before calling this method");561 562 Dbg.Diagnostics.Assert(563 context != null,564 "Caller should validate context before calling this method");565 566 try567 {568 providerInstance.SetProperty(path, property, context);569 }570 catch (NotSupportedException)571 {572 throw;573 }574 catch (LoopFlowException)575 {576 throw;577 }578 catch (PipelineStoppedException)579 {580 throw;581 }582 catch (ActionPreferenceStopException)583 {584 throw;585 }586 catch (Exception e) // Catch-all OK, 3rd party callout.587 {588 throw NewProviderInvocationException(589 "SetPropertyProviderException",590 SessionStateStrings.SetPropertyProviderException,591 providerInstance.ProviderInfo,592 path,593 e);594 }595 }596 597 /// <summary>598 /// Gets the dynamic parameters for the clear-itemproperty cmdlet.599 /// </summary>600 /// <param name="path">601 /// The path to the item if it was specified on the command line.602 /// </param>603 /// <param name="propertyValue">604 /// A property table containing the properties and values to be set on the object.605 /// </param>606 /// <param name="context">607 /// The context which the core command is running.608 /// </param>609 /// <returns>610 /// An object that has properties and fields decorated with611 /// parsing attributes similar to a cmdlet class.612 /// </returns>613 /// <exception cref="ProviderNotFoundException">614 /// If the <paramref name="path"/> refers to a provider that could not be found.615 /// </exception>616 /// <exception cref="DriveNotFoundException">617 /// If the <paramref name="path"/> refers to a drive that could not be found.618 /// </exception>619 /// <exception cref="NotSupportedException">620 /// If the provider that the <paramref name="path"/> refers to does621 /// not support this operation.622 /// </exception>623 /// <exception cref="ProviderInvocationException">624 /// If the provider threw an exception.625 /// </exception>626 /// <exception cref="ItemNotFoundException">627 /// If <paramref name="path"/> does not contain glob characters and628 /// could not be found.629 /// </exception>630 internal object SetPropertyDynamicParameters(631 string path,632 PSObject propertyValue,633 CmdletProviderContext context)634 {635 if (path == null)636 {637 return null;638 }639 640 ProviderInfo provider = null;641 CmdletProvider providerInstance = null;642 643 CmdletProviderContext newContext =644 new CmdletProviderContext(context);645 newContext.SetFilters(646 new Collection<string>(),647 new Collection<string>(),648 null);649 650 Collection<string> providerPaths =651 Globber.GetGlobbedProviderPathsFromMonadPath(652 path,653 true,654 newContext,655 out provider,656 out providerInstance);657 658 if (providerPaths.Count > 0)659 {660 // Get the dynamic parameters for the first resolved path661 662 return SetPropertyDynamicParameters(providerInstance, providerPaths[0], propertyValue, newContext);663 }664 665 return null;666 }667 668 /// <summary>669 /// Gets the dynamic parameters for the set-itemproperty cmdlet.670 /// </summary>671 /// <param name="path">672 /// The path to the item if it was specified on the command line.673 /// </param>674 /// <param name="propertyValue">675 /// The value of the property to set.676 /// </param>677 /// <param name="providerInstance">678 /// The instance of the provider to use.679 /// </param>680 /// <param name="context">681 /// The context which the core command is running.682 /// </param>683 /// <returns>684 /// An object that has properties and fields decorated with685 /// parsing attributes similar to a cmdlet class.686 /// </returns>687 /// <exception cref="NotSupportedException">688 /// If the <paramref name="providerInstance"/> does not support this operation.689 /// </exception>690 /// <exception cref="PipelineStoppedException">691 /// If the pipeline is being stopped while executing the command.692 /// </exception>693 /// <exception cref="ProviderInvocationException">694 /// If the provider threw an exception.695 /// </exception>696 private object SetPropertyDynamicParameters(697 CmdletProvider providerInstance,698 string path,699 PSObject propertyValue,700 CmdletProviderContext context)701 {702 // All parameters should have been validated by caller703 Dbg.Diagnostics.Assert(704 providerInstance != null,705 "Caller should validate providerInstance before calling this method");706 707 Dbg.Diagnostics.Assert(708 path != null,709 "Caller should validate path before calling this method");710 711 Dbg.Diagnostics.Assert(712 context != null,713 "Caller should validate context before calling this method");714 715 object result = null;716 try717 {718 result = providerInstance.SetPropertyDynamicParameters(path, propertyValue, context);719 }720 catch (NotSupportedException)721 {722 throw;723 }724 catch (LoopFlowException)725 {726 throw;727 }728 catch (PipelineStoppedException)729 {730 throw;731 }732 catch (ActionPreferenceStopException)733 {734 throw;735 }736 catch (Exception e) // Catch-all OK, 3rd party callout.737 {738 throw NewProviderInvocationException(739 "SetPropertyDynamicParametersProviderException",740 SessionStateStrings.SetPropertyDynamicParametersProviderException,741 providerInstance.ProviderInfo,742 path,743 e);744 }745 746 return result;747 }748 749 #endregion SetProperty750 751 #region ClearProperty752 753 /// <summary>754 /// Clears the specified property on the specified item.755 /// </summary>756 /// <param name="paths">757 /// The path(s) to the item(s) to clear the property on.758 /// </param>759 /// <param name="propertyToClear">760 /// The name of the property to clear.761 /// </param>762 /// <param name="force">763 /// Passed on to providers to force operations.764 /// </param>765 /// <param name="literalPath">766 /// If true, globbing is not done on paths.767 /// </param>768 /// <exception cref="ArgumentNullException">769 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.770 /// </exception>771 /// <exception cref="ProviderNotFoundException">772 /// If the <paramref name="path"/> refers to a provider that could not be found.773 /// </exception>774 /// <exception cref="DriveNotFoundException">775 /// If the <paramref name="path"/> refers to a drive that could not be found.776 /// </exception>777 /// <exception cref="NotSupportedException">778 /// If the provider that the <paramref name="path"/> refers to does779 /// not support this operation.780 /// </exception>781 /// <exception cref="ProviderInvocationException">782 /// If the provider threw an exception.783 /// </exception>784 internal void ClearProperty(785 string[] paths,786 Collection<string> propertyToClear,787 bool force,788 bool literalPath)789 {790 if (paths == null)791 {792 throw PSTraceSource.NewArgumentNullException(nameof(paths));793 }794 795 if (propertyToClear == null)796 {797 throw PSTraceSource.NewArgumentNullException(nameof(propertyToClear));798 }799 800 CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);801 context.Force = force;802 context.SuppressWildcardExpansion = literalPath;803 804 ClearProperty(paths, propertyToClear, context);805 806 context.ThrowFirstErrorOrDoNothing();807 }808 809 /// <summary>810 /// Clears the specified property in the specified item.811 /// </summary>812 /// <param name="paths">813 /// The path(s) to the item(s) to clear the property on.814 /// </param>815 /// <param name="propertyToClear">816 /// A property table containing the property to clear.817 /// </param>818 /// <param name="context">819 /// The context which the core command is running.820 /// </param>821 /// <exception cref="ArgumentNullException">822 /// If <paramref name="path"/> or <paramref name="propertyToClear"/> is null.823 /// </exception>824 /// <exception cref="ProviderNotFoundException">825 /// If the <paramref name="path"/> refers to a provider that could not be found.826 /// </exception>827 /// <exception cref="DriveNotFoundException">828 /// If the <paramref name="path"/> refers to a drive that could not be found.829 /// </exception>830 /// <exception cref="NotSupportedException">831 /// If the provider that the <paramref name="path"/> refers to does832 /// not support this operation.833 /// </exception>834 /// <exception cref="ProviderInvocationException">835 /// If the provider threw an exception.836 /// </exception>837 /// <exception cref="ItemNotFoundException">838 /// If <paramref name="path"/> does not contain glob characters and839 /// could not be found.840 /// </exception>841 internal void ClearProperty(842 string[] paths,843 Collection<string> propertyToClear,844 CmdletProviderContext context)845 {846 if (paths == null)847 {848 throw PSTraceSource.NewArgumentNullException(nameof(paths));849 }850 851 if (propertyToClear == null)852 {853 throw PSTraceSource.NewArgumentNullException(nameof(propertyToClear));854 }855 856 foreach (string path in paths)857 {858 if (path == null)859 {860 throw PSTraceSource.NewArgumentNullException(nameof(paths));861 }862 863 ProviderInfo provider = null;864 CmdletProvider providerInstance = null;865 866 Collection<string> providerPaths =867 Globber.GetGlobbedProviderPathsFromMonadPath(868 path,869 false,870 context,871 out provider,872 out providerInstance);873 874 foreach (string providerPath in providerPaths)875 {876 ClearPropertyPrivate(providerInstance, providerPath, propertyToClear, context);877 }878 }879 }880 881 /// <summary>882 /// Clears the value of the property from the item at the specified path.883 /// </summary>884 /// <param name="providerInstance">885 /// The provider instance to use.886 /// </param>887 /// <param name="path">888 /// The path to the item if it was specified on the command line.889 /// </param>890 /// <param name="propertyToClear">891 /// The name of the property to clear.892 /// </param>893 /// <param name="context">894 /// The context which the core command is running.895 /// </param>896 /// <exception cref="NotSupportedException">897 /// If the <paramref name="providerInstance"/> does not support this operation.898 /// </exception>899 /// <exception cref="PipelineStoppedException">900 /// If the pipeline is being stopped while executing the command.901 /// </exception>902 /// <exception cref="ProviderInvocationException">903 /// If the provider threw an exception.904 /// </exception>905 private void ClearPropertyPrivate(906 CmdletProvider providerInstance,907 string path,908 Collection<string> propertyToClear,909 CmdletProviderContext context)910 {911 // All parameters should have been validated by caller912 Dbg.Diagnostics.Assert(913 providerInstance != null,914 "Caller should validate providerInstance before calling this method");915 916 Dbg.Diagnostics.Assert(917 path != null,918 "Caller should validate path before calling this method");919 920 Dbg.Diagnostics.Assert(921 propertyToClear != null,922 "Caller should validate propertyToClear before calling this method");923 924 Dbg.Diagnostics.Assert(925 context != null,926 "Caller should validate context before calling this method");927 928 try929 {930 providerInstance.ClearProperty(path, propertyToClear, context);931 }932 catch (NotSupportedException)933 {934 throw;935 }936 catch (LoopFlowException)937 {938 throw;939 }940 catch (PipelineStoppedException)941 {942 throw;943 }944 catch (ActionPreferenceStopException)945 {946 throw;947 }948 catch (Exception e) // Catch-all OK, 3rd party callout.949 {950 throw NewProviderInvocationException(951 "ClearPropertyProviderException",952 SessionStateStrings.ClearPropertyProviderException,953 providerInstance.ProviderInfo,954 path,955 e);956 }957 }958 959 /// <summary>960 /// Gets the dynamic parameters for the clear-itemproperty cmdlet.961 /// </summary>962 /// <param name="path">963 /// The path to the item if it was specified on the command line.964 /// </param>965 /// <param name="propertyToClear">966 /// A property table containing the property to clear.967 /// </param>968 /// <param name="context">969 /// The context which the core command is running.970 /// </param>971 /// <returns>972 /// An object that has properties and fields decorated with973 /// parsing attributes similar to a cmdlet class.974 /// </returns>975 /// <exception cref="ProviderNotFoundException">976 /// If the <paramref name="path"/> refers to a provider that could not be found.977 /// </exception>978 /// <exception cref="DriveNotFoundException">979 /// If the <paramref name="path"/> refers to a drive that could not be found.980 /// </exception>981 /// <exception cref="NotSupportedException">982 /// If the provider that the <paramref name="path"/> refers to does983 /// not support this operation.984 /// </exception>985 /// <exception cref="ProviderInvocationException">986 /// If the provider threw an exception.987 /// </exception>988 /// <exception cref="ItemNotFoundException">989 /// If <paramref name="path"/> does not contain glob characters and990 /// could not be found.991 /// </exception>992 internal object ClearPropertyDynamicParameters(993 string path,994 Collection<string> propertyToClear,995 CmdletProviderContext context)996 {997 if (path == null)998 {999 return null;1000 }1001 1002 ProviderInfo provider = null;1003 CmdletProvider providerInstance = null;1004 1005 CmdletProviderContext newContext =1006 new CmdletProviderContext(context);1007 newContext.SetFilters(1008 new Collection<string>(),1009 new Collection<string>(),1010 null);1011 1012 Collection<string> providerPaths =1013 Globber.GetGlobbedProviderPathsFromMonadPath(1014 path,1015 true,1016 newContext,1017 out provider,1018 out providerInstance);1019 1020 if (providerPaths.Count > 0)1021 {1022 // Get the dynamic parameters for the first resolved path1023 1024 return ClearPropertyDynamicParameters(providerInstance, providerPaths[0], propertyToClear, newContext);1025 }1026 1027 return null;1028 }1029 1030 /// <summary>1031 /// Gets the dynamic parameters for the clear-itemproperty cmdlet.1032 /// </summary>1033 /// <param name="path">1034 /// The path to the item if it was specified on the command line.1035 /// </param>1036 /// <param name="propertyToClear">1037 /// The name of the property to clear.1038 /// </param>1039 /// <param name="providerInstance">1040 /// The instance of the provider to use.1041 /// </param>1042 /// <param name="context">1043 /// The context which the core command is running.1044 /// </param>1045 /// <returns>1046 /// An object that has properties and fields decorated with1047 /// parsing attributes similar to a cmdlet class.1048 /// </returns>1049 /// <exception cref="NotSupportedException">1050 /// If the <paramref name="providerInstance"/> does not support this operation.1051 /// </exception>1052 /// <exception cref="PipelineStoppedException">1053 /// If the pipeline is being stopped while executing the command.1054 /// </exception>1055 /// <exception cref="ProviderInvocationException">1056 /// If the provider threw an exception.1057 /// </exception>1058 private object ClearPropertyDynamicParameters(1059 CmdletProvider providerInstance,1060 string path,1061 Collection<string> propertyToClear,1062 CmdletProviderContext context)1063 {1064 // All parameters should have been validated by caller1065 Dbg.Diagnostics.Assert(1066 providerInstance != null,1067 "Caller should validate providerInstance before calling this method");1068 1069 Dbg.Diagnostics.Assert(1070 path != null,1071 "Caller should validate path before calling this method");1072 1073 Dbg.Diagnostics.Assert(1074 context != null,1075 "Caller should validate context before calling this method");1076 1077 object result = null;1078 1079 try1080 {1081 result = providerInstance.ClearPropertyDynamicParameters(path, propertyToClear, context);1082 }1083 catch (NotSupportedException)1084 {1085 throw;1086 }1087 catch (LoopFlowException)1088 {1089 throw;1090 }1091 catch (PipelineStoppedException)1092 {1093 throw;1094 }1095 catch (ActionPreferenceStopException)1096 {1097 throw;1098 }1099 catch (Exception e) // Catch-all OK, 3rd party callout.1100 {1101 throw NewProviderInvocationException(1102 "ClearPropertyDynamicParametersProviderException",1103 SessionStateStrings.ClearPropertyDynamicParametersProviderException,1104 providerInstance.ProviderInfo,1105 path,1106 e);1107 }1108 1109 return result;1110 }1111 1112 #endregion ClearProperty1113 1114 #endregion IPropertyCmdletProvider accessors1115 }1116}1117 1118#pragma warning restore 565001119 