Пример #1
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Padding

            ushort      volumeId       = requestStream.ReadUInt16();
            uint        sourceDirId    = requestStream.ReadUInt32();
            uint        destDirId      = requestStream.ReadUInt32();
            AfpPathType sourcePathType = requestStream.ReadEnum <AfpPathType>();
            string      sourcePathName = null;

            switch (sourcePathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                sourcePathName = requestStream.ReadPascalString();
                break;

            case AfpPathType.kFPUTF8Name:
                sourcePathName = requestStream.ReadUTF8StringWithHint();
                break;
            }

            AfpPathType destPathType = requestStream.ReadEnum <AfpPathType>();
            string      destPathName = null;

            switch (destPathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                destPathName = requestStream.ReadPascalString();
                break;

            case AfpPathType.kFPUTF8Name:
                destPathName = requestStream.ReadUTF8StringWithHint();
                break;
            }

            AfpPathType newPathType = requestStream.ReadEnum <AfpPathType>();
            string      newPathName = null;

            switch (newPathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                newPathName = requestStream.ReadPascalString();
                break;

            case AfpPathType.kFPUTF8Name:
                newPathName = requestStream.ReadUTF8StringWithHint();
                break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            IStorageContainer sourceContainer      = sourceDirId == 2 ? volume.StorageProvider : (IStorageContainer)volume.GetNode(sourceDirId);
            IStorageContainer destinationContainer = destDirId == 2 ? volume.StorageProvider : (IStorageContainer)volume.GetNode(destDirId);

            if (sourceContainer == null || destinationContainer == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IStorageItem sourceItem = null;

            if (!string.IsNullOrEmpty(destPathName))
            {
                destinationContainer = destinationContainer.Content(destPathName) as IStorageContainer;

                if (destinationContainer == null)
                {
                    return(AfpResultCode.FPObjectNotFound);
                }
            }

            if (!string.IsNullOrEmpty(sourcePathName))
            {
                sourceItem = sourceContainer.Content(sourcePathName);
            }
            else
            {
                sourceItem = sourceContainer;
            }

            if (sourceItem == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            if (string.IsNullOrEmpty(newPathName))
            {
                newPathName = sourceItem.Name;
            }

            if (destinationContainer.Content(newPathName) != null)
            {
                return(AfpResultCode.FPObjectExists);
            }

            sourceItem.Move(destinationContainer);
            sourceItem.Rename(newPathName);

            return(AfpResultCode.FPNoErr);
        }