Beispiel #1
0
        public static Bitmap SetImageOpacity(String cacheKey, float opacity)
        {
            cacheKey = Path.GetFileNameWithoutExtension(new Uri(cacheKey).LocalPath);

            String oKey = cacheKey + @"@" + opacity;

            Bitmap oImg = APICache.Get <Bitmap>(oKey);

            if (oImg != null)
            {
                return(oImg);
            }

            Bitmap img = APICache.Get <Bitmap>(cacheKey);

            if (img == null)
            {
                return(null);
            }

            oImg = SetImageOpacity(img, opacity);

            if (oImg != null)
            {
                APICache.Put(oKey, oImg);
            }

            return(oImg);
        }
Beispiel #2
0
        public Bitmap GetPhoto()
        {
            Bitmap img = null;

            if (!String.IsNullOrEmpty(this.Photo))
            {
                String p = Path.GetFileNameWithoutExtension(new Uri(this.Photo).LocalPath);
                img = APICache.Get <Bitmap>(p);

                if (img == null)
                {
                    WebRequest  request        = WebRequest.Create(this.Photo);
                    WebResponse response       = request.GetResponse();
                    Stream      responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        img = new Bitmap(responseStream);
                    }

                    APICache.Put <Bitmap>(p, img);
                }
            }

            return(img);
        }
Beispiel #3
0
        public Bitmap Load(PhotoSize sz = PhotoSize._130)
        {
            Bitmap img = null;
            String url = "";

            switch (sz)
            {
            case PhotoSize._130:
                img = this._photo130;
                url = this.Photo130;
                break;

            case PhotoSize._604:
                img = this._photo604;
                url = this.Photo604;
                break;

            case PhotoSize._807:
                img = this._photo807;
                url = this.Photo807;
                break;

            case PhotoSize._1280:
                img = this._photo1280;
                url = this.Photo1280;
                break;

            case PhotoSize._2560:
                img = this._photo2560;
                url = this.Photo2560;
                break;
            }

            if (img == null && !String.IsNullOrEmpty(url))
            {
                String p = Path.GetFileNameWithoutExtension(new Uri(url).LocalPath);
                img = APICache.Get <Bitmap>(p);

                if (img == null)
                {
                    WebRequest  request        = WebRequest.Create(url);
                    WebResponse response       = request.GetResponse();
                    Stream      responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        img = new Bitmap(responseStream);
                    }

                    APICache.Put <Bitmap>(p, img);
                }
            }

            return(img);
        }
Beispiel #4
0
        public static async Task <User[]> GetAll(IEnumerable <int> ids)
        {
            APIResponse <User[]> r = (await API.Call <User[]>("users.get", "user_ids=" + String.Join(",", ids) + "&fields=photo_200,online"));

            if (r != null && r.Response != null)
            {
                User[] users = r.Response;

                foreach (User usr in users)
                {
                    APICache.Put <User>(usr.ID, usr);
                }

                return(users);
            }

            return(null);
        }
Beispiel #5
0
        public static async Task <User> Get(int id)
        {
            User usr = APICache.Get <User>(id);

            if (usr != null)
            {
                return(usr);
            }

            APIResponse <User[]> r = (await API.Call <User[]>("users.get", "user_ids=" + id + "&fields=photo_200,online"));

            if (r != null && r.Response != null)
            {
                usr = r.Response[0];
            }

            APICache.Put <User>(id, usr);
            return(usr);
        }
Beispiel #6
0
        public static async Task <List <Message> > Get(int[] ids)
        {
            try
            {
                List <Message> msgs = (await API.Call <ObjList <Message> >("messages.getById", "message_ids=" + String.Join(",", ids))).Response.ToList();

                foreach (Message msg in msgs)
                {
                    APICache.Put <Message>(msg.ID, msg);
                }

                return(msgs);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }
Beispiel #7
0
        public async Task <List <Message> > GetMessages(int offset = 0, int count = 200)
        {
            try
            {
                String chat = "&user_id=" + this.Message.UserID;
                if (this.Message.ChatID > 0)
                {
                    chat = "&chat_id=" + this.Message.ChatID;
                }

                APIResponse <ObjList <Message> > r = (await API.Call <ObjList <Message> >("messages.getHistory", "offset=" + offset + "&count=" + count + chat));

                if (r != null && r.Response != null)
                {
                    List <Message> msgs = r.Response.ToList();

                    foreach (Message msg in msgs)
                    {
                        APICache.Put <Message>(msg.ID, msg);

                        if (msg.CryptedNow || msg.Crypted)
                        {
                            this.Crypt = true;
                            if (!String.IsNullOrEmpty(this.CryptKey) && msg.CryptedNow)
                            {
                                msg.Decrypt(this.CryptKey);
                            }
                        }
                    }

                    return(msgs);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }
Beispiel #8
0
        public static async Task <Message> Get(int id)
        {
            try
            {
                Message msg = APICache.Get <Message>(id);

                if (msg != null)
                {
                    return(msg);
                }

                msg = (await API.Call <ObjList <Message> >("messages.getById", "message_ids=" + id)).Response.Items[0];

                APICache.Put <Message>(msg.ID, msg);

                return(msg);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }