public ActionResult Post() { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); String guid = Request.Params["guid"]; String section = Request.Params["guid"]; AnnotationInfo annotationInfo = imageHandler.GetAnnotation(guid).Annotation; long annotationId = imageHandler.GetAnnotation(guid).Id; switch (section) { case "fieldtext": var jsonString = String.Empty; using (var inputStream = new StreamReader(Request.InputStream)) { jsonString = inputStream.ReadToEnd(); } TextFieldInfo info = JsonConvert.DeserializeObject <TextFieldInfo>(jsonString); SaveAnnotationTextResult result = imageHandler.SaveTextField(annotationId, info); return(Content(JsonConvert.SerializeObject( result, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); case "position": var jsonStringPos = String.Empty; using (var inputStream = new StreamReader(Request.InputStream)) { jsonStringPos = inputStream.ReadToEnd(); } Point point = JsonConvert.DeserializeObject <Point>(jsonStringPos); MoveAnnotationResult moveresult = imageHandler.MoveAnnotationMarker(annotationId, point, annotationInfo.PageNumber); return(Content(JsonConvert.SerializeObject( moveresult, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); default: return(Content(null)); } }
/// <summary> /// Removes annotations /// </summary> public static void RemoveAnnotation() { try { //ExStart:RemoveAnnotation // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); IDocumentDataHandler documentRepository = annotator.GetDocumentDataHandler(); if (!Directory.Exists(cfg.StoragePath)) { Directory.CreateDirectory(cfg.StoragePath); } // Create document data object in storage. var document = documentRepository.GetDocument("Document.pdf"); long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf"); // Create annotation object AnnotationInfo pointAnnotation = new AnnotationInfo { AnnotationPosition = new Point(852.0, 81.0), Box = new Rectangle(212f, 81f, 142f, 0.0f), Type = AnnotationType.Point, PageNumber = 0, CreatorName = "Anonym", DocumentGuid = documentId }; // Get all annotations from storage ListAnnotationsResult listAnnotationsResult = annotator.GetAnnotations(documentId); // Get annotation var annotation = annotator.GetAnnotation(listAnnotationsResult.Annotations[0].Guid); // Delete single annotation var deleteAnnotationResult = annotator.DeleteAnnotation(annotation.Id); //Delete all annotations annotator.DeleteAnnotations(documentId); //ExEnd:RemoveAnnotation } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
public ActionResult Get(string guid) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); return(Content(JsonConvert.SerializeObject( imageHandler.GetAnnotation(guid).Annotation, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); }
// GET: Annotation public ActionResult List(string file) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler handler = Utils.createAnnotationImageHandler(); String filename = file; Document doc = Utils.findDocumentByName(filename); ListAnnotationsResult listResult = handler.GetAnnotations(doc.Id); List <GetAnnotationResult> list = new List <GetAnnotationResult>(); foreach (AnnotationInfo inf in listResult.Annotations) { list.Add(handler.GetAnnotation(inf.Guid)); } return(Content(JsonConvert.SerializeObject( list, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); //Response.Write(list); /* * * response.setHeader("Content-Type", "application/json"); * AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); * String filename = request.getParameter("file"); * * Document doc = Utils.findDocumentByName(filename); * ListAnnotationsResult listResult = imageHandler.getAnnotations(doc.getId()); * * ArrayList<GetAnnotationResult> list = new ArrayList<>(); * for (AnnotationInfo inf : listResult.getAnnotations()) { * list.add(imageHandler.getAnnotation(inf.getGuid())); * } * * new ObjectMapper().writeValue(response.getOutputStream(), list);*/ return(View()); }
/// <summary> /// Removes an annotation from a document /// </summary> /// <param name="connectionId">Socket connection identifier to validate user permissions for</param> /// <param name="fileId">The document path to remove the annotation from</param> /// <param name="annotationGuid">The annotation global unique identifier</param> /// <returns>An instance of an object containing the removed annotation metadata</returns> public DeleteAnnotationResult DeleteAnnotation(string connectionId, string fileId, string annotationGuid) { var reviewer = _annotationBroadcaster.GetConnectionUser(connectionId); if (reviewer == null) { throw new AnnotatorException("There is no such reviewer."); } var user = _userSvc.GetUserByGuid(reviewer.Value.UserGuid); var document = GetDocument(fileId, user.Id); var collaboratorsInfo = _mapper.Map <GetCollaboratorsResult>(_annotator.GetCollaborators(document.Id)); var annotation = _annotator.GetAnnotation(annotationGuid, document.Id, user.Id); var result = _annotator.DeleteAnnotation(annotation.Id, document.Id, user.Id); _annotationBroadcaster.DeleteAnnotation(collaboratorsInfo.Collaborators.Select(c => c.Guid).ToList(), fileId, connectionId, annotationGuid); return(_mapper.Map <DeleteAnnotationResult>(result)); }
public ActionResult Put(string guid) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); AnnotationReplyInfo info = JsonConvert.DeserializeObject(new StreamReader(Request.InputStream).ReadToEnd()) as AnnotationReplyInfo; long annotationId = imageHandler.GetAnnotation(info.Guid).Id; AddReplyResult result = imageHandler.CreateAnnotationReply(annotationId, ""); return(Content(JsonConvert.SerializeObject( result, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); }
public ActionResult Get(string file) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); String filename = file; Document doc = Utils.findDocumentByName(filename); ListAnnotationsResult listResult = imageHandler.GetAnnotations(doc.Id); List <GetAnnotationResult> list = new List <GetAnnotationResult>(); foreach (AnnotationInfo inf in listResult.Annotations) { list.Add(imageHandler.GetAnnotation(inf.Guid)); } return(Content(JsonConvert.SerializeObject( list, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); }
public ActionResult Get(string guid) { Response.AddHeader("Content-Type", "application/json"); AnnotationImageHandler imageHandler = Utils.createAnnotationImageHandler(); //String guid = request.getParameter("guid"); GetAnnotationResult annotationResult = imageHandler.GetAnnotation(guid); if (annotationResult == null) { return(new HttpNotFoundResult("Not found")); } long annotationId = annotationResult.Id; AnnotationReplyInfo[] list = imageHandler.ListAnnotationReplies(annotationId).Replies; return(Content(JsonConvert.SerializeObject( list, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() } ), "application/json")); }
/// <summary> /// Maps annotations and creates dcocument data object in the storage /// </summary> public static void CreateAndGetAnnotation() { try { //ExStart:CreateAndGetAnnotation // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); IDocumentDataHandler documentRepository = annotator.GetDocumentDataHandler(); if (!Directory.Exists(cfg.StoragePath)) { Directory.CreateDirectory(cfg.StoragePath); } // Create document data object in storage. var document = documentRepository.GetDocument("Document.pdf"); long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf"); // Create annotation object AnnotationInfo pointAnnotation = new AnnotationInfo { AnnotationPosition = new Point(852.0, 81.0), Box = new Rectangle(212f, 81f, 142f, 0.0f), Type = AnnotationType.Point, PageNumber = 0, CreatorName = "Anonym", DocumentGuid = documentId }; // Add annotation to storage CreateAnnotationResult createPointAnnotationResult = annotator.CreateAnnotation(pointAnnotation); //============================================================================= // Create annotation object AnnotationInfo textFieldAnnotation = new AnnotationInfo { AnnotationPosition = new Point(852.0, 201.0), FieldText = "text in the box", FontFamily = "Arial", FontSize = 10, Box = new Rectangle(66f, 201f, 64f, 37f), PageNumber = 0, Type = AnnotationType.TextField, CreatorName = "Anonym", DocumentGuid = documentId }; //Add annotation to storage CreateAnnotationResult createTextFieldAnnotationResult = annotator.CreateAnnotation(textFieldAnnotation); // Get annotation from storage GetAnnotationResult result = annotator.GetAnnotation(createPointAnnotationResult.Guid); //ExEnd:CreateAndGetAnnotation } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }