public static void getMolImg(ICswResources CswResources, MolDataReturn Return, MolData ImgData)
        {
            string molData      = ImgData.molString;
            string nodeId       = ImgData.nodeId;
            string base64String = "";

            CswNbtResources NbtResources = (CswNbtResources)CswResources;

            if (String.IsNullOrEmpty(molData) && false == String.IsNullOrEmpty(nodeId))      //if we only have a nodeid, get the mol text from the mol property if there is one
            {
                CswPrimaryKey pk   = CswConvert.ToPrimaryKey(nodeId);
                CswNbtNode    node = NbtResources.Nodes[pk];
                CswNbtMetaDataNodeTypeProp molNTP = node.getNodeType().getMolProperty();
                if (null != molNTP)
                {
                    molData = node.Properties[molNTP].AsMol.getMol();
                }
            }

            if (false == String.IsNullOrEmpty(molData))
            {
                //If the Direct Structure Search module is enabled, use the AcclDirect methods to generate an image. Otherwise, use the legacy code.
                byte[] bytes =
                    (NbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.DirectStructureSearch) ?
                     NbtResources.AcclDirect.GetImage(molData) :
                     CswStructureSearch.GetImage(molData));

                base64String = Convert.ToBase64String(bytes);
            }

            ImgData.molImgAsBase64String = base64String;
            ImgData.molString            = molData;
            Return.Data = ImgData;
        }
Example #2
0
        public void saveMol(string MolString, string PropId, out string Href, out string FormattedMolString, out string errorMsg, bool PostChanges = true, CswNbtNode Node = null)
        {
            CswPropIdAttr PropIdAttr = new CswPropIdAttr(PropId);
            CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(PropIdAttr.NodeTypePropId);

            //Case 29769 - enforce correct mol file format
            FormattedMolString = MoleculeBuilder.FormatMolFile(MolString);

            errorMsg = string.Empty;
            Href     = string.Empty;
            if (null == Node)
            {
                Node = _CswNbtResources.Nodes[PropIdAttr.NodeId];
            }
            if (null != Node)
            {
                CswNbtNodePropMol molProp = Node.Properties[MetaDataProp];
                if (null != molProp)
                {
                    molProp.setMol(FormattedMolString);

                    //If DirectStructureSearch is enabled, use the new code to generate an image. Otherwise, use the legacy code.
                    byte[] molImage =
                        (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.DirectStructureSearch) ?
                         _CswNbtResources.AcclDirect.GetImage(FormattedMolString) :
                         CswStructureSearch.GetImage(FormattedMolString));

                    CswNbtSdBlobData SdBlobData = new CswNbtSdBlobData(_CswNbtResources);
                    Href = CswNbtNodePropMol.getLink(molProp.JctNodePropId, Node.NodeId);

                    //Save the mol image to blob_data
                    SdBlobData.saveFile(PropId, molImage, CswNbtNodePropMol.MolImgFileContentType, CswNbtNodePropMol.MolImgFileName, out Href, Int32.MinValue, PostChanges, Node: Node);

                    //case 28364 - calculate fingerprint and save it
                    _CswNbtResources.StructureSearchManager.InsertFingerprintRecord(PropIdAttr.NodeId.PrimaryKey, FormattedMolString, out errorMsg);
                }
            }
        }