Exemplo n.º 1
0
        void UploadWebService(MediaUploadDTO MediaUploadDTO1, byte[] mediabyte, YUKLENECEK_SABLON GuncellenecekSablon, int count)
        {
            string jsonString = JsonConvert.SerializeObject(MediaUploadDTO1);
            string uzanti     = ".png";

            if (MediaUploadDTO1.video)
            {
                uzanti = ".mp4";
            }
            var client = new RestSharp.RestClient("http://31.169.67.210:8080/api/template-medias");

            client.Timeout = -1;
            var request = new RestSharp.RestRequest(RestSharp.Method.POST);

            //request.Accept = "*/*";
            //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
            //client.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36");
            request.AddHeader("Accept", "*/*");
            request.AddHeader("Content-Type", "multipart/form-data");
            request.AddHeader("Authorization", "Bearer " + MeId.API_TOKEN);
            request.AddParameter("mediaCount", MediaUploadDTO1.mediaCount);
            request.AddParameter("postText", MediaUploadDTO1.postText);
            request.AddParameter("templateId", MediaUploadDTO1.templateId);
            request.AddParameter("video", MediaUploadDTO1.video);
            request.AddParameter("userId", MeId.id);
            request.AddParameter("processed", false);
            request.AddParameter("type", "POST");
            request.AddFile("photo", mediabyte, "sosi_media_file" + uzanti);
            RestSharp.IRestResponse response = client.Execute(request);
            if (response.StatusCode != HttpStatusCode.Unauthorized &&
                response.StatusCode != HttpStatusCode.InternalServerError &&
                response.StatusCode != HttpStatusCode.BadRequest &&
                response.StatusCode != HttpStatusCode.Forbidden &&
                response.StatusCode != HttpStatusCode.MethodNotAllowed &&
                response.StatusCode != HttpStatusCode.NotAcceptable &&
                response.StatusCode != HttpStatusCode.RequestTimeout &&
                response.StatusCode != HttpStatusCode.NotFound)
            {
                GuncellenecekSablon.isUploaded = true;
                DataBase.YUKLENECEK_SABLON_Guncelle(GuncellenecekSablon);
                GleenBase2.RunOnUiThread(delegate()
                {
                    MedyaUploadServiceDialogFragment1.UploadProgress(count + 1);
                });
            }
        }
Exemplo n.º 2
0
        void UploadMedias()
        {
            var YuklenecekMedialar = DataBase.YUKLENECEK_SABLON_GETIR();

            if (YuklenecekMedialar.Count > 0)
            {
                var YuklenmeyenVarmi = YuklenecekMedialar.FindAll(item => item.isUploaded == false);
                if (YuklenmeyenVarmi.Count > 0)
                {
                    GleenBase2.RunOnUiThread(delegate()
                    {
                        MedyaUploadServiceDialogFragment1.Cancelable = false;
                        MedyaUploadServiceDialogFragment1.Show(GleenBase2.SupportFragmentManager, "MedyaUploadServiceDialogFragment1");
                    });
                    for (int i = 0; i < YuklenecekMedialar.Count; i++)
                    {
                        if (!YuklenecekMedialar[i].isUploaded)
                        {
                            //Android.Net.Uri newUri;
                            //newUri = Android.Net.Uri.Parse(YuklenecekMedialar[i].MediaUri);

                            MediaUploadDTO mediaUploadDTO = new MediaUploadDTO()
                            {
                                mediaCount = YuklenecekMedialar[i].maxMediaCount,
                                postText   = YuklenecekMedialar[i].aciklama,
                                templateId = DataBase.GUNCEL_SABLON_GETIR()[0].id,
                                video      = YuklenecekMedialar[i].isVideo,
                                userId     = MeId.id,
                                processed  = false,
                                type       = "POST"
                            };
                            var bytess = ConvertImageToByte(YuklenecekMedialar[i].MediaUri);
                            UploadWebService(mediaUploadDTO, bytess, YuklenecekMedialar[i], i + 1);
                        }
                        else
                        {
                            GleenBase2.RunOnUiThread(delegate()
                            {
                                MedyaUploadServiceDialogFragment1.UploadProgress(i + 1);
                            });
                        }
                    }

                    var YuklenecekMedialar2 = DataBase.YUKLENECEK_SABLON_GETIR();
                    var YuklenmeyenVarmi2   = YuklenecekMedialar2.FindAll(item => item.isUploaded == false);
                    if (YuklenmeyenVarmi2.Count <= 0)
                    {
                        DataBase.YUKLENECEK_SABLON_TEMIZLE();
                        DataBase.GUNCEL_SABLON_TEMIZLE();
                    }
                }
                else
                {
                    DataBase.GUNCEL_SABLON_TEMIZLE();
                }
            }
            else
            {
                DataBase.GUNCEL_SABLON_TEMIZLE();
            }
        }