Yonka2019

ServerResponse.cs

Apr 13th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: WindowsFormsApplication1.ServerResponse
  3. // Assembly: WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: A0967493-2B5E-45DB-9F7E-6A0B14E2A48A
  5. // Assembly location: C:\Users\yonka\Desktop\WeatherClient\WeatherClient.exe
  6.  
  7. using System.Collections.Generic;
  8.  
  9. namespace WindowsFormsApplication1
  10. {
  11.   internal class ServerResponse
  12.   {
  13.     public static string TEST_RESPONSE = "200:ANSWER:date=18/07/2016&city=Beersheba&temp=29.16&text=Clear : few clouds";
  14.     private int code;
  15.     private float temperture;
  16.     private string date;
  17.     private string location;
  18.     private string text;
  19.  
  20.     public ServerResponse(string raw_response)
  21.     {
  22.       this.code = int.Parse(raw_response.Substring(0, 3));
  23.       if (this.code == 200)
  24.       {
  25.         string[] strArray1 = raw_response.Substring(11).Split('&');
  26.         Dictionary<string, string> dictionary = new Dictionary<string, string>();
  27.         foreach (string str in strArray1)
  28.         {
  29.           char[] chArray = new char[1]{ '=' };
  30.           string[] strArray2 = str.Split(chArray);
  31.           dictionary[strArray2[0]] = strArray2[1];
  32.         }
  33.         this.temperture = float.Parse(dictionary["temp"]);
  34.         this.date = dictionary[nameof (date)];
  35.         this.location = dictionary["city"];
  36.         this.text = dictionary[nameof (text)];
  37.       }
  38.       else
  39.       {
  40.         if (this.code != 500)
  41.           return;
  42.         this.temperture = -1f;
  43.         this.date = "error";
  44.         this.location = "error";
  45.         this.text = "error";
  46.       }
  47.     }
  48.  
  49.     public int getCode() => this.code;
  50.  
  51.     public float getTemperture() => this.temperture;
  52.  
  53.     public string getDate() => this.date;
  54.  
  55.     public string getLocation() => this.location;
  56.  
  57.     public string getText() => this.text;
  58.   }
  59. }
  60.  
Add Comment
Please, Sign In to add comment