public async Task <Job> ScheduleAsync(JobDescription description) { var toCreate = new List <Job>(); var invalidChars = Path.GetInvalidFileNameChars(); void Create(JobDescription description, Guid?parent) { bool isLeaf = description.Children == null || description.Children.Count == 0; if (!isLeaf && parent != null) { throw new InvalidOperationException( "Multiple nested job is not supported yet."); } if (invalidChars.Any(description.SuggestedFileName.Contains)) { throw new InvalidOperationException( "The suggested file name is invalid."); } var newJob = new Job { JobId = _guid.Create(), OwnerId = description.OwnerId, Status = isLeaf ? JobStatus.Pending : JobStatus.Composite, Composite = !isLeaf, SuggestedFileName = description.SuggestedFileName, Arguments = description.Arguments ?? "{}", CreationTime = DateTimeOffset.Now, JobType = description.JobType, ParentJobId = parent, }; toCreate.Add(newJob); if (isLeaf) { return; } foreach (var child in description.Children) { Create(child, newJob.JobId); } } Create(description, null); _dbContext.Add(toCreate[0]); await _dbContext.SaveChangesAsync(); if (toCreate.Count > 1) { _dbContext.AddRange(toCreate.Skip(1)); await _dbContext.SaveChangesAsync(); } _signal.Notify(); return(toCreate[0]); }
public string NewId() => SequentialGuidGenerator.Create(_sequentialGuidType).ToString("N");
public static Guid GenGuidId() { return(_generator.Create()); }
/// <summary> /// 生成有序GUID /// </summary> /// <returns></returns> protected virtual Guid NewGuid() { return(SequentialGuidGenerator.Create()); }
public BaseEntity() { Id = SequentialGuidGenerator.Create(SequentialGuidType.SequentialAtEnd); }
public string NewId() => SequentialGuidGenerator.Create(SequentialGuidType.SequentialAsString).ToString("N");