Exemple #1
0
        public int Read(String FileFullName, long Offset, int Count, ref Byte[] Buffer)
        {
            if (_ProtocolV2 == null)
            {
                throw new NFSConnectionException("NFS Client not connected!");
            }

            if (_MountProtocolV2 == null)
            {
                throw new NFSMountConnectionException("NFS Device not connected!");
            }

            int rCount = 0;

            if (Count == 0)
            {
                return(0);
            }


            if (_CurrentItem != FileFullName)
            {
                NFSAttributes Attributes = GetItemAttributes(FileFullName);
                _CurrentItemHandleObject = new NFSHandle(Attributes.Handle, V2.RPC.NFSv2Protocol.NFS_VERSION);
                _CurrentItem             = FileFullName;
            }

            ReadArguments dpArgRead = new ReadArguments();

            dpArgRead.File   = _CurrentItemHandleObject;
            dpArgRead.Offset = (int)Offset;
            dpArgRead.Count  = Count;

            ReadStatus pReadRes =
                _ProtocolV2.NFSPROC_READ(dpArgRead);

            if (pReadRes != null)
            {
                if (pReadRes.Status != NFSStats.NFS_OK)
                {
                    ExceptionHelpers.ThrowException(pReadRes.Status);
                }

                rCount = pReadRes.OK.Data.Length;

                Array.Copy(pReadRes.OK.Data, Buffer, rCount);
            }
            else
            {
                throw new NFSGeneralException("NFSPROC_READ: failure");
            }

            return(rCount);
        }
        /*
         * Handle read request from client
         */
        public (string, ImmutableVectorClock) OnReadRequest(ReadArguments arguments)
        {
            valueTimestamps.TryGetValue(arguments.PartitionId, out MutableVectorClock timestamp);
            lock (timestamp) {
                while (!(VectorClock.Equal(timestamp, arguments.Timestamp) ||
                         VectorClock.HappensAfter(timestamp, arguments.Timestamp)))
                {
                    Monitor.Wait(timestamp);
                }

                store.Read(arguments.PartitionId, arguments.ObjectId, out string value);

                return(value, timestamp.ToImmutable());
            }
        }
        public PipelineData Process(PipelineData Input)
        {
            RoutedPipelineStreamOptions Options = (RoutedPipelineStreamOptions)(Input.Options);
            Stream BaseStream = (Stream)Input.PrimaryData;

            switch (Options.Method)
            {
            case RoutedPipelineStreamMethod.READ:
            {
                ReadArguments readArguments = (ReadArguments)Input.SecondaryData;
                readArguments.Result = BaseStream.Read(readArguments.Buffer, readArguments.Offset, readArguments.Count);
            }
            break;

            case RoutedPipelineStreamMethod.SEEK:
            {
                SeekArguments seekArguments = (SeekArguments)Input.SecondaryData;
                seekArguments.Result = BaseStream.Seek(seekArguments.Offset, seekArguments.Origin);
            }
            break;

            case RoutedPipelineStreamMethod.SETLENGTH:
                BaseStream.SetLength((long)Input.SecondaryData);
                break;

            case RoutedPipelineStreamMethod.WRITE:
            {
                WriteArguments writeArguments = (WriteArguments)Input.SecondaryData;
                BaseStream.Write(writeArguments.Buffer, writeArguments.Offset, writeArguments.Count);
            }
            break;

            case RoutedPipelineStreamMethod.FLUSH:
            {
                BaseStream.Flush();
            }
            break;

            default:
                Trace.WriteLine("Unknown stream operation");
                break;
            }
            return(Input);
        }
 public string Read(ReadArguments arguments)
 {
     store.TryGet(arguments.PartitionId, arguments.ObjectId, out string value);
     return(value);
 }