KeyValueService.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. // ----------------------------------------------------------
  2. // <copyright file="KeyValueService.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // ----------------------------------------------------------
  6. namespace Microsoft.Hawaii.KeyValue.Client
  7. {
  8. using System;
  9. using System.Security;
  10. /// <summary>
  11. /// Helper class that provides access to the KeyValue service.
  12. /// </summary>
  13. public class KeyValueService
  14. {
  15. /// <summary>
  16. /// Specifies the default service host name. This will be used to create the service url.
  17. /// </summary>
  18. public const string DefaultHostName = "http://api.hawaii-services.net/keyvalue/v1";
  19. /// <summary>
  20. /// Specifies a signature for the REST methods that manage KeyValue item.
  21. /// </summary>
  22. public const string KeyValueSignature = "values";
  23. /// <summary>
  24. /// Specifies a query string key of prefix.
  25. /// </summary>
  26. public const string PrefixKey = "prefix";
  27. /// <summary>
  28. /// Specifies a query string key of size.
  29. /// </summary>
  30. public const string SizeKey = "size";
  31. /// <summary>
  32. /// Specifies a query string key of continuationToken.
  33. /// </summary>
  34. public const string ContinuationTokenKey = "continuationToken";
  35. /// <summary>
  36. /// Specifies a query string key of batch operation.
  37. /// </summary>
  38. public const string GetBatchKey = "$batch";
  39. /// <summary>
  40. /// Specifies a query string key of timestamp before.
  41. /// </summary>
  42. public const string BeforeKey = "before";
  43. /// <summary>
  44. /// The name of the config file that indicates where the KVS staging service is located. Used only as a test hook.
  45. /// </summary>
  46. private static readonly string StagingConfigFileName = @"C:\AzureStagingDeploymentConfig\KeyValueStagingHostConfig.ini";
  47. /// <summary>
  48. /// The service host name. This is the private variable that is initialized on first
  49. /// access via the GetHostName() method. If a config file is present to point to a
  50. /// staging server, that host will be stored. Otherwise, the default is used.
  51. /// </summary>
  52. private static string hostName;
  53. /// <summary>
  54. /// The service scope. This is the private variable that is initialized on first
  55. /// access via the ServiceScope get accessor. If a config file is present to point to a
  56. /// staging server, that host will be stored. Otherwise, the default is used.
  57. /// </summary>
  58. private static string serviceScope;
  59. /// <summary>
  60. /// Gets the Host Name to be used when accessing the service.
  61. /// </summary>
  62. public static string HostName
  63. {
  64. get
  65. {
  66. return KeyValueService.GetHostName();
  67. }
  68. }
  69. /// <summary>
  70. /// Gets the service scope to be used when accessing the adm OAuth service.
  71. /// </summary>
  72. private static string ServiceScope
  73. {
  74. get
  75. {
  76. if (string.IsNullOrEmpty(KeyValueService.serviceScope))
  77. {
  78. KeyValueService.serviceScope = AdmAuthClientIdentity.GetServiceScope(KeyValueService.HostName);
  79. }
  80. return KeyValueService.serviceScope;
  81. }
  82. }
  83. /// <summary>
  84. /// Helper method to initiate the call that gets KeyValue items by key.
  85. /// </summary>
  86. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  87. /// <param name="key">Specifies a key to search.</param>
  88. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  89. /// <param name="stateObject">Specifies a user-defined object.</param>
  90. public static void GetByKeyAsync(
  91. string hawaiiAppId,
  92. string key,
  93. ServiceAgent<GetByKeyResult>.OnCompleteDelegate onComplete,
  94. object stateObject)
  95. {
  96. if (string.IsNullOrEmpty(hawaiiAppId))
  97. {
  98. throw new ArgumentNullException("hawaiiAppId");
  99. }
  100. GetByKeyAsync(
  101. new GuidAuthClientIdentity(hawaiiAppId),
  102. key,
  103. onComplete,
  104. stateObject);
  105. }
  106. /// <summary>
  107. /// Helper method to initiate the call that gets KeyValue items by key.
  108. /// </summary>
  109. /// <param name="clientId">The adm client Id.</param>
  110. /// <param name="clientSecret">The adm client secret.</param>
  111. /// <param name="key">Specifies a key to search.</param>
  112. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  113. /// <param name="stateObject">Specifies a user-defined object.</param>
  114. public static void GetByKeyAsync(
  115. string clientId,
  116. string clientSecret,
  117. string key,
  118. ServiceAgent<GetByKeyResult>.OnCompleteDelegate onComplete,
  119. object stateObject)
  120. {
  121. if (string.IsNullOrEmpty(clientId))
  122. {
  123. throw new ArgumentNullException("clientId");
  124. }
  125. if (string.IsNullOrEmpty(clientSecret))
  126. {
  127. throw new ArgumentNullException("clientSecret");
  128. }
  129. GetByKeyAsync(
  130. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  131. key,
  132. onComplete,
  133. stateObject);
  134. }
  135. /// <summary>
  136. /// Helper method to initiate the call that gets KeyValue items by keys.
  137. /// </summary>
  138. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  139. /// <param name="keys">Specifies the keys to search.</param>
  140. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  141. /// <param name="stateObject">Specifies a user-defined object.</param>
  142. public static void GetByKeysAsync(
  143. string hawaiiAppId,
  144. string[] keys,
  145. ServiceAgent<GetByKeysResult>.OnCompleteDelegate onComplete,
  146. object stateObject)
  147. {
  148. if (string.IsNullOrEmpty(hawaiiAppId))
  149. {
  150. throw new ArgumentNullException("hawaiiAppId");
  151. }
  152. GetByKeysAsync(
  153. new GuidAuthClientIdentity(hawaiiAppId),
  154. keys,
  155. onComplete,
  156. stateObject);
  157. }
  158. /// <summary>
  159. /// Helper method to initiate the call that gets KeyValue items by keys.
  160. /// </summary>
  161. /// <param name="clientId">The adm client Id.</param>
  162. /// <param name="clientSecret">The adm client secret.</param>
  163. /// <param name="keys">Specifies the keys to search.</param>
  164. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  165. /// <param name="stateObject">Specifies a user-defined object.</param>
  166. public static void GetByKeysAsync(
  167. string clientId,
  168. string clientSecret,
  169. string[] keys,
  170. ServiceAgent<GetByKeysResult>.OnCompleteDelegate onComplete,
  171. object stateObject)
  172. {
  173. if (string.IsNullOrEmpty(clientId))
  174. {
  175. throw new ArgumentNullException("clientId");
  176. }
  177. if (string.IsNullOrEmpty(clientSecret))
  178. {
  179. throw new ArgumentNullException("clientSecret");
  180. }
  181. GetByKeysAsync(
  182. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  183. keys,
  184. onComplete,
  185. stateObject);
  186. }
  187. /// <summary>
  188. /// Helper method to initiate the call that gets KeyValue items.
  189. /// </summary>
  190. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  191. /// <param name="prefix">Specifies the search prefix keyword.</param>
  192. /// <param name="size">Specifies the size of result.</param>
  193. /// <param name="continuationToken">Specifies the continuation token.</param>
  194. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  195. /// <param name="stateObject">Specifies a user-defined object.</param>
  196. public static void GetAsync(
  197. string hawaiiAppId,
  198. string prefix,
  199. int size,
  200. string continuationToken,
  201. ServiceAgent<GetResult>.OnCompleteDelegate onComplete,
  202. object stateObject)
  203. {
  204. if (string.IsNullOrEmpty(hawaiiAppId))
  205. {
  206. throw new ArgumentNullException("hawaiiAppId");
  207. }
  208. GetAsync(
  209. new GuidAuthClientIdentity(hawaiiAppId),
  210. prefix,
  211. size,
  212. continuationToken,
  213. onComplete,
  214. stateObject);
  215. }
  216. /// <summary>
  217. /// Helper method to initiate the call that gets KeyValue items.
  218. /// </summary>
  219. /// <param name="clientId">The adm client Id.</param>
  220. /// <param name="clientSecret">The adm client secret.</param>
  221. /// <param name="prefix">Specifies the search prefix keyword.</param>
  222. /// <param name="size">Specifies the size of result.</param>
  223. /// <param name="continuationToken">Specifies the continuation token.</param>
  224. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  225. /// <param name="stateObject">Specifies a user-defined object.</param>
  226. public static void GetAsync(
  227. string clientId,
  228. string clientSecret,
  229. string prefix,
  230. int size,
  231. string continuationToken,
  232. ServiceAgent<GetResult>.OnCompleteDelegate onComplete,
  233. object stateObject)
  234. {
  235. if (string.IsNullOrEmpty(clientId))
  236. {
  237. throw new ArgumentNullException("clientId");
  238. }
  239. if (string.IsNullOrEmpty(clientSecret))
  240. {
  241. throw new ArgumentNullException("clientSecret");
  242. }
  243. GetAsync(
  244. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  245. prefix,
  246. size,
  247. continuationToken,
  248. onComplete,
  249. stateObject);
  250. }
  251. /// <summary>
  252. /// Helper method to initiate the call that creates KeyValue item.
  253. /// </summary>
  254. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  255. /// <param name="items">Specifies the KeyValue items to create.</param>
  256. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  257. /// <param name="stateObject">Specifies a user-defined object.</param>
  258. public static void CreateAsync(
  259. string hawaiiAppId,
  260. KeyValueItem[] items,
  261. ServiceAgent<SetResult>.OnCompleteDelegate onComplete,
  262. object stateObject)
  263. {
  264. if (string.IsNullOrEmpty(hawaiiAppId))
  265. {
  266. throw new ArgumentNullException("hawaiiAppId");
  267. }
  268. CreateAsync(
  269. new GuidAuthClientIdentity(hawaiiAppId),
  270. items,
  271. onComplete,
  272. stateObject);
  273. }
  274. /// <summary>
  275. /// Helper method to initiate the call that creates KeyValue item.
  276. /// </summary>
  277. /// <param name="clientId">The adm client Id.</param>
  278. /// <param name="clientSecret">The adm client secret.</param>
  279. /// <param name="items">Specifies the KeyValue items to create.</param>
  280. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  281. /// <param name="stateObject">Specifies a user-defined object.</param>
  282. public static void CreateAsync(
  283. string clientId,
  284. string clientSecret,
  285. KeyValueItem[] items,
  286. ServiceAgent<SetResult>.OnCompleteDelegate onComplete,
  287. object stateObject)
  288. {
  289. if (string.IsNullOrEmpty(clientId))
  290. {
  291. throw new ArgumentNullException("clientId");
  292. }
  293. if (string.IsNullOrEmpty(clientSecret))
  294. {
  295. throw new ArgumentNullException("clientSecret");
  296. }
  297. CreateAsync(
  298. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  299. items,
  300. onComplete,
  301. stateObject);
  302. }
  303. /// <summary>
  304. /// Helper method to initiate the call that sets KeyValue item.
  305. /// </summary>
  306. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  307. /// <param name="items">Specifies the KeyValue items to create.</param>
  308. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  309. /// <param name="stateObject">Specifies a user-defined object.</param>
  310. public static void SetAsync(
  311. string hawaiiAppId,
  312. KeyValueItem[] items,
  313. ServiceAgent<SetResult>.OnCompleteDelegate onComplete,
  314. object stateObject)
  315. {
  316. if (string.IsNullOrEmpty(hawaiiAppId))
  317. {
  318. throw new ArgumentNullException("hawaiiAppId");
  319. }
  320. SetAsync(
  321. new GuidAuthClientIdentity(hawaiiAppId),
  322. items,
  323. onComplete,
  324. stateObject);
  325. }
  326. /// <summary>
  327. /// Helper method to initiate the call that sets KeyValue item.
  328. /// </summary>
  329. /// <param name="clientId">The adm client Id.</param>
  330. /// <param name="clientSecret">The adm client secret.</param>
  331. /// <param name="items">Specifies the KeyValue items to create.</param>
  332. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  333. /// <param name="stateObject">Specifies a user-defined object.</param>
  334. public static void SetAsync(
  335. string clientId,
  336. string clientSecret,
  337. KeyValueItem[] items,
  338. ServiceAgent<SetResult>.OnCompleteDelegate onComplete,
  339. object stateObject)
  340. {
  341. if (string.IsNullOrEmpty(clientId))
  342. {
  343. throw new ArgumentNullException("clientId");
  344. }
  345. if (string.IsNullOrEmpty(clientSecret))
  346. {
  347. throw new ArgumentNullException("clientSecret");
  348. }
  349. SetAsync(
  350. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  351. items,
  352. onComplete,
  353. stateObject);
  354. }
  355. /// <summary>
  356. /// Helper method to initiate the call that deletes KeyValue items.
  357. /// </summary>
  358. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  359. /// <param name="prefix">Specifies the search prefix keyword.</param>
  360. /// <param name="before">Specifies the timpstamp for delete operation.</param>
  361. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  362. /// <param name="stateObject">Specifies a user-defined object.</param>
  363. public static void DeleteAsync(
  364. string hawaiiAppId,
  365. string prefix,
  366. DateTime before,
  367. ServiceAgent<DeleteResult>.OnCompleteDelegate onComplete,
  368. object stateObject)
  369. {
  370. if (string.IsNullOrEmpty(hawaiiAppId))
  371. {
  372. throw new ArgumentNullException("hawaiiAppId");
  373. }
  374. DeleteAsync(
  375. new GuidAuthClientIdentity(hawaiiAppId),
  376. prefix,
  377. before,
  378. onComplete,
  379. stateObject);
  380. }
  381. /// <summary>
  382. /// Helper method to initiate the call that deletes KeyValue items.
  383. /// </summary>
  384. /// <param name="clientId">The adm client Id.</param>
  385. /// <param name="clientSecret">The adm client secret.</param>
  386. /// <param name="prefix">Specifies the search prefix keyword.</param>
  387. /// <param name="before">Specifies the timpstamp for delete operation.</param>
  388. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  389. /// <param name="stateObject">Specifies a user-defined object.</param>
  390. public static void DeleteAsync(
  391. string clientId,
  392. string clientSecret,
  393. string prefix,
  394. DateTime before,
  395. ServiceAgent<DeleteResult>.OnCompleteDelegate onComplete,
  396. object stateObject)
  397. {
  398. if (string.IsNullOrEmpty(clientId))
  399. {
  400. throw new ArgumentNullException("clientId");
  401. }
  402. if (string.IsNullOrEmpty(clientSecret))
  403. {
  404. throw new ArgumentNullException("clientSecret");
  405. }
  406. DeleteAsync(
  407. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  408. prefix,
  409. before,
  410. onComplete,
  411. stateObject);
  412. }
  413. /// <summary>
  414. /// Helper method to initiate the call that deletes KeyValue items by keys.
  415. /// </summary>
  416. /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
  417. /// <param name="keys">Specifies the keys to search.</param>
  418. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  419. /// <param name="stateObject">Specifies a user-defined object.</param>
  420. public static void DeleteByKeysAsync(
  421. string hawaiiAppId,
  422. string[] keys,
  423. ServiceAgent<DeleteResult>.OnCompleteDelegate onComplete,
  424. object stateObject)
  425. {
  426. if (string.IsNullOrEmpty(hawaiiAppId))
  427. {
  428. throw new ArgumentNullException("hawaiiAppId");
  429. }
  430. DeleteByKeysAsync(
  431. new GuidAuthClientIdentity(hawaiiAppId),
  432. keys,
  433. onComplete,
  434. stateObject);
  435. }
  436. /// <summary>
  437. /// Helper method to initiate the call that deletes KeyValue items by keys.
  438. /// </summary>
  439. /// <param name="clientId">The adm client Id.</param>
  440. /// <param name="clientSecret">The adm client secret.</param>
  441. /// <param name="keys">Specifies the keys to search.</param>
  442. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  443. /// <param name="stateObject">Specifies a user-defined object.</param>
  444. public static void DeleteByKeysAsync(
  445. string clientId,
  446. string clientSecret,
  447. string[] keys,
  448. ServiceAgent<DeleteResult>.OnCompleteDelegate onComplete,
  449. object stateObject)
  450. {
  451. if (string.IsNullOrEmpty(clientId))
  452. {
  453. throw new ArgumentNullException("clientId");
  454. }
  455. if (string.IsNullOrEmpty(clientSecret))
  456. {
  457. throw new ArgumentNullException("clientSecret");
  458. }
  459. DeleteByKeysAsync(
  460. new AdmAuthClientIdentity(clientId, clientSecret, KeyValueService.ServiceScope),
  461. keys,
  462. onComplete,
  463. stateObject);
  464. }
  465. /// <summary>
  466. /// Helper method to initiate the call that gets KeyValue items by key.
  467. /// </summary>
  468. /// <param name="clientIdentity">The hawaii client identity.</param>
  469. /// <param name="key">Specifies a key to search.</param>
  470. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  471. /// <param name="stateObject">Specifies a user-defined object.</param>
  472. private static void GetByKeyAsync(
  473. ClientIdentity clientIdentity,
  474. string key,
  475. ServiceAgent<GetByKeyResult>.OnCompleteDelegate onComplete,
  476. object stateObject)
  477. {
  478. GetByKeyAgent agent = new GetByKeyAgent(
  479. KeyValueService.HostName,
  480. clientIdentity,
  481. key,
  482. stateObject);
  483. agent.ProcessRequest(onComplete);
  484. }
  485. /// <summary>
  486. /// Helper method to initiate the call that gets KeyValue items by keys.
  487. /// </summary>
  488. /// <param name="clientIdentity">The hawaii client identity.</param>
  489. /// <param name="keys">Specifies the keys to search.</param>
  490. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  491. /// <param name="stateObject">Specifies a user-defined object.</param>
  492. private static void GetByKeysAsync(
  493. ClientIdentity clientIdentity,
  494. string[] keys,
  495. ServiceAgent<GetByKeysResult>.OnCompleteDelegate onComplete,
  496. object stateObject)
  497. {
  498. GetByKeysAgent agent = new GetByKeysAgent(
  499. KeyValueService.HostName,
  500. clientIdentity,
  501. keys,
  502. stateObject);
  503. agent.ProcessRequest(onComplete);
  504. }
  505. /// <summary>
  506. /// Helper method to initiate the call that gets KeyValue items.
  507. /// </summary>
  508. /// <param name="clientIdentity">The hawaii client identity.</param>
  509. /// <param name="prefix">Specifies the search prefix keyword.</param>
  510. /// <param name="size">Specifies the size of result.</param>
  511. /// <param name="continuationToken">Specifies the continuation token.</param>
  512. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  513. /// <param name="stateObject">Specifies a user-defined object.</param>
  514. private static void GetAsync(
  515. ClientIdentity clientIdentity,
  516. string prefix,
  517. int size,
  518. string continuationToken,
  519. ServiceAgent<GetResult>.OnCompleteDelegate onComplete,
  520. object stateObject)
  521. {
  522. GetAgent agent = new GetAgent(
  523. KeyValueService.HostName,
  524. clientIdentity,
  525. prefix,
  526. size,
  527. continuationToken,
  528. stateObject);
  529. agent.ProcessRequest(onComplete);
  530. }
  531. /// <summary>
  532. /// Helper method to initiate the call that creates KeyValue item.
  533. /// </summary>
  534. /// <param name="clientIdentity">The hawaii client identity.</param>
  535. /// <param name="items">Specifies the KeyValue items to create.</param>
  536. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  537. /// <param name="stateObject">Specifies a user-defined object.</param>
  538. private static void CreateAsync(
  539. ClientIdentity clientIdentity,
  540. KeyValueItem[] items,
  541. ServiceAgent<SetResult>.OnCompleteDelegate onComplete,
  542. object stateObject)
  543. {
  544. CreateAgent agent = new CreateAgent(
  545. KeyValueService.HostName,
  546. clientIdentity,
  547. items,
  548. stateObject);
  549. agent.ProcessRequest(onComplete);
  550. }
  551. /// <summary>
  552. /// Helper method to initiate the call that sets KeyValue item.
  553. /// </summary>
  554. /// <param name="clientIdentity">The hawaii client identity.</param>
  555. /// <param name="items">Specifies the KeyValue items to create.</param>
  556. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  557. /// <param name="stateObject">Specifies a user-defined object.</param>
  558. private static void SetAsync(
  559. ClientIdentity clientIdentity,
  560. KeyValueItem[] items,
  561. ServiceAgent<SetResult>.OnCompleteDelegate onComplete,
  562. object stateObject)
  563. {
  564. SetAgent agent = new SetAgent(
  565. KeyValueService.HostName,
  566. clientIdentity,
  567. items,
  568. stateObject);
  569. agent.ProcessRequest(onComplete);
  570. }
  571. /// <summary>
  572. /// Helper method to initiate the call that deletes KeyValue items.
  573. /// </summary>
  574. /// <param name="clientIdentity">The hawaii client identity.</param>
  575. /// <param name="prefix">Specifies the search prefix keyword.</param>
  576. /// <param name="before">Specifies the timpstamp for delete operation.</param>
  577. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  578. /// <param name="stateObject">Specifies a user-defined object.</param>
  579. private static void DeleteAsync(
  580. ClientIdentity clientIdentity,
  581. string prefix,
  582. DateTime before,
  583. ServiceAgent<DeleteResult>.OnCompleteDelegate onComplete,
  584. object stateObject)
  585. {
  586. DeleteAgent agent = new DeleteAgent(
  587. KeyValueService.HostName,
  588. clientIdentity,
  589. prefix,
  590. before,
  591. stateObject);
  592. agent.ProcessRequest(onComplete);
  593. }
  594. /// <summary>
  595. /// Helper method to initiate the call that deletes KeyValue items by keys.
  596. /// </summary>
  597. /// <param name="clientIdentity">The hawaii client identity.</param>
  598. /// <param name="keys">Specifies the keys to search.</param>
  599. /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
  600. /// <param name="stateObject">Specifies a user-defined object.</param>
  601. private static void DeleteByKeysAsync(
  602. ClientIdentity clientIdentity,
  603. string[] keys,
  604. ServiceAgent<DeleteResult>.OnCompleteDelegate onComplete,
  605. object stateObject)
  606. {
  607. DeleteByKeysAgent agent = new DeleteByKeysAgent(
  608. KeyValueService.HostName,
  609. clientIdentity,
  610. keys,
  611. stateObject);
  612. agent.ProcessRequest(onComplete);
  613. }
  614. /// <summary>
  615. /// Returns the Host Name to be used when accessing the service. This will generally
  616. /// be the value specified in the DefaultHostName, but it can conditionally be set with
  617. /// the presence of a config file on first access.
  618. /// </summary>
  619. /// <returns>A string containing the host name of the service</returns>
  620. [SecuritySafeCritical]
  621. private static string GetHostName()
  622. {
  623. if (string.IsNullOrEmpty(KeyValueService.hostName))
  624. {
  625. KeyValueService.hostName = ClientLibraryUtils.LookupHostNameFromConfig(StagingConfigFileName, KeyValueService.DefaultHostName);
  626. }
  627. return KeyValueService.hostName;
  628. }
  629. }
  630. }