Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.09 KB | None | 0 0
  1. //Example Quick Start Code Begin
  2.  
  3. namespace PhoneInformationSample
  4. {
  5. using System;
  6. using System.Linq;
  7. using System.ServiceModel;
  8. using System.ServiceModel.Channels;
  9. using Login;
  10. using UltiProEmployeePhoneInformation;
  11.  
  12. public class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. // Setup your user credentials.
  17. const string userName = "YOUR WEB USER NAME";
  18. const string password = "YOUR PASSWORD";
  19. const string userApiKey = "YOUR USER API KEY";
  20. const string customerApiKey = "YOUR CUSTOMER API KEY";
  21.  
  22. // Create a proxy to the login service.
  23. LoginServiceClient loginClient = null;
  24.  
  25. try
  26. {
  27. loginClient = new LoginServiceClient("WSHttpBinding_ILoginService");
  28.  
  29. // Submit the login request to authenticate the user.
  30. string message = "";
  31. string authenticationToken = "";
  32. AuthenticationStatus loginStatus = loginClient.Authenticate(customerApiKey, password, userApiKey, userName, out message, out authenticationToken);
  33.  
  34. if (loginStatus == AuthenticationStatus.Ok)
  35. {
  36. // User is authenticated and the authentication token is provided.
  37. Console.WriteLine("User authentication was successful.\n");
  38.  
  39. // Find Employees
  40. Console.WriteLine("----------Start Find----------");
  41. FindPhoneInformation(customerApiKey, authenticationToken);
  42. Console.WriteLine("----------End Find----------\n");
  43.  
  44. // Get Phone Information
  45. Console.WriteLine("----------Start Get----------");
  46. GetPhoneInformation(customerApiKey, authenticationToken);
  47. Console.WriteLine("----------End Get----------\n");
  48.  
  49. // Update Phone Information
  50. Console.WriteLine("----------Start Update----------");
  51. UpdatePhoneInformation(customerApiKey, authenticationToken);
  52. Console.WriteLine("----------End Update----------\n");
  53.  
  54. // Create Alternate Number
  55. Console.WriteLine("----------Start Create----------");
  56. CreateAlternateNumber(customerApiKey, authenticationToken);
  57. Console.WriteLine("----------End Create----------\n");
  58.  
  59. // Get Phone Information
  60. Console.WriteLine("----------Start Get----------");
  61. GetPhoneInformation(customerApiKey, authenticationToken);
  62. Console.WriteLine("----------End Get----------\n");
  63.  
  64. // Delete Alternate Number
  65. Console.WriteLine("----------Start Delete----------");
  66. DeleteAlternateNumber(customerApiKey, authenticationToken);
  67. Console.WriteLine("----------End Delete----------\n");
  68.  
  69. // Get Phone Information
  70. Console.WriteLine("----------Start Get----------");
  71. GetPhoneInformation(customerApiKey, authenticationToken);
  72. Console.WriteLine("----------End Get----------\n");
  73. }
  74. else
  75. {
  76. // User authentication has failed. Review the message for details.
  77. Console.WriteLine("User authentication failed: " + message);
  78. }
  79.  
  80. loginClient.Close();
  81. Console.WriteLine("Press a key to exit");
  82. Console.ReadKey(true);
  83.  
  84. }
  85. catch (Exception e)
  86. {
  87. Console.WriteLine(e);
  88. }
  89. finally
  90. {
  91. if (loginClient != null)
  92. {
  93. loginClient.Close();
  94. }
  95. }
  96. }
  97.  
  98. static void FindPhoneInformation(string customerApiKey, string authenticationToken)
  99. {
  100. EmployeePhoneInformationClient proxy = null;
  101. try
  102. {
  103. // Create a proxy to the EmployeePhoneInformation service.
  104. proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
  105.  
  106. // Add the headers for the Customer api key and authentication token.
  107. using (new OperationContextScope(proxy.InnerChannel))
  108. {
  109. OperationContext.Current.OutgoingMessageHeaders
  110. .Add(MessageHeader
  111. .CreateHeader("UltiProToken",
  112. "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
  113. authenticationToken));
  114.  
  115. OperationContext.Current.OutgoingMessageHeaders
  116. .Add(MessageHeader
  117. .CreateHeader("ClientAccessKey",
  118. "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
  119. customerApiKey));
  120.  
  121. // Create a query object to find the employees.
  122. EmployeeQuery query = new EmployeeQuery();
  123.  
  124. // Set one or more properties to search.
  125. query.LastName = "LIKE (ba%)";
  126. query.FullOrPartTime = "=F";
  127.  
  128. // Set paging properties
  129. query.PageSize = "10";
  130. query.PageNumber = "1";
  131.  
  132. // Search for the employees.
  133. PhoneInformationFindResponse response = proxy.FindPhoneInformations(query);
  134.  
  135. // Check the results of the find to see if there are any errors.
  136. if (response.OperationResult.HasErrors)
  137. {
  138. // Review each error.
  139. foreach (OperationMessage message in response.OperationResult.Messages)
  140. {
  141. Console.WriteLine("Error message: " + message.Message);
  142. }
  143. }
  144. else
  145. {
  146. // If employee records are returned,
  147. // loop through the results and write out the data.
  148. EmployeePhoneInformation[] employees = response.Results;
  149.  
  150. foreach (EmployeePhoneInformation employee in employees)
  151. {
  152. Console.WriteLine("Employee: " + employee.FirstName + " " + employee.LastName);
  153.  
  154. foreach (PhoneInformation phoneInformation in employee.PhoneInformations)
  155. {
  156. Console.WriteLine("\tHome Number: " + phoneInformation.HomeNumber);
  157. Console.WriteLine("\tWork Number: " + phoneInformation.WorkNumber);
  158.  
  159. foreach (AlternateNumber alternateNumber in phoneInformation.AlternateNumbers)
  160. {
  161. Console.WriteLine("\tAlternate Number: " + alternateNumber.Number);
  162. }
  163. }
  164. }
  165.  
  166. if (employees.Length > 0)
  167. {
  168. Console.WriteLine("Find was successful.");
  169. }
  170. else
  171. {
  172. Console.WriteLine("No employees were found for the provided EmployeeQuery.");
  173. }
  174.  
  175. var pagingInfo = response.OperationResult.PagingInfo;
  176.  
  177. Console.WriteLine("\nPaging Information:");
  178. Console.WriteLine("\tThe employee query returned a total of " + pagingInfo.TotalItems + " records.");
  179. Console.WriteLine("\tThe employee query returned a total of " + pagingInfo.PageTotal + " pages.");
  180. Console.WriteLine("\tEach page contains " + pagingInfo.PageSize + " records.");
  181. Console.WriteLine("\tThe Results contain the records for page " + pagingInfo.CurrentPage + ".");
  182. }
  183. }
  184. }
  185. catch (Exception e)
  186. {
  187. Console.WriteLine(e);
  188. }
  189. finally
  190. {
  191. if (proxy != null)
  192. {
  193. proxy.Close();
  194. }
  195. }
  196. }
  197.  
  198. static void GetPhoneInformation(string customerApiKey, string authenticationToken)
  199. {
  200. EmployeePhoneInformationClient proxy = null;
  201. try
  202. {
  203. // Create a proxy to the EmployeePhoneInformation service.
  204. proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
  205.  
  206. // Add the headers for the Customer api key and authentication token.
  207. using (new OperationContextScope(proxy.InnerChannel))
  208. {
  209. OperationContext.Current.OutgoingMessageHeaders
  210. .Add(MessageHeader.CreateHeader("UltiProToken",
  211. "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
  212. authenticationToken));
  213. OperationContext.Current.OutgoingMessageHeaders
  214. .Add(MessageHeader.CreateHeader("ClientAccessKey",
  215. "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
  216. customerApiKey));
  217.  
  218. // Define employee whose phone information you want to get.
  219. EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
  220. {
  221. CompanyCode = "C0013",
  222. EmployeeNumber = "638945004"
  223. };
  224. // Get the phone information.
  225. PhoneInformationGetResponse response =
  226. proxy.GetPhoneInformationByEmployeeIdentifier(employeeIdentifier);
  227.  
  228. // Check the results of the get to see if there are any errors.
  229. if (response.OperationResult.HasErrors)
  230. {
  231. // Review each error.
  232. foreach (OperationMessage message in response.OperationResult.Messages)
  233. {
  234. Console.WriteLine("Error message: " + message.Message);
  235. }
  236. }
  237. else
  238. {
  239. // If we did not get any errors then 1 phone information
  240. // or no phone information was found.
  241. if (response.Results.Length > 0)
  242. {
  243. // One phone information was found.
  244. Console.WriteLine("Phone Information:");
  245.  
  246. PhoneInformation phoneInformation = response.Results[0];
  247. Console.WriteLine("\tHome Number: " + phoneInformation.HomeNumber);
  248. Console.WriteLine("\tWork Number: " + phoneInformation.WorkNumber);
  249. Console.WriteLine("\tAlternate Numbers: " + phoneInformation.WorkNumber);
  250.  
  251. foreach (var alternateNumber in phoneInformation.AlternateNumbers)
  252. {
  253. Console.WriteLine("\t\tAlternate Number Id: " + alternateNumber.NumberId);
  254. Console.WriteLine("\t\tAlternate Number: " + alternateNumber.Number);
  255. }
  256.  
  257. Console.WriteLine("Get was Successful.");
  258. }
  259. else
  260. {
  261. // No phone information was found for this employee.
  262. Console.WriteLine(string.Format("No phone information was found for employee with Employee Number = {0} and Company Code = {1}",
  263. ((EmployeeNumberIdentifier)employeeIdentifier).EmployeeNumber, employeeIdentifier.CompanyCode));
  264. }
  265. }
  266. }
  267. }
  268. catch (Exception e)
  269. {
  270. Console.WriteLine(e);
  271. }
  272. finally
  273. {
  274. if (proxy != null)
  275. {
  276. proxy.Close();
  277. }
  278. }
  279. }
  280.  
  281. static void UpdatePhoneInformation(string customerApiKey, string authenticationToken)
  282. {
  283. EmployeePhoneInformationClient proxy = null;
  284. try
  285. {
  286. // Create a proxy to the EmployeePhoneInformation service.
  287. proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
  288.  
  289. // Add the headers for the Customer api key and authentication token.
  290. using (new OperationContextScope(proxy.InnerChannel))
  291. {
  292. OperationContext.Current.OutgoingMessageHeaders
  293. .Add(MessageHeader.CreateHeader("UltiProToken",
  294. "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
  295. authenticationToken));
  296. OperationContext.Current.OutgoingMessageHeaders
  297. .Add(MessageHeader.CreateHeader("ClientAccessKey",
  298. "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
  299. customerApiKey));
  300.  
  301. // Define employee whose phone information you want to update.
  302. EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
  303. {
  304. CompanyCode = "C0013",
  305. EmployeeNumber = "638945004"
  306. };
  307. // Get the phone information.
  308. PhoneInformationGetResponse getResponse =
  309. proxy.GetPhoneInformationByEmployeeIdentifier(employeeIdentifier);
  310.  
  311. // Check the results of the get to see if there are any errors.
  312. if (getResponse.OperationResult.HasErrors)
  313. {
  314. // Review each error.
  315. foreach (OperationMessage message in getResponse.OperationResult.Messages)
  316. {
  317. Console.WriteLine("Error message: " + message.Message);
  318. }
  319. }
  320. else
  321. {
  322. // If we did not get any errors then 1 phone information
  323. // or no phone information was found.
  324. if (getResponse.Results.Length > 0)
  325. {
  326. // One phone information was found.
  327. PhoneInformation phoneInformation = getResponse.Results[0];
  328.  
  329. Console.WriteLine("Phone information to be updated was found.");
  330.  
  331. // Update phone information.
  332. phoneInformation.HomeNumber = "2225556677";
  333. phoneInformation.HomeNumberCountry = "CAN";
  334. phoneInformation.HomeNumberIsPrivate = true;
  335.  
  336. PhoneInformationUpdateResponse updateResponse = proxy.UpdatePhoneInformation(new[] { phoneInformation });
  337.  
  338. // Check the results to see if the update was successful.
  339. if (updateResponse.HasErrors)
  340. {
  341. if (updateResponse.OperationResult.HasErrors)
  342. {
  343. // Review each operation error.
  344. foreach (OperationMessage message in updateResponse.OperationResult.Messages)
  345. {
  346. Console.WriteLine("Operation Error Message: " + message.Message);
  347. }
  348. }
  349.  
  350. // Review each result errors.
  351. foreach (Result result in updateResponse.Results.Where(r => r.HasErrors))
  352. {
  353. // Review messages for this result error.
  354. foreach (OperationMessage message in result.Messages)
  355. {
  356. Console.WriteLine("Result " + result.RequestNumber
  357. + " Error Message: " + message.Message);
  358. }
  359. }
  360. }
  361. else
  362. {
  363. // The update was successful.
  364. Console.WriteLine("Update was successful.");
  365. }
  366. }
  367. else
  368. {
  369. // No phone information was found for this employee.
  370. Console.WriteLine(string.Format("No phone information was found for employee with Employee Number = {0} and Company Code = {1}",
  371. ((EmployeeNumberIdentifier)employeeIdentifier).EmployeeNumber, employeeIdentifier.CompanyCode));
  372. }
  373. }
  374. }
  375. }
  376. catch (Exception e)
  377. {
  378. Console.WriteLine(e);
  379. }
  380. finally
  381. {
  382. if (proxy != null)
  383. {
  384. proxy.Close();
  385. }
  386. }
  387. }
  388.  
  389. static void CreateAlternateNumber(string customerApiKey, string authenticationToken)
  390. {
  391. EmployeePhoneInformationClient proxy = null;
  392. try
  393. {
  394. // Create a proxy to the EmployeePhoneInformation service.
  395. proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
  396.  
  397. // Add the headers for the Customer api key and authentication token.
  398. using (new OperationContextScope(proxy.InnerChannel))
  399. {
  400. OperationContext.Current.OutgoingMessageHeaders
  401. .Add(MessageHeader.CreateHeader("UltiProToken",
  402. "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
  403. authenticationToken));
  404. OperationContext.Current.OutgoingMessageHeaders
  405. .Add(MessageHeader.CreateHeader("ClientAccessKey",
  406. "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
  407. customerApiKey));
  408.  
  409. // Define employee for whom you want to create an alternate number.
  410. EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
  411. {
  412. CompanyCode = "C0013",
  413. EmployeeNumber = "638945004"
  414. };
  415.  
  416. AlternateNumber alternateNumber = new AlternateNumber
  417. {
  418. Country = "ARG",
  419. Number = "4447778899",
  420. Type = "CEL"
  421. };
  422.  
  423. PhoneInformationCreateResponse response = proxy.CreateAlternateNumber(new[] { alternateNumber }, employeeIdentifier);
  424.  
  425. // Check the results to see if the create was successful.
  426. if (response.HasErrors)
  427. {
  428. if (response.OperationResult.HasErrors)
  429. {
  430. // Review each operation error.
  431. foreach (OperationMessage message in response.OperationResult.Messages)
  432. {
  433. Console.WriteLine("Operation Error Message: " + message.Message);
  434. }
  435. }
  436.  
  437. // Review each result errors.
  438. foreach (Result result in response.Results.Where(r => r.HasErrors))
  439. {
  440. // Review messages for this result error.
  441. foreach (OperationMessage message in result.Messages)
  442. {
  443. Console.WriteLine("Result " + result.RequestNumber
  444. + " Error Message: " + message.Message);
  445. }
  446. }
  447. }
  448. else
  449. {
  450. // The create was successful.
  451. Console.WriteLine("Create of alternate number was successful.");
  452. }
  453. }
  454. }
  455. catch (Exception e)
  456. {
  457. Console.WriteLine(e);
  458. }
  459. finally
  460. {
  461. if (proxy != null)
  462. {
  463. proxy.Close();
  464. }
  465. }
  466. }
  467.  
  468. static void DeleteAlternateNumber(string customerApiKey, string authenticationToken)
  469. {
  470. EmployeePhoneInformationClient proxy = null;
  471. try
  472. {
  473. // Create a proxy to the EmployeePhoneInformation service.
  474. proxy = new EmployeePhoneInformationClient("WSHttpBinding_IEmployeePhoneInformation");
  475.  
  476. // Add the headers for the Customer api key and authentication token.
  477. using (new OperationContextScope(proxy.InnerChannel))
  478. {
  479. OperationContext.Current.OutgoingMessageHeaders
  480. .Add(MessageHeader.CreateHeader("UltiProToken",
  481. "http://www.ultimatesoftware.com/foundation/authentication/ultiprotoken",
  482. authenticationToken));
  483. OperationContext.Current.OutgoingMessageHeaders
  484. .Add(MessageHeader.CreateHeader("ClientAccessKey",
  485. "http://www.ultimatesoftware.com/foundation/authentication/clientaccesskey",
  486. customerApiKey));
  487.  
  488. // Define employee for whom you want to delete an alternate number.
  489. EmployeeIdentifier employeeIdentifier = new EmployeeNumberIdentifier
  490. {
  491. CompanyCode = "C0013",
  492. EmployeeNumber = "638945004"
  493. };
  494.  
  495. // Get the phone information for this employee.
  496. PhoneInformationGetResponse getResponse =
  497. proxy.GetPhoneInformationByEmployeeIdentifier(employeeIdentifier);
  498.  
  499. // Check the results of the get to see if there are any errors.
  500. if (getResponse.OperationResult.HasErrors)
  501. {
  502. // Review each error.
  503. foreach (OperationMessage message in getResponse.OperationResult.Messages)
  504. {
  505. Console.WriteLine("Error message: " + message.Message);
  506. }
  507. }
  508. else
  509. {
  510. // If we did not get any errors then 1 phone information
  511. // or no phone information was found.
  512. if (getResponse.Results.Length > 0)
  513. {
  514. // One phone information was found.
  515. PhoneInformation phoneInformation = getResponse.Results[0];
  516.  
  517. // Get alternate number to delete from employee's phone information.
  518. AlternateNumber alternateNumber = null;
  519. if (phoneInformation.AlternateNumbers.Length > 0)
  520. {
  521. // Save alternate number to delete
  522. alternateNumber = phoneInformation.AlternateNumbers[0];
  523. Console.WriteLine("Alternate number to be deleted was found:");
  524. Console.WriteLine("\tAlternate Number Id: " + alternateNumber.NumberId);
  525. }
  526. else
  527. {
  528. Console.WriteLine("This employee does not have an alternate number to delete.");
  529. }
  530.  
  531. if (alternateNumber != null)
  532. {
  533. // Delete alternate number
  534. PhoneInformationDeleteResponse deleteResponse =
  535. proxy.DeleteAlternateNumber(new[] { alternateNumber }, employeeIdentifier);
  536.  
  537. // Check the results to see if the delete was successful.
  538. if (deleteResponse.HasErrors)
  539. {
  540. if (deleteResponse.OperationResult.HasErrors)
  541. {
  542. // Review each operation error.
  543. foreach (OperationMessage message in deleteResponse.OperationResult.Messages)
  544. {
  545. Console.WriteLine("Operation Error Message: " + message.Message);
  546. }
  547. }
  548.  
  549. // Review each result errors.
  550. foreach (Result result in deleteResponse.Results.Where(r => r.HasErrors))
  551. {
  552. // Review messages for this result error.
  553. foreach (OperationMessage message in result.Messages)
  554. {
  555. Console.WriteLine("Result " + result.RequestNumber
  556. + " Error Message: " + message.Message);
  557. }
  558. }
  559. }
  560. else
  561. {
  562. // The delete was successful.
  563. Console.WriteLine("Delete of alternate number was successful.");
  564. }
  565. }
  566. }
  567. else
  568. {
  569. // No phone information was found for this employee.
  570. Console.WriteLine(
  571. string.Format(
  572. "No phone information was found for employee with Employee Number = {0} and Company Code = {1}",
  573. ((EmployeeNumberIdentifier)employeeIdentifier).EmployeeNumber,
  574. employeeIdentifier.CompanyCode));
  575. }
  576. }
  577. }
  578. }
  579. catch (Exception e)
  580. {
  581. Console.WriteLine(e);
  582. }
  583. finally
  584. {
  585. if (proxy != null)
  586. {
  587. proxy.Close();
  588. }
  589. }
  590. }
  591. }
  592. }
  593.  
  594.  
  595. // Example Quick Start Code End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement