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
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Globalization;
namespace System.Management.Instrumentation
{
#region CommonUMPAttributes
/// <summary>
/// This attribute declares a class to be exposed as a management
/// interface.
///
/// It declares the noun to expose in Monad and
/// optionally the XML Namespace to expose the class
/// through WMI.NET and WS-Management.
///
/// </summary>
///
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false,Inherited=false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementEntityAttribute : Attribute
{
public ManagementEntityAttribute()
{
}
public string Name
{
get { return _nounName; }
set
{
_nounName = value;
}
}
public bool External
{
get { return _isExternalClass; }
set
{
_isExternalClass = value;
}
}
public bool Singleton
{
get { return _isSingleton; }
set
{
_isSingleton = value;
}
}
private string _nounName;
private bool _isExternalClass = false;
private bool _isSingleton = false;
/*
/// <summary>
/// Reference to the Type which acts as a factory for instances
/// of this class.
/// </summary>
///
public Type Factory
{
get { return _factory; }
set { _factory = value; }
}
private Type _factory;
public Type FactoryFor
{
get { return _factoryfor; }
set { _factoryfor = value; }
}
private Type _factoryfor;
*/
}
#endregion CommonUMPAttributes
/// <remarks>
/// WMI is able to deal with Decoupled and Hosted providers.
/// UserHosted for component loaded inproc to the client is not allowed for .NET extension providers.
public enum ManagementHostingModel
{
Decoupled,
NetworkService,
LocalService,
LocalSystem
}
[AttributeUsage(AttributeTargets.Assembly)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class WmiConfigurationAttribute : Attribute
{
private string _Scope = null;
private string _SecurityRestriction = null;
private string _NamespaceSecurity = null;
private ManagementHostingModel _HostingModel = ManagementHostingModel.Decoupled;
private string _HostingGroup = null;
private bool _IdentifyLevel = true;
public WmiConfigurationAttribute(string scope)
{
string namespaceName = scope;
if (namespaceName != null)
namespaceName = namespaceName.Replace('/', '\\');
if (namespaceName == null || namespaceName.Length == 0)
namespaceName = "root\\default";
bool once = true;
foreach (string namespacePart in namespaceName.Split('\\'))
{
if (namespacePart.Length == 0
|| (once && String.Compare(namespacePart, "root", StringComparison.OrdinalIgnoreCase) != 0) // Must start with 'root'
|| !Regex.Match(namespacePart, @"^[a-z,A-Z]").Success // All parts must start with letter
|| Regex.Match(namespacePart, @"_$").Success // Must not end with an underscore
|| Regex.Match(namespacePart, @"[^a-z,A-Z,0-9,_,\u0080-\uFFFF]").Success) // Only letters, digits, or underscores
{
//ManagementException.ThrowWithExtendedInfo(ManagementStatus.InvalidNamespace);
}
once = false;
}
_Scope = namespaceName;
}
/// <remarks>
/// The security descriptor used by instrumentation to filter the providers
public string SecurityRestriction
{
get { return _SecurityRestriction; }
set { _SecurityRestriction = value; }
}
public string NamespaceSecurity
{
get { return _NamespaceSecurity; }
set { _NamespaceSecurity = value; }
}
public bool IdentifyLevel
{
get { return _IdentifyLevel; }
set { _IdentifyLevel = value; }
}
public ManagementHostingModel HostingModel
{
get { return _HostingModel; }
set { _HostingModel = value; }
}
/// <remarks>
/// To support provider separation
public string HostingGroup
{
get { return _HostingGroup; }
set { _HostingGroup = value; }
}
/// <remarks>
/// Scope of the assembly in the target instrumentation space
/// In WMI speak is the namespace
public string Scope
{
get { return _Scope; }
}
}
/// <summary>
/// This is the base class for all attribute which can be applied
/// to members of the Automation class.
/// </summary>
///
/// <remarks>
/// The Exception member tells Monad which exception coming from the
/// member can be treated as non-fatal errors for the pipeline.
/// </remarks>
///
[AttributeUsage(AttributeTargets.All)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public abstract class ManagementMemberAttribute : Attribute
{
/// <summary>
/// The exceptions that can be thrown by the member.
/// </summary>
///
public string Name
{
get { return _Name; }
set { _Name = value; }
}
private string _Name;
}
/// <summary>
/// This abstract attribute determines how one would get an instance of the class.
/// You can get an instance by:
/// 1) Binding to an instance [Bind]
/// 2) Creating an instance [Create]
/// 3) Using a factory to get an instance [Factory]
/// For any particular NOUN, there can only be ONE way to get instances.
/// </summary>
///
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public abstract class ManagementNewInstanceAttribute : ManagementMemberAttribute
{
}
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementBindAttribute : ManagementNewInstanceAttribute
{
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public ManagementBindAttribute() { }
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementCreateAttribute : ManagementNewInstanceAttribute
{
///// <summary>
///// Declares the type that the output should be
///// treated as even if the return value is of
///// type System.Object.
///// </summary>
/////
}
/// <summary>
/// This attribute determines how one would remove a real object
/// </summary>
///
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementRemoveAttribute : ManagementMemberAttribute
{
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
/// <summary>
/// This attribute defines the enumerator of instances of the class
/// </summary>
///
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementEnumeratorAttribute : ManagementNewInstanceAttribute
{
/* /// <summary>
/// Declares the member as an enumerator for other classes. The other
/// Type must specify the Factory property of the AutomationAttribute to
/// be this Type.
/// </summary>
///
public Type FactoryFor
{
get { return _factoryFor; }
set { _factoryFor = value; }
}
private Type _factoryFor;
*/ /// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
/// <summary>
/// Exposes a method or property as a Probe
/// </summary>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementProbeAttribute : ManagementMemberAttribute
{
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
#region Task
/// <summary>
/// Exposes a method as a task.
/// </summary>
///
/// <remarks>
/// The TaskAttribute is placed on a method to expose it as a management task.
///
/// If the task enumerates manageable objects, the task declaration should set
/// the Enumeration option to true.
///
/// ISSUE-2005/06/08-jeffjon
/// Does the task need a Schema parameter or should we have a separate Probe
/// attribute?
/// </remarks>
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementTaskAttribute : ManagementMemberAttribute
{
public ManagementTaskAttribute()
{
}
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
#endregion Task
#region Naming
/// <summary>
/// This attribute defines the ID (key) property of the class.
/// </summary>
///
/// <remarks>
/// For Monad, this property is used to do filtering of enumerations.
///
/// If used on a parameter, then the attribute must also exist on a property in
/// the class.
/// </remarks>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementKeyAttribute : ManagementMemberAttribute
{
public ManagementKeyAttribute()
{
}
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementReferenceAttribute : Attribute
{
public ManagementReferenceAttribute()
{
}
public string Type
{
get { return _Type; }
set { _Type = value; }
}
private string _Type;
}
#endregion Naming
#region Configuration
/// <summary>
/// Defines a property as the storage for configuration data.
/// </summary>
///
public enum ManagementConfigurationType { Apply, OnCommit };
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementConfigurationAttribute : ManagementMemberAttribute
{
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public ManagementConfigurationAttribute()
{
updateMode = ManagementConfigurationType.Apply;
}
public ManagementConfigurationType Mode
{
get { return updateMode; }
set { updateMode = value; }
}
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private ManagementConfigurationType updateMode;
private Type _schema;
}
[AttributeUsage(AttributeTargets.Method)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementCommitAttribute : ManagementMemberAttribute
{
}
/// <summary>
/// This attribute defines the naming (user friendly name) of method parameters
/// </summary>
///
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
sealed public class ManagementNameAttribute : Attribute
{
public ManagementNameAttribute(string name)
{
_Name = name;
}
public string Name
{
get { return _Name; }
}
private string _Name;
}
#endregion Configuration
/*
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class FactoryAttribute : NewInstanceAttribute
{
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public FactoryAttribute() { }
public FactoryAttribute(Type t) { }
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class FactoryForAttribute : ManagementMemberAttribute
{
/// <summary>
/// Declares the type that the output should be
/// treated as even if the return value is of
/// type System.Object.
/// </summary>
///
public FactoryForAttribute(Type t) { }
public Type Schema
{
get { return _schema; }
set { _schema = value; }
}
private Type _schema;
}
#region Constraints
/// <summary>
/// Constraints the member/option to a minimum and/or maximum length.
/// </summary>
///
/// <remarks>
/// This can be used for strings or collections.
/// </remarks>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class ValidateLengthAttribute : Attribute
{
/// <summary>
/// The minimum length
/// </summary>
///
public int Min
{
get { return _min; }
set { _min = value; }
}
private int _min = int.MinValue;
/// <summary>
/// The maximum length
/// </summary>
///
public int Max
{
get { return _max; }
set { _max = value; }
}
private int _max = int.MaxValue;
}
/// <summary>
/// Constraints the member/option to a range of values.
/// </summary>
///
/// <remarks>
/// This can be used for strings or collections.
/// </remarks>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class ValidateRangeAttribute : Attribute
{
/// <summary>
/// Defines the range for the constraint
/// </summary>
///
/// <param name="lower">
/// The minimum of the range.
/// </param>
///
/// <param name="upper">
/// The maximum of the range.
/// </param>
///
public ValidateRangeAttribute(object lower, object upper)
{
this._lower = lower;
this._upper = upper;
}
/// <summary>
/// The lower bound for the range
/// </summary>
///
public object Lower
{
get { return _lower; }
set { _lower = value; }
}
private object _lower;
/// <summary>
/// The upper bound for the range
/// </summary>
///
public object Upper
{
get { return _upper; }
set { _upper = value; }
}
private object _upper;
}
/// <summary>
/// Constraints the member/option to a pattern represented by a regular expression
/// </summary>
///
/// <remarks>
/// This can be used for strings or collections.
/// </remarks>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class ValidatePatternAttribute : Attribute
{
/// <summary>
/// Defines the pattern for the constraint
/// </summary>
///
/// <param name="pattern">
/// The minimum of the range.
/// </param>
///
public ValidatePatternAttribute(string pattern)
{
this._pattern = pattern;
}
/// <summary>
/// The pattern which defines the constraint
/// </summary>
///
public string Pattern
{
get { return _pattern; }
set { _pattern = value; }
}
private string _pattern;
/// <summary>
/// The options for the regular expression defined by the pattern.
/// </summary>
///
public RegexOptions Options
{
get { return _options; }
set { _options = value; }
}
private RegexOptions _options = RegexOptions.IgnoreCase;
}
/// <summary>
/// Constraints the member/option to a number of values.
/// </summary>
///
/// <remarks>
/// This can be used for strings or collections.
/// </remarks>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class ValidateCountAttribute : Attribute
{
/// <summary>
/// Defines the minimum and maximum number of elements.
/// </summary>
///
/// <param name="minimum">
/// The minimum minimum number of elements.
/// </param>
///
/// <param name="maximum">
/// The maximum number of elements.
/// </param>
///
public ValidateCountAttribute(int minimum, int maximum)
{
}
/// <summary>
/// The minimum number of elements
/// </summary>
///
public int Minimum;
/// <summary>
/// The maximum number of elements
/// </summary>
///
public int Maximum;
}
/// <summary>
/// Constraints the member/option to a set of values.
/// </summary>
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = true)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class ValidateSetAttribute : Attribute
{
/// <summary>
/// Defines the range for the constraint
/// </summary>
///
/// <param name="validValues">
/// The valid values for the set.
/// </param>
///
public ValidateSetAttribute(params string[] validValues)
{
}
/// <summary>
/// The valid values for the set.
/// </summary>
///
public string[] ValidValues
{
get { return null; }
set { }
}
/// <summary>
/// If true, the values are compared in a case-insensitive way.
/// If false, the set is constrained to exact matches.
/// </summary>
///
public bool IgnoreCase
{
get { return _ignoreCase; }
set { _ignoreCase = value; }
}
private bool _ignoreCase = true;
}
#endregion Constraints
/// <summary>
/// Specifies the options for a task.
/// </summary>
///
/// <remarks>
/// When placed on a parameter of a task method, this attribute
/// describes the options for the parameter.
/// </remarks>
///
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public class ManagementTaskOptionAttribute : Attribute
{
/// <summary>
/// If true, the option must be specified.
/// </summary>
///
/// <remarks>
/// If false, and the InitialValue is not specified, then
/// an initial value will be deduced using the "default"
/// keyword in C#.
/// </remarks>
///
public bool Mandatory
{
get { return _mandatory; }
set { _mandatory = value; }
}
private bool _mandatory = true;
/// <summary>
/// The initial value of the parameter. Used if Mandatory=false.
/// </summary>
///
public object InitialValue
{
get { return _initialValue; }
set { _initialValue = value; }
}
private object _initialValue;
/// <summary>
/// Monad specific - provides mapping of the pipeline object
/// to the parameter value.
/// </summary>
///
public bool ValueFromPipeline
{
get { return _valueFromPipeline; }
set { _valueFromPipeline = value; }
}
private bool _valueFromPipeline;
/// <summary>
/// Monad specific - provides mapping of the pipeline object's
/// property with the same name as the parameter to the parameter
/// value.
/// </summary>
public bool ValueFromPipelineByPropertyName
{
get { return _valueFromPipelineByPropertyName; }
set { _valueFromPipelineByPropertyName = value; }
}
private bool _valueFromPipelineByPropertyName;
}
*/
};
|