Example #1
0
        protected override JsonResult RunInBackground(params Java.Lang.Void[] @params)
        {
            var client  = new RestClient(GlobalClass.BaseUrl + "Event/UploadPicture");
            var request = new RestRequest(Method.POST);

            request.AddHeader("authorization", "bearer " + GlobalClass.AccessToken);

            Java.IO.File file   = new Java.IO.File(uploadImagePath);
            long         length = file.Length() / 1024; // Size in KB

            if (length > 500)
            {
                compressImage = CompressFile.compressImage(uploadImagePath);
            }
            else
            {
                compressImage = uploadImagePath;
            }

            request.AddFile("file", compressImage, null);
            var response = client.Execute <JsonResult>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                jsonResult = JsonConvert.DeserializeObject <JsonResult>(response.Content);
                return(jsonResult);
            }
            else
            {
                return(jsonResult);
            }
        }
Example #2
0
        public void MultiExport(ExportBook bookExport, string filename)
        {
            List <List <AssetsMain> > Lists = bookExport.GetPageList <AssetsMain>();
            int          count = bookExport.GetPagecount();
            ZipParameter zp    = new ZipParameter();

            zp.ZIPDirectoryName = filename;
            zp.ZIPName          = "bookExport.zip";
            for (int i = 0; i < count; i++)
            {
                bookExport.SetCurrentAs(Lists[i]);
                bookExport.CreatTemplate();
                bookExport.Filldata();
                var tempFile = filename;
                var savePath = Path.Combine(tempFile,
                                            string.Format("{0}.xls", DateTime.Now.ToString("yyMMddHHmmss") + "ZC09_图书档案" + i));
                bookExport.Save(savePath);
                bookExport.ResetRowIndex();
                zp.ZIPFileList.Add(savePath);
            }
            ;
            CompressFile cprFile = new CompressFile();

            cprFile.ZipParameter = zp;
            string strMessage = cprFile.CompressReturnMsg();
        }
Example #3
0
        public async Task GetProfile(IGuildUser UserTag = null)
        {
            if (UserTag == null)
            {
                UserTag = Context.Message.Author as IGuildUser;
            }

            var tmp = await ReplyAsync("", false, Embed.GetEmbed("Profile", "Working..."));

            if (!File.Exists($"{Program.Rootdir}\\Users\\Profile\\{UserTag.Id}.gif"))
            {
                await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Profile", "You havn't uploaded a profile image yet"));

                return;
            }

            try
            {
                var avatar = await GetFromWeb.PullImageFromWebAsync(UserTag.GetAvatarUrl());

                string name   = UserTag.Nickname ?? UserTag.Username;
                var    tmpimg = await Profile.GetProfile(Program.Users.GetValueOrDefault(UserTag.Id), name, avatar);

                if (tmpimg.Length > 8000000)
                {
                    await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Profile", "File too big"));

                    GC.Collect();
                    return;
                }
                else
                {
                    var file = await CompressFile.CheckForDupesAndSave(tmpimg);

                    await Context.Message.Channel.SendFileAsync(file);

                    File.Delete(file);
                }
            }
            catch (Exception e)
            {
                await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Profile", e.Message));

                GC.Collect();
                return;
            }

            await tmp.ModifyAsync(x => x.Embed = Embed.GetEmbed("Get Profile", "Done"));

            System.Threading.Thread.Sleep(5000);
            await tmp.DeleteAsync();

            GC.Collect();
        }
