File size: 47,611 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Diagnostics.CodeAnalysis;
using System.Management.Automation.Internal;
namespace System.Management.Automation.Provider
{
#region ContainerCmdletProvider
/// <summary>
/// The base class for Cmdlet providers that expose a single level of items.
/// </summary>
/// <remarks>
/// The ContainerCmdletProvider class is base class that a provider derives from
/// to implement methods that allow
/// the use of a set of core commands against the objects that the provider
/// gives access to. By deriving from this class users can take advantage of
/// all the features of the <see cref="ItemCmdletProvider"/> as well as
/// globbing and the following commands when targeting this provider:
/// get-childitem
/// rename-item
/// new-item
/// remove-item
/// set-location
/// push-location
/// pop-location
/// get-location -stack
/// </remarks>
public abstract class ContainerCmdletProvider : ItemCmdletProvider
{
#region Internal methods
/// <summary>
/// Internal wrapper for the GetChildItems protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path (or name in a flat namespace) to the item from which to retrieve the children.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be retrieved, false if only a single
/// level of children should be retrieved. This parameter should only be true for
/// the NavigationCmdletProvider derived class.
/// </param>
/// <param name="depth">
/// Limits the depth of recursion; uint.MaxValue performs full recursion.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Nothing is returned, but all children should be written to the Write*Object or
/// Write*Objects method.
/// </returns>
internal void GetChildItems(
string path,
bool recurse,
uint depth,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
GetChildItems(path, recurse, depth);
}
/// <summary>
/// Gives the provider to attach additional parameters to
/// the get-childitem cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be retrieved, false if only a single
/// level of children should be retrieved. This parameter should only be true for
/// the NavigationCmdletProvider derived class.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
internal object GetChildItemsDynamicParameters(
string path,
bool recurse,
CmdletProviderContext context)
{
Context = context;
return GetChildItemsDynamicParameters(path, recurse);
}
/// <summary>
/// Internal wrapper for the GetChildNames protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path to the item from which to retrieve the child names.
/// </param>
/// <param name="returnContainers">
/// Determines if all containers should be returned or only those containers that match the
/// filter(s).
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Nothing is returned, but all names should be written to the Write*Object or
/// Write*Objects method.
/// </returns>
/// <remarks>
/// The child names are the leaf portion of the path. Example, for the file system
/// the name for the path c:\windows\system32\foo.dll would be foo.dll or for
/// the directory c:\windows\system32 would be system32. For Active Directory the
/// child names would be RDN values of the child objects of the container.
/// </remarks>
internal void GetChildNames(
string path,
ReturnContainers returnContainers,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
GetChildNames(path, returnContainers);
}
/// <summary>
/// Gets a new provider-specific path and filter (if any) that corresponds to the given
/// path.
/// </summary>
/// <param name="path">
/// The path to the item. Unlike most other provider APIs, this path is likely to
/// contain PowerShell wildcards.
/// </param>
/// <param name="filter">
/// The provider-specific filter currently applied.
/// </param>
/// <param name="updatedPath">
/// The new path to the item.
/// </param>
/// <param name="updatedFilter">
/// The new filter.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// True if the path or filter were altered. False otherwise.
/// </returns>
/// <remarks>
/// Providers override this method if they support a native filtering syntax that
/// can offer performance improvements over wildcard matching done by the PowerShell
/// engine.
/// If the provider can handle a portion (or all) of the PowerShell wildcard with
/// semantics equivalent to the PowerShell wildcard, it may adjust the path to exclude
/// the PowerShell wildcard.
/// If the provider can augment the PowerShell wildcard with an approximate filter (but
/// not replace it entirely,) it may simply return a filter without modifying the path.
/// In this situation, PowerShell's wildcarding will still be applied to a smaller result
/// set, resulting in improved performance.
///
/// The default implementation of this method leaves both Path and Filter unmodified.
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "2#")]
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "3#")]
internal virtual bool ConvertPath(
string path,
string filter,
ref string updatedPath,
ref string updatedFilter,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
return ConvertPath(path, filter, ref updatedPath, ref updatedFilter);
}
/// <summary>
/// Gives the provider to attach additional parameters to
/// the get-childitem -name cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
internal object GetChildNamesDynamicParameters(
string path,
CmdletProviderContext context)
{
Context = context;
return GetChildNamesDynamicParameters(path);
}
/// <summary>
/// Internal wrapper for the RenameItem protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path to the item to rename.
/// </param>
/// <param name="newName">
/// The name to which the item should be renamed. This name should always be
/// relative to the parent container.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Nothing is returned, but all renamed items should be written to the Write*Object or
/// Write*Objects.
/// </returns>
internal void RenameItem(
string path,
string newName,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
RenameItem(path, newName);
}
/// <summary>
/// Gives the provider to attach additional parameters to
/// the rename-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="newName">
/// The name to which the item should be renamed. This name should always be
/// relative to the parent container.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
internal object RenameItemDynamicParameters(
string path,
string newName,
CmdletProviderContext context)
{
Context = context;
return RenameItemDynamicParameters(path, newName);
}
/// <summary>
/// Internal wrapper for the New protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path to the item to create.
/// </param>
/// <param name="type">
/// The provider defined type of the item to create.
/// </param>
/// <param name="newItemValue">
/// This is a provider specific type that the provider can use to create a new
/// instance of an item at the specified path.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Nothing is returned, but all new items should be written to the Write*Object or
/// Write*Objects.
/// </returns>
internal void NewItem(
string path,
string type,
object newItemValue,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
NewItem(path, type, newItemValue);
}
/// <summary>
/// Gives the provider to attach additional parameters to
/// the new-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="type">
/// The provider defined type of the item to create.
/// </param>
/// <param name="newItemValue">
/// This is a provider specific type that the provider can use to create a new
/// instance of an item at the specified path.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
internal object NewItemDynamicParameters(
string path,
string type,
object newItemValue,
CmdletProviderContext context)
{
Context = context;
return NewItemDynamicParameters(path, type, newItemValue);
}
/// <summary>
/// Internal wrapper for the Remove protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path to the item to remove.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be removed, false if only a single
/// level of children should be removed. This parameter should only be true for
/// NavigationCmdletProvider and its derived classes.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
internal void RemoveItem(
string path,
bool recurse,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
RemoveItem(path, recurse);
}
/// <summary>
/// Gives the provider to attach additional parameters to
/// the remove-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be removed, false if only a single
/// level of children should be removed. This parameter should only be true for
/// NavigationCmdletProvider and its derived classes.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
internal object RemoveItemDynamicParameters(
string path,
bool recurse,
CmdletProviderContext context)
{
Context = context;
return RemoveItemDynamicParameters(path, recurse);
}
/// <summary>
/// Internal wrapper for the HasChildItems protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path to the item to see if it has children.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// True if the item has children, false otherwise.
/// </returns>
/// <remarks>
/// For implementers of ContainerCmdletProvider classes and those derived from it,
/// if a null or empty path is passed,
/// the provider should consider any items in the data store to be children
/// and return true.
/// </remarks>
internal bool HasChildItems(string path, CmdletProviderContext context)
{
Context = context;
// Call virtual method
return HasChildItems(path);
}
/// <summary>
/// Internal wrapper for the Copy protected method. It is called instead
/// of the protected method that is overridden by derived classes so that the
/// context of the command can be set.
/// </summary>
/// <param name="path">
/// The path of the item to copy.
/// </param>
/// <param name="copyPath">
/// The path of the item to copy to.
/// </param>
/// <param name="recurse">
/// Tells the provider to recurse sub-containers when copying.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// Nothing. All objects that are copied should be written to the Write*Object or
/// Write*Objects methods.
/// </returns>
internal void CopyItem(
string path,
string copyPath,
bool recurse,
CmdletProviderContext context)
{
Context = context;
// Call virtual method
CopyItem(path, copyPath, recurse);
}
/// <summary>
/// Gives the provider to attach additional parameters to
/// the copy-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="destination">
/// The path of the item to copy to.
/// </param>
/// <param name="recurse">
/// Tells the provider to recurse sub-containers when copying.
/// </param>
/// <param name="context">
/// The context under which this method is being called.
/// </param>
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
internal object CopyItemDynamicParameters(
string path,
string destination,
bool recurse,
CmdletProviderContext context)
{
Context = context;
return CopyItemDynamicParameters(path, destination, recurse);
}
#endregion Internal members
#region Protected methods
/// <summary>
/// Gets the children of the item at the specified path.
/// </summary>
/// <param name="path">
/// The path (or name in a flat namespace) to the item from which to retrieve the children.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be retrieved, false if only a single
/// level of children should be retrieved. This parameter should only be true for
/// the NavigationCmdletProvider derived class.
/// </param>
/// <returns>
/// Nothing is returned, but all objects should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the user access to the provider objects using
/// the get-childitem cmdlets.
///
/// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
/// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
/// requirements by accessing the appropriate property from the base class.
///
/// By default overrides of this method should not write objects that are generally hidden from
/// the user unless the Force property is set to true. For instance, the FileSystem provider should
/// not call WriteItemObject for hidden or system files unless the Force property is set to true.
///
/// The provider implementation is responsible for preventing infinite recursion when there are
/// circular links and the like. An appropriate terminating exception should be thrown if this
/// situation occurs.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void GetChildItems(
string path,
bool recurse)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Gets the children of the item at the specified path.
/// </summary>
/// <param name="path">
/// The path (or name in a flat namespace) to the item from which to retrieve the children.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be retrieved, false if only a single
/// level of children should be retrieved. This parameter should only be true for
/// the NavigationCmdletProvider derived class.
/// </param>
/// <param name="depth">
/// Limits the depth of recursion; uint.MaxValue performs full recursion.
/// </param>
/// <returns>
/// Nothing is returned, but all objects should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the user access to the provider objects using
/// the get-childitem cmdlets.
///
/// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
/// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
/// requirements by accessing the appropriate property from the base class.
///
/// By default overrides of this method should not write objects that are generally hidden from
/// the user unless the Force property is set to true. For instance, the FileSystem provider should
/// not call WriteItemObject for hidden or system files unless the Force property is set to true.
///
/// The provider implementation is responsible for preventing infinite recursion when there are
/// circular links and the like. An appropriate terminating exception should be thrown if this
/// situation occurs.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void GetChildItems(
string path,
bool recurse,
uint depth)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
if (depth == uint.MaxValue)
{
this.GetChildItems(path, recurse);
}
else
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupportedRecursionDepth);
}
}
}
/// <summary>
/// Gives the provider an opportunity to attach additional parameters to
/// the get-childitem cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be retrieved, false if only a single
/// level of children should be retrieved. This parameter should only be true for
/// the NavigationCmdletProvider derived class.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
protected virtual object GetChildItemsDynamicParameters(string path, bool recurse)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return null;
}
}
/// <summary>
/// Gets names of the children of the specified path.
/// </summary>
/// <param name="path">
/// The path to the item from which to retrieve the child names.
/// </param>
/// <param name="returnContainers">
/// Determines if all containers should be returned or only those containers that match the
/// filter(s).
/// </param>
/// <returns>
/// Nothing is returned, but all objects should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the user access to the provider objects using
/// the get-childitem -name cmdlet.
///
/// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
/// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
/// requirements by accessing the appropriate property from the base class. The exception to this
/// is if <paramref name="returnAllContainers"/> is true, then any child name for a container should
/// be returned even if it doesn't match the Filter, Include, or Exclude.
///
/// By default overrides of this method should not write the names of objects that are generally hidden from
/// the user unless the Force property is set to true. For instance, the FileSystem provider should
/// not call WriteItemObject for hidden or system files unless the Force property is set to true.
///
/// The provider implementation is responsible for preventing infinite recursion when there are
/// circular links and the like. An appropriate terminating exception should be thrown if this
/// situation occurs.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void GetChildNames(
string path,
ReturnContainers returnContainers)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Gets a new provider-specific path and filter (if any) that corresponds to the given
/// path.
/// </summary>
/// <param name="path">
/// The path to the item. Unlike most other provider APIs, this path is likely to
/// contain PowerShell wildcards.
/// </param>
/// <param name="filter">
/// The provider-specific filter currently applied.
/// </param>
/// <param name="updatedPath">
/// The new path to the item.
/// </param>
/// <param name="updatedFilter">
/// The new filter.
/// </param>
/// <returns>
/// True if the path or filter were altered. False otherwise.
/// </returns>
/// <remarks>
/// Providers override this method if they support a native filtering syntax that
/// can offer performance improvements over wildcard matching done by the PowerShell
/// engine.
/// If the provider can handle a portion (or all) of the PowerShell wildcard with
/// semantics equivalent to the PowerShell wildcard, it may adjust the path to exclude
/// the PowerShell wildcard.
/// If the provider can augment the PowerShell wildcard with an approximate filter (but
/// not replace it entirely,) it may simply return a filter without modifying the path.
/// In this situation, PowerShell's wildcarding will still be applied to a smaller result
/// set, resulting in improved performance.
///
/// The default implementation of this method leaves both Path and Filter unmodified.
///
/// PowerShell wildcarding semantics are handled by the System.Management.Automation.Wildcardpattern
/// class.
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "2#")]
[SuppressMessage("Microsoft.Design", "CA1045:DoNotPassTypesByReference", MessageId = "3#")]
protected virtual bool ConvertPath(
string path,
string filter,
ref string updatedPath,
ref string updatedFilter)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return false;
}
}
/// <summary>
/// Gives the provider an opportunity to attach additional parameters to
/// the get-childitem -name cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
protected virtual object GetChildNamesDynamicParameters(string path)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return null;
}
}
/// <summary>
/// Renames the item at the specified path to the new name provided.
/// </summary>
/// <param name="path">
/// The path to the item to rename.
/// </param>
/// <param name="newName">
/// The name to which the item should be renamed. This name should always be
/// relative to the parent container.
/// </param>
/// <returns>
/// Nothing is returned, but the renamed items should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the user the ability to rename provider objects using
/// the rename-item cmdlet.
///
/// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
/// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
/// requirements by accessing the appropriate property from the base class.
///
/// By default overrides of this method should not allow renaming objects that are generally hidden from
/// the user unless the Force property is set to true. For instance, the FileSystem provider should
/// not allow renaming of a hidden or system file unless the Force property is set to true.
///
/// This method is intended for the modification of the item's name only and not for Move operations.
/// An error should be written to <see cref="CmdletProvider.WriteError"/> if the <paramref name="newName"/>
/// parameter contains path separators or would cause the item to change its parent location.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void RenameItem(
string path,
string newName)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Gives the provider an opportunity to attach additional parameters to
/// the rename-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="newName">
/// The name to which the item should be renamed. This name should always be
/// relative to the parent container.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
protected virtual object RenameItemDynamicParameters(string path, string newName)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return null;
}
}
/// <summary>
/// Creates a new item at the specified path.
/// </summary>
/// <param name="path">
/// The path to the item to create.
/// </param>
/// <param name="itemTypeName">
/// The provider defined type for the object to create.
/// </param>
/// <param name="newItemValue">
/// This is a provider specific type that the provider can use to create a new
/// instance of an item at the specified path.
/// </param>
/// <returns>
/// Nothing is returned, but the renamed items should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the user the ability to create new provider objects using
/// the new-item cmdlet.
///
/// The <paramref name="itemTypeName"/> parameter is a provider specific string that the user specifies to tell
/// the provider what type of object to create. For instance, in the FileSystem provider the <paramref name="type"/>
/// parameter can take a value of "file" or "directory". The comparison of this string should be
/// case-insensitive and you should also allow for least ambiguous matches. So if the provider allows
/// for the types "file" and "directory", only the first letter is required to disambiguate.
/// If <paramref name="itemTypeName"/> refers to a type the provider cannot create, the provider should produce
/// an <see cref="ArgumentException"/> with a message indicating the types the provider can create.
///
/// The <paramref name="newItemValue"/> parameter can be any type of object that the provider can use
/// to create the item. It is recommended that the provider accept at a minimum strings, and an instance
/// of the type of object that would be returned from GetItem() for this path. <see cref="LanguagePrimitives.ConvertTo(object, System.Type)"/>
/// can be used to convert some types to the desired type.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void NewItem(
string path,
string itemTypeName,
object newItemValue)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Gives the provider an opportunity to attach additional parameters to
/// the new-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="itemTypeName">
/// The provider defined type of the item to create.
/// </param>
/// <param name="newItemValue">
/// This is a provider specific type that the provider can use to create a new
/// instance of an item at the specified path.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
protected virtual object NewItemDynamicParameters(
string path,
string itemTypeName,
object newItemValue)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return null;
}
}
/// <summary>
/// Removes (deletes) the item at the specified path.
/// </summary>
/// <param name="path">
/// The path to the item to remove.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be removed, false if only a single
/// level of children should be removed. This parameter should only be true for
/// NavigationCmdletProvider and its derived classes.
/// </param>
/// <returns>
/// Nothing should be returned or written from this method.
/// </returns>
/// <remarks>
/// Providers override this method to allow the user the ability to remove provider objects using
/// the remove-item cmdlet.
///
/// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
/// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those
/// requirements by accessing the appropriate property from the base class.
///
/// By default overrides of this method should not remove objects that are generally hidden from
/// the user unless the Force property is set to true. For instance, the FileSystem provider should
/// not remove a hidden or system file unless the Force property is set to true.
///
/// The provider implementation is responsible for preventing infinite recursion when there are
/// circular links and the like. An appropriate terminating exception should be thrown if this
/// situation occurs.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void RemoveItem(
string path,
bool recurse)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Gives the provider an opportunity to attach additional parameters to
/// the remove-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="recurse">
/// True if all children in a subtree should be removed, false if only a single
/// level of children should be removed. This parameter should only be true for
/// NavigationCmdletProvider and its derived classes.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
protected virtual object RemoveItemDynamicParameters(
string path,
bool recurse)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return null;
}
}
/// <summary>
/// Determines if the item at the specified path has children.
/// </summary>
/// <param name="path">
/// The path to the item to see if it has children.
/// </param>
/// <returns>
/// True if the item has children, false otherwise.
/// </returns>
/// <returns>
/// Nothing is returned, but all objects should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the provider infrastructure the ability to determine
/// if a particular provider object has children without having to retrieve all the child items.
///
/// For implementers of <see cref="ContainerCmdletProvider"/> classes and those derived from it,
/// if a null or empty path is passed,
/// the provider should consider any items in the data store to be children
/// and return true.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual bool HasChildItems(string path)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Copies an item at the specified path to an item at the <paramref name="copyPath"/>.
/// </summary>
/// <param name="path">
/// The path of the item to copy.
/// </param>
/// <param name="copyPath">
/// The path of the item to copy to.
/// </param>
/// <param name="recurse">
/// Tells the provider to recurse sub-containers when copying.
/// </param>
/// <returns>
/// Nothing is returned, but all the objects that were copied should be written to the WriteItemObject method.
/// </returns>
/// <remarks>
/// Providers override this method to give the user the ability to copy provider objects using
/// the copy-item cmdlet.
///
/// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/>
/// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path and items being copied
/// meets those requirements by accessing the appropriate property from the base class.
///
/// By default overrides of this method should not copy objects over existing items unless the Force
/// property is set to true. For instance, the FileSystem provider should not copy c:\temp\foo.txt over
/// c:\bar.txt if c:\bar.txt already exists unless the Force parameter is true.
///
/// If <paramref name="copyPath"/> exists and is a container then Force isn't required and <paramref name="path"/>
/// should be copied into the <paramref name="copyPath"/> container as a child.
///
/// If <paramref name="recurse"/> is true, the provider implementation is responsible for
/// preventing infinite recursion when there are circular links and the like. An appropriate
/// terminating exception should be thrown if this situation occurs.
///
/// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>.
/// </remarks>
protected virtual void CopyItem(
string path,
string copyPath,
bool recurse)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
throw
PSTraceSource.NewNotSupportedException(
SessionStateStrings.CmdletProvider_NotSupported);
}
}
/// <summary>
/// Gives the provider an opportunity to attach additional parameters to
/// the copy-item cmdlet.
/// </summary>
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
/// <param name="destination">
/// The path of the item to copy to.
/// </param>
/// <param name="recurse">
/// Tells the provider to recurse sub-containers when copying.
/// </param>
/// <returns>
/// Overrides of this method should return an object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class or a
/// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>.
///
/// The default implementation returns null. (no additional parameters)
/// </returns>
protected virtual object CopyItemDynamicParameters(
string path,
string destination,
bool recurse)
{
using (PSTransactionManager.GetEngineProtectionScope())
{
return null;
}
}
#endregion Protected members
}
#endregion ContainerCmdletProvider
}
|