Ejemplo n.º 1
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Padding

            ushort      volumeId    = requestStream.ReadUInt16();
            uint        directoryId = requestStream.ReadUInt32();
            AfpPathType pathType    = requestStream.ReadEnum <AfpPathType>();
            string      pathName    = null;

            switch (pathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                pathName = requestStream.ReadPascalString();
                break;

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

            AfpPathType newNameType = requestStream.ReadEnum <AfpPathType>();
            string      newName     = null;

            switch (newNameType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                newName = requestStream.ReadPascalString();
                break;

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

            IAfpVolume volume = session.GetVolume(volumeId);

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

            IStorageContainer container = null;

            if (directoryId == 2)
            {
                container = volume.StorageProvider;
            }
            else
            {
                container = (volume.GetNode(directoryId) as IStorageContainer);
            }

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

            IStorageItem renameItem = container.Content(pathName);

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

            renameItem.Rename(newName);

            return(AfpResultCode.FPNoErr);
        }
Ejemplo n.º 2
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);
        }