Esempio n. 1
0
        private static DocuSignAccount GetDocuSignAccount(OAuth20Token token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            var userInfoString = RequestHelper.PerformRequest(DocuSignLoginProvider.Instance.DocuSignHost + "/oauth/userinfo",
                                                              headers: new Dictionary <string, string> {
                { "Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token) }
            });

            Log.Debug("DocuSing userInfo: " + userInfoString);

            var userInfo = (DocuSignUserInfo)JsonConvert.DeserializeObject(userInfoString, typeof(DocuSignUserInfo));

            if (userInfo.Accounts == null || userInfo.Accounts.Count == 0)
            {
                throw new Exception("Account is null");
            }

            var account = userInfo.Accounts[0];

            return(account);
        }
Esempio n. 2
0
 public DocuSignHelper(
     DocuSignToken docuSignToken,
     FileSecurity fileSecurity,
     IDaoFactory daoFactory,
     IOptionsMonitor <ILog> options,
     BaseCommonLinkUtility baseCommonLinkUtility,
     UserManager userManager,
     AuthContext authContext,
     DisplayUserSettingsHelper displayUserSettingsHelper,
     FileMarker fileMarker,
     GlobalFolderHelper globalFolderHelper,
     FilesMessageService filesMessageService,
     FilesLinkUtility filesLinkUtility,
     IServiceProvider serviceProvider,
     ConsumerFactory consumerFactory)
 {
     DocuSignToken             = docuSignToken;
     FileSecurity              = fileSecurity;
     DaoFactory                = daoFactory;
     BaseCommonLinkUtility     = baseCommonLinkUtility;
     UserManager               = userManager;
     AuthContext               = authContext;
     DisplayUserSettingsHelper = displayUserSettingsHelper;
     FileMarker                = fileMarker;
     GlobalFolderHelper        = globalFolderHelper;
     FilesMessageService       = filesMessageService;
     FilesLinkUtility          = filesLinkUtility;
     ServiceProvider           = serviceProvider;
     ConsumerFactory           = consumerFactory;
     Log = options.CurrentValue;
 }
Esempio n. 3
0
        public string SendDocuSign <T>(T fileId, DocuSignData docuSignData, Dictionary <string, string> requestHeaders)
        {
            if (docuSignData == null)
            {
                throw new ArgumentNullException("docuSignData");
            }
            var token   = DocuSignToken.GetToken();
            var account = GetDocuSignAccount(token);

            var configuration = GetConfiguration(account, token);
            var document      = CreateDocument(fileId, docuSignData.Name, docuSignData.FolderId, out var sourceFile);

            var url = CreateEnvelope(account.AccountId, document, docuSignData, configuration);

            FilesMessageService.Send(sourceFile, requestHeaders, MessageAction.DocumentSendToSign, "DocuSign", sourceFile.Title);

            return(url);
        }
Esempio n. 4
0
        private static DocuSign.eSign.Client.Configuration GetConfiguration(DocuSignAccount account, OAuth20Token token)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            var apiClient = new ApiClient(account.BaseUri + "/restapi");

            var configuration = new DocuSign.eSign.Client.Configuration {
                ApiClient = apiClient
            };

            configuration.AddDefaultHeader("Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token));

            return(configuration);
        }
Esempio n. 5
0
        public static File SaveDocument(string envelopeId, string documentId, string documentName, object folderId)
        {
            if (string.IsNullOrEmpty(envelopeId))
            {
                throw new ArgumentNullException("envelopeId");
            }
            if (string.IsNullOrEmpty(documentId))
            {
                throw new ArgumentNullException("documentId");
            }

            var token         = DocuSignToken.GetToken();
            var account       = GetDocuSignAccount(token);
            var configuration = GetConfiguration(account, token);

            using (var fileDao = Global.DaoFactory.GetFileDao())
                using (var folderDao = Global.DaoFactory.GetFolderDao())
                {
                    if (string.IsNullOrEmpty(documentName))
                    {
                        documentName = "new.pdf";
                    }

                    Folder folder;
                    if (folderId == null ||
                        (folder = folderDao.GetFolder(folderId)) == null ||
                        folder.RootFolderType == FolderType.TRASH ||
                        !Global.GetFilesSecurity().CanCreate(folder))
                    {
                        if (Global.FolderMy != null)
                        {
                            folderId = Global.FolderMy;
                        }
                        else
                        {
                            throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
                        }
                    }

                    var file = new File
                    {
                        FolderID = folderId,
                        Comment  = FilesCommonResource.CommentCreateByDocuSign,
                        Title    = FileUtility.ReplaceFileExtension(documentName, ".pdf"),
                    };

                    var envelopesApi = new EnvelopesApi(configuration);
                    Log.Info("DocuSign webhook get stream: " + documentId);
                    using (var stream = envelopesApi.GetDocument(account.AccountId, envelopeId, documentId))
                    {
                        file.ContentLength = stream.Length;
                        file = fileDao.SaveFile(file, stream);
                    }

                    FilesMessageService.Send(file, MessageInitiator.ThirdPartyProvider, MessageAction.DocumentSignComplete, "DocuSign", file.Title);

                    FileMarker.MarkAsNew(file);

                    return(file);
                }
        }