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.

440 lines
8.9 KiB

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.IO;
  5. using System.Collections;
  6. using System.Xml.Serialization;
  7. using UDDI;
  8. using UDDI.Diagnostics;
  9. using UDDI.Replication;
  10. namespace UDDI.Web
  11. {
  12. /// <summary>
  13. /// Summary description for oepratorsearchcontrols.
  14. /// </summary>
  15. [ XmlRoot( "changeRecordCache" ) ]
  16. public class ChangeRecordsSessionCache
  17. {
  18. public ChangeRecordsSessionCache()
  19. {
  20. }
  21. private string key;//=Guid.NewGuid().ToString();
  22. [ XmlAttribute( "key" ) ]
  23. public string Key
  24. {
  25. get{ return key; }
  26. set{ key=value; }
  27. }
  28. private FindChangeRecordsHelper findCache;
  29. [ XmlElement( "findChangeRecordCache" ) ]
  30. public FindChangeRecordsHelper FindCache
  31. {
  32. get
  33. {
  34. if( null==findCache )
  35. {
  36. findCache = new FindChangeRecordsHelper();
  37. }
  38. return findCache;
  39. }
  40. }
  41. private GetChangeRecords getCache;
  42. [ XmlElement( "getChangeRecordCache" ) ]
  43. public GetChangeRecords GetCache
  44. {
  45. get{ return getCache; }
  46. set{ getCache = (GetChangeRecords)value; }
  47. }
  48. private ChangeRecordDetail changes;
  49. [XmlIgnore]
  50. public ChangeRecordDetail Changes
  51. {
  52. get{ return changes; }
  53. }
  54. private ChangeRecordVectorCollection changelist;
  55. [XmlIgnore]
  56. public ChangeRecordVectorCollection ChangeList
  57. {
  58. get{ return changelist; }
  59. }
  60. public void GetChanges()
  61. {
  62. if( null!=GetCache )
  63. {
  64. changes = GetCache.Get();
  65. }
  66. }
  67. public void FindChanges()
  68. {
  69. }
  70. public void SaveCache()
  71. {
  72. Debug.Enter();
  73. //
  74. // Serialize the data into a stream.
  75. //
  76. XmlSerializer serializer = new XmlSerializer( this.GetType() );
  77. StringWriter writer = new StringWriter();
  78. serializer.Serialize( writer, this );
  79. //
  80. // Write the cache object to the database.
  81. //
  82. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "UI_setSessionCache" );
  83. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar );
  84. sp.Parameters.Add( "@cacheValue", SqlDbType.NText );
  85. sp.Parameters.Add( "@context", SqlDbType.NVarChar );
  86. sp.Parameters.SetString( "@PUID",Key );
  87. sp.Parameters.SetString( "@cacheValue",writer.ToString() );
  88. sp.Parameters.SetString( "@context","ReplicationServer" );
  89. sp.ExecuteNonQuery();
  90. sp.Close();
  91. writer.Close();
  92. Debug.Leave();
  93. }
  94. public static ChangeRecordsSessionCache RetrieveCache( string key )
  95. {
  96. ChangeRecordsSessionCache session = RetrieveCacheFromDB( key );
  97. return session;
  98. }
  99. protected static ChangeRecordsSessionCache RetrieveCacheFromDB( string key )
  100. {
  101. Debug.Enter();
  102. //
  103. // Retrieve the cache object from the database.
  104. //
  105. string data = "";
  106. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "UI_getSessionCache" );
  107. sp.Parameters.Add( "@PUID", SqlDbType.NVarChar );
  108. sp.Parameters.Add( "@context", SqlDbType.NVarChar );
  109. sp.Parameters.SetString( "@PUID" , key );
  110. sp.Parameters.SetString("@context" , "ReplicationServer" );
  111. data = (string)sp.ExecuteScalar();
  112. //
  113. // Deserialize into a cache object.
  114. //
  115. ChangeRecordsSessionCache cache = null;
  116. if( !Utility.StringEmpty( data ) )
  117. {
  118. XmlSerializer serializer = new XmlSerializer( typeof( ChangeRecordsSessionCache ) );
  119. StringReader reader = new StringReader( data );
  120. cache = (ChangeRecordsSessionCache)serializer.Deserialize( reader );
  121. cache.Key = key;
  122. }
  123. Debug.Leave();
  124. return cache;
  125. }
  126. }
  127. [XmlRoot( "findChangeRecordCache" )]
  128. public class FindChangeRecordsHelper
  129. {
  130. public FindChangeRecordsHelper()
  131. {
  132. }
  133. [ XmlAttribute( "startUSN" ) ]
  134. protected long StartUSN;
  135. [ XmlAttribute( "endUSN" ) ]
  136. protected long EndUSN;
  137. [ XmlAttribute( "maxRows" ) ]
  138. protected long MaxRows;
  139. [ XmlAttribute( "operatorID" ) ]
  140. protected string OperatorNodeID;
  141. private FindFilterCollection filters;
  142. [ XmlArray( "filters" ), XmlArrayItem( "filter" ) ]
  143. public FindFilterCollection Filters
  144. {
  145. get{ return filters; }
  146. set{ filters=(FindFilterCollection)value; }
  147. }
  148. public ChangeRecordCollection GetChangeRecords( )
  149. {
  150. ChangeRecordCollection crc = new ChangeRecordCollection();
  151. return crc;
  152. }
  153. }
  154. [ XmlRoot( "filters" ) ]
  155. public class FindFilterCollection : CollectionBase
  156. {
  157. public FindFilter this[ int index ]
  158. {
  159. get{ return (FindFilter)this.List[ index ]; }
  160. set{ this.List[ index] = value; }
  161. }
  162. public FindFilter Add( string field, FilterOperator oper, string val )
  163. {
  164. return this.Add( field,
  165. oper,
  166. val,
  167. ( (this.Count > 0) ? FilterConjuctionOperator.And : FilterConjuctionOperator.None ) );
  168. }
  169. public FindFilter Add( string field, FilterOperator oper, string val, FilterConjuctionOperator conj )
  170. {
  171. return this.Add( new FindFilter( field,oper, val, conj ) );
  172. }
  173. public FindFilter Add( FindFilter filter )
  174. {
  175. this.List.Add( filter );
  176. return filter;
  177. }
  178. public void Remove( int index )
  179. {
  180. this.List.RemoveAt( index );
  181. }
  182. public void Remove( FindFilter filter )
  183. {
  184. this.List.Remove( filter );
  185. }
  186. public FindFilter Insert( int index, FindFilter filter )
  187. {
  188. this.List.Insert( index, filter );
  189. return filter;
  190. }
  191. public string GetFullFilterString()
  192. {
  193. string fullstring = "";
  194. foreach( FindFilter filter in this )
  195. {
  196. fullstring += filter.GetFilterString();
  197. }
  198. return fullstring;
  199. }
  200. }
  201. [ XmlRoot( "filter" ) ]
  202. public class FindFilter
  203. {
  204. public FindFilter( string field, FilterOperator oper, string val, FilterConjuctionOperator conj )
  205. {
  206. this.fieldname = field;
  207. this.filteroperator = oper;
  208. this.filtervalue = val;
  209. this.conjuction = conj;
  210. }
  211. [ XmlAttribute( "conjuction" ) ]
  212. protected FilterConjuctionOperator conjuction;
  213. public FilterConjuctionOperator Conjuction
  214. {
  215. get{ return conjuction; }
  216. }
  217. [ XmlAttribute( "fieldName" ) ]
  218. protected string fieldname;
  219. public string FieldName
  220. {
  221. get{ return fieldname; }
  222. }
  223. [ XmlAttribute( "operator" ) ]
  224. protected FilterOperator filteroperator;
  225. public FilterOperator Operator
  226. {
  227. get{ return filteroperator; }
  228. }
  229. [ XmlText ]
  230. protected string filtervalue;
  231. public string FilterValue
  232. {
  233. get{ return filtervalue; }
  234. }
  235. protected bool Validate()
  236. {
  237. return ( IsValidFieldName() &&
  238. IsValidOperator() &&
  239. IsValidValue() );
  240. }
  241. bool IsValidOperator()
  242. {
  243. return true;
  244. }
  245. bool IsValidValue()
  246. {
  247. return true;
  248. }
  249. bool IsValidFieldName()
  250. {
  251. return true;
  252. }
  253. //
  254. // TODO: Maybe make this a readonly property instead
  255. // and genarte the this string in the ctor.
  256. //
  257. public string GetFilterString()
  258. {
  259. string filter = "";
  260. if( Validate() )
  261. {
  262. //
  263. //if it is a valid filter, then fill the string.
  264. //
  265. //set the fielname
  266. filter = this.FieldName + " ";
  267. //set the operator
  268. filter+=GetFilterOperatorString();
  269. //set the value
  270. filter += GetFilterValueString();
  271. //set the conjuction operator
  272. filter += GetFilterConjuctionString();
  273. }
  274. return filter;
  275. }
  276. protected string GetFilterConjuctionString()
  277. {
  278. string conj = "";
  279. switch( this.Conjuction )
  280. {
  281. case FilterConjuctionOperator.And:
  282. conj = " AND ";
  283. break;
  284. case FilterConjuctionOperator.AndNot:
  285. conj = " AND NOT ";
  286. break;
  287. case FilterConjuctionOperator.Or:
  288. conj = " OR ";
  289. break;
  290. case FilterConjuctionOperator.OrNot:
  291. conj = " OR NOT ";
  292. break;
  293. }
  294. return conj;
  295. }
  296. protected string GetFilterValueString()
  297. {
  298. string val = "'";
  299. if( FilterOperator.Contains==this.Operator )
  300. {
  301. val += "*" + this.FilterValue + "*";
  302. }
  303. else
  304. {
  305. val += this.FilterValue ;
  306. }
  307. val += "'";
  308. return val;
  309. }
  310. protected string GetFilterOperatorString()
  311. {
  312. switch( this.Operator )
  313. {
  314. case FilterOperator.EqualTo:
  315. return " = ";
  316. case FilterOperator.NotEqualTo:
  317. return " <> ";
  318. case FilterOperator.LessThan:
  319. return " < ";
  320. case FilterOperator.GreaterThan:
  321. return " > ";
  322. case FilterOperator.Contains:
  323. return " LIKE ";
  324. default:
  325. return "";
  326. }
  327. }
  328. }
  329. public enum FilterOperator
  330. {
  331. [ XmlEnum( "equalTo" ) ]
  332. EqualTo,
  333. [ XmlEnum( "notEqualTo" ) ]
  334. NotEqualTo,
  335. [ XmlEnum( "greaterThan" ) ]
  336. GreaterThan,
  337. [ XmlEnum( "lessThan" ) ]
  338. LessThan,
  339. [ XmlEnum( "contains" ) ]
  340. Contains
  341. }
  342. public enum FilterConjuctionOperator
  343. {
  344. [ XmlEnum( "" ) ]
  345. None,
  346. [ XmlEnum( "and" ) ]
  347. And,
  348. [ XmlEnum( "andNot" ) ]
  349. AndNot,
  350. [ XmlEnum( "or" ) ]
  351. Or,
  352. [ XmlEnum( "orNot" ) ]
  353. OrNot
  354. }
  355. }