Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. [WebGet( UriTemplate = "/gast/{customer_id}/{year}/{gast_id}", ResponseFormat = WebMessageFormat.Json )]
  2. [OperationContract]
  3. public acsEintrittGast GetGastInfo( string customer_id, string year, string gast_id ) {
  4. acsEintrittGast gast = new acsEintrittGast();
  5. gast.ID = Guid.Parse( gast_id );
  6. gast.Bitmap = File.ReadAllBytes( dataPath + customer_id + "\" + year + "\" + gast_id + ".jpg" );
  7. return gast;
  8. }
  9.  
  10. [WebInvoke( UriTemplate = "/gast/{customer_id}/{year}",
  11. ResponseFormat = WebMessageFormat.Json,
  12. RequestFormat = WebMessageFormat.Json,
  13. BodyStyle = WebMessageBodyStyle.Wrapped,
  14. Method = "POST" )]
  15.  
  16. [OperationContract]
  17. public acsEintrittGast SetGastInfo( string customer_id, string year, acsEintrittGast GastObject /*string GastString*/ ) {
  18. acsEintrittGast Gast = null;
  19. try {
  20. //Gast = JsonConvert.DeserializeObject<acsEintrittGast>( (string)GastObject);
  21. File.WriteAllBytes( dataPath + customer_id + "\" + year + "\" + Gast.ID.ToString() + ".jpg", Gast.Bitmap.ToArray<byte>() );
  22. }
  23. catch {
  24. }
  25. return Gast;
  26. }
  27.  
  28. public async static Task<T> SetRESTData( string URI, T Content ) {
  29. T res = default( T );
  30.  
  31. HttpClient httpClient = null;
  32. HttpResponseMessage response = null;
  33. StreamReader sr = null;
  34. StreamWriter writer = null;
  35. MemoryStream ms = null;
  36. try {
  37. httpClient = new HttpClient();
  38.  
  39. string s = JsonConvert.SerializeObject( Content );
  40. StringContent theContent = new StringContent( s, System.Text.Encoding.UTF8, "application/json" );
  41.  
  42. using( HttpRequestMessage request = new HttpRequestMessage( HttpMethod.Post, BaseURI + URI ) ) {
  43. request.Content = theContent;
  44. response = await httpClient.SendAsync( request );
  45. }
  46. }
  47. catch {
  48. }
  49. finally {
  50. if( sr != null ) {
  51. sr.Close();
  52. sr = null;
  53. }
  54. if( writer != null ) {
  55. writer.Close();
  56. writer = null;
  57. }
  58. if( ms != null ) {
  59. ms.Dispose();
  60. ms = null;
  61. }
  62. if( response != null ) {
  63. response.Dispose();
  64. response = null;
  65. }
  66. if( httpClient != null ) {
  67. httpClient.Dispose();
  68. httpClient = null;
  69. }
  70. }
  71. return res;
  72. }
  73.  
  74. [DataContract( Name = "acsEintrittGast", Namespace = "" )]
  75. public class acsEintrittGast {
  76. private Guid id = Guid.NewGuid();
  77. [DataMember( Name = "id", Order = 1 )]
  78. public Guid ID {
  79. get { return id; }
  80. set { id = value; }
  81. }
  82.  
  83. private Byte[] bitmap = null;
  84. [DataMember( Name = "bitmap", Order = 1 )]
  85. public Byte[] Bitmap {
  86. get { return bitmap; }
  87. set { bitmap = value; }
  88. }
  89.  
  90. private DateTime lastEntry = new DateTime( 1900, 1, 1 );
  91. [DataMember( Name = "lastEntry", Order = 1 )]
  92. public DateTime LastEntry {
  93. get { return lastEntry; }
  94. set { lastEntry = value; }
  95. }
  96. }
  97.  
  98. acsEintrittGast gast = new acsEintrittGast();
  99. gast.Bitmap = new byte[80455];
  100. gast.ID = Guid.NewGuid();
  101. await acsService.SetGastImfo( ftpLicID, currentYear, gast );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement