Ejemplo n.º 1
0
        private void StartSendingServer(List <ListViewItem> items)
        {
            string countryCode = txt_country.Text;
            string onlineState = txt_onlineState.Text;
            Thread th          = new Thread(() =>
            {
                foreach (ListViewItem lvi in items)
                {
                    dynamic item     = lvi.Tag;
                    string extension = Path.GetExtension(item["image"]);
                    string fileName  = "image" + extension;
                    if (!Directory.Exists(Globals.CACHE_FOLDER))
                    {
                        Directory.CreateDirectory(Globals.CACHE_FOLDER);
                    }

                    string filePath = Globals.CACHE_FOLDER + @"\" + fileName;
                    DownloadRemoteImageFile(item["image"], filePath);

                    string response = hr.postFile(Globals.API_URL + "/gateway/tube/picture/upload", filePath, "videospicture");

                    if (response != string.Empty)
                    {
                        dynamic blob = ser.DeserializeObject(response);
                        blob         = Encryption.Decrypt(Globals.ENCRYPTION_KEY, blob["d"]);
                        dynamic data = ser.DeserializeObject(blob);

                        if (data["success"])
                        {
                            object dataObj = new
                            {
                                name = item["name"],
                                collectionStreamLink = ser.Serialize(item["parts"]),
                                description          = item["description"],
                                picture_id           = data["picture_id"],
                                source      = item["domain"],
                                countryCode = countryCode,
                                online      = onlineState,
                            };

                            string dataPost = "d=" + HttpUtility.UrlEncode(Encryption.Encrypt(Globals.ENCRYPTION_KEY, ser.Serialize(dataObj)));

                            response = hr.post(Globals.API_URL + "/gateway/tube/post", dataPost);
                            blob     = ser.DeserializeObject(response);
                            response = Encryption.Decrypt(Globals.ENCRYPTION_KEY, blob["d"]);
                            Console.Write(response);
                        }
                    }
                    list_sended.Invoke((MethodInvoker)(() =>
                    {
                        list_sended.Items.Add((ListViewItem)lvi.Clone());
                        lvi.Remove();
                    }));
                }
            });

            th.Start();
        }