public static void Upload_Insert(UploadEntity ue) { using (MainDB db = new MainDB(BOAdv.MasterConnectionString)) { db.StoredProcedures.Upload_Insert(ue); } }
public void OnCompontentComplated(UploadEntity entity) { UploadCompontent _compontent = this.UploadCompontents.Where(c => c.CurrentUploadEntity == entity).FirstOrDefault(); UploadCompontentComplatedEvent.Invoke(entity); if (entity.Total <= entity.Uploaded) { _compontent.Abort(); // compontent.Join(); } }
public void UploadCompontentComplated(UploadEntity entity) { int newThreadId = 0; lock (LockObject) { DispatcherHelper.CheckBeginInvokeOnUI(() => { this.UploadEnities.Where(xc => xc.Id == entity.Id).FirstOrDefault().Uploaded = entity.Uploaded; if (entity.Uploaded >= entity.Total) { this.UploadEnities.Where(xc => xc.Id == entity.Id).FirstOrDefault().IsComplated = true; WorkingThreadNUm = WorkingThreadNUm - 1; CompletedNum = CompletedNum + 1; if (IsAutomatic) { if (AutoRuning) { Id = Id + 1; newThreadId = Id; UploadDataOption option = new UploadDataOption() { Id = newThreadId, IsComplated = false, TableName = entity.TableName, TableDiscription = entity.TableDiscription, OperatingRange = DateTime.ParseExact(entity.OperatingRange.ToString(), "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture).AddDays(1).ToString("yyyy-MM-dd") }; _dataService.GetData(option, (items, error) => { if (error != null) { return; } foreach (var item in items) { this.UploadEnities.Add(item); } }); } } StatrtAllUploadThread(newThreadId); } //合计总数量 UploadedTotal = this.UploadEnities.Sum(c => c.Uploaded); }); } }
public void Items_Add(UploadEntity uploadEntity) { try { this.uploadDataGrid.Items.Add(uploadEntity); this.uploadEntityList.Add(uploadEntity); } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
private void ItemDelste_Click(object sender, MouseButtonEventArgs e) { try { Object selectedItem = this.uploadDataGrid.SelectedItem; if (selectedItem is UploadEntity) { UploadEntity uploadEntity = selectedItem as UploadEntity; this.uploadDataGrid.Items.Remove(uploadEntity); } } catch (Exception ex) { LogManage.WriteLog(this.GetType(), ex); } finally { } }
public async Task <JsonResult> ConfirmUpload(UploadDataModel model) { if (ModelState.IsValid & model != null) { var upload = new UploadEntity(User.Identity.GetUserId(), model.BankId, model.BranchId, 0); bool result = false; try { result = await UploadManager.CreateAsync(upload); } catch (Exception ex) { throw new Exception(ex.Message); } if (result) { try { foreach (var data in model.PData) { var uploaddata = new UploadDataEntity(upload.Id, data.Narration, data.Amount, data.AccountNumber, data.Debit1Credit0, data.PostingCode, data.TranID, data.TranDate, 0); UploadDataManager.Create(uploaddata); } } catch (Exception ex) { //TODO: implement log UploadDataManager.Delete(upload.Id); UploadManager.Delete(upload); throw new Exception("Upload failed"); } var branchDetail = await Helper.GetBranchNameAndCode(upload.BranchId); new EmailSender().SendToBranchOperator(branchDetail["BranchCode"]); return(Json(new { code = "00", message = "Successful" }, JsonRequestBehavior.AllowGet)); } else { throw new Exception("Upload creation failed"); } } throw new Exception("Invalid Data Submitted"); }
public static void GetUploadEntity(Dictionary <byte, Dictionary <byte, UploadEntity> > result, byte[] originData, int index = 0) { try { result = result ?? new Dictionary <byte, Dictionary <byte, UploadEntity> >(); UploadEntity uploadData = new UploadEntity(); if (originData.Length <= 0) { return; } uploadData.ChannelNumber = originData[index]; uploadData.MemeroyID = originData[index + 1]; uploadData.MemeroyLength = originData[index + 2]; uploadData.MemeroyData = GetHexBytes(originData, index + 3, uploadData.MemeroyLength); //uploadData.MemeroyData = uploadData.MemeroyData.Reverse().ToArray(); if (!result.ContainsKey(uploadData.ChannelNumber)) { result.Add(uploadData.ChannelNumber, new Dictionary <byte, UploadEntity> { { uploadData.MemeroyID, uploadData } }); } else { if (!result[uploadData.ChannelNumber].ContainsKey(uploadData.MemeroyID)) { result[uploadData.ChannelNumber].Add(uploadData.MemeroyID, uploadData); } } index = index + 3 + uploadData.MemeroyLength; if (index > originData.Length - 1) { return; } GetUploadEntity(result, originData, index); } catch (Exception e) { //UPLogger.Error(e.ToString()); //Console.Write($"Index:{index}"); throw e; } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext context) { var clientPrincipalName = req.Headers["X-MS-CLIENT-PRINCIPAL-NAME"].FirstOrDefault(); if (string.IsNullOrEmpty(clientPrincipalName)) { return(new UnauthorizedResult()); } var devEnvironmentVariable = Environment.GetEnvironmentVariable("NETCORE_ENVIRONMENT"); var isDevelopment = string.IsNullOrEmpty(devEnvironmentVariable) || devEnvironmentVariable.ToLower() == "development"; var builder = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); if (isDevelopment) { builder.AddUserSecrets(typeof(CreateUploadFunc).Assembly); } var config = builder.Build(); // log.LogInformation("C# HTTP trigger function processed a request."); string filename = req.Query["filename"]; if (string.IsNullOrEmpty(filename)) { return(new BadRequestObjectResult("Please pass a filename on the query string")); } var randomNumber = new byte[9]; rngCsp.GetBytes(randomNumber); var uploadId = Convert.ToBase64String(randomNumber).Replace('+', '-').Replace('/', '_').Substring(0, 8); var storageAccount = CloudStorageAccount.Parse(config["StorageAccountConnectionString"]); var blobClient = storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference(config["ContainerName"]); // todo: different path prefix for different lifecycle auto-delete e.g. 30d, 60d, 90d var blob = container.GetBlockBlobReference($"{uploadId}/{filename}"); var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() { SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTime.UtcNow.AddHours(3), Permissions = SharedAccessBlobPermissions.Write, }); var uploadUrl = $"{blob.Uri}{sasToken}"; var downloadUrl = $"{blob.Uri}"; // save details to table var tableClient = storageAccount.CreateCloudTableClient(); CloudTable uploadsTable = tableClient.GetTableReference("uploads"); await uploadsTable.CreateIfNotExistsAsync(); var uploadEntity = new UploadEntity(uploadId) { FileName = filename, User = clientPrincipalName, UploadDate = DateTime.UtcNow, DownloadUrl = downloadUrl, }; await uploadsTable.ExecuteAsync(TableOperation.Insert(uploadEntity)); return(new JsonResult(new { uploadUrl = uploadUrl, downloadUrl = downloadUrl })); }
public UploadCompontent(UploadEntity uploadEntity) { CurrentUploadEntity = uploadEntity; this.UploadThreadNum = uploadEntity.Id; this.IsComplated = false; }
public async Task <bool> UpLoadFile <T>(T t, FileInformation source, string taskId) { string auth = t as string; UploadEntity uploadEntity = new UploadEntity { FileSize = source.FileSize, TaskId = taskId, SourcePath = source.FilePath, SourceName = source.FileName, //之后从配置文件读取 ChunkSize = 320 * 1024 }; //-:获取上传地址 Log.WriteLog("Request uploadurl"); uploadEntity.Url = GetUploadUrl(source.ParentId, source.FileName, auth); Log.WriteLog("Request uploadurl success"); //二:正式上传 NetUtil netUtil = new NetUtil(); uploadEntity.Method = "PUT"; IDictionary <string, string> fixedHeaders = new Dictionary <string, string> { //给固定头部赋值 { "SdkVersion", "Graph-dotnet-1.6.2" }, { "Cache-Control", "no-store, no-cache" } }; bool result = await netUtil.UploadAsync(uploadEntity, fixedHeaders, (netClient, unfixedHeadInfo) => { //这里给随着块数变化而变化的头部赋值 if (unfixedHeadInfo.IsAdd) { //添加头部 string range = string.Format("bytes {0}-{1}/{2}", unfixedHeadInfo.Offset, unfixedHeadInfo.Offset + unfixedHeadInfo.BlockSize - 1, unfixedHeadInfo.FileSize); Log.WriteLog("range:" + range); netClient.AddHeader("Content-Range", range); } else { //移除上面添加的头部,必须跟上面对应 netClient.Headers.Remove("Content-Range"); } }, (offset, fileSize, des) => { Log.WriteLog("process:" + offset + ":" + fileSize + ":" + des); //这里处理进度 if (string.IsNullOrEmpty(des)) { } else { ProgressEvent?.Invoke(offset, fileSize, des); } }); FinishedEvent(""); return(result); }
public async Task <UploadId> Handle(UploadFilesCommand request, CancellationToken cancellationToken) { AppUserEntity?uploader = await context.Entities.AppUsers.FirstOrDefaultAsync(x => x.UserName == context.Requestor.UserName.Value); if (uploader is null) { throw new ArgumentException("Invalid requestor."); // todo: custom exception } UtcTimestamp startTimestamp = context.UtcNow; var tempFiles = new List <FileEntity>(); var duplicates = new List <string>(); foreach (SourceFile sourceFile in request.Parameters.SourceFiles) { UtcTimestamp timestamp = context.UtcNow; Sha256Hash hash = sha256Generator.GenerateHash(sourceFile.Content); if (IsDuplicate(hash)) { duplicates.Add(sourceFile.OrginalFileName ?? "???"); } else { string newFileName = FileUtils.GetRandomFileNameWithTimestamp(timestamp.Value, sourceFile.OrginalFileName); IFileInfo fileInfo = fileDatabase.SourceFiles.Create(sourceFile.Content, new FileName(newFileName)); ThumbnailMakerResult?thumbResult = thumbnailMaker.TryMakeAndSaveThumbnail(fileInfo, timestamp); var fileEntity = new FileEntity { MimeType = sourceFile.MimeType.Value, FileName = sourceFile.OrginalFileName, UtcWhenAdded = timestamp.Value, SourceFileName = newFileName, SourceFileSize = sourceFile.Content.Length, Description = null, Title = null, Hash = hash.ToHexString(), PrimaryDateTime = null, Image = new ImageEntity() { Width = thumbResult?.OrginalImageSize.Width, Height = thumbResult?.OrginalImageSize.Height, ThumbnailFileName = thumbResult?.ThumbnailFileName.Value, }, Uploader = uploader }; tempFiles.Add(fileEntity); } } var uploadEntity = new UploadEntity { Description = request.Parameters.Description.Value, UtcWhenAdded = startTimestamp.Value, FileCount = tempFiles.Count, TotalSize = tempFiles.Select(x => x.SourceFileSize).Aggregate(0L, (a, b) => a + b), Uploader = uploader }; foreach (var file in tempFiles) { file.Upload = uploadEntity; // TODO: handle 0 files as error } context.Entities.Files.AddRange(tempFiles); await context.Entities.SaveChangesAsync(); logger.Add($"New upload #{uploadEntity.Id}. Files added (except duplicates): {uploadEntity.FileCount}"); return(new UploadId(uploadEntity.Id)); }