Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

911 lines
26 KiB

  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Security.Principal;
  7. using System.Xml;
  8. using System.Text;
  9. using System.Xml.Serialization;
  10. using System.Globalization;
  11. using UDDI.Diagnostics;
  12. namespace UDDI
  13. {
  14. //
  15. // 739955 - Make sure date is parsed in the same format it was written.
  16. //
  17. public class UDDILastResetDate
  18. {
  19. private const string dateTimeFormat = "MM/dd/yyyy HH:mm:ss";
  20. private static DateTimeFormatInfo dateTimeFormatInfo;
  21. static UDDILastResetDate()
  22. {
  23. dateTimeFormatInfo = new DateTimeFormatInfo();
  24. //
  25. // When you specify a '/' in a date/time format string, this tells the DateTime
  26. // class to use the default Date Separator, not the character '/'. Same goes
  27. // for ':' and Time Separator.
  28. //
  29. // So all we do is change the defaults to '/' and ':'.
  30. //
  31. dateTimeFormatInfo.DateSeparator = "/";
  32. dateTimeFormatInfo.TimeSeparator = ":";
  33. }
  34. public static DateTime Get()
  35. {
  36. return DateTime.ParseExact( Config.GetString( "Security.KeyLastResetDate" ), dateTimeFormat, dateTimeFormatInfo );
  37. }
  38. public static void Set( DateTime dateTime )
  39. {
  40. Config.SetString( "Security.KeyLastResetDate", dateTime.ToString( dateTimeFormat, dateTimeFormatInfo ) );
  41. }
  42. }
  43. public class Constants
  44. {
  45. public const int ReadLockTimeout = 120000; // milliseconds
  46. //
  47. // Subtract this offset from error numbers that come from our DB layer to get an
  48. // ErrorType value. This offset is added in our DB to keep us away from SQL-defined
  49. // error numbers.
  50. //
  51. public const int ErrorTypeSQLOffset = 50000;
  52. public const string OwningBusinessTModelKey = "uuid:4064c064-6d14-4f35-8953-9652106476a9";
  53. public const string UDDITypeTaxonomyTModelKey = "uuid:c1acf26d-9672-4404-9d70-39b756e62ab4";
  54. public const string UDDITypeTaxonomyWSDLSpecKeyValue = "wsdlSpec";
  55. public const int Run = 1;
  56. public class Site
  57. {
  58. public const string Version = "";
  59. }
  60. public class Passport
  61. {
  62. public const int TimeWindow = 14400;
  63. }
  64. public class Web
  65. {
  66. public const int HttpsPort = 443;
  67. public const int HttpPort = 80;
  68. public const int BetaSite = 0;
  69. public const int TestSite = 0;
  70. public const string SiteStatus = "open";
  71. public const string OutageStart = "";
  72. public const string OutageEnd = "";
  73. public const int EnableRegistration = 1;
  74. }
  75. public class Security
  76. {
  77. public const int HTTPS = 1;
  78. }
  79. public class Debug
  80. {
  81. public const int StackTrace = 0;
  82. }
  83. public class Lengths
  84. {
  85. //public const int Behavior = 1;
  86. //public const int ReplicationBehavior = 2;
  87. public const int AccessPoint = 255;
  88. public const int AddressLine = 80;
  89. public const int AuthInfo = 4096;
  90. public const int AuthorizedName = 255;
  91. //public const int BindingKey = 41;
  92. //public const int BusinessKey = 41;
  93. //public const int ServiceKey = 41;
  94. public const int Key = 41;
  95. public const int TModelKey = 255;
  96. public const int Description = 255;
  97. public const int DiscoveryURL = 255;
  98. public const int Email = 255;
  99. public const int HostingRedirector = 41;
  100. public const int InstanceParms = 255;
  101. public const int KeyName = 255;
  102. public const int KeyType = 16;
  103. public const int KeyValue = 255;
  104. //public const int MaxRows = 5;
  105. public const int Name = 255;
  106. public const int Operator = 48;
  107. public const int OverviewURL = 255;
  108. public const int PersonName = 255;
  109. public const int Phone = 50;
  110. public const int SortCode = 10;
  111. public const int UploadRegister = 255;
  112. public const int URLType = 16;
  113. public const int UseType = 255;
  114. public const int UserID = 450;
  115. // additional lengths
  116. public const int ConfigName = 450;
  117. public const int ConfigValue = 4000;
  118. public const int Context = 20;
  119. public const int IsoLangCode = 17;
  120. public const int generic = 20;
  121. public const int OperatorName = 450;
  122. public const int CertSerialNo = 450;
  123. public const int PublisherStatus = 256;
  124. public const int SoapReplicationURL = 4000;
  125. public const int CertIssuer = 225;
  126. public const int CertSubject = 225;
  127. public const int Certificate = 225;
  128. public const int CompanyName = 100;
  129. public const int City = 100;
  130. public const int StateProvince = 100;
  131. public const int PostalCode = 100;
  132. public const int Country = 100;
  133. public const int Tier = 256;
  134. }
  135. }
  136. public enum EntityType
  137. {
  138. TModel = 0,
  139. BusinessEntity = 1,
  140. BusinessService = 2,
  141. BindingTemplate = 3,
  142. Contact = 4,
  143. TModelInstanceInfo = 5,
  144. InstanceDetail = 6,
  145. TModelOverviewDoc = 7,
  146. InstanceDetailOverviewDoc = 8
  147. }
  148. public enum KeyedReferenceType
  149. {
  150. CategoryBag = 1,
  151. IdentifierBag = 2,
  152. Assertion = 3
  153. }
  154. public enum ErrorType
  155. {
  156. E_success = 0,
  157. E_nameTooLong = 10020,
  158. E_tooManyOptions = 10030,
  159. E_unrecognizedVersion = 10040,
  160. E_unsupported = 10050,
  161. E_authTokenExpired = 10110,
  162. E_authTokenRequired = 10120,
  163. E_operatorMismatch = 10130, // Deprecated.
  164. E_userMismatch = 10140,
  165. E_unknownUser = 10150,
  166. E_accountLimitExceeded = 10160,
  167. E_invalidKeyPassed = 10210,
  168. E_invalidURLPassed = 10220, // Deprecated.
  169. E_keyRetired = 10310,
  170. E_busy = 10400, // Deprecated.
  171. E_fatalError = 10500,
  172. E_languageError = 10060,
  173. E_invalidCategory = 20000, // Deprecated. Use E_invalidValue
  174. E_categorizationNotAllowed = 20100, // Deprecated. Use E_valueNotAllowed
  175. E_invalidValue = 20200,
  176. E_valueNotAllowed = 20210,
  177. E_invalidProjection = 20230,
  178. E_assertionNotFound = 30000,
  179. E_messageTooLarge = 30110, // TODO: Error codes duplicated?
  180. E_invalidCompletionStatus = 30100, // TODO: Error codes duplicated?
  181. E_transferAborted = 30200,
  182. E_requestDenied = 30210,
  183. E_publisherCancelled = 30220,
  184. E_secretUnknown = 30230
  185. }
  186. public enum QueryType
  187. {
  188. Get = 0,
  189. Find = 1
  190. }
  191. //
  192. // Use this enumerated type to determine where the UDDIException instance is being
  193. // used.
  194. //
  195. public enum UDDITextContext
  196. {
  197. API,
  198. UI,
  199. EventLog,
  200. FileLog
  201. }
  202. //
  203. // This class should be used for any message that the user would see. Depending on the
  204. // context, this class will localize it's message as the system locale, or the user's locale.
  205. //
  206. public class UDDIText
  207. {
  208. private string defaultLocaleText;
  209. private string textName;
  210. private object[] textFormatParts;
  211. public UDDIText( string textName ) : this( textName, null )
  212. {
  213. }
  214. public UDDIText( string textName, params object[] textFormatParts )
  215. {
  216. this.textName = textName;
  217. this.textFormatParts = textFormatParts;
  218. defaultLocaleText = ConstructString( Localization.GetStringLocalMachineCulture( textName ) );
  219. }
  220. public string GetText()
  221. {
  222. return defaultLocaleText;
  223. }
  224. public override string ToString()
  225. {
  226. return defaultLocaleText;
  227. }
  228. public string GetText( UDDITextContext context )
  229. {
  230. switch( context )
  231. {
  232. case UDDITextContext.API:
  233. {
  234. return defaultLocaleText;
  235. }
  236. case UDDITextContext.UI:
  237. {
  238. return ConstructString( Localization.GetString( textName ) );
  239. }
  240. case UDDITextContext.EventLog:
  241. {
  242. return defaultLocaleText;
  243. }
  244. case UDDITextContext.FileLog:
  245. {
  246. return defaultLocaleText;
  247. }
  248. default:
  249. {
  250. return defaultLocaleText;
  251. }
  252. }
  253. }
  254. private string ConstructString( string stringToConstruct )
  255. {
  256. if( null != textFormatParts )
  257. {
  258. stringToConstruct = string.Format( stringToConstruct, textFormatParts );
  259. }
  260. return stringToConstruct;
  261. }
  262. }
  263. public class UDDIException : ApplicationException
  264. {
  265. private UDDIText uddiText;
  266. public UDDIException() : this( ErrorType.E_fatalError, "", null )
  267. {
  268. }
  269. public UDDIException( ErrorType number, string errorMsgName ) : this( number, errorMsgName, null )
  270. {
  271. }
  272. public UDDIException( ErrorType number, string errorMsgName, params object[] errorMsgFormatParts ) : this( number, new UDDIText( errorMsgName, errorMsgFormatParts ) )
  273. {
  274. }
  275. public UDDIException( ErrorType number, UDDIText uddiText )
  276. {
  277. this.uddiText = uddiText;
  278. this.Number = number;
  279. }
  280. //
  281. // GetMessage will localize the exception message depending on who is
  282. // using the exception. Currently, in all cases we localize the message
  283. // using the server local, except if the exception is coming from the
  284. // UI.
  285. //
  286. public string GetMessage( UDDITextContext context )
  287. {
  288. return uddiText.GetText( context );
  289. }
  290. public override string Message
  291. {
  292. get
  293. {
  294. return uddiText.GetText();
  295. }
  296. }
  297. public override string ToString()
  298. {
  299. return uddiText.GetText();
  300. }
  301. public ErrorType Number = 0;
  302. }
  303. public class Conversions
  304. {
  305. public static string EntityNameFromID( EntityType entityType )
  306. {
  307. switch( entityType )
  308. {
  309. case EntityType.BusinessEntity:
  310. return "businessEntity";
  311. case EntityType.BusinessService:
  312. return "businessService";
  313. case EntityType.BindingTemplate:
  314. return "bindingTemplate";
  315. case EntityType.TModel:
  316. return "tModel";
  317. default:
  318. return null;
  319. }
  320. }
  321. /// ****************************************************************
  322. /// public GuidFromKey [static]
  323. /// ----------------------------------------------------------------
  324. /// <summary>
  325. /// Converts "uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" keys to
  326. /// a standard GUID.
  327. /// </summary>
  328. /// ----------------------------------------------------------------
  329. /// <param name="key">
  330. /// The key to convert.
  331. /// </param>
  332. /// ----------------------------------------------------------------
  333. /// <returns>
  334. /// The equivalent GUID.
  335. /// </returns>
  336. /// ****************************************************************
  337. ///
  338. public static Guid GuidFromKey( string key )
  339. {
  340. Debug.VerifyKey( key );
  341. return new Guid( key.Substring(5) );
  342. }
  343. /// ****************************************************************
  344. /// public KeyFromGuid [static]
  345. /// ----------------------------------------------------------------
  346. /// <summary>
  347. /// Converts standard GUIDs to a key of the form
  348. /// "uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
  349. /// </summary>
  350. /// ----------------------------------------------------------------
  351. /// <param name="guid">
  352. /// The GUID to convert.
  353. /// </param>
  354. /// ----------------------------------------------------------------
  355. /// <returns>
  356. /// The equivalent key.
  357. /// </returns>
  358. /// ****************************************************************
  359. ///
  360. public static string KeyFromGuid( Guid guid )
  361. {
  362. if( null == (object)guid )
  363. return null;
  364. return "uuid:" + Convert.ToString( guid );
  365. }
  366. /// ****************************************************************
  367. /// public KeyFromGuid [static]
  368. /// ----------------------------------------------------------------
  369. /// <summary>
  370. /// Converts standard GUIDs to a key of the form
  371. /// "uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
  372. /// </summary>
  373. /// ----------------------------------------------------------------
  374. /// <param name="guid">
  375. /// The GUID to convert.
  376. /// </param>
  377. /// ----------------------------------------------------------------
  378. /// <returns>
  379. /// The equivalent key.
  380. /// </returns>
  381. /// ****************************************************************
  382. ///
  383. public static string KeyFromGuid( string guid )
  384. {
  385. if( null == guid )
  386. return null;
  387. return "uuid:" + guid;
  388. }
  389. public static string GuidStringFromKey( string key )
  390. {
  391. //
  392. // Convert uuid:E31A569A-AEFF-4468-BA4D-2BF22FE4ACEE
  393. // to string type without uuid:
  394. // Example: E31A569A-AEFF-4468-BA4D-2BF22FE4ACEE
  395. //
  396. string NewGuidStr = "";
  397. switch ( key )
  398. {
  399. case null:
  400. NewGuidStr = null;
  401. break;
  402. case "":
  403. NewGuidStr = "";
  404. break;
  405. default:
  406. Debug.VerifyKey( key );
  407. NewGuidStr = new Guid( key.Substring(5) ).ToString();
  408. break;
  409. }
  410. return( NewGuidStr );
  411. }
  412. }
  413. /// ********************************************************************
  414. /// public class Utility
  415. /// --------------------------------------------------------------------
  416. /// <summary>
  417. /// </summary>
  418. /// ********************************************************************
  419. ///
  420. public class Utility
  421. {
  422. public enum LengthBehavior
  423. {
  424. Ignore = 0,
  425. Truncate = 1,
  426. ThrowException = 2
  427. };
  428. /// ****************************************************************
  429. /// public Iff [static]
  430. /// ----------------------------------------------------------------
  431. /// <summary>
  432. /// Returns a particular value depending on whether the given
  433. /// expression is true or false. Useful for web page templates
  434. /// where arbitrary expressions cannot be evaluated, but
  435. /// functions that take expressions as arguments can be
  436. /// evaluated.
  437. /// </summary>
  438. /// ----------------------------------------------------------------
  439. /// <param name="expression">
  440. /// The boolean result of an expression.
  441. /// </param>
  442. ///
  443. /// <param name="trueReturnValue">
  444. /// The object to return if the expression is true.
  445. /// </param>
  446. ///
  447. /// <param name="falseReturnValue">
  448. /// The object to return if the expression is false.
  449. /// </param>
  450. /// ----------------------------------------------------------------
  451. /// <returns>
  452. /// The value of trueReturnValue if the expression is true,
  453. /// otherwise falseReturnValue.
  454. /// </returns>
  455. /// ****************************************************************
  456. ///
  457. public static object Iff( bool expression, object trueReturnValue, object falseReturnValue )
  458. {
  459. if( expression )
  460. return trueReturnValue;
  461. else
  462. return falseReturnValue;
  463. }
  464. /// ****************************************************************
  465. /// public StringEmpty [static]
  466. /// ----------------------------------------------------------------
  467. /// <summary>
  468. /// Checks if a string is empty.
  469. /// </summary>
  470. /// ----------------------------------------------------------------
  471. /// <param name="str">
  472. /// The string to check.
  473. /// </param>
  474. /// ----------------------------------------------------------------
  475. /// <returns>
  476. /// True if the string is empty or null.
  477. /// </returns>
  478. /// ****************************************************************
  479. ///
  480. public static bool StringEmpty( string str )
  481. {
  482. if( null == str )
  483. return true;
  484. return String.Empty == str;
  485. }
  486. /// ****************************************************************
  487. /// public CollectionEmpty [static]
  488. /// ----------------------------------------------------------------
  489. /// <summary>
  490. /// Checks if a collection is empty.
  491. /// </summary>
  492. /// ----------------------------------------------------------------
  493. /// <param name="col">
  494. /// The collection to check.
  495. /// </param>
  496. /// ----------------------------------------------------------------
  497. /// <returns>
  498. /// True if the collection is empty or null.
  499. /// </returns>
  500. /// ****************************************************************
  501. ///
  502. public static bool CollectionEmpty( ICollection col )
  503. {
  504. if( null == col || 0 == col.Count )
  505. return true;
  506. return false;
  507. }
  508. /// ****************************************************************
  509. /// public ValidateLength [static]
  510. /// ----------------------------------------------------------------
  511. /// <summary>
  512. /// Removes leading and trailing whitespace.
  513. /// The resulting string is then truncated to the specified length.
  514. /// </summary>
  515. /// ----------------------------------------------------------------
  516. /// <param name="str">
  517. /// The string to check.
  518. /// </param>
  519. ///
  520. /// <param name="field">
  521. /// The attribute or element from which the string came.
  522. /// </param>
  523. ///
  524. /// <param name="maxLength">
  525. /// The maximum length for the string.
  526. /// </param>
  527. /// ****************************************************************
  528. ///
  529. public static void ValidateLength( ref string str, string field, int maxLength )
  530. {
  531. if( Utility.StringEmpty( str ) )
  532. return;
  533. //
  534. // Remove leading and trailing whitespace
  535. //
  536. str = str.Trim();
  537. // FixCRLF( ref str );
  538. if( str.Length > maxLength )
  539. {
  540. Debug.Write( SeverityType.Info, CategoryType.Data, "String is too long" );
  541. Debug.Write( SeverityType.Info, CategoryType.Data, "Trimmed length is " + str.Length.ToString() );
  542. Debug.Write( SeverityType.Info, CategoryType.Data, "Trimmed String follows:\n" + str );
  543. Debug.Write( SeverityType.Info, CategoryType.Data, "Trimmed field follows:\n" + field );
  544. for( int i=0; i<str.Length; i++ )
  545. {
  546. Debug.Write( SeverityType.Info, CategoryType.Data, i.ToString() + ": " + str[i].ToString() + " -- 0x" + Convert.ToInt32( str[i] ).ToString( "x" ) );
  547. }
  548. LengthBehavior mode;
  549. if( ContextType.Replication == Context.ContextType )
  550. mode = (LengthBehavior)Config.GetInt( "Length.ReplicationBehavior", (int)LengthBehavior.ThrowException );
  551. else
  552. mode = (LengthBehavior)Config.GetInt( "Length.Behavior", (int)LengthBehavior.Truncate );
  553. if( LengthBehavior.Truncate == mode )
  554. {
  555. str = str.Substring( 0, maxLength );
  556. str = str.Trim();
  557. }
  558. else if( LengthBehavior.ThrowException == mode )
  559. {
  560. #if never
  561. throw new UDDIException(
  562. ErrorType.E_nameTooLong,
  563. "Field " + field + " exceeds maximum length" );
  564. #endif
  565. throw new UDDIException( ErrorType.E_nameTooLong, "UDDI_ERROR_FIELD_TOO_LONG", field );
  566. }
  567. }
  568. }
  569. //
  570. // Strip out the non-printable characters
  571. //
  572. public static string XmlEncode( string str )
  573. {
  574. StringBuilder newstring = new StringBuilder();
  575. foreach( char ch in str )
  576. {
  577. //#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] |
  578. if( 0x09 == ch || 0x0A == ch || 0x0D == ch || ( ch >= 0x20 && ch <= 0xD7FF ) || ( ch >= 0xE000 && ch <= 0xFFFD ) )
  579. {
  580. newstring.Append( ch );
  581. }
  582. }
  583. return newstring.ToString();
  584. }
  585. public static string GetDefaultPublisher()
  586. {
  587. //
  588. // TODO: Need to do the right thing here
  589. //
  590. return "System";
  591. }
  592. //
  593. // TODO: remove once we have verified .NET does this for us
  594. //
  595. private static void FixCRLF( ref string str )
  596. {
  597. char[] bytes = new char[ str.Length ];
  598. int n = 0;
  599. int length = str.Length;
  600. for( int i = 0; i < length; i++ )
  601. {
  602. //
  603. // If the char is not a CR write it out
  604. //
  605. if( 0x0D != str[ i ] )
  606. bytes[ n++ ] = str[ i ];
  607. else
  608. {
  609. //
  610. // If a CRLF combo is found or we are on a CR
  611. // at the end of the string write out a LF
  612. //
  613. if( ( ( i != length - 1 ) && ( 0x0A != str[ i + 1 ] ) ) ||
  614. ( i == length - 1 ) )
  615. {
  616. bytes[ n++ ] = (char) 0x0A;
  617. }
  618. }
  619. }
  620. str = new string( bytes, 0, n );
  621. }
  622. /// ****************************************************************
  623. /// public ValidateLength [static]
  624. /// ----------------------------------------------------------------
  625. /// <summary>
  626. /// Checks that a string is shorter than a given maximum and longer than the specified
  627. /// minimum. It also removes any leading or trailing whitespace.
  628. /// </summary>
  629. /// ----------------------------------------------------------------
  630. /// <param name="str">
  631. /// The string to check.
  632. /// </param>
  633. ///
  634. /// <param name="field">
  635. /// The attribute or element from which the string came.
  636. /// </param>
  637. ///
  638. /// <param name="maxLength">
  639. /// The maximum length for the string.
  640. /// </param>
  641. ///
  642. /// <param name="minLength">
  643. /// The minimum length for the string.
  644. /// </param>
  645. /// ****************************************************************
  646. ///
  647. //
  648. // TODO: This function should call the other overload for ValidateLength
  649. //
  650. public static void ValidateLength( ref string str, string field, int maxLength, int minLength )
  651. {
  652. int length = 0;
  653. if( null != str )
  654. {
  655. //
  656. // Remove leading and trailing whitespace
  657. //
  658. str = str.Trim();
  659. // FixCRLF( ref str );
  660. length = str.Length;
  661. }
  662. if( length < minLength )
  663. {
  664. #if never
  665. throw new UDDIException(
  666. ErrorType.E_fatalError,
  667. "Value for '" + field + "' does not meet minimum length requirement of " + minLength.ToString() );
  668. #endif
  669. throw new UDDIException( ErrorType.E_fatalError, "UDDI_ERROR_FIELD_TOO_SHORT", field, minLength.ToString() );
  670. }
  671. if( null != str && length > maxLength )
  672. {
  673. LengthBehavior mode;
  674. if( ContextType.Replication == Context.ContextType )
  675. mode = (LengthBehavior)Config.GetInt( "Length.ReplicationBehavior", (int)LengthBehavior.ThrowException );
  676. else
  677. mode = (LengthBehavior)Config.GetInt( "Length.Behavior", (int)LengthBehavior.Truncate );
  678. if( LengthBehavior.Truncate == mode )
  679. {
  680. str = str.Substring( 0, maxLength );
  681. str = str.Trim();
  682. }
  683. else if( LengthBehavior.ThrowException == mode )
  684. {
  685. #if never
  686. throw new UDDIException(
  687. ErrorType.E_nameTooLong,
  688. "Field " + field + " exceeds maximum length" );
  689. #endif
  690. throw new UDDIException( ErrorType.E_nameTooLong, "UDDI_ERROR_FIELD_TOO_LONG", field );
  691. }
  692. }
  693. }
  694. /// ****************************************************************
  695. /// public ParseDelimitedToken [static]
  696. /// ----------------------------------------------------------------
  697. /// <summary>
  698. /// Retrieves a token from a string given the delimiter that
  699. /// immediately preceeds (and optionally, the delimiter that
  700. /// follows) the desired token.
  701. /// </summary>
  702. /// ----------------------------------------------------------------
  703. /// <param name="beginDelimiter">
  704. /// The starting delimiter.
  705. /// </param>
  706. ///
  707. /// <param name="endDelimiter">
  708. /// [Optional] The ending delimiter. This can be null.
  709. /// </param>
  710. ///
  711. /// <param name="text">
  712. /// The string to search.
  713. /// </param>
  714. /// ----------------------------------------------------------------
  715. /// <returns>
  716. /// The token, if successful. Otherwise, null.
  717. /// </returns>
  718. /// ****************************************************************
  719. ///
  720. public static string ParseDelimitedToken( string beginDelimiter, string endDelimiter, string text )
  721. {
  722. Debug.Assert( null != beginDelimiter, "beginDelimiter cannot be null" );
  723. Debug.Assert( null != text, "text cannot be null" );
  724. //
  725. // Find the beginning of the starting delimiter. Add the length to
  726. // give the starting position of the token.
  727. //
  728. int startPos = text.IndexOf( beginDelimiter );
  729. if( -1 == startPos )
  730. return null;
  731. startPos += beginDelimiter.Length;
  732. //
  733. // Find the ending delimiter. If no ending delimiter was specified, then
  734. // simply return the remaining string after the beginning delimiter.
  735. //
  736. if( null == endDelimiter )
  737. return text.Substring( startPos );
  738. int endPos = text.IndexOf( endDelimiter, startPos );
  739. if( -1 == endPos )
  740. return null;
  741. return text.Substring( startPos, endPos - startPos );
  742. }
  743. /// ****************************************************************
  744. /// public IsValidKey [static]
  745. /// ----------------------------------------------------------------
  746. /// <summary>
  747. /// Checks to see if the entity associated with a key actually
  748. /// exists in the database.
  749. /// </summary>
  750. /// ****************************************************************
  751. ///
  752. //
  753. // TODO: This function need to be re-written
  754. //
  755. public static void IsValidKey( EntityType entityType, string key )
  756. {
  757. SqlCommand cmd = new SqlCommand( "net_key_validate", ConnectionManager.GetConnection() );
  758. cmd.CommandType = CommandType.StoredProcedure;
  759. cmd.Parameters.Add( new SqlParameter( "@entityTypeID", SqlDbType.TinyInt ) ).Direction = ParameterDirection.Input;
  760. cmd.Parameters.Add( new SqlParameter( "@entityKey", SqlDbType.UniqueIdentifier ) ).Direction = ParameterDirection.Input;
  761. SqlParameterAccessor parmacc = new SqlParameterAccessor( cmd.Parameters );
  762. parmacc.SetShort( "@entityTypeID", (short)entityType );
  763. //
  764. // Check for a tModel key vs other
  765. //
  766. if( key.ToLower().StartsWith( "uuid:" ) )
  767. {
  768. if( entityType != EntityType.TModel )
  769. {
  770. //throw new UDDIException( ErrorType.E_invalidKeyPassed, "Only TModel Keys can start with uuid:" );
  771. throw new UDDIException( ErrorType.E_invalidKeyPassed, "UDDI_ERROR_INVALID_TMODEL_KEY" );
  772. }
  773. parmacc.SetGuidFromKey( "@entityKey", key );
  774. }
  775. else
  776. {
  777. if( EntityType.TModel == entityType )
  778. {
  779. //throw new UDDIException( ErrorType.E_invalidKeyPassed, "Only TModel Keys can start with uuid:" );
  780. throw new UDDIException( ErrorType.E_invalidKeyPassed, "UDDI_ERROR_INVALID_TMODEL_KEY" );
  781. }
  782. try
  783. {
  784. parmacc.SetGuidFromString( "@entityKey", key );
  785. }
  786. catch( Exception )
  787. {
  788. //throw new UDDIException( ErrorType.E_invalidKeyPassed, "Key has invalid format" );
  789. throw new UDDIException( ErrorType.E_invalidKeyPassed, "UDDI_ERROR_INVALID_KEY_FORMAT" );
  790. }
  791. }
  792. cmd.ExecuteScalar();
  793. }
  794. }
  795. public class UTF8EncodedStringWriter : StringWriter
  796. {
  797. private System.Text.UTF8Encoding utfEncoding;
  798. public UTF8EncodedStringWriter() : base()
  799. {
  800. utfEncoding = new UTF8Encoding();
  801. }
  802. public override Encoding Encoding
  803. {
  804. get
  805. {
  806. return utfEncoding;
  807. }
  808. }
  809. }
  810. }