Exemple #1
0
        public void addSingleNodeProp(CswNbtNode Node, JObject PropObj, CswNbtMetaDataNodeTypeTab Tab)
        {
            CswPropIdAttr PropIdAttr = new CswPropIdAttr(CswConvert.ToString(PropObj["id"]));

            CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(PropIdAttr.NodeTypePropId);

            if (null != MetaDataProp)
            {
                CswNbtMetaDataNodeType NodeType = MetaDataProp.getNodeType();

                if (_CswNbtResources.Permit.canNodeType(Security.CswEnumNbtNodeTypePermission.Edit, NodeType) ||
                    _CswNbtResources.Permit.canTab(Security.CswEnumNbtNodeTypePermission.Edit, NodeType, Tab) ||
                    _CswNbtResources.Permit.isPropWritable(Security.CswEnumNbtNodeTypePermission.Edit, MetaDataProp, Tab))
                {
                    Node.Properties[MetaDataProp].ReadJSON(PropObj, null, null);

                    // Recurse on sub-props
                    if (null != PropObj["subprops"])
                    {
                        JObject SubPropsObj = (JObject)PropObj["subprops"];
                        if (SubPropsObj.HasValues)
                        {
                            foreach (JObject ChildPropObj in SubPropsObj.Properties()
                                     .Where(ChildProp => null != ChildProp.Value && ChildProp.Value.HasValues)
                                     .Select(ChildProp => (JObject)ChildProp.Value)
                                     .Where(ChildPropObj => ChildPropObj.HasValues))
                            {
                                addSingleNodeProp(Node, ChildPropObj, Tab);
                            }
                        }
                    }
                } //if user has permission to edit the property
            }     //if not null
        }         // addSingleNodeProp()
        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);
                }
            }
        }
        public int saveFile(string PropIdAttr, byte[] BlobData, string ContentType, string FileName, out string Href, int BlobDataId = Int32.MinValue, bool PostChanges = true, CswNbtNode Node = null)
        {
            CswPropIdAttr PropId = new CswPropIdAttr(PropIdAttr);

            CswNbtMetaDataNodeTypeProp MetaDataProp = _CswNbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId);

            if (null == Node)
            {
                Node = _CswNbtResources.Nodes[PropId.NodeId];
            }
            CswNbtNodePropWrapper FileProp = Node.Properties[MetaDataProp];

            if (_CswNbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.Edit, MetaDataProp.getNodeType(), _CswNbtResources.CurrentNbtUser) &&
                _CswNbtResources.Permit.isPropWritable(CswEnumNbtNodeTypePermission.Edit, MetaDataProp, null, FileProp))
            {
                if (Int32.MinValue == FileProp.JctNodePropId)
                {
                    FileProp.makePropRow(); //if we don't have a jct_node_prop row for this prop, we do now
                    if (PostChanges)
                    {
                        Node.postChanges(true);
                    }
                }

                if (FileProp.getFieldType().FieldType == CswEnumNbtFieldType.Image)
                {
                    //case 29692: support EXIF image rotation metadata to properly orient photos
                    bool         img_ok = false;
                    MemoryStream ms     = new MemoryStream(BlobData, 0, BlobData.Length);
                    ms.Write(BlobData, 0, BlobData.Length);
                    System.Drawing.Image img = null;

                    try
                    {
                        img    = Image.FromStream(ms, true);
                        img_ok = true;
                    }
                    catch
                    {
                    }

                    if (img_ok == true)
                    {
                        FixOrientation(ref img);
                        ImageConverter converter = new ImageConverter();
                        BlobData = (byte[])converter.ConvertTo(img, typeof(byte[]));
                    }
                }



                //Save the file to blob_data
                CswTableUpdate BlobUpdate  = _CswNbtResources.makeCswTableUpdate("saveBlob", "blob_data");
                string         whereClause = "where jctnodepropid = " + FileProp.JctNodePropId;
                if (Int32.MinValue != BlobDataId)
                {
                    whereClause += " and blobdataid = " + BlobDataId;
                }
                DataTable BlobTbl = BlobUpdate.getTable(whereClause);
                if (BlobTbl.Rows.Count > 0 &&
                    (Int32.MinValue != BlobDataId ||
                     FileProp.getFieldTypeValue() == CswEnumNbtFieldType.File ||
                     FileProp.getFieldTypeValue() == CswEnumNbtFieldType.MOL))
                {
                    BlobTbl.Rows[0]["blobdata"]    = BlobData;
                    BlobTbl.Rows[0]["contenttype"] = ContentType;
                    BlobTbl.Rows[0]["filename"]    = FileName;
                    BlobTbl.Rows[0]["auditlevel"]  = MetaDataProp.AuditLevel;
                    BlobDataId = CswConvert.ToInt32(BlobTbl.Rows[0]["blobdataid"]);
                }
                else
                {
                    DataRow NewRow = BlobTbl.NewRow();
                    NewRow["jctnodepropid"] = FileProp.JctNodePropId;
                    NewRow["blobdata"]      = BlobData;
                    NewRow["contenttype"]   = ContentType;
                    NewRow["filename"]      = FileName;
                    NewRow["auditlevel"]    = MetaDataProp.AuditLevel;
                    BlobDataId = CswConvert.ToInt32(NewRow["blobdataid"]);
                    BlobTbl.Rows.Add(NewRow);
                }
                BlobUpdate.update(BlobTbl);

                if (Node.getObjectClass().ObjectClass == CswEnumNbtObjectClass.ReportClass)
                {
                    CswNbtObjClassReport Report        = Node;
                    CswFilePath          FilePathTools = new CswFilePath(_CswNbtResources);
                    string ReportPath = FilePathTools.getFullReportFilePath(Report.RPTFile.JctNodePropId.ToString());
                    _createReportFile(ReportPath, Report.RPTFile.JctNodePropId, BlobData);
                }

                if (CswEnumNbtFieldType.File == FileProp.getFieldTypeValue())
                {
                    SetLastModified(FileProp);
                }

                FileProp.SyncGestalt();
                if (PostChanges)
                {
                    Node.postChanges(false);
                }

                Href = CswNbtNodePropBlob.getLink(FileProp.JctNodePropId, PropId.NodeId, BlobDataId);
            } //canNodeType() && isPropWritable()
            else
            {
                Href = string.Empty; //To satifsy the "ref string Href"
                throw new CswDniException(CswEnumErrorType.Error, "You do not have sufficient priveledges to save files", "User " + _CswNbtResources.CurrentNbtUser.UserId + " attemped to save blobdata on JctNodeProp " + FileProp.JctNodePropId);
            }
            return(BlobDataId);
        }
Exemple #4
0
        public JObject doObjectClassButtonClick(CswPropIdAttr PropId, string SelectedText, string TabIds, JObject PropsToSave, string NodeIds, string PropIds)
        {
            JObject RetObj = new JObject();

            if (null == PropId ||
                Int32.MinValue == PropId.NodeTypePropId ||
                null == PropId.NodeId ||
                Int32.MinValue == PropId.NodeId.PrimaryKey)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot execute a button click without valid parameters.", "Attempted to call DoObjectClassButtonClick with invalid NodeId and NodeTypePropId.");
            }

            CswNbtNode Node = _CswNbtResources.Nodes.GetNode(PropId.NodeId);

            if (null == Node)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot find a valid node with the provided parameters.", "No node exists for NodePk " + PropId.NodeId.ToString() + ".");
            }

            CswNbtMetaDataNodeTypeProp NodeTypeProp = _CswNbtResources.MetaData.getNodeTypeProp(PropId.NodeTypePropId);

            if (null == NodeTypeProp)
            {
                throw new CswDniException(CswEnumErrorType.Error, "Cannot find a valid property with the provided parameters.", "No property exists for NodeTypePropId " + PropId.NodeTypePropId.ToString() + ".");
            }

            CswNbtObjClass NbtObjClass = CswNbtObjClassFactory.makeObjClass(_CswNbtResources, Node.getObjectClassId(), Node);

            CswCommaDelimitedString TabIdsCDS = new CswCommaDelimitedString();

            TabIdsCDS.FromString(TabIds);
            CswNbtObjClass.NbtButtonData ButtonData = new CswNbtObjClass.NbtButtonData(NodeTypeProp)
            {
                SelectedText = SelectedText,
                PropsToSave  = PropsToSave,
                TabIds       = TabIdsCDS,
                NodeIds      = new CswCommaDelimitedString(),
                PropIds      = new CswCommaDelimitedString()
            };
            ButtonData.NodeIds.FromString(NodeIds);
            ButtonData.PropIds.FromString(PropIds);

            bool Success = NbtObjClass.triggerOnButtonClick(ButtonData);

            if (null == ButtonData.Action || ButtonData.Action == CswEnumNbtButtonAction.Unknown)
            {
                ButtonData.Action = CswEnumNbtButtonAction.nothing;
            }
            if (Node.NodeId == _CswNbtResources.CurrentNbtUser.UserId)
            {
                RetObj["updateDefaults"] = true;
            }
            RetObj["action"]     = ButtonData.Action.ToString();
            RetObj["actionData"] = ButtonData.Data;  //e.g. popup url
            RetObj["message"]    = ButtonData.Message;
            RetObj["tabids"]     = ButtonData.TabIds.ToString();
            RetObj["savedprops"] = ButtonData.PropsToReturn;
            RetObj["success"]    = Success.ToString().ToLower();

            return(RetObj);
        }