}//if we got any result

        public static void getImageProp(ICswResources CswResources, NodePropImageReturn Return, BlobDataParams Request)
        {
            CswNbtResources NbtResources = (CswNbtResources)CswResources;

            CswPropIdAttr PropIdAttr = new CswPropIdAttr(Request.propid);
            CswNbtNode    node       = NbtResources.Nodes[PropIdAttr.NodeId];

            if (null != node)
            {
                CswNbtMetaDataNodeType NodeType = node.getNodeType();
                CswNbtNodePropWrapper  prop     = node.Properties[PropIdAttr.NodeTypePropId];

                if (NbtResources.Permit.canNodeType(CswEnumNbtNodeTypePermission.View, NodeType, NbtResources.CurrentNbtUser))
                {
                    if (Int32.MinValue == prop.JctNodePropId)
                    {
                        prop.makePropRow(); //if we don't have a jct_node_prop row for this prop, we do now
                        node.postChanges(true);
                    }
                    prop.AsImage.SetImages(Request.date);
                    if (null != prop)
                    {
                        Return.Data = prop;
                    }
                }
                else
                {
                    throw new CswDniException(CswEnumErrorType.Warning, "You do not have sufficient priviledges to get this image property", "User " + NbtResources.CurrentNbtUser.UserId + " attempted to call getImageProp on prop " + prop.JctNodePropId);
                }
            }
        }
예제 #2
0
        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);
        }