Ejemplo n.º 1
0
        public static bool GetProcessedFileNode(
            WebServiceBaseTimeoutable _Request,
            ENodeType _FileType,
            IBDatabaseServiceInterface _DatabaseService,
            IBFileServiceInterface _FileService,
            string _CadFileStorageBucketName,
            string _ModelID,
            int _RevisionIndex,
            bool _bRootNodeRequested, ulong _NodeID,
            out BWebServiceResponse _SuccessResponse,
            out BWebServiceResponse _FailureResponse,
            Action <string> _ErrorMessageAction = null)
        {
            _SuccessResponse = BWebResponse.InternalError("");

            uint StartIndex = 0, Size = 0;

            if (!_bRootNodeRequested)
            {
                Convert.UniqueIDToStartIndexAndSize(_NodeID, out StartIndex, out Size);
                if (StartIndex == 0 || Size == 0)
                {
                    _FailureResponse = BWebResponse.BadRequest("Invalid Node ID.");
                    return(false);
                }
            }

            if (!Controller_AtomicDBOperation.Get().GetClearanceForDBOperation(_Request.InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), _ModelID, _ErrorMessageAction))
            {
                _FailureResponse = BWebResponse.InternalError("Atomic operation control has failed.");
                return(false);
            }

            var bResult = GetProcessedFileNode_Internal(
                _FileType,
                _DatabaseService,
                _FileService,
                _CadFileStorageBucketName,
                _ModelID,
                _RevisionIndex,
                _bRootNodeRequested,
                StartIndex,
                Size,
                out _SuccessResponse,
                out _FailureResponse,
                _ErrorMessageAction);

            Controller_AtomicDBOperation.Get().SetClearanceForDBOperationForOthers(_Request.InnerProcessor, ModelDBEntry.DBSERVICE_MODELS_TABLE(), _ModelID, _ErrorMessageAction);

            return(bResult);
        }
Ejemplo n.º 2
0
        private static bool GetProcessedFileNode_Internal(
            ENodeType _FileType,
            IBDatabaseServiceInterface _DatabaseService,
            IBFileServiceInterface _FileService,
            string _CadFileStorageBucketName,
            string _ModelID,
            int _RevisionIndex,
            bool _bRootNodeRequested, uint _NodeStartIndex, uint _NodeSize,
            out BWebServiceResponse _SuccessResponse,
            out BWebServiceResponse _FailureResponse,
            Action <string> _ErrorMessageAction = null)
        {
            _SuccessResponse = BWebResponse.InternalError("");

            if (!TryGettingAllInfo(
                    _DatabaseService,
                    _ModelID,
                    _RevisionIndex,
                    out ModelDBEntry ModelObject,
                    out Revision RevisionObject,
                    out int _,
                    out _FailureResponse,
                    _ErrorMessageAction))
            {
                return(false);
            }

            if (RevisionObject.FileEntry.FileProcessStage != (int)Constants.EProcessStage.Uploaded_Processed)
            {
                _FailureResponse = BWebResponse.NotFound("Raw file has not been processed yet.");
                return(false);
            }

            if (_bRootNodeRequested)
            {
                Convert.UniqueIDToStartIndexAndSize(RevisionObject.FileEntry.ProcessedFilesRootNodeID, out _NodeStartIndex, out _NodeSize);
                if (_NodeStartIndex == 0 || _NodeSize == 0)
                {
                    _FailureResponse = BWebResponse.InternalError("Invalid Root Node ID.");
                    return(false);
                }
            }

            string RelativeFileUrl = null;

            switch (_FileType)
            {
            case ENodeType.Hierarchy:
                RelativeFileUrl = RevisionObject.FileEntry.HierarchyRAFRelativeUrl;
                break;

            case ENodeType.Geometry:
                RelativeFileUrl = RevisionObject.FileEntry.GeometryRAFRelativeUrl;
                break;

            case ENodeType.Metadata:
                RelativeFileUrl = RevisionObject.FileEntry.MetadataRAFRelativeUrl;
                break;
            }

            Node RetrievedNode;

            var Buffer = new byte[_NodeSize];

            try
            {
                using (var MemStream = new MemoryStream((int)_NodeStartIndex))
                {
                    var Destination = new BStringOrStream(MemStream, _NodeSize);

                    if (!_FileService.DownloadFile(_CadFileStorageBucketName, RelativeFileUrl, Destination, _ErrorMessageAction, _NodeStartIndex, _NodeSize))
                    {
                        _ErrorMessageAction?.Invoke("DownloadFile has failed in GetProcessedFileNode_Internal. ModelID: " + _ModelID + ", RevisionIndex: " + _RevisionIndex + ", NodeStartIndex: " + _NodeStartIndex + ", NodeSize: " + _NodeSize);
                        _FailureResponse = BWebResponse.NotFound("Given Node ID does not exist.");
                        return(false);
                    }

                    MemStream.Seek(0, SeekOrigin.Begin);
                    if (MemStream.Read(Buffer, 0, (int)_NodeSize) < (int)_NodeSize)
                    {
                        _FailureResponse = BWebResponse.InternalError("Stream read operation has failed.");
                        return(false);
                    }

                    Convert.BufferToNode(out RetrievedNode, _FileType, Buffer, 0);
                }
            }
            catch (Exception e)
            {
                _ErrorMessageAction?.Invoke("File random access/stream operations have failed. ModelID: " + _ModelID + ", RevisionIndex: " + _RevisionIndex + ", NodeStartIndex: " + _NodeStartIndex + ", NodeSize: " + _NodeSize + ", Message: " + e.Message + ", Trace: " + e.StackTrace);
                _FailureResponse = BWebResponse.NotFound("Given Node ID does not exist.");
                return(false);
            }

            if (RetrievedNode == null)
            {
                _FailureResponse = BWebResponse.InternalError("File node parse operation has failed.");
                return(false);
            }

            _SuccessResponse = BWebResponse.StatusOK("Node has been located.", new JObject()
            {
                ["node"] = JObject.Parse(JsonConvert.SerializeObject(RetrievedNode))
            });
            return(true);
        }