コード例 #1
0
 /// <summary>
 /// If the documentsigningtasks of a specific documentsigning are signed, then generate the pades document(s)
 /// </summary>
 /// <param name="docsignRef"></param>
 /// <param name="regardingRef"></param>
 /// <param name="saveinsp"></param>
 /// <param name="service"></param>
 /// <returns>List of pades url's</returns>
 private HttpStatusCode CheckOverAllStatus(EntityReference docsignRef, EntityReference regardingRef,
                                           bool saveinsp, bool sendcopy, EntityReference senderRef, string orgname, int lcid,
                                           IOrganizationService service)
 {
     try
     {
         var results = new CallBackCrmHandler().GetDocumentSiginingTasks(docsignRef, 1, service);
         //if all tasks are completed, the return is null
         if (results.Entities.Count == 0)
         {
             ConvertSdoDocument(docsignRef, regardingRef, saveinsp, sendcopy, senderRef, orgname,
                                lcid, service);
             return(HttpStatusCode.OK);
         }
         return(HttpStatusCode.NoContent);
     }
     catch (Exception ex)
     {
         return(HttpStatusCode.BadRequest);
     }
 }
コード例 #2
0
        internal async Task <HttpStatusCode> DeactivateTask(string requestId, string taskId, string orgname)
        {
            if (string.IsNullOrEmpty((requestId)))
            {
                return(HttpStatusCode.BadRequest);
            }
            try
            {
                var service = new CallBackCrmHandler().ConnectToCRM(orgname); //Connect to the customers CRM
                if (service == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                new CallBackCrmHandler().DeactivateTask(requestId, taskId, service);
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return(HttpStatusCode.BadRequest);
            }
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="taskid"></param>
        /// <param name="orgname"></param>
        internal async Task <HttpStatusCode> GetDocumentSigning(string requestid, string taskid, string orgname)
        {
            if (string.IsNullOrEmpty((requestid)))
            {
                return(HttpStatusCode.BadRequest);
            }
            try
            {
                var service = new CallBackCrmHandler().ConnectToCRM(orgname); //Connect to the customers CRM
                if (service == null)
                {
                    return(HttpStatusCode.NotFound);
                }

                var documentsigning = new CallBackCrmHandler().GetDocumentSigning(requestid, taskid, service);
                HandleTasks(documentsigning, orgname, service);
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return(HttpStatusCode.BadRequest);
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="documentsigning"></param>
        /// <param name="service"></param>
        private HttpStatusCode HandleTasks(Entity documentsigning, string orgname, IOrganizationService service)
        {
            try
            {
                var documentsigningtasks = new CallBackCrmHandler().GetDocumentSiginingTasks(
                    documentsigning.ToEntityReference(), 1, service); //status sent
                var regardingRef = new Helpers().GetRegarding(documentsigning, service);
                var sendcopy     = (bool)documentsigning["pp_sendcopy"];
                var method       = (OptionSetValue)documentsigning["pp_signing"];
                var saveinsp     = (bool)documentsigning["pp_saveindocumentlocation"];
                var senderRef    = (EntityReference)documentsigning["ownerid"];

                var lcid = new CallBackCrmHandler().RetrieveUserUiLanguageCode(service, senderRef.Id);

                foreach (var documentsigningtask in documentsigningtasks.Entities)
                {
                    var sdsurl = documentsigningtask.Attributes["pp_sdsurl"].ToString();
                    var taskid = documentsigningtask.Attributes["pp_name"].ToString();

                    var subString = sdsurl.Substring(sdsurl.IndexOf('=') + 1);
                    var requestId = subString.Substring(0, subString.IndexOf('&'));

                    var taskinfo = new CallBackSignicatHandler().GetSignicatTaskInfo(requestId, taskid);

                    if (taskinfo == null)
                    {
                        continue;
                    }

                    if (taskinfo.taskstatus == taskstatus.created)
                    {
                        continue;
                    }

                    if (taskinfo.taskstatus == taskstatus.rejected)
                    {
                        new CallBackCrmHandler().ChangeDocumentSigningTaskStatus(documentsigningtask.Id, 778380001, service);
                    }
                    //Rejected

                    if (taskinfo.taskstatus == taskstatus.completed)
                    {
                        foreach (var documentstatus in taskinfo.documentstatus)
                        {
                            var documentsigningRef = (EntityReference)documentsigningtask["pp_documentsigningid"];
                            var saveonlymerged     = (bool)documentsigning["pp_saveonlymerged"];
                            var name = new Helpers().GetNameFromUrl(documentstatus.originaluri);

                            new CallBackCrmHandler().CreateSignicatResult(documentsigningRef,
                                                                          documentsigningtask.ToEntityReference(), documentstatus.resulturi, name, service);

                            new CallBackCrmHandler().CreateTransaction(orgname, method.Value, senderRef, service);

                            if (!saveonlymerged)
                            {
                                var title = Resources.Resourceeng.singledocument;
                                if (lcid == 1044)
                                {
                                    title = Resources.Resourcenb.singledocument;
                                }

                                var padesurl = new CallBackSignicatHandler().CreatePades(null, documentstatus.resulturi);
                                new CallBackCrmHandler().CreateAnnotations(padesurl, name, title,
                                                                           documentsigningRef.Id, documentsigningRef.LogicalName, lcid, service);

                                if (sendcopy)
                                {
                                    var customer = (EntityReference)documentsigningtask.Attributes["pp_customerid"];
                                    new CallBackCrmHandler().SendEmail(documentsigning.ToEntityReference(), senderRef,
                                                                       padesurl, name, customer, lcid, service);
                                }
                            }
                        }

                        new CallBackCrmHandler().ChangeDocumentSigningTaskStatus(documentsigningtask.Id, 778380000,
                                                                                 service);
                        //Signed
                    }
                }

                CheckOverAllStatus(documentsigning.ToEntityReference(), regardingRef, saveinsp, sendcopy,
                                   senderRef, orgname, lcid, service);
                return(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return(HttpStatusCode.BadRequest);
            }
        }
コード例 #5
0
        /// <summary>
        /// Loops throught the signingresults and
        /// </summary>
        /// <param name="docsignRef"></param>
        /// <param name="regardingRef"></param>
        /// <param name="saveinsp"></param>
        /// <param name="service"></param>
        /// <returns>List of pades url's</returns>
        private void ConvertSdoDocument(EntityReference docsignRef, EntityReference regardingRef,
                                        bool saveinsp, bool sendcopy, EntityReference senderRef, string orgname, int lcid,
                                        IOrganizationService service)
        {
            try
            {
                var signingresults = new CallBackCrmHandler().GetAllSigningResults(docsignRef.Id, service);
                var docList        = new List <ResultObject>();

                foreach (var item in signingresults.Entities)
                {
                    string padesurl  = null;
                    var    resulturl = item.Attributes["pp_resulturl"].ToString();
                    if (item.Contains("pp_xpadesurl"))
                    {
                        padesurl = item.Attributes["pp_xpadesurl"].ToString();
                    }
                    var name    = item.Attributes["pp_name"].ToString();
                    var taskRef = (EntityReference)item.Attributes["pp_signicatdocurlid"];
                    var sdsurl  = new CallBackCrmHandler().GetSDSUrlFromTask(taskRef.Id, service);

                    var subString = sdsurl.Substring(sdsurl.IndexOf('=') + 1);
                    var requestid = subString.Substring(0, subString.IndexOf('&'));

                    var obj = new ResultObject
                    {
                        Id        = item.Id,
                        name      = name,
                        resulturl = resulturl,
                        sdsurl    = sdsurl,
                        rquestid  = requestid,
                        padesurl  = padesurl,
                        taskId    = taskRef.Id
                    };
                    docList.Add(obj);
                }

                var groups = docList.GroupBy(x => x.name).OrderBy(x => x.Key);

                var title = Resources.Resourceeng.singledocument;
                if (lcid == 1044)
                {
                    title = Resources.Resourcenb.singledocument;
                }

                foreach (var item in groups)
                {
                    var tempList = item.ToList();

                    if (tempList.Count < 2) //If one signer and one document
                    {
                        if (tempList[0].padesurl != null)
                        {
                            new CallBackCrmHandler().CreateAnnotations(tempList[0].padesurl, tempList[0].name,
                                                                       title, docsignRef.Id, docsignRef.LogicalName, lcid, service);
                            if (sendcopy)
                            {
                                new CallBackCrmHandler().SendSignedMergedCopy(docsignRef, senderRef,
                                                                              tempList[0].padesurl, tempList[0].name, lcid, service);
                            }
                        }

                        else
                        {
                            new CallBackCrmHandler().CreateAnnotations(tempList[0].resulturl, tempList[0].name,
                                                                       title, docsignRef.Id, docsignRef.LogicalName, lcid, service);
                            if (sendcopy)
                            {
                                new CallBackCrmHandler().SendSignedMergedCopy(docsignRef, senderRef,
                                                                              tempList[0].padesurl, tempList[0].name, lcid, service);
                            }
                        }


                        if (saveinsp && regardingRef != null)
                        {
                            if (tempList[0].padesurl != null)
                            {
                                new CallBackSharePointHandler().SaveInSP(regardingRef, tempList[0].padesurl,
                                                                         tempList[0].name, orgname, lcid, service);
                            }
                            else
                            {
                                new CallBackSharePointHandler().SaveInSP(regardingRef, tempList[0].resulturl,
                                                                         tempList[0].name, orgname, lcid, service);
                            }
                        }
                        continue;
                    }

                    var padesurl = new CallBackSignicatHandler().CreatePades(tempList, null);
                    if (padesurl != null)
                    {
                        var mergedTitle = Resources.Resourceeng.merged;
                        if (lcid == 1044)
                        {
                            mergedTitle = Resources.Resourcenb.merged;
                        }

                        new CallBackCrmHandler().CreateSignicatResult(docsignRef, null, padesurl, mergedTitle +
                                                                      ": " + tempList[0].name, service);
                        new CallBackCrmHandler().CreateAnnotations(padesurl, tempList[0].name, mergedTitle,
                                                                   docsignRef.Id, docsignRef.LogicalName, lcid, service);

                        if (sendcopy)
                        {
                            new CallBackCrmHandler().SendSignedMergedCopy(docsignRef, senderRef, padesurl,
                                                                          tempList[0].name, lcid, service);
                        }

                        if (saveinsp && regardingRef != null)
                        {
                            new CallBackSharePointHandler().SaveInSP(regardingRef, padesurl, tempList[0].name, orgname, lcid, service);
                        }
                    }
                }

                //HandlerCRM.DeaktivateSignicatResults(groups, service);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #6
0
        /// <summary>
        /// Saving documents into sharepoint online
        /// </summary>
        /// <param name="regardingRef"></param>
        /// <param name="resulturi"></param>
        /// <param name="docName"></param>
        /// <param name="service"></param>
        internal void SaveInSP(EntityReference regardingRef, string resulturi, string docName, string orgname, int lcid, IOrganizationService service)
        {
            try
            {
                folderRelativeUrl = "";
                SharePointSite    = null;
                var crmconfig  = new CallBackCrmHandler().GetCRMConfig(service);
                var spUsername = crmconfig.SPUser;
                var spPassword = crmconfig.SPpassword;

                if (spPassword == null || spPassword == null)
                {
                    var customerCredentials = new CustomerCredentialsHandler().GetCredentials(orgname);
                    spUsername = customerCredentials.username;
                    spPassword = customerCredentials.password;
                }

                var pdfBytes = new CallBackSignicatHandler().ReadAsyncFile(resulturi);
                var currentSharePointFolderEntity = GetDocumentLocation(regardingRef, "regardingobjectid", service);
                var sharePointUrl = GetDefaultSPSiteUrlFromCRMSiteCollectionEntity(service);

                HandleRelativeUrl(currentSharePointFolderEntity, service);

                var urlSplit   = folderRelativeUrl.Split('/').ToList();
                var listTitle  = urlSplit.First();
                var folderName = urlSplit[1];
                docName = CleanName(docName);

                using (ClientContext clientContext = new ClientContext(sharePointUrl))
                {
                    SecureString passWord = new SecureString();
                    foreach (char c in spPassword.ToCharArray())
                    {
                        passWord.AppendChar(c);
                    }
                    clientContext.Credentials = new SharePointOnlineCredentials(spUsername, passWord);
                    Web web = clientContext.Web;
                    clientContext.Load(web);
                    clientContext.Load(web.Lists);
                    clientContext.ExecuteQuery();

                    MemoryStream mStream = new MemoryStream();
                    mStream.Write(pdfBytes.Result.file, 0, pdfBytes.Result.file.Length);

                    FileCreationInformation flciNewFile = new FileCreationInformation();
                    //using ContentStream property for large files
                    mStream.Seek(0, SeekOrigin.Begin);
                    flciNewFile.ContentStream = mStream;
                    flciNewFile.Url           = sharePointUrl + "/" + folderRelativeUrl + docName + ".pdf";
                    flciNewFile.Overwrite     = true;

                    List accountList = GetAccountList(listTitle, web, clientContext, crmconfig, service);
                    if (accountList == null)
                    {
                        return;
                    }

                    var folder = accountList.RootFolder.Folders.GetByUrl(folderName);

                    var uploadFile = folder.Files.Add(flciNewFile);

                    clientContext.Load(uploadFile);
                    clientContext.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
                return;

                throw new Exception(ex.Message);
            }
        }
コード例 #7
0
        internal void SendEmail(EntityReference docsignRef, EntityReference senderRef, string padesurl,
                                string name, EntityReference customer, int lcid, IOrganizationService service)
        {
            try
            {
                var crmConfig    = new CallBackCrmHandler().GetCRMConfig(service);
                var emailLogoImg = "https://ppsignicatresources.blob.core.windows.net/signicatlinkbutton/SignicatMailLogo.png";

                Entity fromParty = new Entity("activityparty");
                fromParty["partyid"] = new EntityReference("systemuser", senderRef.Id);

                Entity toParty = new Entity("activityparty");
                toParty["partyid"] = new EntityReference(customer.LogicalName, customer.Id);

                var listfrom = new List <Entity>()
                {
                    fromParty
                };
                var listto = new List <Entity>()
                {
                    toParty
                };

                // Create an e-mail message.
                Entity email = new Entity("email");
                email["to"]   = new EntityCollection(listto);
                email["from"] = new EntityCollection(listfrom);

                if (lcid == 1044)
                {
                    email["subject"] = Resources.Resourcenb.emailsubject + ": " + name;
                }
                else
                {
                    email["subject"] = Resources.Resourceeng.emailsubject + ": " + name;
                }

                email["directioncode"]     = true;
                email["regardingobjectid"] = new EntityReference(docsignRef.LogicalName, docsignRef.Id);
                var newText = "";
                //newText = "<img src='" + emailLogoImg + "'/><br/><br/>";
                if (lcid == 1044)
                {
                    newText += "Hei,<br/><br/>" + Resources.Resourcenb.emaildescription + ": " + name;
                    newText += "<br/><br/> Med vennlig Hilsen<br/>";
                }
                else
                {
                    newText += "Hi,<br/><br/>" + Resources.Resourceeng.emaildescription + ": " + name;
                    newText += "<br/><br/> With Regards<br/>";
                }
                newText += crmConfig.SigningUsername;
                email["description"] = newText;



                var _emailId = service.Create(email);

                // Create email attachment
                var    fileobj     = new CallBackSignicatHandler().ReadAsyncFile(padesurl);
                string encodedData = Convert.ToBase64String(fileobj.Result.file);

                Entity _emailAttachment = new Entity("activitymimeattachment");
                _emailAttachment["objectid"]       = new EntityReference(email.LogicalName, _emailId);
                _emailAttachment["objecttypecode"] = email.LogicalName;
                _emailAttachment["subject"]        = name;
                _emailAttachment["body"]           = encodedData;
                _emailAttachment["filename"]       = name + ".pdf";


                var _emailAttachmentId = service.Create(_emailAttachment);

                // Use the SendEmail message to send an e-mail message.
                SendEmailRequest sendEmailreq = new SendEmailRequest
                {
                    EmailId       = _emailId,
                    TrackingToken = "",
                    IssueSend     = true
                };

                SendEmailResponse sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }