示例#1
0
        private ChemicalName XmlToName(XElement cmlElement)
        {
            // Example: <name id="m1.n1" dictRef="pubchem:cid">241</name>

            ChemicalName n = new ChemicalName();

            n.Id = cmlElement.Attribute("id")?.Value;

            if (cmlElement.Attribute("dictRef") == null)
            {
                n.DictRef = "chem4word:Synonym";
            }
            else
            {
                n.DictRef = cmlElement.Attribute("dictRef")?.Value;
            }

            // Correct import from legacy Add-In
            if (string.IsNullOrEmpty(n.DictRef) || n.DictRef.Equals("nameDict:unknown"))
            {
                n.DictRef = "chem4word:Synonym";
            }

            n.Name = cmlElement.Value;

            return(n);
        }
示例#2
0
        public XElement GetXElement(ChemicalName name)
        {
            XElement result = new XElement(CML.cml + "name", name.Name);

            if (name.Id != null)
            {
                result.Add(new XAttribute("id", name.Id));
            }

            if (name.DictRef != null)
            {
                result.Add(new XAttribute("dictRef", name.DictRef));
            }

            return(result);
        }
示例#3
0
        private void OnAddNameClick(object sender, EventArgs e)
        {
            string module = $"{_product}.{_class}.{MethodBase.GetCurrentMethod().Name}()";

            Globals.Chem4WordV3.Telemetry.Write(module, "Action", "Triggered");

            try
            {
                ChemicalName n = new ChemicalName();
                n.DictRef = Constants.Chem4WordUserSynonym;
                n.Name    = "";
                n.Id      = $"{Molecule.Id}.n{++_maxNameId}";
                Molecule.ChemicalNames.Add(n);
                RefreshNamesPanel();
            }
            catch (Exception ex)
            {
                new ReportError(Globals.Chem4WordV3.Telemetry, Globals.Chem4WordV3.WordTopLeft, module, ex).ShowDialog();
            }
        }
示例#4
0
        public override SdfState ImportFromStream(StreamReader reader, Molecule molecule, out string message)
        {
            message   = null;
            _molecule = molecule;

            SdfState result = SdfState.Null;

            try
            {
                bool   isFormula    = false;
                string internalName = "";

                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();

                    if (!string.IsNullOrEmpty(line))
                    {
                        if (line.Equals(MDLConstants.SDF_END))
                        {
                            // End of SDF Section
                            result = SdfState.EndOfData;
                            break;
                        }

                        if (line.StartsWith(">"))
                        {
                            // Clear existing Property Name
                            internalName = string.Empty;

                            // See if we can find the property in our translation table
                            foreach (var property in _propertyTypes)
                            {
                                if (line.Equals(property.ExternalName))
                                {
                                    isFormula    = property.IsFormula;
                                    internalName = property.InternalName;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // Property Data
                            if (!string.IsNullOrEmpty(internalName))
                            {
                                if (isFormula)
                                {
                                    var formula = new Formula();
                                    formula.Convention = internalName;
                                    formula.Inline     = line;
                                    _molecule.Formulas.Add(formula);
                                }
                                else
                                {
                                    var name = new ChemicalName();
                                    name.DictRef = internalName;
                                    name.Name    = line;
                                    _molecule.ChemicalNames.Add(name);
                                }
                            }
                        }
                    }
                    else
                    {
                        internalName = string.Empty;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(ex.Message);
                result = SdfState.Error;
            }

            return(result);
        }