/// <summary> /// Manages collaborator rights /// </summary> public static void ManageCollaboratorRights() { try { //ExStart:ManageCollaboratorRights // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); //Create annotation handler AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); IUserDataHandler userRepository = annotator.GetUserDataHandler(); IDocumentDataHandler documentRepository = annotator.GetDocumentDataHandler(); if (!Directory.Exists(cfg.StoragePath)) { Directory.CreateDirectory(cfg.StoragePath); } // Create owner. var johnOwner = userRepository.GetUserByEmail("*****@*****.**"); if (johnOwner == null) { userRepository.Add(new User { FirstName = "John", LastName = "Doe", Email = "*****@*****.**" }); johnOwner = userRepository.GetUserByEmail("*****@*****.**"); } // Create document data object in storage var document = documentRepository.GetDocument("Document.pdf"); long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf", DocumentType.Pdf, johnOwner.Id); // Create reviewer. var reviewerInfo = new ReviewerInfo { PrimaryEmail = "*****@*****.**", FirstName = "Judy", LastName = "Doe", // Can only get view annotations AccessRights = AnnotationReviewerRights.CanView }; // Add collaboorator to the document. If user with Email equals to reviewers PrimaryEmail is absent it will be created. var addCollaboratorResult = annotator.AddCollaborator(documentId, reviewerInfo); // Get document collaborators var getCollaboratorsResult = annotator.GetCollaborators(documentId); var judy = userRepository.GetUserByEmail("*****@*****.**"); // 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 A." }; // John try to add annotations. User is owner of the document. var johnResult = annotator.CreateAnnotation(pointAnnotation, documentId, johnOwner.Id); // Judy try to add annotations try { var judyResult = annotator.CreateAnnotation(pointAnnotation, documentId, judy.Id); } //Get exceptions, because user can only view annotations catch (AnnotatorException e) { Console.Write(e.Message); Console.ReadKey(); } // Allow Judy create annotations. reviewerInfo.AccessRights = AnnotationReviewerRights.CanAnnotate; var updateCollaboratorResult = annotator.UpdateCollaborator(documentId, reviewerInfo); // Now user can add annotations var judyResultCanAnnotate = annotator.CreateAnnotation(pointAnnotation, documentId, judy.Id); //ExEnd:ManageCollaboratorRights } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Creates a new annotation for a document /// </summary> /// <param name="connectionId">Socket connection identifier to validate user permissions for</param> /// <param name="fileId">The document path to create the annotation for</param> /// <param name="type">The annotation type</param> /// <param name="message">The annotation text message</param> /// <param name="rectangle">The annotation bounds</param> /// <param name="pageNumber">The document page number to create the annotation at</param> /// <param name="annotationPosition">The annotation left-top position</param> /// <param name="svgPath">The annotation SVG path</param> /// <param name="options">The annotation drawing options (pen color, width etc.)</param> /// <param name="font">The annotation text font</param> /// <returns>An instance of an object containing information about a created annotation</returns> public CreateAnnotationResult CreateAnnotation(string connectionId, string fileId, byte type, string message, Rectangle rectangle, int pageNumber, Point annotationPosition, string svgPath, DrawingOptions options, FontOptions font) { 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 caller = collaboratorsInfo.Collaborators.FirstOrDefault(c => c.Guid == reviewer.Value.UserGuid); var annotation = new GroupDocs.Annotation.Domain.AnnotationInfo { Type = (AnnotationType)type, Box = new GroupDocs.Annotation.Domain.Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), PageNumber = pageNumber, AnnotationPosition = new GroupDocs.Annotation.Domain.Point(annotationPosition.X, annotationPosition.Y), SvgPath = svgPath, PenColor = options != null ? options.PenColor : -984833, PenWidth = options != null ? (byte?)options.PenWidth : 1, PenStyle = options != null ? (byte?)options.DashStyle : (byte?)DashStyle.Solid, BackgroundColor = options != null ? options.BrushColor : -984833, FontFamily = !string.IsNullOrEmpty(font.Family) ? "Arial" : "Calibri", FontSize = font.Size != null ? font.Size : 4, }; if (!string.IsNullOrWhiteSpace(message)) { annotation.Replies = new[] { new GroupDocs.Annotation.Domain.AnnotationReplyInfo { Message = message } }; } var result = _annotator.CreateAnnotation(annotation, document.Id, user.Id); _annotationBroadcaster.CreateAnnotation( collaboratorsInfo.Collaborators.Select(c => c.Guid).ToList(), connectionId, reviewer.Value.UserGuid, caller != null ? caller.PrimaryEmail : _authenticationSvc.AnonymousUserName, fileId, annotation.Type, result.Guid, (byte)result.Access, result.ReplyGuid, pageNumber, _mapper.Map <Rectangle>(rectangle), annotationPosition, svgPath, options, font); return(_mapper.Map <CreateAnnotationResult>(result)); }
/// <summary> /// Gets document collaborator /// </summary> public static void GetCollaborator() { try { //ExStart:GetCollaborator // Create instance of annotator. AnnotationConfig cfg = CommonUtilities.GetConfiguration(); //Create annotation handler AnnotationImageHandler annotator = new AnnotationImageHandler(cfg); IUserDataHandler userRepository = annotator.GetUserDataHandler(); IDocumentDataHandler documentRepository = annotator.GetDocumentDataHandler(); if (!Directory.Exists(cfg.StoragePath)) { Directory.CreateDirectory(cfg.StoragePath); } // Create a user that will be an owner. // Get user from the storage var owner = userRepository.GetUserByEmail("*****@*****.**"); // If user doesn’t exist in the storage then create it. if (owner == null) { userRepository.Add(new User { FirstName = "John", LastName = "Doe", Email = "*****@*****.**" }); owner = userRepository.GetUserByEmail("*****@*****.**"); } // Get document data object in the storage var document = documentRepository.GetDocument("Document.pdf"); // If document already created or it hasn’t owner then delete document if (document != null && document.OwnerId != owner.Id) { documentRepository.Remove(document); document = null; } // Get document id if document already created or create new document long documentId = document != null ? document.Id : annotator.CreateDocument("Document.pdf", DocumentType.Pdf, owner.Id); // Create reviewer. var reviewerInfo = new ReviewerInfo { PrimaryEmail = "*****@*****.**", //user email, unique identifier FirstName = "Judy", LastName = "Doe", AccessRights = AnnotationReviewerRights.All }; // Get document collaborators. var getCollaboratorsResult = annotator.GetCollaborators(documentId); // Get document collaborator by email var getCollaboratorsResultByEmail = annotator.GetDocumentCollaborator(documentId, reviewerInfo.PrimaryEmail); // Get collaborator metadata var user = userRepository.GetUserByEmail(reviewerInfo.PrimaryEmail); ReviewerInfo collaboratorMetadataResult = annotator.GetCollaboratorMetadata(user.Guid); //ExEnd:GetCollaborator } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }