示例#1
0
        public void processOutbound()
        {
            Logger.log("start processing outbound...");
            List <string> outbound = new List <string>();

            try
            {
                outbound.AddRange(Directory.GetFiles(conf.Outbound.DefaultPath).ToList());
            }
            catch (Exception ex)
            {
                Logger.log("ERROR: outbound will NOT be procceed . Reason : " + ex.Message);
                return;
            }

            /*
             * adding all others files from custom folders
             */
            outbound.AddRange(DFSHelper.GetOutFiles(conf.Outbound.Document));

            foreach (string name in outbound)
            {
                try
                {
                    string   docType     = DFSHelper.GetDocType(Path.GetFileName(name));
                    Document docSettings = conf.GetCustomOutboundSettingsByPath(docType, name);
                    if (docSettings != null)
                    {
                        if (docSettings.NeedToBeSigned) // for signed docs
                        {
                            string thumbPrint = docSettings.Thumpprint != null ? docSettings.Thumpprint : conf.Thumpprint;
                            string body       = Utils.Base64Encode(File.ReadAllBytes(name), "windows-1251");
                            string sign       = controller.Sign(thumbPrint, body);
                            if (docSettings.NeedToBeZipped) // trick with non-secure soap and xp (w/o support tls over 1.0)
                            {
                                zipAndProcessDoc(docSettings, name, body, sign);
                            }
                            else if (
                                (docType.StartsWith("DP_") || docType.StartsWith("ON_SCHFDOPPOK") || docType.StartsWith("ON_KORSCHFDOPPOK"))
                                &&
                                name.EndsWith(".xml")
                                )
                            {
                                if ((controller.sendDoc(Path.GetFileName(name), body))
                                    &&
                                    (controller.sendDoc(Path.GetFileName(name).Replace(".xml", ".bin"), sign)))
                                {
                                    Logger.log(Path.GetFileName(name) + " sent successfully.");
                                    if (conf.Outbound.IsArchive)
                                    {
                                        if ((DFSHelper.moveDocToArc(Path.GetFileName(name), (File.ReadAllBytes(name)), docSettings))
                                            &&
                                            (DFSHelper.moveDocToArc(Path.GetFileName(name).Replace(".xml", ".bin"), Utils.StringToBytes(sign, "UTF-8"), docSettings)))
                                        {
                                            File.Delete(name);
                                        }
                                    }
                                }
                            }
                            else if (docType.Equals("CONDRA", StringComparison.OrdinalIgnoreCase))
                            {
                                var c = Condra.toObj(name);

                                string condraXmlBody = body;
                                string filePath      = Path.GetDirectoryName(name) + Path.DirectorySeparatorChar + c.getFileName();

                                body = Utils.Base64Encode(File.ReadAllBytes(filePath), "UTF-8");
                                sign = controller.Sign(thumbPrint, body);

                                string condraName = "condra_" + Guid.NewGuid() + ".zip";
                                byte[] condra     = ZipHelper.createCondraZip(condraXmlBody, c.getFileName(), body, c.getSignName(), sign);

                                if (controller.sendDoc(condraName, Utils.Base64Encode(condra, "UTF-8")))
                                {
                                    Logger.log(Path.GetFileName(condraName) + " sent successfully.");
                                    if (conf.Outbound.IsArchive)
                                    {
                                        if (DFSHelper.moveDocToArc(condraName, condra, docSettings))
                                        {
                                            File.Delete(name);
                                            File.Delete(filePath);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                try
                                {
                                    controller.sendDocApi(body, sign, docType);
                                    Logger.log(Path.GetFileName(name) + " sent successfully.");
                                    if (conf.Outbound.IsArchive)
                                    {
                                        if (DFSHelper.moveDocToArc(Path.GetFileName(name), File.ReadAllBytes(name), docSettings))
                                        {
                                            File.Delete(name);
                                        }
                                        if (DFSHelper.moveDocToArc(Path.GetFileName(name).Replace(".xml", ".bin"), Utils.StringToBytes(sign, "UTF-8"), docSettings))
                                        {
                                            File.Delete(name.Replace(".xml", ".bin"));
                                        }
                                    }

                                    /*
                                     * when configured -> creating xml status
                                     */
                                    DFSHelper.saveStatus(controller, body, docSettings, null);
                                }
                                catch (Exception e)
                                {
                                    try
                                    {
                                        /*
                                         * when configured -> creating xml status
                                         */
                                        DFSHelper.saveStatus(controller, body, docSettings, e.Message);
                                        handleSendException(new Exception(e.Message + " [ " + controller.GetIDFileFromTicket(body) + " ]"), name, sign);
                                    }
                                    catch (Exception ex)
                                    {
                                        handleSendException(new Exception("XML document not well formed"), name, sign);
                                    }
                                }
                            }
                        }
                        else // for simple docs
                        {
                            string body       = Utils.Base64Encode(File.ReadAllBytes(name), "UTF-8");
                            string remoteName = Path.GetFileName(name);
                            if (docSettings.remoteFileNamePrefix != null)
                            {
                                remoteName = docSettings.remoteFileNamePrefix + remoteName;
                            }
                            if (controller.sendDoc(remoteName, body))
                            {
                                Logger.log(remoteName + " sent successfully.");
                                if (conf.Outbound.IsArchive)
                                {
                                    if (DFSHelper.moveDocToArc(Path.GetFileName(name), (File.ReadAllBytes(name)), docSettings))
                                    {
                                        File.Delete(name);
                                    }
                                }
                            }
                            else
                            {
                                if (DFSHelper.moveDocToError(Path.GetFileName(name), (File.ReadAllBytes(name))))
                                {
                                    File.Delete(name);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);//debug only
                    Logger.log(ex.Message);
                }
            }
        }
示例#2
0
        public bool signAndConfirmEvent(Event e)
        {
            try
            {
                GetContentResponse content = controller.GetContent(e);

                string   eventName   = controller.GetIDFileFromTicket(content.body, e);
                string   docType     = eventName.Split('_')[0] + "_" + eventName.Split('_')[1];
                Document docSettings = conf.GetCustomEDOTicketSettings(docType);
                if (docSettings != null)
                {
                    string signExt = ".bin";
                    if (docSettings.custom_sign_extension != null)
                    {
                        signExt = docSettings.custom_sign_extension;
                    }

                    Dictionary <string, byte[]> additionalTicketsToBeChained = new Dictionary <string, byte[]>();
                    if (!docSettings.TicketsGenerate)
                    {
                        /*
                         *         just saving incoming ticket
                         */
                        DFSHelper.saveTicket(docSettings.LocalPath, eventName + ".xml", Utils.Base64DecodeToBytes(content.body, "windows-1251"));
                        DFSHelper.saveTicket(docSettings.LocalPath, eventName + signExt, Utils.StringToBytes(content.sign, "UTF-8"));

                        /*
                         * when configured -> creating xml status
                         */
                        DFSHelper.saveStatus(controller, content.body, docSettings, null);
                    }
                    else
                    {
                        string thumbPrint = docSettings.Thumpprint != null ? docSettings.Thumpprint : conf.Thumpprint;
                        Ticket ticket     = controller.Ticket(thumbPrint, eventName);
                        if (ticket != null)
                        {
                            string body = Utils.Base64Encode(ticket.body, "windows-1251");
                            string sign = controller.Sign(thumbPrint, body);
                            if (controller.confirmEvent(e, body, sign))
                            {
                                if (eventName.Contains(".xml"))
                                {
                                    eventName = eventName.Replace(".xml", string.Empty);
                                }

                                /*
                                 *  saving incoming ticket
                                 */
                                DFSHelper.saveTicket(docSettings.LocalPath, eventName + ".xml", Utils.Base64DecodeToBytes(content.body, "windows-1251"));
                                DFSHelper.saveTicket(docSettings.LocalPath, eventName + signExt, Utils.StringToBytes(content.sign, "UTF-8"));

                                /*
                                 *  saving outgoing ticket
                                 */
                                additionalTicketsToBeChained.Add(ticket.fileName, ticket.body);
                                additionalTicketsToBeChained.Add(ticket.fileName.Replace(".xml", GetSignExtensionForContainer()), GetSignEncodedBodyForContainer(sign));
                                DFSHelper.saveTicket(docSettings.TicketPath, ticket.fileName, ticket.body);
                                DFSHelper.saveTicket(docSettings.TicketPath, ticket.fileName.Replace(".xml", signExt), Utils.StringToBytes(sign, "UTF-8"));

                                /*
                                 * when configured -> creating xml status
                                 */
                                DFSHelper.saveStatus(controller, content.body, docSettings, null);
                            }
                        }
                    }

                    /*
                     * check if need to be contained
                     */
                    if (e.performChainContainer)
                    {
                        performChainContainer(e.document_id, additionalTicketsToBeChained);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                Logger.log(ex.Message);
                return(false);
            }
        }