Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor() ||
                    !FilesSettings.EnableThirdParty || !ImportConfiguration.SupportDocuSignInclusion)
                {
                    throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
                }

                var error = Request["error"];
                if (!string.IsNullOrEmpty(error))
                {
                    if (error == "access_denied")
                    {
                        error = "Canceled at provider";
                    }
                    throw new Exception(error);
                }

                OAuth20Token token;

                var code = Request["code"];
                if (!string.IsNullOrEmpty(code))
                {
                    token = DocuSignLoginProvider.GetAccessToken(code);
                    DocuSignHelper.ValidateToken(token);
                    DocuSignToken.SaveToken(token);
                }
                else
                {
                    token = DocuSignToken.GetToken();
                    if (token == null)
                    {
                        OAuth20TokenHelper.RequestCode(HttpContext.Current,
                                                       DocuSignLoginProvider.DocuSignOauthCodeUrl,
                                                       DocuSignLoginProvider.DocuSignOAuth20ClientId,
                                                       DocuSignLoginProvider.DocuSignOAuth20RedirectUrl,
                                                       DocuSignLoginProvider.DocuSignScope);
                        return;
                    }
                }

                SubmitToken("", Source);
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Global.Logger.Error("DocuSign", ex);
                SubmitError(ex.Message, Source);
            }
        }
        public static string SendDocuSign(object 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);
            File sourceFile;
            var  document = CreateDocument(fileId, docuSignData.Name, docuSignData.FolderId, out sourceFile);

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

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

            return(url);
        }
        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);
                }
        }