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 IContentCmdletProvider accessors20 21 #region GetContentReader22 23 /// <summary>24 /// Gets the content reader for the specified item.25 /// </summary>26 /// <param name="paths">27 /// The path(s) to the item(s) to get the content reader for.28 /// </param>29 /// <param name="force">30 /// Passed on to providers to force operations.31 /// </param>32 /// <param name="literalPath">33 /// If true, globbing is not done on paths.34 /// </param>35 /// <returns>36 /// The content readers for all items that the path resolves to.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<IContentReader> GetContentReader(string[] paths, bool force, bool literalPath)55 {56 if (paths == null)57 {58 throw PSTraceSource.NewArgumentNullException(nameof(paths));59 }60 61 CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);62 context.Force = force;63 context.SuppressWildcardExpansion = literalPath;64 65 Collection<IContentReader> results = GetContentReader(paths, context);66 67 context.ThrowFirstErrorOrDoNothing();68 69 return results;70 }71 72 /// <summary>73 /// Gets the content reader for the specified item.74 /// </summary>75 /// <param name="paths">76 /// The path(s) to the item(s) to get the content reader from.77 /// </param>78 /// <param name="context">79 /// The context which the core command is running.80 /// </param>81 /// <returns>82 /// The content readers for all items that the path resolves to.83 /// </returns>84 /// <exception cref="ArgumentNullException">85 /// If <paramref name="path"/> is null.86 /// </exception>87 /// <exception cref="ProviderNotFoundException">88 /// If the <paramref name="path"/> refers to a provider that could not be found.89 /// </exception>90 /// <exception cref="DriveNotFoundException">91 /// If the <paramref name="path"/> refers to a drive that could not be found.92 /// </exception>93 /// <exception cref="NotSupportedException">94 /// If the provider that the <paramref name="path"/> refers to does95 /// not support this operation.96 /// </exception>97 /// <exception cref="ProviderInvocationException">98 /// If the provider threw an exception.99 /// </exception>100 /// <exception cref="ItemNotFoundException">101 /// If <paramref name="path"/> does not contain glob characters and102 /// could not be found.103 /// </exception>104 internal Collection<IContentReader> GetContentReader(105 string[] paths,106 CmdletProviderContext context)107 {108 if (paths == null)109 {110 throw PSTraceSource.NewArgumentNullException(nameof(paths));111 }112 113 ProviderInfo provider = null;114 CmdletProvider providerInstance = null;115 116 Collection<IContentReader> results = new Collection<IContentReader>();117 118 foreach (string path in paths)119 {120 if (path == null)121 {122 throw PSTraceSource.NewArgumentNullException(nameof(paths));123 }124 125 Collection<string> providerPaths =126 Globber.GetGlobbedProviderPathsFromMonadPath(127 path,128 false,129 context,130 out provider,131 out providerInstance);132 133 foreach (string providerPath in providerPaths)134 {135 IContentReader reader = GetContentReaderPrivate(providerInstance, providerPath, context);136 137 if (reader != null)138 {139 results.Add(reader);140 }141 142 context.ThrowFirstErrorOrDoNothing(true);143 }144 }145 146 return results;147 }148 149 /// <summary>150 /// Gets the content reader for the item at the specified path.151 /// </summary>152 /// <param name="providerInstance">153 /// The provider instance to use.154 /// </param>155 /// <param name="path">156 /// The path to the item if it was specified on the command line.157 /// </param>158 /// <param name="context">159 /// The context which the core command is running.160 /// </param>161 /// <exception cref="NotSupportedException">162 /// If the <paramref name="providerInstance"/> does not support this operation.163 /// </exception>164 /// <exception cref="PipelineStoppedException">165 /// If the pipeline is being stopped while executing the command.166 /// </exception>167 /// <exception cref="ProviderInvocationException">168 /// If the provider threw an exception.169 /// </exception>170 private IContentReader GetContentReaderPrivate(171 CmdletProvider providerInstance,172 string path,173 CmdletProviderContext context)174 {175 // All parameters should have been validated by caller176 Dbg.Diagnostics.Assert(177 providerInstance != null,178 "Caller should validate providerInstance before calling this method");179 180 Dbg.Diagnostics.Assert(181 path != null,182 "Caller should validate path before calling this method");183 184 Dbg.Diagnostics.Assert(185 context != null,186 "Caller should validate context before calling this method");187 188 IContentReader result = null;189 190 try191 {192 result = providerInstance.GetContentReader(path, context);193 }194 catch (NotSupportedException)195 {196 throw;197 }198 catch (LoopFlowException)199 {200 throw;201 }202 catch (PipelineStoppedException)203 {204 throw;205 }206 catch (ActionPreferenceStopException)207 {208 throw;209 }210 catch (Exception e) // Catch-all OK, 3rd party callout.211 {212 throw NewProviderInvocationException(213 "GetContentReaderProviderException",214 SessionStateStrings.GetContentReaderProviderException,215 providerInstance.ProviderInfo,216 path,217 e);218 }219 220 return result;221 }222 223 /// <summary>224 /// Gets the dynamic parameters for the get-content cmdlet.225 /// </summary>226 /// <param name="path">227 /// The path to the item if it was specified on the command line.228 /// </param>229 /// <param name="context">230 /// The context which the core command is running.231 /// </param>232 /// <returns>233 /// An object that has properties and fields decorated with234 /// parsing attributes similar to a cmdlet class.235 /// </returns>236 /// <exception cref="ProviderNotFoundException">237 /// If the <paramref name="path"/> refers to a provider that could not be found.238 /// </exception>239 /// <exception cref="DriveNotFoundException">240 /// If the <paramref name="path"/> refers to a drive that could not be found.241 /// </exception>242 /// <exception cref="NotSupportedException">243 /// If the provider that the <paramref name="path"/> refers to does244 /// not support this operation.245 /// </exception>246 /// <exception cref="ProviderInvocationException">247 /// If the provider threw an exception.248 /// </exception>249 /// <exception cref="ItemNotFoundException">250 /// If <paramref name="path"/> does not contain glob characters and251 /// could not be found.252 /// </exception>253 internal object GetContentReaderDynamicParameters(254 string path,255 CmdletProviderContext context)256 {257 if (path == null)258 {259 return null;260 }261 262 ProviderInfo provider = null;263 CmdletProvider providerInstance = null;264 265 CmdletProviderContext newContext =266 new CmdletProviderContext(context);267 newContext.SetFilters(268 new Collection<string>(),269 new Collection<string>(),270 null);271 272 Collection<string> providerPaths =273 Globber.GetGlobbedProviderPathsFromMonadPath(274 path,275 true,276 newContext,277 out provider,278 out providerInstance);279 280 return GetContentReaderDynamicParameters(providerInstance, path, newContext);281 }282 283 /// <summary>284 /// Gets the dynamic parameters for the get-content cmdlet.285 /// </summary>286 /// <param name="path">287 /// The path to the item if it was specified on the command line.288 /// </param>289 /// <param name="providerInstance">290 /// The instance of the provider to use.291 /// </param>292 /// <param name="context">293 /// The context which the core command is running.294 /// </param>295 /// <returns>296 /// An object that has properties and fields decorated with297 /// parsing attributes similar to a cmdlet class.298 /// </returns>299 /// <exception cref="NotSupportedException">300 /// If the <paramref name="providerInstance"/> does not support this operation.301 /// </exception>302 /// <exception cref="PipelineStoppedException">303 /// If the pipeline is being stopped while executing the command.304 /// </exception>305 /// <exception cref="ProviderInvocationException">306 /// If the provider threw an exception.307 /// </exception>308 private object GetContentReaderDynamicParameters(309 CmdletProvider providerInstance,310 string path,311 CmdletProviderContext context)312 {313 // All parameters should have been validated by caller314 Dbg.Diagnostics.Assert(315 providerInstance != null,316 "Caller should validate providerInstance before calling this method");317 318 Dbg.Diagnostics.Assert(319 path != null,320 "Caller should validate path before calling this method");321 322 Dbg.Diagnostics.Assert(323 context != null,324 "Caller should validate context before calling this method");325 326 object result = null;327 try328 {329 result = providerInstance.GetContentReaderDynamicParameters(path, context);330 }331 catch (NotSupportedException)332 {333 throw;334 }335 catch (LoopFlowException)336 {337 throw;338 }339 catch (PipelineStoppedException)340 {341 throw;342 }343 catch (ActionPreferenceStopException)344 {345 throw;346 }347 catch (Exception e) // Catch-all OK, 3rd party callout.348 {349 throw NewProviderInvocationException(350 "GetContentReaderDynamicParametersProviderException",351 SessionStateStrings.GetContentReaderDynamicParametersProviderException,352 providerInstance.ProviderInfo,353 path,354 e);355 }356 357 return result;358 }359 360 #endregion GetContentReader361 362 #region GetContentWriter363 364 /// <summary>365 /// Gets the content writer for the specified item.366 /// </summary>367 /// <param name="paths">368 /// The path(s) to the item(s) to get the content writer for.369 /// </param>370 /// <param name="force">371 /// Passed on to providers to force operations.372 /// </param>373 /// <param name="literalPath">374 /// If true, globbing is not done on paths.375 /// </param>376 /// <returns>377 /// The content writers for all items that the path resolves to.378 /// </returns>379 /// <exception cref="ArgumentNullException">380 /// If <paramref name="path"/> is null.381 /// </exception>382 /// <exception cref="ProviderNotFoundException">383 /// If the <paramref name="path"/> refers to a provider that could not be found.384 /// </exception>385 /// <exception cref="DriveNotFoundException">386 /// If the <paramref name="path"/> refers to a drive that could not be found.387 /// </exception>388 /// <exception cref="NotSupportedException">389 /// If the provider that the <paramref name="path"/> refers to does390 /// not support this operation.391 /// </exception>392 /// <exception cref="ProviderInvocationException">393 /// If the provider threw an exception.394 /// </exception>395 internal Collection<IContentWriter> GetContentWriter(string[] paths, bool force, bool literalPath)396 {397 if (paths == null)398 {399 throw PSTraceSource.NewArgumentNullException(nameof(paths));400 }401 402 CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);403 context.Force = force;404 context.SuppressWildcardExpansion = literalPath;405 406 Collection<IContentWriter> results = GetContentWriter(paths, context);407 408 context.ThrowFirstErrorOrDoNothing();409 410 return results;411 }412 413 /// <summary>414 /// Gets the content writer for the specified item.415 /// </summary>416 /// <param name="paths">417 /// The path(s) to the item(s) to get the content writer from.418 /// </param>419 /// <param name="context">420 /// The context which the core command is running.421 /// </param>422 /// <returns>423 /// The content writers for all items that the path resolves to.424 /// </returns>425 /// <exception cref="ArgumentNullException">426 /// If <paramref name="path"/> is null.427 /// </exception>428 /// <exception cref="ProviderNotFoundException">429 /// If the <paramref name="path"/> refers to a provider that could not be found.430 /// </exception>431 /// <exception cref="DriveNotFoundException">432 /// If the <paramref name="path"/> refers to a drive that could not be found.433 /// </exception>434 /// <exception cref="NotSupportedException">435 /// If the provider that the <paramref name="path"/> refers to does436 /// not support this operation.437 /// </exception>438 /// <exception cref="ProviderInvocationException">439 /// If the provider threw an exception.440 /// </exception>441 /// <exception cref="ItemNotFoundException">442 /// If <paramref name="path"/> does not contain glob characters and443 /// could not be found.444 /// </exception>445 internal Collection<IContentWriter> GetContentWriter(446 string[] paths,447 CmdletProviderContext context)448 {449 if (paths == null)450 {451 throw PSTraceSource.NewArgumentNullException(nameof(paths));452 }453 454 ProviderInfo provider = null;455 CmdletProvider providerInstance = null;456 Collection<IContentWriter> results = new Collection<IContentWriter>();457 458 foreach (string path in paths)459 {460 if (path == null)461 {462 throw PSTraceSource.NewArgumentNullException(nameof(paths));463 }464 465 Collection<string> providerPaths =466 Globber.GetGlobbedProviderPathsFromMonadPath(467 path,468 true,469 context,470 out provider,471 out providerInstance);472 473 foreach (string providerPath in providerPaths)474 {475 IContentWriter result =476 GetContentWriterPrivate(providerInstance, providerPath, context);477 478 if (result != null)479 {480 results.Add(result);481 }482 }483 }484 485 return results;486 }487 488 /// <summary>489 /// Gets the content writer for the item at the specified path.490 /// </summary>491 /// <param name="providerInstance">492 /// The provider instance to use.493 /// </param>494 /// <param name="path">495 /// The path to the item if it was specified on the command line.496 /// </param>497 /// <param name="context">498 /// The context which the core command is running.499 /// </param>500 /// <exception cref="NotSupportedException">501 /// If the <paramref name="providerInstance"/> does not support this operation.502 /// </exception>503 /// <exception cref="PipelineStoppedException">504 /// If the pipeline is being stopped while executing the command.505 /// </exception>506 /// <exception cref="ProviderInvocationException">507 /// If the provider threw an exception.508 /// </exception>509 private IContentWriter GetContentWriterPrivate(510 CmdletProvider providerInstance,511 string path,512 CmdletProviderContext context)513 {514 // All parameters should have been validated by caller515 Dbg.Diagnostics.Assert(516 providerInstance != null,517 "Caller should validate providerInstance before calling this method");518 519 Dbg.Diagnostics.Assert(520 path != null,521 "Caller should validate path before calling this method");522 523 Dbg.Diagnostics.Assert(524 context != null,525 "Caller should validate context before calling this method");526 527 IContentWriter result = null;528 try529 {530 result = providerInstance.GetContentWriter(path, context);531 }532 catch (NotSupportedException)533 {534 throw;535 }536 catch (LoopFlowException)537 {538 throw;539 }540 catch (PipelineStoppedException)541 {542 throw;543 }544 catch (ActionPreferenceStopException)545 {546 throw;547 }548 catch (Exception e) // Catch-all OK, 3rd party callout.549 {550 throw NewProviderInvocationException(551 "GetContentWriterProviderException",552 SessionStateStrings.GetContentWriterProviderException,553 providerInstance.ProviderInfo,554 path,555 e);556 }557 558 return result;559 }560 561 /// <summary>562 /// Gets the dynamic parameters for the set-content and add-content cmdlet.563 /// </summary>564 /// <param name="path">565 /// The path to the item if it was specified on the command line.566 /// </param>567 /// <param name="context">568 /// The context which the core command is running.569 /// </param>570 /// <returns>571 /// An object that has properties and fields decorated with572 /// parsing attributes similar to a cmdlet class.573 /// </returns>574 /// <exception cref="ProviderNotFoundException">575 /// If the <paramref name="path"/> refers to a provider that could not be found.576 /// </exception>577 /// <exception cref="DriveNotFoundException">578 /// If the <paramref name="path"/> refers to a drive that could not be found.579 /// </exception>580 /// <exception cref="NotSupportedException">581 /// If the provider that the <paramref name="path"/> refers to does582 /// not support this operation.583 /// </exception>584 /// <exception cref="ProviderInvocationException">585 /// If the provider threw an exception.586 /// </exception>587 /// <exception cref="ItemNotFoundException">588 /// If <paramref name="path"/> does not contain glob characters and589 /// could not be found.590 /// </exception>591 internal object GetContentWriterDynamicParameters(592 string path,593 CmdletProviderContext context)594 {595 if (path == null)596 {597 return null;598 }599 600 ProviderInfo provider = null;601 CmdletProvider providerInstance = null;602 603 CmdletProviderContext newContext =604 new CmdletProviderContext(context);605 newContext.SetFilters(606 new Collection<string>(),607 new Collection<string>(),608 null);609 610 Collection<string> providerPaths =611 Globber.GetGlobbedProviderPathsFromMonadPath(612 path,613 true,614 newContext,615 out provider,616 out providerInstance);617 618 if (providerPaths.Count > 0)619 {620 // Get the dynamic parameters for the first resolved path621 622 return GetContentWriterDynamicParameters(providerInstance, providerPaths[0], newContext);623 }624 625 return null;626 }627 628 /// <summary>629 /// Gets the dynamic parameters for the set-content and add-content cmdlet.630 /// </summary>631 /// <param name="path">632 /// The path to the item if it was specified on the command line.633 /// </param>634 /// <param name="providerInstance">635 /// The instance of the provider to use.636 /// </param>637 /// <param name="context">638 /// The context which the core command is running.639 /// </param>640 /// <returns>641 /// An object that has properties and fields decorated with642 /// parsing attributes similar to a cmdlet class.643 /// </returns>644 /// <exception cref="NotSupportedException">645 /// If the <paramref name="providerInstance"/> does not support this operation.646 /// </exception>647 /// <exception cref="PipelineStoppedException">648 /// If the pipeline is being stopped while executing the command.649 /// </exception>650 /// <exception cref="ProviderInvocationException">651 /// If the provider threw an exception.652 /// </exception>653 private object GetContentWriterDynamicParameters(654 CmdletProvider providerInstance,655 string path,656 CmdletProviderContext context)657 {658 // All parameters should have been validated by caller659 Dbg.Diagnostics.Assert(660 providerInstance != null,661 "Caller should validate providerInstance before calling this method");662 663 Dbg.Diagnostics.Assert(664 path != null,665 "Caller should validate path before calling this method");666 667 Dbg.Diagnostics.Assert(668 context != null,669 "Caller should validate context before calling this method");670 671 object result = null;672 try673 {674 result = providerInstance.GetContentWriterDynamicParameters(path, context);675 }676 catch (NotSupportedException)677 {678 throw;679 }680 catch (LoopFlowException)681 {682 throw;683 }684 catch (PipelineStoppedException)685 {686 throw;687 }688 catch (ActionPreferenceStopException)689 {690 throw;691 }692 catch (Exception e) // Catch-all OK, 3rd party callout.693 {694 throw NewProviderInvocationException(695 "GetContentWriterDynamicParametersProviderException",696 SessionStateStrings.GetContentWriterDynamicParametersProviderException,697 providerInstance.ProviderInfo,698 path,699 e);700 }701 702 return result;703 }704 705 #endregion GetContentWriter706 707 #region ClearContent708 709 /// <summary>710 /// Clears all the content from the specified item.711 /// </summary>712 /// <param name="paths">713 /// The path(s) to the item(s) to clear the content from.714 /// </param>715 /// <param name="force">716 /// Passed on to providers to force operations.717 /// </param>718 /// <param name="literalPath">719 /// If true, globbing is not done on paths.720 /// </param>721 /// <exception cref="ArgumentNullException">722 /// If <paramref name="path"/> is null.723 /// </exception>724 /// <exception cref="ProviderNotFoundException">725 /// If the <paramref name="path"/> refers to a provider that could not be found.726 /// </exception>727 /// <exception cref="DriveNotFoundException">728 /// If the <paramref name="path"/> refers to a drive that could not be found.729 /// </exception>730 /// <exception cref="NotSupportedException">731 /// If the provider that the <paramref name="path"/> refers to does732 /// not support this operation.733 /// </exception>734 /// <exception cref="ProviderInvocationException">735 /// If the provider threw an exception.736 /// </exception>737 internal void ClearContent(string[] paths, bool force, bool literalPath)738 {739 if (paths == null)740 {741 throw PSTraceSource.NewArgumentNullException(nameof(paths));742 }743 744 CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);745 context.Force = force;746 context.SuppressWildcardExpansion = literalPath;747 748 ClearContent(paths, context);749 750 context.ThrowFirstErrorOrDoNothing();751 }752 753 /// <summary>754 /// Clears all of the content from the specified item.755 /// </summary>756 /// <param name="paths">757 /// The path to the item to clear the content from.758 /// </param>759 /// <param name="context">760 /// The context which the core command is running.761 /// </param>762 /// <exception cref="ArgumentNullException">763 /// If <paramref name="path"/> is null.764 /// </exception>765 /// <exception cref="ProviderNotFoundException">766 /// If the <paramref name="path"/> refers to a provider that could not be found.767 /// </exception>768 /// <exception cref="DriveNotFoundException">769 /// If the <paramref name="path"/> refers to a drive that could not be found.770 /// </exception>771 /// <exception cref="NotSupportedException">772 /// If the provider that the <paramref name="path"/> refers to does773 /// not support this operation.774 /// </exception>775 /// <exception cref="ProviderInvocationException">776 /// If the provider threw an exception.777 /// </exception>778 /// <exception cref="ItemNotFoundException">779 /// If <paramref name="path"/> does not contain glob characters and780 /// could not be found.781 /// </exception>782 internal void ClearContent(783 string[] paths,784 CmdletProviderContext context)785 {786 if (paths == null)787 {788 throw PSTraceSource.NewArgumentNullException(nameof(paths));789 }790 791 ProviderInfo provider = null;792 CmdletProvider providerInstance = null;793 794 foreach (string path in paths)795 {796 if (path == null)797 {798 PSTraceSource.NewArgumentNullException(nameof(paths));799 }800 801 Collection<string> providerPaths =802 Globber.GetGlobbedProviderPathsFromMonadPath(803 path,804 false,805 context,806 out provider,807 out providerInstance);808 809 foreach (string providerPath in providerPaths)810 {811 ClearContentPrivate(providerInstance, providerPath, context);812 }813 }814 }815 816 /// <summary>817 /// Clears the content from the item at the specified path.818 /// </summary>819 /// <param name="providerInstance">820 /// The provider instance to use.821 /// </param>822 /// <param name="path">823 /// The path to the item if it was specified on the command line.824 /// </param>825 /// <param name="context">826 /// The context which the core command is running.827 /// </param>828 /// <exception cref="NotSupportedException">829 /// If the <paramref name="providerInstance"/> does not support this operation.830 /// </exception>831 /// <exception cref="PipelineStoppedException">832 /// If the pipeline is being stopped while executing the command.833 /// </exception>834 /// <exception cref="ProviderInvocationException">835 /// If the provider threw an exception.836 /// </exception>837 private void ClearContentPrivate(838 CmdletProvider providerInstance,839 string path,840 CmdletProviderContext context)841 {842 // All parameters should have been validated by caller843 Dbg.Diagnostics.Assert(844 providerInstance != null,845 "Caller should validate providerInstance before calling this method");846 847 Dbg.Diagnostics.Assert(848 path != null,849 "Caller should validate path before calling this method");850 851 Dbg.Diagnostics.Assert(852 context != null,853 "Caller should validate context before calling this method");854 855 try856 {857 providerInstance.ClearContent(path, context);858 }859 catch (NotSupportedException)860 {861 throw;862 }863 catch (LoopFlowException)864 {865 throw;866 }867 catch (PipelineStoppedException)868 {869 throw;870 }871 catch (ActionPreferenceStopException)872 {873 throw;874 }875 catch (Exception e) // Catch-all OK, 3rd party callout.876 {877 throw NewProviderInvocationException(878 "ClearContentProviderException",879 SessionStateStrings.ClearContentProviderException,880 providerInstance.ProviderInfo,881 path,882 e);883 }884 }885 886 /// <summary>887 /// Gets the dynamic parameters for the clear-content cmdlet.888 /// </summary>889 /// <param name="path">890 /// The path to the item if it was specified on the command line.891 /// </param>892 /// <param name="context">893 /// The context which the core command is running.894 /// </param>895 /// <returns>896 /// An object that has properties and fields decorated with897 /// parsing attributes similar to a cmdlet class.898 /// </returns>899 /// <exception cref="ProviderNotFoundException">900 /// If the <paramref name="path"/> refers to a provider that could not be found.901 /// </exception>902 /// <exception cref="DriveNotFoundException">903 /// If the <paramref name="path"/> refers to a drive that could not be found.904 /// </exception>905 /// <exception cref="NotSupportedException">906 /// If the provider that the <paramref name="path"/> refers to does907 /// not support this operation.908 /// </exception>909 /// <exception cref="ProviderInvocationException">910 /// If the provider threw an exception.911 /// </exception>912 /// <exception cref="ItemNotFoundException">913 /// If <paramref name="path"/> does not contain glob characters and914 /// could not be found.915 /// </exception>916 internal object ClearContentDynamicParameters(917 string path,918 CmdletProviderContext context)919 {920 if (path == null)921 {922 return null;923 }924 925 ProviderInfo provider = null;926 CmdletProvider providerInstance = null;927 928 CmdletProviderContext newContext =929 new CmdletProviderContext(context);930 newContext.SetFilters(931 new Collection<string>(),932 new Collection<string>(),933 null);934 935 Collection<string> providerPaths =936 Globber.GetGlobbedProviderPathsFromMonadPath(937 path,938 true,939 newContext,940 out provider,941 out providerInstance);942 943 if (providerPaths.Count > 0)944 {945 // Get the dynamic parameters for the first resolved path946 947 return ClearContentDynamicParameters(providerInstance, providerPaths[0], newContext);948 }949 950 return null;951 }952 953 /// <summary>954 /// Calls the provider to get the clear-content dynamic parameters.955 /// </summary>956 /// <param name="providerInstance">957 /// The instance of the provider to call958 /// </param>959 /// <param name="path">960 /// The path to pass to the provider.961 /// </param>962 /// <param name="context">963 /// The context the command is executing under.964 /// </param>965 /// <returns>966 /// The dynamic parameter object returned by the provider.967 /// </returns>968 /// <exception cref="NotSupportedException">969 /// If the <paramref name="providerInstance"/> does not support this operation.970 /// </exception>971 /// <exception cref="PipelineStoppedException">972 /// If the pipeline is being stopped while executing the command.973 /// </exception>974 /// <exception cref="ProviderInvocationException">975 /// If the provider threw an exception.976 /// </exception>977 private object ClearContentDynamicParameters(978 CmdletProvider providerInstance,979 string path,980 CmdletProviderContext context)981 {982 // All parameters should have been validated by caller983 Dbg.Diagnostics.Assert(984 providerInstance != null,985 "Caller should validate providerInstance before calling this method");986 987 Dbg.Diagnostics.Assert(988 path != null,989 "Caller should validate path before calling this method");990 991 Dbg.Diagnostics.Assert(992 context != null,993 "Caller should validate context before calling this method");994 995 object result = null;996 try997 {998 result = providerInstance.ClearContentDynamicParameters(path, context);999 }1000 catch (NotSupportedException)1001 {1002 throw;1003 }1004 catch (LoopFlowException)1005 {1006 throw;1007 }1008 catch (PipelineStoppedException)1009 {1010 throw;1011 }1012 catch (ActionPreferenceStopException)1013 {1014 throw;1015 }1016 catch (Exception e) // Catch-all OK, 3rd party callout.1017 {1018 throw NewProviderInvocationException(1019 "ClearContentDynamicParametersProviderException",1020 SessionStateStrings.ClearContentDynamicParametersProviderException,1021 providerInstance.ProviderInfo,1022 path,1023 e);1024 }1025 1026 return result;1027 }1028 1029 #endregion ClearContent1030 1031 #endregion IContentCmdletProvider accessors1032 }1033}1034 1035#pragma warning restore 565001036 