protected override void ProcessRecord() { if (InputObject == null) { return; } try { // new document or none yet var document = DocumentInput.NewDocumentWithId(NewId, Id, InputObject, SessionState); // document from input document = Actor.ToBsonDocument(document, InputObject, new DocumentInput(SessionState, Convert), _Selectors); // write if (FileFormat == FileFormat.Json) { using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture)) using (var bsonWriter = BsonWriter.Create(stringWriter, Actor.DefaultJsonWriterSettings)) { BsonSerializer.Serialize(bsonWriter, document); _streamWriter.WriteLine(stringWriter.ToString()); } } else { BsonSerializer.Serialize(_bsonWriter, document); } } catch (ArgumentException ex) { WriteError(DocumentInput.NewErrorRecordBsonValue(ex, InputObject)); } }
protected override void ProcessRecord() { try { if (ParameterSetName == nsValue) { WriteObject(Actor.ToBsonValue(Value)); return; } // always new document var document = DocumentInput.NewDocumentWithId(NewId, Id, InputObject, SessionState) ?? new BsonDocument(); if (InputObject != null) { document = Actor.ToBsonDocument(document, InputObject, new DocumentInput(SessionState, Convert), _Selectors); } WriteObject(new Dictionary(document)); } catch (ArgumentException ex) { WriteError(DocumentInput.NewErrorRecordBsonValue(ex, InputObject)); } }
protected override void ProcessRecord() { if (InputObject == null) { return; } try { // new document or none yet var document = DocumentInput.NewDocumentWithId(NewId, Id, InputObject, SessionState); document = Actor.ToBsonDocument(document, InputObject, new DocumentInput(SessionState, Convert), _Selectors); if (Update) { WriteResult(TargetCollection.Save(document, WriteConcern, Result)); } else { WriteResult(TargetCollection.Insert(document, WriteConcern, Result)); } } catch (ArgumentException ex) { WriteError(DocumentInput.NewErrorRecordBsonValue(ex, InputObject)); } catch (MongoException ex) { WriteException(ex, InputObject); } }
/// <summary> /// AddDocumentAsync takes POST document API parameters and calls the data repositories required. /// </summary> /// <param name="documentDetails"></param> /// <param name="ownerId">AADId of the owner</param> /// <returns>Document created</returns> public async Task <Document> AddDocumentAsync(DocumentInput documentDetails, string ownerId) { try { var viewersSet = new HashSet <User>(documentDetails.Viewers); var signersSet = new HashSet <User>(documentDetails.Signers); //Add Users await this.AddUsersAsync(viewersSet, signersSet); //Add Signatures IList <Signature>?signatures = await this.AddSignaturesAsync(signersSet); //Add Viewers IList <Viewer>?viewers = await this.AddViewerAsync(viewersSet); var newDocument = new Document { DocumentType = documentDetails.DocumentType, Signatures = signatures, OwnerId = ownerId, Viewers = viewers, }; Document?createdDocument = await this._documentRepository.CreateDocument(newDocument); return(createdDocument); } catch (Exception ex) { this._logger.LogError("Failed to create document with exception", ex.Message); throw; } }
public async Task <ActionResult <Document> > PostDocument(int companyId, DocumentInput document) { // Get user email id from claim. UserInfo authoUserInfo = await UserInformation(); var documentDto = _mapper.Map <Document>(document); if (_dataRepository.IsValidUser(authoUserInfo.Email, companyId)) { try { documentDto.CompanyId = companyId; documentDto.Author = authoUserInfo.Email; _dataRepository.Add(documentDto); } catch (DbUpdateException) { if (_dataRepository.FindById(documentDto.Id) != null) //DocumentExists { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetDocument", new { id = documentDto.Id }, documentDto)); } else { return(Unauthorized("Insufficient Privileges.")); } }
public async Task <Document> Create(DocumentInput input) { var file = input.File; var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition); var parsedFilename = HeaderUtilities.RemoveQuotes(parsedContentDisposition.FileName); var filename = Guid.NewGuid().ToString() + Path.GetExtension(parsedFilename); var fileDestination = Path.Combine(_hostingEnvironment.WebRootPath, "Uploads", filename); var upload = new Document() { Name = input.Name, PathToFile = fileDestination }; using (var fileStream = new FileStream(fileDestination, FileMode.Create)) { var inputStream = file.OpenReadStream(); await inputStream.CopyToAsync(fileStream); } _context.Documents.Add(upload); await _context.SaveChangesAsync(); return(upload); }
public async void AddToDB(ApplicationDbContext context, int documentId, string inputName, object inputValue) { DocumentInput docInput = await context.DocumentInputs.FirstOrDefaultAsync(x => x.DocumentId == documentId && x.Name == inputName); if (docInput != null) { docInput = new DocumentInput { Name = inputName, InputTypeId = 3, DocumentId = documentId, CreateBy = "admin", CreateDate = DateTime.UtcNow, ModifyBy = "admin", ModifyDate = DateTime.UtcNow }; context.DocumentInputs.Add(docInput); await context.SaveChangesAsync(); } ContractXDocumentInput contractXDocumentInput = new ContractXDocumentInput { ContractXDocumentId = 3, DocumentInputId = docInput.DocumentInputId, Value = inputValue.ToString(), CreateBy = "admin", CreateDate = DateTime.UtcNow, ModifyBy = "admin", ModifyDate = DateTime.UtcNow }; await context.SaveChangesAsync(); }
public async Task Uploads_Stored_In_Documents_Folder() { var contextOptions = CreateNewContextOptions(); var fileMock = GetMockFormFileWithQuotedContentDisposition("UploadTest", "UploadTest.txt"); var mockEnvironment = new Mock <IHostingEnvironment>(); mockEnvironment.Setup(m => m.WebRootPath).Returns(Path.GetTempPath()); mockEnvironment.Setup(m => m.ContentRootPath).Returns(Path.GetTempPath()); using (var context = new ApplicationDbContext(mockEnvironment.Object, contextOptions)) { // Ensure the path exists. Directory.CreateDirectory(Path.GetTempPath() + "Uploads"); var sut = new DocumentsRepository(context, mockEnvironment.Object); var file = fileMock.Object; var input = new DocumentInput() { Name = "Upload Test", File = fileMock.Object }; //Act var result = await sut.Create(input); Assert.True(File.Exists(result.PathToFile)); Assert.Equal(result.Name, input.Name); // Clean up. File.Delete(result.PathToFile); } }
/// <inheritdoc/> public async Task <Document> CreateDocumentAsync(DocumentInput documentDetails, string ownerId) { _logger.LogInformation("About to create a document"); Document document = await this.AddDocumentAsync(documentDetails, ownerId); _logger.LogInformation("Completed document creation"); return(document); }
public async Task DocumentController_CreateDocumentsAsync_EmptyDocumentType_ThrowsApiArgumentException() { var documentInput = new DocumentInput { DocumentType = null, Signers = new List <User>(), Viewers = new List <User>() }; var documentController = new DocumentController(documentService.Object, authorizationService.Object); await documentController.CreateDocumentAsync(documentInput); }
public void Init() { DefaultsSetup(); _actionsGraph = new ActionsGraph(); var documentInput = new DocumentInput(new Document()); documentInput.OnConnect(); _actionsGraph.Register(documentInput); }
public async Task <ActionResult <Document> > CreateDocumentAsync([FromBody] DocumentInput documentDetails) { ApiArgumentNullException.ThrowIfNull(documentDetails?.DocumentType); ApiArgumentNullException.ThrowIfNull(documentDetails?.Signers); Document document = await documentService.CreateDocumentAsync(documentDetails, HttpContext.User.GetUserId()).ConfigureAwait(false); return(new OkObjectResult(document)); }
public async Task <IActionResult> Post([FromForm] DocumentInput upload) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _documentRepository.Create(upload); return(Ok(result)); }
public void Setup() { DefaultInterpreters.Setup(); _actionsGraph = new ActionsGraph(); _actionsGraph.Register(new FunctionFactoryInput()); _actionsGraph.Register(new OptionsSetupInput()); _document = TestUtils.DefaultsSetup(); DefaultFunctions.Setup(_actionsGraph); var documentInput = new DocumentInput(_document); documentInput.OnConnect(); _actionsGraph.Register(documentInput); _document.Transact(); }
public void SetupTest() { DefaultsSetup(); var document = new Document(); document.Root.Set <ActionGraphInterpreter>().ActionsGraph = _actionsGraph; var documentInput = new DocumentInput(document); _actionsGraph.Register(documentInput); documentInput.OnConnect(); _document = _actionsGraph.InputContainer[InputNames.Document].GetData(NotificationNames.GetValue).Get <Document>(); _document.Transact(); }
public async Task TestCreateDocumentReturnsDefault() { var documentInput = new DocumentInput { DocumentType = "Leasing", Signers = new List <User> { }, Viewers = new List <User> { } }; var documentService = new Mock <IDocumentService>(MockBehavior.Loose); var createdDocument = await documentService.Object.CreateDocumentAsync(documentInput, "001").ConfigureAwait(false); Assert.AreEqual(createdDocument, default); }
protected override void ProcessRecord() { try { // always new document var document = DocumentInput.NewDocumentWithId(NewId, Id, InputObject) ?? new BsonDocument(); if (InputObject != null) { document = Actor.ToBsonDocument(document, InputObject, Convert, _Selectors); } WriteObject(new Dictionary(document)); } catch (ArgumentException ex) { WriteError(DocumentInput.NewErrorRecordBsonValue(ex, InputObject)); } }
public async Task <APIResult> Create(DocumentInput input) { var file = input.File; input.Name = file.FileName.Split('\\').LastOrDefault().Split('/').LastOrDefault(); var parsedContentDisposition = ContentDispositionHeaderValue.Parse(file.ContentDisposition); var parsedFilename = HeaderUtilities.RemoveQuotes(parsedContentDisposition.FileName); var filename = Guid.NewGuid().ToString() + Path.GetExtension(parsedFilename); if (!Directory.Exists("\\\\CNVFCUSTIF01.home.e-kmall.com" + "\\uploads\\")) { try { Directory.CreateDirectory("\\\\CNVFCUSTIF01.home.e-kmall.com" + "\\uploads\\"); } catch { } } var fileDestination = Path.Combine("\\\\CNVFCUSTIF01.home.e-kmall.com", "uploads", filename); var upload = new AttachDto() { AttachName = input.Name, Url = "http://fiat.qa.elandcloud.com/uploads/" + filename, SeqNo = input.Id }; using (var fileStream = new FileStream(fileDestination, FileMode.Create)) { var inputStream = file.OpenReadStream(); await inputStream.CopyToAsync(fileStream); //JsonConvert.SerializeObject(t) }; IEnumerable <AttachDto> resultInfo = new AttachDto[] { upload }; APIResult result = new APIResult { Body = CommonHelper.EncodeDto <AttachDto>(resultInfo), ResultCode = ResultType.Success, Msg = "" }; return(result); }
void InitializeInputs() { // Build the inputs and pipes inputFactory = new InputFactory(); var viewInput = new View2dInput(view2d, viewer2d); inputFactory.Register(viewInput); mouseInput = new MouseEventsInput(); inputFactory.Register(mouseInput); var mousePipe = new OCCMouseEventsPipe(view2d, viewer2d); inputFactory.RegisterPipe(mouseInput.Name, mousePipe); inputFactory.Register(mousePipe); var solverDrawerPipe = new SolverDrawerPipe(context2d, view2d, _solver, _solverDrawer); inputFactory.RegisterPipe(mousePipe.Name, solverDrawerPipe); inputFactory.Register(solverDrawerPipe); _editDetectionPipe = new EditDetectionPipe(context2d, view2d, _solver); inputFactory.RegisterPipe(solverDrawerPipe.Name, _editDetectionPipe); inputFactory.Register(_editDetectionPipe); _editDetectionPipe.ActivateActionHandler += new ActionActivatedEventHandler(EditDetectionPipe_ActivateActionHandler); var docInput = new DocumentInput(WorkItem.Services.Get <ILocalContextService>().CurrentOcafDocument); inputFactory.Register(docInput); var contextInput = new Context2dInput(context2d); inputFactory.Register(contextInput); OCTopoDS_Shape topoShape = WorkItem.Services.Get <ILocalContextService>().CurrentSelectedShape; workingPlaneInput = new WorkingPlaneInput(GeomUtils.ExtractAxis(topoShape)); inputFactory.Register(workingPlaneInput); }
protected override void ProcessRecord() { if (InputObject == null) { return; } try { // new document or none yet var document = DocumentInput.NewDocumentWithId(NewId, Id, InputObject); // document from input document = Actor.ToBsonDocument(document, InputObject, Convert, _Selectors); // write BsonDocumentSerializer.Instance.Serialize(_context, document); _endDocument?.Invoke(); } catch (ArgumentException ex) { WriteError(DocumentInput.NewErrorRecordBsonValue(ex, InputObject)); } }
protected override void ProcessRecord() { if (InputObject == null) { return; } try { // new document or none yet var document = DocumentInput.NewDocumentWithId(NewId, Id, InputObject); document = Actor.ToBsonDocument(document, InputObject, Convert, _Selectors); Collection.InsertOne(Session, document); } catch (ArgumentException ex) { WriteError(DocumentInput.NewErrorRecordBsonValue(ex, InputObject)); } catch (MongoException ex) { WriteException(ex, InputObject); } }
public async Task <IActionResult> Post([FromForm] DocumentInput upload) { var result = await _uploadFileService.Create(upload); return(Ok(result)); }