Ejemplo n.º 1
0
 public WhetherInfo GetWhetherInfo(string location)
 {
     Console.WriteLine("Last location: {0}", LastLocation);
     LastLocation = location;
     if (string.Compare(location, "Minsk", true) == 0)
     {
         var res = new WhetherInfo()
         {
             Temperature = 15,
             Humidity    = 50,
             Pressure    = 760,
         };
         return(res);
     }
     else if (string.Compare(location, "Vitebsk", true) == 0)
     {
         var res = new WhetherInfo()
         {
             Temperature = 13,
             Humidity    = 48,
             Pressure    = 750,
         };
         return(res);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
 private Stream GetWhetherInfoAsHtml(string location)
 {
     //OperationContext.Current.OutgoingMessageHeaders.Add(
     //    MessageHeader.CreateHeader("charset", "", "utf-8 text/plain"));
     Console.WriteLine("Last location: {0}", LastLocation);
     LastLocation = location;
     if (string.Compare(location, "Minsk", true) == 0)
     {
         var res = new WhetherInfo()
         {
             Temperature = 15,
             Humidity    = 50,
             Pressure    = 760,
         };
         var stream = new MemoryStream();
         var t      = new StreamWriter(stream, Encoding.UTF8);
         t.WriteLine("<html><body>");
         t.WriteLine("Temperature: {0}", res.Temperature);
         t.WriteLine("Humidity: {0}", res.Humidity);
         t.WriteLine("Pressure: {0}", res.Pressure);
         t.WriteLine("</body></html>");
         t.Flush();
         stream.Seek(0, SeekOrigin.Begin);
         return(stream);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 3
0
        private Stream GetWhetherInfoAsCustomXml(string location)
        {
            WhetherInfo res = GetWhetherInfo(location);

            if (res != null)
            {
                var stream = new MemoryStream();
                var t      = new XmlSerializer(typeof(WhetherInfo));
                t.Serialize(stream, res);
                stream.Seek(0, SeekOrigin.Begin);
                return(stream);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        private Stream GetWhetherInfoAsJson(string location)
        {
            WhetherInfo res = GetWhetherInfo(location);

            if (res != null)
            {
                var stream = new MemoryStream();
                DataContractJsonSerializer s =
                    new DataContractJsonSerializer(typeof(WhetherInfo));
                s.WriteObject(stream, res);
                stream.Seek(0, SeekOrigin.Begin);
                WebOperationContext.Current.OutgoingResponse.ContentType =
                    "application/json; charset=utf-8";
                return(stream);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        private Stream GetWhetherInfoAsText(string location)
        {
            WhetherInfo res = GetWhetherInfo(location);

            if (res != null)
            {
                var stream = new MemoryStream();
                var t      = new StreamWriter(stream, Encoding.UTF8);
                t.WriteLine("Temperature: {0}", res.Temperature);
                t.WriteLine("Humidity: {0}", res.Humidity);
                t.WriteLine("Pressure: {0}", res.Pressure);
                t.Flush();
                stream.Seek(0, SeekOrigin.Begin);
                return(stream);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        public WhetherInfo GetWhetherInfo(string location)
        {
            //Console.WriteLine("Last location: {0}", LastLocation);
            LastLocation = location;
            WhetherInfo result = new WhetherInfo();

            if (string.Compare(location, "Minsk", true) == 0)
            {
                result.Temperature = 15;
                result.Humidity    = 65;
                result.Pressure    = 710;
            }
            else
            {
                result.Temperature = 0;
                result.Humidity    = 50;
                result.Pressure    = 760;
            };
            return(result);
        }