private void AntiplagiatService_OnDocumentChecked(object sender, string documentPath, string resultPath) { if (context.PathUserId.ContainsKey(documentPath)) { long userId = context.PathUserId[documentPath]; if (resultPath == string.Empty) { vkApi.Reply(userId, AppData.Strings.QuotaError); } else { var uploadServer = vkApi.Docs.GetMessagesUploadServer(userId); int repeatTime = 10; bool ok = false; while (!ok && repeatTime > 0) { repeatTime--; using var wc = new WebClient(); try { var result = Encoding.ASCII.GetString(wc.UploadFile(uploadServer.UploadUrl, resultPath)); var docs = vkApi.Docs.Save(result, title: Path.GetFileName(resultPath), tags: null); vkApi.Messages.Send(new MessagesSendParams() { RandomId = new Random().Next(), UserId = userId, Message = AppData.Strings.CheckComplete, Attachments = new List <MediaAttachment> { docs.First().Instance }, }); } catch (Exception e) { ok = false; System.Threading.Thread.Sleep(10000); } ok = true; } } } }