Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
SessionStateDynamicProperty.cs2177 linesDownload Raw Back to engine
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 IDynamicPropertyCmdletProvider accessors20 21        #region NewProperty22 23        /// <summary>24        /// Creates a new property on the specified item.25        /// </summary>26        /// <param name="paths">27        /// The path(s) to the item(s) on which the new property should be created.28        /// </param>29        /// <param name="property">30        /// The name of the property that should be created.31        /// </param>32        /// <param name="type">33        /// The type of the property that should be created.34        /// </param>35        /// <param name="value">36        /// The new value of the property that should be created.37        /// </param>38        /// <param name="force">39        /// Passed on to providers to force operations.40        /// </param>41        /// <param name="literalPath">42        /// If true, globbing is not done on paths.43        /// </param>44        /// <returns>45        /// A property table containing the properties and their values.46        /// </returns>47        /// <exception cref="ArgumentNullException">48        /// If <paramref name="path"/> is null.49        /// </exception>50        /// <exception cref="ProviderNotFoundException">51        /// If the <paramref name="path"/> refers to a provider that could not be found.52        /// </exception>53        /// <exception cref="DriveNotFoundException">54        /// If the <paramref name="path"/> refers to a drive that could not be found.55        /// </exception>56        /// <exception cref="NotSupportedException">57        /// If the provider that the <paramref name="path"/> refers to does58        /// not support this operation.59        /// </exception>60        /// <exception cref="ProviderInvocationException">61        /// If the provider threw an exception.62        /// </exception>63        internal Collection<PSObject> NewProperty(64            string[] paths,65            string property,66            string type,67            object value,68            bool force,69            bool literalPath)70        {71            if (paths == null)72            {73                throw PSTraceSource.NewArgumentNullException(nameof(paths));74            }75 76            if (property == null)77            {78                throw PSTraceSource.NewArgumentNullException(nameof(property));79            }80 81            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);82            context.Force = force;83            context.SuppressWildcardExpansion = literalPath;84 85            NewProperty(paths, property, type, value, context);86 87            context.ThrowFirstErrorOrDoNothing();88 89            Collection<PSObject> results = context.GetAccumulatedObjects();90 91            return results;92        }93 94        /// <summary>95        /// Creates a new property on the specified item.96        /// </summary>97        /// <param name="paths">98        /// The path(s) to the item(s) on which the new property should be created.99        /// </param>100        /// <param name="property">101        /// The name of the property that should be created.102        /// </param>103        /// <param name="type">104        /// The type of the property that should be created.105        /// </param>106        /// <param name="value">107        /// The new value of the property that should be created.108        /// </param>109        /// <param name="context">110        /// The context which the core command is running.111        /// </param>112        /// <returns>113        /// Nothing. The property should be passed to the context as a PSObject.114        /// </returns>115        /// <exception cref="ArgumentNullException">116        /// If <paramref name="path"/> is null.117        /// </exception>118        /// <exception cref="ProviderNotFoundException">119        /// If the <paramref name="path"/> refers to a provider that could not be found.120        /// </exception>121        /// <exception cref="DriveNotFoundException">122        /// If the <paramref name="path"/> refers to a drive that could not be found.123        /// </exception>124        /// <exception cref="NotSupportedException">125        /// If the provider that the <paramref name="path"/> refers to does126        /// not support this operation.127        /// </exception>128        /// <exception cref="ProviderInvocationException">129        /// If the provider threw an exception.130        /// </exception>131        /// <exception cref="ItemNotFoundException">132        /// If <paramref name="path"/> does not contain glob characters and133        /// could not be found.134        /// </exception>135        internal void NewProperty(136            string[] paths,137            string property,138            string type,139            object value,140            CmdletProviderContext context)141        {142            if (paths == null)143            {144                throw PSTraceSource.NewArgumentNullException(nameof(paths));145            }146 147            if (property == null)148            {149                throw PSTraceSource.NewArgumentNullException(nameof(property));150            }151 152            ProviderInfo provider = null;153            CmdletProvider providerInstance = null;154 155            foreach (string path in paths)156            {157                if (path == null)158                {159                    throw PSTraceSource.NewArgumentNullException(nameof(paths));160                }161 162                Collection<string> providerPaths =163                    Globber.GetGlobbedProviderPathsFromMonadPath(164                        path,165                        false,166                        context,167                        out provider,168                        out providerInstance);169 170                foreach (string providerPath in providerPaths)171                {172                    NewProperty(providerInstance, providerPath, property, type, value, context);173                }174            }175        }176 177        /// <summary>178        /// Creates a new property on the item at the specified path.179        /// </summary>180        /// <param name="providerInstance">181        /// The provider instance to use.182        /// </param>183        /// <param name="path">184        /// The path to the item if it was specified on the command line.185        /// </param>186        /// <param name="property">187        /// The name of the property to create.188        /// </param>189        /// <param name="type">190        /// The type of the property to create.191        /// </param>192        /// <param name="value">193        /// The value of the property to create.194        /// </param>195        /// <param name="context">196        /// The context which the core command is running.197        /// </param>198        /// <exception cref="NotSupportedException">199        /// If the <paramref name="providerInstance"/> does not support this operation.200        /// </exception>201        /// <exception cref="PipelineStoppedException">202        /// If the pipeline is being stopped while executing the command.203        /// </exception>204        /// <exception cref="ProviderInvocationException">205        /// If the provider threw an exception.206        /// </exception>207        private void NewProperty(208            CmdletProvider providerInstance,209            string path,210            string property,211            string type,212            object value,213            CmdletProviderContext context)214        {215            // All parameters should have been validated by caller216            Dbg.Diagnostics.Assert(217                providerInstance != null,218                "Caller should validate providerInstance before calling this method");219 220            Dbg.Diagnostics.Assert(221                path != null,222                "Caller should validate path before calling this method");223 224            Dbg.Diagnostics.Assert(225                property != null,226                "Caller should validate path before calling this method");227 228            Dbg.Diagnostics.Assert(229                context != null,230                "Caller should validate context before calling this method");231 232            try233            {234                providerInstance.NewProperty(path, property, type, value, context);235            }236            catch (NotSupportedException)237            {238                throw;239            }240            catch (LoopFlowException)241            {242                throw;243            }244            catch (PipelineStoppedException)245            {246                throw;247            }248            catch (ActionPreferenceStopException)249            {250                throw;251            }252            catch (Exception e) // Catch-all OK, 3rd party callout.253            {254                throw NewProviderInvocationException(255                    "NewPropertyProviderException",256                    SessionStateStrings.NewPropertyProviderException,257                    providerInstance.ProviderInfo,258                    path,259                    e);260            }261        }262 263        /// <summary>264        /// Gets the dynamic parameters for the new-itemproperty cmdlet.265        /// </summary>266        /// <param name="path">267        /// The path to the item if it was specified on the command line.268        /// </param>269        /// <param name="propertyName">270        /// The name of the property that should be created.271        /// </param>272        /// <param name="type">273        /// The type of the property that should be created.274        /// </param>275        /// <param name="value">276        /// The new value of the property that should be created.277        /// </param>278        /// <param name="context">279        /// The context which the core command is running.280        /// </param>281        /// <returns>282        /// An object that has properties and fields decorated with283        /// parsing attributes similar to a cmdlet class.284        /// </returns>285        /// <exception cref="ProviderNotFoundException">286        /// If the <paramref name="path"/> refers to a provider that could not be found.287        /// </exception>288        /// <exception cref="DriveNotFoundException">289        /// If the <paramref name="path"/> refers to a drive that could not be found.290        /// </exception>291        /// <exception cref="NotSupportedException">292        /// If the provider that the <paramref name="path"/> refers to does293        /// not support this operation.294        /// </exception>295        /// <exception cref="ProviderInvocationException">296        /// If the provider threw an exception.297        /// </exception>298        /// <exception cref="ItemNotFoundException">299        /// If <paramref name="path"/> does not contain glob characters and300        /// could not be found.301        /// </exception>302        internal object NewPropertyDynamicParameters(303             string path,304            string propertyName,305            string type,306            object value,307            CmdletProviderContext context)308        {309            if (path == null)310            {311                return null;312            }313 314            ProviderInfo provider = null;315            CmdletProvider providerInstance = null;316 317            CmdletProviderContext newContext =318                new CmdletProviderContext(context);319            newContext.SetFilters(320                new Collection<string>(),321                new Collection<string>(),322                null);323 324            Collection<string> providerPaths =325                Globber.GetGlobbedProviderPathsFromMonadPath(326                    path,327                    true,328                    newContext,329                    out provider,330                    out providerInstance);331 332            if (providerPaths.Count > 0)333            {334                // Get the dynamic parameters for the first resolved path335 336                return NewPropertyDynamicParameters(providerInstance, providerPaths[0], propertyName, type, value, newContext);337            }338 339            return null;340        }341 342        /// <summary>343        /// Gets the dynamic parameters for the new-itemproperty cmdlet.344        /// </summary>345        /// <param name="path">346        /// The path to the item if it was specified on the command line.347        /// </param>348        /// <param name="propertyName">349        /// The name of the property to create.350        /// </param>351        /// <param name="type">352        /// The type of the property to create.353        /// </param>354        /// <param name="value">355        /// The value of the property.356        /// </param>357        /// <param name="providerInstance">358        /// The instance of the provider to use.359        /// </param>360        /// <param name="context">361        /// The context which the core command is running.362        /// </param>363        /// <returns>364        /// An object that has properties and fields decorated with365        /// parsing attributes similar to a cmdlet class.366        /// </returns>367        /// <exception cref="NotSupportedException">368        /// If the <paramref name="providerInstance"/> does not support this operation.369        /// </exception>370        /// <exception cref="PipelineStoppedException">371        /// If the pipeline is being stopped while executing the command.372        /// </exception>373        /// <exception cref="ProviderInvocationException">374        /// If the provider threw an exception.375        /// </exception>376        private object NewPropertyDynamicParameters(377            CmdletProvider providerInstance,378            string path,379            string propertyName,380            string type,381            object value,382            CmdletProviderContext context)383        {384            // All parameters should have been validated by caller385            Dbg.Diagnostics.Assert(386                providerInstance != null,387                "Caller should validate providerInstance before calling this method");388 389            Dbg.Diagnostics.Assert(390                path != null,391                "Caller should validate path before calling this method");392 393            Dbg.Diagnostics.Assert(394                context != null,395                "Caller should validate context before calling this method");396 397            object result = null;398            try399            {400                result = providerInstance.NewPropertyDynamicParameters(path, propertyName, type, value, context);401            }402            catch (NotSupportedException)403            {404                throw;405            }406            catch (LoopFlowException)407            {408                throw;409            }410            catch (PipelineStoppedException)411            {412                throw;413            }414            catch (ActionPreferenceStopException)415            {416                throw;417            }418            catch (Exception e) // Catch-all OK, 3rd party callout.419            {420                throw NewProviderInvocationException(421                    "NewPropertyDynamicParametersProviderException",422                    SessionStateStrings.NewPropertyDynamicParametersProviderException,423                    providerInstance.ProviderInfo,424                    path,425                    e);426            }427 428            return result;429        }430 431        #endregion NewProperty432 433        #region RemoveProperty434 435        /// <summary>436        /// Removes the specified property from the specified item.437        /// </summary>438        /// <param name="paths">439        /// The path(s) to the item(s) to remove the property from.440        /// </param>441        /// <param name="property">442        /// The name of the property to remove443        /// </param>444        /// <param name="force">445        /// Passed on to providers to force operations.446        /// </param>447        /// <param name="literalPath">448        /// If true, globbing is not done on paths.449        /// </param>450        /// <exception cref="ArgumentNullException">451        /// If <paramref name="path"/> or <paramref name="property"/> is null.452        /// </exception>453        /// <exception cref="ProviderNotFoundException">454        /// If the <paramref name="path"/> refers to a provider that could not be found.455        /// </exception>456        /// <exception cref="DriveNotFoundException">457        /// If the <paramref name="path"/> refers to a drive that could not be found.458        /// </exception>459        /// <exception cref="NotSupportedException">460        /// If the provider that the <paramref name="path"/> refers to does461        /// not support this operation.462        /// </exception>463        /// <exception cref="ProviderInvocationException">464        /// If the provider threw an exception.465        /// </exception>466        internal void RemoveProperty(string[] paths, string property, bool force, bool literalPath)467        {468            if (paths == null)469            {470                throw PSTraceSource.NewArgumentNullException(nameof(paths));471            }472 473            if (property == null)474            {475                throw PSTraceSource.NewArgumentNullException(nameof(property));476            }477 478            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);479            context.Force = force;480            context.SuppressWildcardExpansion = literalPath;481 482            RemoveProperty(paths, property, context);483 484            context.ThrowFirstErrorOrDoNothing();485        }486 487        /// <summary>488        /// Removes the specified properties from the specified item.489        /// </summary>490        /// <param name="paths">491        /// The path(s) to the item(s) to remove the properties from.492        /// </param>493        /// <param name="property">494        /// The name of the property to remove495        /// </param>496        /// <param name="context">497        /// The context which the core command is running.498        /// </param>499        /// <exception cref="ArgumentNullException">500        /// If <paramref name="path"/> or <paramref name="property"/> is null.501        /// </exception>502        /// <exception cref="ProviderNotFoundException">503        /// If the <paramref name="path"/> refers to a provider that could not be found.504        /// </exception>505        /// <exception cref="DriveNotFoundException">506        /// If the <paramref name="path"/> refers to a drive that could not be found.507        /// </exception>508        /// <exception cref="NotSupportedException">509        /// If the provider that the <paramref name="path"/> refers to does510        /// not support this operation.511        /// </exception>512        /// <exception cref="ProviderInvocationException">513        /// If the provider threw an exception.514        /// </exception>515        /// <exception cref="ItemNotFoundException">516        /// If <paramref name="path"/> does not contain glob characters and517        /// could not be found.518        /// </exception>519        internal void RemoveProperty(520            string[] paths,521            string property,522            CmdletProviderContext context)523        {524            if (paths == null)525            {526                throw PSTraceSource.NewArgumentNullException(nameof(paths));527            }528 529            if (property == null)530            {531                throw PSTraceSource.NewArgumentNullException(nameof(property));532            }533 534            foreach (string path in paths)535            {536                if (path == null)537                {538                    throw PSTraceSource.NewArgumentNullException(nameof(paths));539                }540 541                ProviderInfo provider = null;542                CmdletProvider providerInstance = null;543 544                Collection<string> providerPaths =545                    Globber.GetGlobbedProviderPathsFromMonadPath(546                        path,547                        false,548                        context,549                        out provider,550                        out providerInstance);551 552                foreach (string providerPath in providerPaths)553                {554                    RemoveProperty(providerInstance, providerPath, property, context);555                }556            }557        }558 559        /// <summary>560        /// Removes the property from the item at the specified path.561        /// </summary>562        /// <param name="providerInstance">563        /// The provider instance to use.564        /// </param>565        /// <param name="path">566        /// The path to the item if it was specified on the command line.567        /// </param>568        /// <param name="property">569        /// The name of the property to remove.570        /// </param>571        /// <param name="context">572        /// The context which the core command is running.573        /// </param>574        /// <exception cref="NotSupportedException">575        /// If the <paramref name="providerInstance"/> does not support this operation.576        /// </exception>577        /// <exception cref="PipelineStoppedException">578        /// If the pipeline is being stopped while executing the command.579        /// </exception>580        /// <exception cref="ProviderInvocationException">581        /// If the provider threw an exception.582        /// </exception>583        private void RemoveProperty(584            CmdletProvider providerInstance,585            string path,586            string property,587            CmdletProviderContext context)588        {589            // All parameters should have been validated by caller590            Dbg.Diagnostics.Assert(591                providerInstance != null,592                "Caller should validate providerInstance before calling this method");593 594            Dbg.Diagnostics.Assert(595                path != null,596                "Caller should validate path before calling this method");597 598            Dbg.Diagnostics.Assert(599                property != null,600                "Caller should validate property before calling this method");601 602            Dbg.Diagnostics.Assert(603                context != null,604                "Caller should validate context before calling this method");605 606            try607            {608                providerInstance.RemoveProperty(path, property, context);609            }610            catch (NotSupportedException)611            {612                throw;613            }614            catch (LoopFlowException)615            {616                throw;617            }618            catch (PipelineStoppedException)619            {620                throw;621            }622            catch (ActionPreferenceStopException)623            {624                throw;625            }626            catch (Exception e) // Catch-all OK, 3rd party callout.627            {628                throw NewProviderInvocationException(629                    "RemovePropertyProviderException",630                    SessionStateStrings.RemovePropertyProviderException,631                    providerInstance.ProviderInfo,632                    path,633                    e);634            }635        }636 637        /// <summary>638        /// Gets the dynamic parameters for the remove-itemproperty cmdlet.639        /// </summary>640        /// <param name="path">641        /// The path to the item if it was specified on the command line.642        /// </param>643        /// <param name="propertyName">644        /// The name of the property that should be created.645        /// </param>646        /// <param name="context">647        /// The context which the core command is running.648        /// </param>649        /// <returns>650        /// An object that has properties and fields decorated with651        /// parsing attributes similar to a cmdlet class.652        /// </returns>653        /// <exception cref="ProviderNotFoundException">654        /// If the <paramref name="path"/> refers to a provider that could not be found.655        /// </exception>656        /// <exception cref="DriveNotFoundException">657        /// If the <paramref name="path"/> refers to a drive that could not be found.658        /// </exception>659        /// <exception cref="NotSupportedException">660        /// If the provider that the <paramref name="path"/> refers to does661        /// not support this operation.662        /// </exception>663        /// <exception cref="ProviderInvocationException">664        /// If the provider threw an exception.665        /// </exception>666        /// <exception cref="ItemNotFoundException">667        /// If <paramref name="path"/> does not contain glob characters and668        /// could not be found.669        /// </exception>670        internal object RemovePropertyDynamicParameters(671             string path,672            string propertyName,673            CmdletProviderContext context)674        {675            if (path == null)676            {677                return null;678            }679 680            ProviderInfo provider = null;681            CmdletProvider providerInstance = null;682 683            CmdletProviderContext newContext =684               new CmdletProviderContext(context);685            newContext.SetFilters(686                new Collection<string>(),687                new Collection<string>(),688                null);689 690            Collection<string> providerPaths =691                 Globber.GetGlobbedProviderPathsFromMonadPath(692                    path,693                    true,694                    newContext,695                    out provider,696                    out providerInstance);697 698            if (providerPaths.Count > 0)699            {700                // Get the dynamic parameters for the first resolved path701 702                return RemovePropertyDynamicParameters(providerInstance, providerPaths[0], propertyName, newContext);703            }704 705            return null;706        }707 708        /// <summary>709        /// Gets the dynamic parameters for the remove-itemproperty cmdlet.710        /// </summary>711        /// <param name="path">712        /// The path to the item if it was specified on the command line.713        /// </param>714        /// <param name="propertyName">715        /// The name of the property to remove.716        /// </param>717        /// <param name="providerInstance">718        /// The instance of the provider to use.719        /// </param>720        /// <param name="context">721        /// The context which the core command is running.722        /// </param>723        /// <returns>724        /// An object that has properties and fields decorated with725        /// parsing attributes similar to a cmdlet class.726        /// </returns>727        /// <exception cref="NotSupportedException">728        /// If the <paramref name="providerInstance"/> does not support this operation.729        /// </exception>730        /// <exception cref="PipelineStoppedException">731        /// If the pipeline is being stopped while executing the command.732        /// </exception>733        /// <exception cref="ProviderInvocationException">734        /// If the provider threw an exception.735        /// </exception>736        private object RemovePropertyDynamicParameters(737            CmdletProvider providerInstance,738            string path,739            string propertyName,740            CmdletProviderContext context)741        {742            // All parameters should have been validated by caller743            Dbg.Diagnostics.Assert(744                providerInstance != null,745                "Caller should validate providerInstance before calling this method");746 747            Dbg.Diagnostics.Assert(748                path != null,749                "Caller should validate path before calling this method");750 751            Dbg.Diagnostics.Assert(752                context != null,753                "Caller should validate context before calling this method");754 755            object result = null;756            try757            {758                result = providerInstance.RemovePropertyDynamicParameters(path, propertyName, context);759            }760            catch (NotSupportedException)761            {762                throw;763            }764            catch (LoopFlowException)765            {766                throw;767            }768            catch (PipelineStoppedException)769            {770                throw;771            }772            catch (ActionPreferenceStopException)773            {774                throw;775            }776            catch (Exception e) // Catch-all OK, 3rd party callout.777            {778                throw NewProviderInvocationException(779                    "RemovePropertyDynamicParametersProviderException",780                    SessionStateStrings.RemovePropertyDynamicParametersProviderException,781                    providerInstance.ProviderInfo,782                    path,783                    e);784            }785 786            return result;787        }788 789        #endregion RemoveProperty790 791        #region CopyProperty792 793        /// <summary>794        /// Copies the specified property on the specified item to the specified property795        /// on the destination item.  The source and destination items can be the same item.796        /// </summary>797        /// <param name="sourcePaths">798        /// The path(s) to the item(s) to copy the property from.799        /// </param>800        /// <param name="sourceProperty">801        /// The name of the property to be copied.802        /// </param>803        /// <param name="destinationPath">804        /// The path to the item to copy the property to.805        /// </param>806        /// <param name="destinationProperty">807        /// The name of the property to copy the property to.808        /// </param>809        /// <param name="force">810        /// Passed on to providers to force operations.811        /// </param>812        /// <param name="literalPath">813        /// If true, globbing is not done on paths.814        /// </param>815        /// <exception cref="ArgumentNullException">816        /// If <paramref name="sourcePath"/>, <paramref name="sourceProperty"/>,817        /// <paramref name="destinationPath"/>, or <paramref name="destinationProperty"/>818        ///  is null.819        /// </exception>820        /// <exception cref="ProviderNotFoundException">821        /// If the <paramref name="sourcePath"/> refers to a provider that could not be found.822        /// </exception>823        /// <exception cref="DriveNotFoundException">824        /// If the <paramref name="sourcePath"/> refers to a drive that could not be found.825        /// </exception>826        /// <exception cref="NotSupportedException">827        /// If the provider that the <paramref name="sourcePath"/> refers to does828        /// not support this operation.829        /// </exception>830        /// <exception cref="ProviderInvocationException">831        /// If the provider threw an exception.832        /// </exception>833        internal Collection<PSObject> CopyProperty(834            string[] sourcePaths,835            string sourceProperty,836            string destinationPath,837            string destinationProperty,838            bool force,839            bool literalPath)840        {841            if (sourcePaths == null)842            {843                throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths));844            }845 846            if (sourceProperty == null)847            {848                throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty));849            }850 851            if (destinationPath == null)852            {853                throw PSTraceSource.NewArgumentNullException(nameof(destinationPath));854            }855 856            if (destinationProperty == null)857            {858                throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty));859            }860 861            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);862            context.Force = force;863            context.SuppressWildcardExpansion = literalPath;864 865            CopyProperty(sourcePaths, sourceProperty, destinationPath, destinationProperty, context);866 867            context.ThrowFirstErrorOrDoNothing();868 869            Collection<PSObject> results = context.GetAccumulatedObjects();870 871            return results;872        }873 874        /// <summary>875        /// Copies the specified property on the specified item to the specified property876        /// on the destination item.  The source and destination items can be the same item.877        /// </summary>878        /// <param name="sourcePaths">879        /// The path(s) to the item(s) to copy the property from.880        /// </param>881        /// <param name="sourceProperty">882        /// The name of the property to be copied.883        /// </param>884        /// <param name="destinationPath">885        /// The path to the item to copy the property to.886        /// </param>887        /// <param name="destinationProperty">888        /// The name of the property to copy the property to.889        /// </param>890        /// <param name="context">891        /// The context which the core command is running.892        /// </param>893        /// <exception cref="ArgumentNullException">894        /// If <paramref name="sourcePath"/>, <paramref name="sourceProperty"/>,895        /// <paramref name="destinationPath"/>, or <paramref name="destinationProperty"/>896        ///  is null.897        /// </exception>898        /// <exception cref="ProviderNotFoundException">899        /// If the <paramref name="sourcePath"/> refers to a provider that could not be found.900        /// </exception>901        /// <exception cref="DriveNotFoundException">902        /// If the <paramref name="sourcePath"/> refers to a drive that could not be found.903        /// </exception>904        /// <exception cref="NotSupportedException">905        /// If the provider that the <paramref name="sourcePath"/> refers to does906        /// not support this operation.907        /// </exception>908        /// <exception cref="ProviderInvocationException">909        /// If the provider threw an exception.910        /// </exception>911        /// <exception cref="ItemNotFoundException">912        /// If <paramref name="path"/> does not contain glob characters and913        /// could not be found.914        /// </exception>915        internal void CopyProperty(916            string[] sourcePaths,917            string sourceProperty,918            string destinationPath,919            string destinationProperty,920            CmdletProviderContext context)921        {922            if (sourcePaths == null)923            {924                throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths));925            }926 927            if (sourceProperty == null)928            {929                throw PSTraceSource.NewArgumentNullException(nameof(sourceProperty));930            }931 932            if (destinationPath == null)933            {934                throw PSTraceSource.NewArgumentNullException(nameof(destinationPath));935            }936 937            if (destinationProperty == null)938            {939                throw PSTraceSource.NewArgumentNullException(nameof(destinationProperty));940            }941 942            foreach (string sourcePath in sourcePaths)943            {944                if (sourcePath == null)945                {946                    throw PSTraceSource.NewArgumentNullException(nameof(sourcePaths));947                }948 949                ProviderInfo provider = null;950                CmdletProvider providerInstance = null;951 952                Collection<string> providerPaths =953                    Globber.GetGlobbedProviderPathsFromMonadPath(954                        sourcePath,955                        false,956                        context,957                        out provider,958                        out providerInstance);959 960                if (providerPaths.Count > 0)961                {962                    // Save off the original filters963                    Collection<string> includeFilters = context.Include;964                    Collection<string> excludeFilters = context.Exclude;965                    string filterString = context.Filter;966 967                    // now modify the filters so that the destination isn't filtered968 969                    context.SetFilters(970                        new Collection<string>(),971                        new Collection<string>(),972                        null);973 974                    Collection<string> providerDestinationPaths =975                        Globber.GetGlobbedProviderPathsFromMonadPath(976                            destinationPath,977                            false,978                            context,979                            out provider,980                            out providerInstance);981 982                    // Now reapply the filters983 984                    context.SetFilters(985                        includeFilters,986                        excludeFilters,987                        filterString);988 989                    foreach (string providerPath in providerPaths)990                    {991                        foreach (string providerDestinationPath in providerDestinationPaths)992                        {993                            CopyProperty(providerInstance, providerPath, sourceProperty, providerDestinationPath, destinationProperty, context);994                        }995                    }996                }997            }998        }999 1000        /// <summary>1001        /// Copies the property.1002        /// </summary>1003        /// <param name="providerInstance">1004        /// The instance of the provider to use.1005        /// </param>1006        /// <param name="sourcePath">1007        /// The path to the item if it was specified on the command line.1008        /// </param>1009        /// <param name="sourceProperty">1010        /// The name of the property to be copied.1011        /// </param>1012        /// <param name="destinationPath">1013        /// The path to the item to copy the property to.1014        /// </param>1015        /// <param name="destinationProperty">1016        /// The name of the property to copy the property to.1017        /// </param>1018        /// <param name="context">1019        /// The context which the core command is running.1020        /// </param>1021        /// <exception cref="NotSupportedException">1022        /// If the <paramref name="providerInstance"/> does not support this operation.1023        /// </exception>1024        /// <exception cref="PipelineStoppedException">1025        /// If the pipeline is being stopped while executing the command.1026        /// </exception>1027        /// <exception cref="ProviderInvocationException">1028        /// If the provider threw an exception.1029        /// </exception>1030        private void CopyProperty(1031            CmdletProvider providerInstance,1032            string sourcePath,1033            string sourceProperty,1034            string destinationPath,1035            string destinationProperty,1036            CmdletProviderContext context)1037        {1038            // All parameters should have been validated by caller1039            Dbg.Diagnostics.Assert(1040                providerInstance != null,1041                "Caller should validate providerInstance before calling this method");1042 1043            Dbg.Diagnostics.Assert(1044                sourcePath != null,1045                "Caller should validate sourcePath before calling this method");1046 1047            Dbg.Diagnostics.Assert(1048                sourceProperty != null,1049                "Caller should validate sourceProperty before calling this method");1050 1051            Dbg.Diagnostics.Assert(1052                destinationPath != null,1053                "Caller should validate destinationPath before calling this method");1054 1055            Dbg.Diagnostics.Assert(1056                destinationProperty != null,1057                "Caller should validate destinationProperty before calling this method");1058 1059            Dbg.Diagnostics.Assert(1060                context != null,1061                "Caller should validate context before calling this method");1062 1063            try1064            {1065                providerInstance.CopyProperty(sourcePath, sourceProperty, destinationPath, destinationProperty, context);1066            }1067            catch (NotSupportedException)1068            {1069                throw;1070            }1071            catch (LoopFlowException)1072            {1073                throw;1074            }1075            catch (PipelineStoppedException)1076            {1077                throw;1078            }1079            catch (ActionPreferenceStopException)1080            {1081                throw;1082            }1083            catch (Exception e) // Catch-all OK, 3rd party callout.1084            {1085                throw NewProviderInvocationException(1086                    "CopyPropertyProviderException",1087                    SessionStateStrings.CopyPropertyProviderException,1088                    providerInstance.ProviderInfo,1089                    sourcePath,1090                    e);1091            }1092        }1093 1094        /// <summary>1095        /// Gets the dynamic parameters for the copy-itemproperty cmdlet.1096        /// </summary>1097        /// <param name="path">1098        /// The path to the item if it was specified on the command line.1099        /// </param>1100        /// <param name="sourceProperty">1101        /// The name of the property to be copied.1102        /// </param>1103        /// <param name="destinationPath">1104        /// The path to the item to copy the property to.1105        /// </param>1106        /// <param name="destinationProperty">1107        /// The name of the property to copy the property to.1108        /// </param>1109        /// <param name="context">1110        /// The context which the core command is running.1111        /// </param>1112        /// <returns>1113        /// An object that has properties and fields decorated with1114        /// parsing attributes similar to a cmdlet class.1115        /// </returns>1116        /// <exception cref="ProviderNotFoundException">1117        /// If the <paramref name="path"/> refers to a provider that could not be found.1118        /// </exception>1119        /// <exception cref="DriveNotFoundException">1120        /// If the <paramref name="path"/> refers to a drive that could not be found.1121        /// </exception>1122        /// <exception cref="NotSupportedException">1123        /// If the provider that the <paramref name="path"/> refers to does1124        /// not support this operation.1125        /// </exception>1126        /// <exception cref="ProviderInvocationException">1127        /// If the provider threw an exception.1128        /// </exception>1129        /// <exception cref="ItemNotFoundException">1130        /// If <paramref name="path"/> does not contain glob characters and1131        /// could not be found.1132        /// </exception>1133        internal object CopyPropertyDynamicParameters(1134             string path,1135            string sourceProperty,1136            string destinationPath,1137            string destinationProperty,1138            CmdletProviderContext context)1139        {1140            if (path == null)1141            {1142                return null;1143            }1144 1145            ProviderInfo provider = null;1146            CmdletProvider providerInstance = null;1147 1148            CmdletProviderContext newContext =1149                new CmdletProviderContext(context);1150            newContext.SetFilters(1151                new Collection<string>(),1152                new Collection<string>(),1153                null);1154 1155            Collection<string> providerPaths =1156                Globber.GetGlobbedProviderPathsFromMonadPath(1157                    path,1158                    true,1159                    newContext,1160                    out provider,1161                    out providerInstance);1162 1163            if (providerPaths.Count > 0)1164            {1165                // Get the dynamic parameters for the first resolved path1166 1167                return CopyPropertyDynamicParameters(1168                    providerInstance,1169                    providerPaths[0],1170                    sourceProperty,1171                    destinationPath,1172                    destinationProperty,1173                    newContext);1174            }1175 1176            return null;1177        }1178 1179        /// <summary>1180        /// Gets the dynamic parameters for the copy-itemproperty cmdlet.1181        /// </summary>1182        /// <param name="path">1183        /// The path to the item if it was specified on the command line.1184        /// </param>1185        /// <param name="providerInstance">1186        /// The instance of the provider to use.1187        /// </param>1188        /// <param name="sourceProperty">1189        /// The name of the property to copy.1190        /// </param>1191        /// <param name="destinationPath">1192        /// The path to the item to copy the property to.1193        /// </param>1194        /// <param name="destinationProperty">1195        /// The name of the property to copy the property to on the destination item.1196        /// </param>1197        /// <param name="context">1198        /// The context which the core command is running.1199        /// </param>1200        /// <returns>

Showing the first 1,200 of 2177 lines. Download the file for the rest.