Ejemplo n.º 1
0
        protected async Task <T> PostDictionary <T>(Dictionary <string, string> dic) where T : class
        {
            try
            {
                string json = await HttpBaseService.PostAsync(ApiUri, dic);

                return(JsonHelper.Deserlialize <T>(json));
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("ApiBaseService.PostDictionary :" + e.Message);
#endif
                return(null);
            }
        }
Ejemplo n.º 2
0
        protected async Task <string> GetHtml(string uri)
        {
            try
            {
                string html = await HttpBaseService.GetStringAsync(uri);

                //byte[] bytes = Encoding.UTF8.GetBytes(html);
                //html = Encoding.GetEncoding("GBK").GetString(bytes);
                return(html);
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(e.Message);
#endif
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        protected async Task <WriteableBitmap> GetImage(string uri)
        {
            try
            {
                IBuffer buffer = await HttpBaseService.GetIBufferAsync(uri);

                if (buffer != null)
                {
                    BitmapImage     bi = new BitmapImage();
                    WriteableBitmap wb = null;
                    using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
                    {
                        Stream stream2Write = stream.AsStreamForWrite();

                        await stream2Write.WriteAsync(buffer.ToArray(), 0, (int)buffer.Length);

                        await stream2Write.FlushAsync();

                        stream.Seek(0);

                        await bi.SetSourceAsync(stream);

                        wb = new WriteableBitmap(bi.PixelWidth, bi.PixelHeight);
                        stream.Seek(0);
                        await wb.SetSourceAsync(stream);

                        return(wb);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("ApiBaseService.GetImage" + e.Message);
#endif
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uri"></param>
        /// <param name="body"></param>
        /// <returns></returns>
        protected async Task <T> PostJson <T>(string body) where T : class
        {
            try
            {
                string json = await HttpBaseService.PostAsync(ApiUri, body);

                if (json != null)
                {
                    return(JsonHelper.Deserlialize <T>(json));
                }
                return(null);
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(e.Message);
#endif
                return(null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uri"></param>
        /// <returns></returns>
        protected async Task <T> GetJsonByUri <T>(string uri) where T : class
        {
            try
            {
                string json = await HttpBaseService.GetStringAsync(uri);

                if (json != null)
                {
                    return(JsonHelper.Deserlialize <T>(json));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("ApiBaseService.GetJsonByUri : " + e.Message);
#endif
                return(null);
            }
        }