예제 #1
0
    public static bool processing_f003(ref List <clsConnections> link_connections, ref string[] folders, out string comments, string file = "")
    {
        comments = String.Empty;
        bool result = false;

        //----------------
        try
        {
            string version;

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(file);

            version = xmlDocument.SelectSingleNode("packet").Attributes.GetNamedItem("version").Value;
            ReglamentLinker reglamentLinker = new ReglamentLinker();
            reglamentLinker.getLink(null, null, version, Path.GetFileName(file));

            switch (version)
            {
            case "1.0.1":
                result = processing_f003_1_0_1(ref link_connections, out comments, ref xmlDocument);
                break;
            }
        }
        catch (Exception e)
        {
            comments += e.Message;
        }

        return(result);
    }
    public static bool handling_file(string file, List <clsConnections> link_connections, string[] folders, ReglamentLinker reglamentLinker, out string result_comments, out int count_row)
    {
        result_comments = string.Empty;
        bool result = true; //!!! Исключительный случай - ошибка в методе,  а не в разборе файла

        count_row = 0;
        //-------------------------------------
        string        file_response       = "";
        bool          errors_free         = true;
        string        processing_comments = string.Empty;
        string        filename            = Path.GetFileName(file);
        string        mnemonic            = string.Empty;
        string        idRequest           = string.Empty;
        string        typeVS      = string.Empty;
        string        version     = null;
        object        xml_object  = null;
        List <string> list_errors = new List <string>();

        list_errors.Add(String.Format("Ошибка обработки файла - {0}", filename));
        try
        {
            mnemonic      = reglamentLinker.getMnemonic();
            file_response = string.Format(@"fail{0}-{1}.txt", mnemonic, Path.GetFileNameWithoutExtension(filename).ToUpper());// Path.Combine(folders[1], );
            typeVS        = reglamentLinker.link.comment;
            XmlDocument HEADER = new XmlDocument();
            if (!clsLibrary.getTeg_HEADER(file, ref HEADER, ref version))
            {
                errors_free = false; //result = true;
                throw new System.ArgumentException(string.Format("Не установлена версия файла данного вида сведений: '{0}'", typeVS));
            }

            reglamentLinker.getLink(null, null, version, Path.GetFileName(file));
            if (reglamentLinker.link == null)
            {
                errors_free = false; //result = true;
                throw new System.ArgumentException(string.Format("Не зарегистрирована версия '{0}' для вида сведений: '{1}'", version, typeVS));
            }

            if (clsLibrary.execQuery_PGR_getString(ref link_connections, "postgres", String.Format("select id from buf_eir.request where filename = '{0}' and fail = false and state is not null;", filename.ToUpper())) != null)
            {
                errors_free = false; //result = true;
                throw new System.ArgumentException("Файл принят ранее, имена файлов должны быть уникальны");
            }

            xml_object = XML_abstract_file.FromXml(
                new FileStream(file, FileMode.Open, FileAccess.Read),
                reglamentLinker.link.schemaClassRoot,
                Path.Combine(Path.Combine(Directory.GetParent(folders[1]).Parent.FullName, "schemes", reglamentLinker.link.nameSchema + ".xsd")),
                mnemonic
                );
            GC.Collect();
            errors_free = (xml_object as XML_abstract_file)._Errors.Count == 0;
            //result = true;
            if (errors_free)
            {
                idRequest = clsLibrary.execQuery_PGR_getString(ref link_connections, "postgres"
                                                               , String.Format("SELECT buf_eir.insert_request('{0}','{1}','{2}','{3}')", HEADER.InnerXml, mnemonic, reglamentLinker.link.nameSchema, Path.GetFileName(file).ToUpper()));
                if (idRequest == "-1" || idRequest == "0")
                {
                    idRequest = string.Empty; throw new System.ArgumentException("Ошибка регистрации запроса");
                }
                #region Запуск метода импорта в буфер
                switch (reglamentLinker.link.nameSchema)
                {
                case "si_schema_1_0":
                    result = processingRequest_si_schema_1_0(ref link_connections, "postgres", idRequest, ref xml_object, mnemonic, out count_row, out processing_comments, 1000);
                    break;

                case "si_schema_1_1":
                    result = processingRequest_si_schema_1_1(ref link_connections, "postgres", idRequest, ref xml_object, mnemonic, out count_row, out processing_comments, 1000);
                    break;

                case "zldn_schema_2_0":
                    result = processingRequest_zldn_schema_2_0(ref link_connections, "postgres", idRequest, ref xml_object, mnemonic, out count_row, out processing_comments, 1000);
                    break;

                case "zldn_schema_2_1":
                    result = processingRequest_zldn_schema_2_1(ref link_connections, "postgres", idRequest, ref xml_object, mnemonic, out count_row, out processing_comments, 1000);
                    break;

                default:
                    result = false;
                    throw new System.ArgumentException("Неизвестен метод обработки бизнес данных");
                }
                #endregion
            }
        }
        catch (Exception e)
        {
            if (!errors_free)
            {
                list_errors.Add(e.Message);
            }
            else
            {
                result = false; processing_comments = e.Message;
            }
        }
        if (/*result &&*/ !errors_free)
        {
            try
            {
                if (xml_object != null && (xml_object as XML_abstract_file)._Errors.Count > 0)
                {
                    foreach (object pr in (xml_object as XML_abstract_file)._Errors)
                    {
                        list_errors.Add((pr as Protocol).N_REC + ", " +//(pr as Sp.XML.PR).OSHIB,
                                        (pr as Protocol).IM_POL + " - " + (pr as Protocol).COMMENT);
                    }
                }
                clsLibrary.createFileTXT_FromList(list_errors, Path.Combine(folders[1], file_response));
            }
            catch
            {
                result = false;
                processing_comments = " ошибка! : Формирование файла с ответом по ошибкам";
            }
        }
        //меняем статус обработки пакета, если он был зарегистрирован
        if (idRequest != string.Empty)
        {
            clsLibrary.execQuery_PGR(
                ref link_connections
                , "postgres"
                , (result) ? string.Format("update buf_eir.request set state = '{0}', count_row = {1} where id = '{2}';", (errors_free) ? "0" : "-1", count_row, idRequest)
                          : string.Format("update buf_eir.request set fail = true where id = '{0}';", idRequest)
                , 118000
                );
        }
        if (!result)
        {
            result_comments = "error: " + result_comments + processing_comments;
        }
        else
        {
            if (!errors_free)
            {
                result_comments = "Ok, response file: " + file_response;
            }
            else
            {
                result_comments = "Ок";
            }
        }
        return(result);
    }
예제 #3
0
    public static bool handling_file(string file, List <clsConnections> link_connections, string[] folders, ReglamentLinker reglamentLinker, out string result_comments)
    {
        result_comments = "";
        bool result = false;

        try
        {
            switch (reglamentLinker.link.prefixFile)
            {
            case "F003":
                result = processing_f003(ref link_connections, ref folders, out result_comments, file);
                break;

            default:         //unknown messageType
                break;
            }
            if (!result)
            {
                throw new Exception("...");
            }
            else
            {
                result_comments += " - handled";
            }
        }
        catch (Exception ss)
        {
            result_comments = " error! in metod " + result_comments;
        }
        return(result);
    }