Example #4
0
        static int Main(string[] args)
        {
            var timer = Stopwatch.StartNew();

            if (args.Length != 3)
            {
                Console.WriteLine("Не правильное количество аргументов");
                return(1);
            }
            if (args[0].ToLower() == "compress")
            {
                try
                {
                    CompressFile compressFile = new CompressFile(args[1], args[2]);
                    compressFile.Processing();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Программа закончена с ОШИБКОЙ!");
                    //Console.ReadKey();
                    return(1);
                }
            }
            else if (args[0].ToLower() == "decompress")
            {
                try
                {
                    DecompressFile decompressFile = new DecompressFile(args[1], args[2]);
                    decompressFile.Processing();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine("Программа закончена с ОШИБКОЙ!");
                    //Console.ReadKey();
                    return(1);
                }
            }
            else
            {
                Console.WriteLine("Не задан режим работы программы: compress/decompress");
                return(1);
            }
            timer.Stop();
            TimeSpan ts          = timer.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}",
                                                 ts.Hours, ts.Minutes, ts.Seconds);

            Console.WriteLine("Программа закончена ({0})", elapsedTime);
            //Console.ReadKey();
            return(0);
        }
        protected override JsonResult RunInBackground(params Java.Lang.Void[] @params)
        {
            RestClient client;

            if (typeOfFile == 0)
            {
                client = new RestClient(GlobalClass.BaseUrl + "Event/UploadEventFiles?eventid=" + EventID);
            }
            else
            {
                client = new RestClient(GlobalClass.BaseUrl + "Event/UploadVideo?eventid=" + EventID);
            }
            var request = new RestRequest(Method.POST);

            request.AddHeader("authorization", "bearer " + GlobalClass.AccessToken);
            for (int i = 0; i < uploadImagePath.Count; i++)
            {
                if (typeOfFile == 0)
                {
                    Java.IO.File file   = new Java.IO.File(uploadImagePath[i]);
                    long         length = file.Length() / 1024; // Size in KB

                    if (length > 500)
                    {
                        Compressfile[i] = CompressFile.compressImage(uploadImagePath[i]);
                    }
                    else
                    {
                        Compressfile[i] = uploadImagePath[i];
                    }
                    request.AddFile("file", Compressfile[i], null);
                }
                else
                {
                    request.AddFile("file", uploadImagePath[i], null);
                }
            }
            var response = client.Execute <JsonResult>(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                jsonResult = JsonConvert.DeserializeObject <JsonResult>(response.Content);
                return(jsonResult);
            }
            else
            {
                return(jsonResult);
            }
        }
            protected override JsonResult RunInBackground(params Java.Lang.Void[] @params)
            {
                Java.IO.File file   = new Java.IO.File(uploadImagePath);
                long         length = file.Length() / 1024; // Size in KB

                if (length > 500)
                {
                    compressImage = CompressFile.compressImage(uploadImagePath);
                }
                else
                {
                    compressImage = uploadImagePath;
                }

                jsonResult = RestSharpCall.PostFile <JsonResult>(compressImage, "Event/SetEventPicture?eventid=" + eventID + "&userId=" + GlobalClass.UserID);
                CompressFile.deleteTempFile();
                return(jsonResult);
            }
        private async Task UploadSingleFile(MediaFile file)
        {
            Uri uri;

            if (file.MediaType == Core.Model.MediaType.Photo)
            {
                uri = new Uri(GlobalClass.BaseUrl + "Event/UploadEventFiles?eventid=" + file.EventID);
            }
            else
            {
                uri = new Uri(GlobalClass.BaseUrl + "Event/UploadVideo?eventid=" + file.EventID);
            }

            string uploadFilePath = file.FilePath;

            Java.IO.File mediaFile = new Java.IO.File(uploadFilePath);
            totalBytes = mediaFile.Length();

            if (totalBytes == 0)
            {
                return;
            }

            double totalMB = Convert.ToDouble(totalBytes) / (1024 * 1024); // Size in MB

            if (totalMB > MaxVideoSize)
            {
                notificationBuilder = new Notification.Builder(ApplicationContext);
                notificationManager = (NotificationManager)GetSystemService(NotificationService);

                notificationBuilder.SetOngoing(false)
                .SetSmallIcon(Resource.Drawable.icon);

                notificationBuilder.SetContentTitle("Upload failed");
                Intent        notificationIntent = new Intent(ApplicationContext, typeof(UploadErrorActivity));
                PendingIntent contentIntent      = PendingIntent.GetActivity(ApplicationContext,
                                                                             0, notificationIntent, PendingIntentFlags.UpdateCurrent);
                notificationBuilder.SetContentIntent(contentIntent);
                notificationBuilder.SetContentText("Video size is too large");
                notificationBuilder.SetAutoCancel(true);

                notification   = notificationBuilder.Build();
                notificationID = new Random().Next(10000, 99999);
                notificationManager.Notify(notificationID, notification);
                notificationID = 0;
                notificationBuilder.Dispose();
                notification.Dispose();
                notificationManager.Dispose();

                return;
            }
            else

            //  && (totalBytes / 1024) > 500
            if (file.MediaType == Core.Model.MediaType.Photo)
            {
                uploadFilePath = CompressFile.compressImage(uploadFilePath);
                mediaFile      = new Java.IO.File(uploadFilePath);
                totalBytes     = mediaFile.Length();
            }

            uploadedBytes   = 0;
            percentComplete = 0;
            var totalfileSize = Math.Round(totalMB, 2);

            notificationManager = (NotificationManager)GetSystemService(NotificationService);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(true)
            .SetSmallIcon(Resource.Drawable.ic_file_upload_white_18dp)
            .SetContentTitle("Uploading")
            .SetContentText
                (Math.Round((Convert.ToDecimal(uploadedBytes) / (1024.0m * 1024.0m)), 2) + " MB of " + totalfileSize + " MB")
            .SetProgress(100, percentComplete, false);

            notification   = notificationBuilder.Build();
            notificationID = new Random().Next(10000, 99999);
            notificationManager.Notify(notificationID, notification);
            try
            {
                timer          = new System.Timers.Timer();
                timer.Elapsed += Timer_Elapsed;
                timer.Interval = 1000;
                timer.Enabled  = true;
                timer.Start();
            }
            catch (Exception ex)
            {
                throw;
            }

            wClient = new WebClient();
            wClient.Headers.Add("authorization", "bearer " + GlobalClass.AccessToken);
            wClient.UploadFileAsync(uri, uploadFilePath);
            wClient.UploadProgressChanged += new UploadProgressChangedEventHandler(ProgressChanged);
            wClient.UploadFileCompleted   += WClient_UploadFileCompleted;
        }