Exemplo n.º 1
0
        public static bool WriteXmlFileUsingXSD(string infilename, string tannumber, string outputfilepath)
        {
            bool blStatus = false;

            try
            {
                patentInfo patentInfo_Obj = new patentInfo();
                patentInfo_Obj.tan      = tannumber;
                patentInfo_Obj.language = languageType.en;

                //Specify input file to MolInputStream object
                MolInputStream molInStream = new MolInputStream(new FileInputStream(infilename));
                MolImporter    molImp      = new MolImporter(molInStream);
                Molecule       mol         = new Molecule();

                //int intMolCnt = molImp.getRecordCount();
                int intMolCnt = ChemistryOperations.GetMoleculeCountFromFile(infilename);

                patentLocation patLoc    = null;
                name[]         name_Arr  = null;
                name           name_obj  = null;
                names          names_Arr = null;
                nameType       namType   = null;

                structureDataType structDtype = null;

                string[] strIUpacName = null;

                propheticSubstance   propSubstance_Obj  = null;
                propheticSubstance[] propSubstance_Arr  = new propheticSubstance[intMolCnt];
                propheticSubstances  propSubstances_Obj = null;

                patent patent_Obj = new patent();

                int intCntr = 0;

                //Read molecules from molImporter
                while (molImp.read(mol))
                {
                    patLoc              = new patentLocation();
                    patLoc.pageLabel    = mol.getProperty("Page Label");
                    patLoc.pageNumber   = mol.getProperty("Page Number");
                    patLoc.exampleLabel = mol.getProperty("Example Number");

                    name_Arr = new name[1];

                    name_obj      = new name();
                    name_obj.lang = languageType.en;

                    string[] strArr_EnName = new string[1];
                    strArr_EnName[0] = mol.getProperty("en name").Trim();
                    name_obj.Text    = strArr_EnName;

                    name_Arr[0] = name_obj;

                    strIUpacName    = new string[1];
                    strIUpacName[0] = mol.getProperty("IUPAC Name").Trim();

                    namType      = new nameType();
                    namType.Text = strIUpacName;

                    names_Arr           = new names();
                    names_Arr.IUPACName = namType;
                    names_Arr.name      = name_Arr;

                    string strMol = mol.toFormat("mol");

                    int    v3000   = strMol.IndexOf("V3000");
                    double nullMol = mol.getExactMass();

                    byte[] barr_Mol = null;

                    if (v3000 == -1 && nullMol != 0)
                    {
                        barr_Mol = System.Text.ASCIIEncoding.ASCII.GetBytes(strMol);
                    }

                    structDtype       = new structureDataType();
                    structDtype.Value = barr_Mol;

                    propSubstance_Obj = new propheticSubstance();
                    propSubstance_Obj.structureData  = structDtype;
                    propSubstance_Obj.patentLocation = patLoc;
                    propSubstance_Obj.names          = names_Arr;

                    propSubstance_Arr[intCntr] = propSubstance_Obj;
                    intCntr++;
                }

                propSubstances_Obj = new propheticSubstances();
                propSubstances_Obj.propheticSubstance = propSubstance_Arr;

                patent_Obj.patentInfo          = patentInfo_Obj;
                patent_Obj.propheticSubstances = propSubstances_Obj;

                // Serialization
                XmlSerializer xmlSer    = new XmlSerializer(typeof(patent));
                TextWriter    txtWriter = new StreamWriter(outputfilepath);
                xmlSer.Serialize(txtWriter, patent_Obj);

                txtWriter.Close();
                txtWriter.Dispose();

                molInStream.close();
                molImp.close();

                blStatus = true;
                return(blStatus);
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            return(blStatus);
        }
Exemplo n.º 2
0
        public static bool WriteXmlFileUsingDataTable(DataTable _dtTandetails, string _tannumber, string outxmlfile)
        {
            bool blStatus = false;

            try
            {
                if (_dtTandetails != null)
                {
                    if (_dtTandetails.Rows.Count > 0)
                    {
                        patentInfo patentInfo_Obj = new patentInfo();
                        patentInfo_Obj.tan      = _tannumber;
                        patentInfo_Obj.language = languageType.en;

                        int intMolCnt = _dtTandetails.Rows.Count;

                        patentLocation patLoc    = null;
                        name[]         name_Arr  = null;
                        name           name_obj  = null;
                        names          names_Arr = null;
                        nameType       namType   = null;

                        structureDataType structDtype = null;

                        string[] strIUpacName = null;

                        propheticSubstance   propSubstance_Obj  = null;
                        propheticSubstance[] propSubstance_Arr  = new propheticSubstance[intMolCnt];
                        propheticSubstances  propSubstances_Obj = null;

                        patent patent_Obj = new patent();

                        int    intCntr  = 0;
                        string strMol   = "";
                        byte[] barr_Mol = null;
                        int    v3000    = 0;
                        double nullMol  = 0.0;

                        MolHandler objMHandler = null;

                        for (int i = 0; i < _dtTandetails.Rows.Count; i++)
                        {
                            objMHandler = new MolHandler(_dtTandetails.Rows[i]["structure"].ToString());

                            v3000 = 0;
                            v3000 = objMHandler.toFormat("mol").IndexOf("V3000");

                            nullMol = 0.0;
                            nullMol = objMHandler.calcMolWeight();

                            barr_Mol = null;
                            if (v3000 == -1 && nullMol != 0)
                            {
                                patLoc              = new patentLocation();
                                patLoc.pageLabel    = _dtTandetails.Rows[i]["page_label"].ToString();
                                patLoc.pageNumber   = _dtTandetails.Rows[i]["page_number"].ToString();
                                patLoc.exampleLabel = _dtTandetails.Rows[i]["example_number"].ToString();

                                name_obj      = new name();
                                name_obj.lang = languageType.en;

                                string[] strArr_EnName = new string[1];
                                strArr_EnName[0] = _dtTandetails.Rows[i]["en_name"].ToString();
                                name_obj.Text    = strArr_EnName;

                                name_Arr    = new name[1];
                                name_Arr[0] = name_obj;

                                strIUpacName    = new string[1];
                                strIUpacName[0] = _dtTandetails.Rows[i]["iupac_name"].ToString();

                                namType      = new nameType();
                                namType.Text = strIUpacName;

                                names_Arr           = new names();
                                names_Arr.IUPACName = namType;
                                names_Arr.name      = name_Arr;

                                strMol   = _dtTandetails.Rows[i]["structure"].ToString();
                                barr_Mol = null;
                                barr_Mol = System.Text.ASCIIEncoding.ASCII.GetBytes(strMol);

                                structDtype       = new structureDataType();
                                structDtype.Value = barr_Mol;

                                propSubstance_Obj = new propheticSubstance();
                                propSubstance_Obj.structureData  = structDtype;
                                propSubstance_Obj.patentLocation = patLoc;
                                propSubstance_Obj.names          = names_Arr;

                                propSubstance_Arr[intCntr] = propSubstance_Obj;
                                intCntr++;
                            }
                        }

                        propSubstances_Obj = new propheticSubstances();
                        propSubstances_Obj.propheticSubstance = propSubstance_Arr;

                        patent_Obj.patentInfo          = patentInfo_Obj;
                        patent_Obj.propheticSubstances = propSubstances_Obj;

                        // Serialization
                        XmlSerializer xmlSer    = new XmlSerializer(typeof(patent));
                        TextWriter    txtWriter = new StreamWriter(outxmlfile);
                        xmlSer.Serialize(txtWriter, patent_Obj);

                        txtWriter.Close();
                        txtWriter.Dispose();

                        blStatus = true;
                        return(blStatus);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandling_NTS.WriteErrorLog(ex.ToString());
            }
            return(blStatus);
        }
Exemplo n.º 3
0
        private void WriteXMLUsingXSD()
        {
            try
            {
                patentInfo pinfo = new patentInfo();
                pinfo.tan      = "12345678D";
                pinfo.language = languageType.en;

                patentLocation ploc = new patentLocation();
                ploc.pageLabel    = "00";
                ploc.pageNumber   = "5";
                ploc.exampleLabel = "00";

                name[] nm = new name[1];

                name nm1 = new name();
                nm1.lang = languageType.en;

                nm[0] = nm1;

                string[] strIUpacName = { "Benzene" };

                nameType nType = new nameType();
                nType.Text = strIUpacName;

                names nms = new names();
                nms.IUPACName = nType;
                nms.name      = nm;

                string strMol = @"OS0oMy1BY2V0eWwtNC1mbHVvcm9waGVueWwpLTYtY2hsb3JvcHVyaW5lCiAgTWFydmluICAwNDI0MTAxNzA5Mk";
                byte[] br     = System.Text.ASCIIEncoding.ASCII.GetBytes(strMol);

                structureDataType sDtype = new structureDataType();
                sDtype.type     = structureDataTypeType.MDLMolfileV2000;
                sDtype.encoding = structureDataTypeEncoding.Base64;
                sDtype.Value    = br;

                propheticSubstance ps11 = new propheticSubstance();
                ps11.structureData  = sDtype;
                ps11.structureData  = sDtype;
                ps11.patentLocation = ploc;
                ps11.names          = nms;

                propheticSubstance[] ps1 = new propheticSubstance[1];
                ps1[0] = ps11;

                propheticSubstances ps = new propheticSubstances();
                ps.propheticSubstance = ps1;

                patent pr = new patent();
                pr.patentInfo          = pinfo;
                pr.propheticSubstances = ps;


                // Serialization
                XmlSerializer s = new XmlSerializer(typeof(patent));
                TextWriter    w = new StreamWriter(@"c:\list12345.xml");
                s.Serialize(w, pr);
                w.Close();
            }
            catch (Exception ex)
            {
                PepsiLiteErrorHandling.WriteErrorLog(ex.ToString());
            }
        }