/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); container.RegisterType<IHtmlString, AnnotationWidget>("AnnotationWidget"); string repositoryFolder = AppDomain.CurrentDomain.GetData("DataDirectory") + "/"; var annotator = new AnnotationImageHandler( new AnnotationConfig { StoragePath = repositoryFolder } //new Data.Json.Repositories.UserRepository(repositoryFolder), //new Data.Json.Repositories.DocumentRepository(repositoryFolder), //new Data.Json.Repositories.AnnotationRepository(repositoryFolder), //new Data.Json.Repositories.AnnotationReplyRepository(repositoryFolder), //new Data.Json.Repositories.AnnotationCollaboratorRepository(repositoryFolder) ); container.RegisterInstance(typeof(IUserDataHandler), annotator.GetUserDataHandler()); #region Instances //container.RegisterInstance(typeof (IDocumentDataHandler), new DocumentRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationCollaboratorDataHandler), new AnnotationCollaboratorRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationReplyDataHandler), new AnnotationReplyRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationDataHandler), new AnnotationRepository(repositoryFolder)); //container.RegisterInstance(typeof(IInputDataHandler), new InputDataHandler(repositoryFolder)); //container.RegisterInstance(typeof(IFileDataStore), new FileStore(repositoryFolder)); #endregion Instances container.RegisterInstance(typeof(AnnotationImageHandler), annotator); container.RegisterType<IAnnotationService, AnnotationService>(); container.RegisterType<IAuthenticationService, AuthenticationService>(); container.RegisterType<IAnnotationBroadcaster, AnnotationBroadcaster>(); container.RegisterType<IAnnotationHub, AnnotationHub>(); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); container.RegisterType <IHtmlString, AnnotationWidget>("AnnotationWidget"); string repositoryFolder = AppDomain.CurrentDomain.GetData("DataDirectory") + "/"; var annotator = new AnnotationImageHandler( new AnnotationConfig { StoragePath = repositoryFolder } //new Data.Json.Repositories.UserRepository(repositoryFolder), //new Data.Json.Repositories.DocumentRepository(repositoryFolder), //new Data.Json.Repositories.AnnotationRepository(repositoryFolder), //new Data.Json.Repositories.AnnotationReplyRepository(repositoryFolder), //new Data.Json.Repositories.AnnotationCollaboratorRepository(repositoryFolder) ); container.RegisterInstance(typeof(IUserDataHandler), annotator.GetUserDataHandler()); #region Instances //container.RegisterInstance(typeof (IDocumentDataHandler), new DocumentRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationCollaboratorDataHandler), new AnnotationCollaboratorRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationReplyDataHandler), new AnnotationReplyRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationDataHandler), new AnnotationRepository(repositoryFolder)); //container.RegisterInstance(typeof(IInputDataHandler), new InputDataHandler(repositoryFolder)); //container.RegisterInstance(typeof(IFileDataStore), new FileStore(repositoryFolder)); #endregion Instances container.RegisterInstance(typeof(AnnotationImageHandler), annotator); container.RegisterType <IAnnotationService, AnnotationService>(); container.RegisterType <IAuthenticationService, AuthenticationService>(); container.RegisterType <IAnnotationBroadcaster, AnnotationBroadcaster>(); container.RegisterType <IAnnotationHub, AnnotationHub>(); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); container.RegisterType <IHtmlString, AnnotationWidget>("AnnotationWidget"); string repositoryFolder = HttpContext.Current.Server.MapPath("~/_layouts/15/GroupDocs_Annotation_SharePoint_WebPart/App_Data"); var annotator = new AnnotationImageHandler( new AnnotationConfig { StoragePath = repositoryFolder }, new GroupDocs.Data.Json.Repositories.UserRepository(repositoryFolder), new GroupDocs.Data.Json.Repositories.DocumentRepository(repositoryFolder), new GroupDocs.Data.Json.Repositories.AnnotationRepository(repositoryFolder), new GroupDocs.Data.Json.Repositories.AnnotationReplyRepository(repositoryFolder), new GroupDocs.Data.Json.Repositories.AnnotationCollaboratorRepository(repositoryFolder)); container.RegisterInstance(typeof(IUserDataHandler), annotator.GetUserDataHandler()); #region Instances //container.RegisterInstance(typeof (IDocumentDataHandler), new DocumentRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationCollaboratorDataHandler), new AnnotationCollaboratorRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationReplyDataHandler), new AnnotationReplyRepository(repositoryFolder)); //container.RegisterInstance(typeof(IAnnotationDataHandler), new AnnotationRepository(repositoryFolder)); //container.RegisterInstance(typeof(IInputDataHandler), new InputDataHandler(repositoryFolder)); //container.RegisterInstance(typeof(IFileDataStore), new FileStore(repositoryFolder)); #endregion Instances container.RegisterInstance(typeof(AnnotationImageHandler), annotator); container.RegisterType <IAnnotationService, AnnotationService>(); container.RegisterType <IAuthenticationService, AuthenticationService>(); container.RegisterType <IAnnotationBroadcaster, AnnotationBroadcaster>(); container.RegisterType <IAnnotationHub, AnnotationHub>(); }
/// <summary> /// Initializes a new instance of the AnnotationService class /// </summary> /// <param name="annotationBroadcaster">The annotation Socket events broadcasting object</param> /// <param name="authenticationSvc">The authentication service</param> /// <param name="annotator">The annotation management service</param> public AnnotationService(IAnnotationBroadcaster annotationBroadcaster, IAuthenticationService authenticationSvc, AnnotationImageHandler annotator) { _annotationBroadcaster = annotationBroadcaster; _authenticationSvc = authenticationSvc; _userSvc = annotator.GetUserDataHandler(); _annotator = annotator; _documentSvc = annotator.GetDocumentDataHandler(); _fileSvc = annotator.GetInputDataHandler(); MapperConfiguration config = new MapperConfiguration(cfg => { cfg.CreateMap <GroupDocs.Annotation.Domain.Rectangle, Rectangle>(); cfg.CreateMap <GroupDocs.Annotation.Domain.ReviewerInfo, ReviewerInfo>(); cfg.CreateMap <ReviewerInfo, GroupDocs.Annotation.Domain.ReviewerInfo>(); cfg.CreateMap <GroupDocs.Annotation.Domain.AnnotationReplyInfo, AnnotationReplyInfo>(); cfg.CreateMap <GroupDocs.Annotation.Domain.TextFieldInfo, TextFieldInfo>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.Result, Result>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Point?, Point>() .ForMember(dst => dst.X, opt => opt.MapFrom(src => src.HasValue ? src.Value.X : 0.0)) .ForMember(dst => dst.Y, opt => opt.MapFrom(src => src.HasValue ? src.Value.Y : 0.0)); cfg.CreateMap <GroupDocs.Annotation.Domain.AnnotationInfo, AnnotationInfo>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.ListAnnotationsResult, ListAnnotationsResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.SetCollaboratorsResult, SetCollaboratorsResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.CreateAnnotationResult, CreateAnnotationResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.DeleteAnnotationResult, DeleteAnnotationResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.AddReplyResult, AddReplyResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.DeleteReplyResult, DeleteReplyResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.EditReplyResult, EditReplyResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.MoveAnnotationResult, MoveAnnotationResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.ResizeAnnotationResult, ResizeAnnotationResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.SaveAnnotationTextResult, SaveAnnotationTextResult>(); cfg.CreateMap <GroupDocs.Annotation.Domain.Results.GetCollaboratorsResult, GetCollaboratorsResult>(); }); _mapper = config.CreateMapper(); }
/// <summary> /// Initializes a new instance of the AnnotationService class /// </summary> /// <param name="annotationBroadcaster">The annotation Socket events broadcasting object</param> /// <param name="authenticationSvc">The authentication service</param> /// <param name="annotator">The annotation management service</param> public AnnotationService(IAnnotationBroadcaster annotationBroadcaster, IAuthenticationService authenticationSvc, AnnotationImageHandler annotator) { _annotationBroadcaster = annotationBroadcaster; _authenticationSvc = authenticationSvc; _userSvc = annotator.GetUserDataHandler(); _annotator = annotator; _documentSvc = annotator.GetDocumentDataHandler(); _fileSvc = annotator.GetInputDataHandler(); MapperConfiguration config = new MapperConfiguration(cfg => { cfg.CreateMap<GroupDocs.Annotation.Domain.Rectangle, Rectangle>(); cfg.CreateMap<GroupDocs.Annotation.Domain.ReviewerInfo, ReviewerInfo>(); cfg.CreateMap<ReviewerInfo, GroupDocs.Annotation.Domain.ReviewerInfo>(); cfg.CreateMap<GroupDocs.Annotation.Domain.AnnotationReplyInfo, AnnotationReplyInfo>(); cfg.CreateMap<GroupDocs.Annotation.Domain.TextFieldInfo, TextFieldInfo>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.Result, Result>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Point?, Point>() .ForMember(dst => dst.X, opt => opt.MapFrom(src => src.HasValue ? src.Value.X : 0.0)) .ForMember(dst => dst.Y, opt => opt.MapFrom(src => src.HasValue ? src.Value.Y : 0.0)); cfg.CreateMap<GroupDocs.Annotation.Domain.AnnotationInfo, AnnotationInfo>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.ListAnnotationsResult, ListAnnotationsResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.SetCollaboratorsResult, SetCollaboratorsResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.CreateAnnotationResult, CreateAnnotationResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.DeleteAnnotationResult, DeleteAnnotationResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.AddReplyResult, AddReplyResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.DeleteReplyResult, DeleteReplyResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.EditReplyResult, EditReplyResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.MoveAnnotationResult, MoveAnnotationResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.ResizeAnnotationResult, ResizeAnnotationResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.SaveAnnotationTextResult, SaveAnnotationTextResult>(); cfg.CreateMap<GroupDocs.Annotation.Domain.Results.GetCollaboratorsResult, GetCollaboratorsResult>(); }); _mapper = config.CreateMapper(); }
/// <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> /// Deletes document collaborator /// </summary> public static void DeleteCollaborator() { try { //ExStart:DeleteCollaborator // 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 }; // Delete collaborator var deleteCollaboratorResult = annotator.DeleteCollaborator(documentId, reviewerInfo.PrimaryEmail); //ExEnd:DeleteCollaborator } catch (System.Exception exp) { Console.WriteLine(exp.Message); } }