Пример #1
0
        protected override RequestResponse <Result> DeserializeMessage(NameValueCollection responseHeaders, ResponseBodyStream data)
        {
            switch (data.OperationResult)
            {
            case OperationResult.Ok:
                break;

            default:
                throw new Exception($"{nameof(SharedFoldersListRequest)} failed with result code {data.OperationResult}");
            }


            var res = new Result
            {
                OperationResult = data.OperationResult,
                Container       = new Dictionary <string, FsFolder>()
            };


            //var z = data.ReadAllBytes();
            //
            var opres = data.OperationResult; //data.ReadShort();

            switch (opres)
            {
            case 0:
                long cnt = data.ReadPu32();
                for (long j = 0; j < cnt; j++)
                {
                    var    treeId   = data.ReadTreeId();
                    string fullPath = data.ReadString();
                    res.Container[fullPath] = new FsFolder(fullPath, treeId, CloudFolderType.Shared, null, 0);
                    data.ReadULong();
                }
                break;

            default:
                throw new Exception($"{nameof(SharedFoldersListRequest)}: Unknown parse operation {opres}");
            }

            return(new RequestResponse <Result>
            {
                Ok = data.OperationResult == OperationResult.Ok,
                Result = res
            });
        }
Пример #2
0
        private FsItem GetItem(ResponseBodyStream data, FsFolder folder)
        {
            FsItem item;
            TreeId treeId;

            int head = data.ReadIntSpl();

            if ((head & 4096) != 0)
            {
                byte[] nodeId = data.ReadNBytes(16);
            }
            string name = data.ReadNBytesAsString(data.ReadShort());

            data.ReadULong(); // dunno

            ulong?GetFolderSize() => (Options & Option.FolderSize) != 0
                ? (ulong?)data.ReadULong()
                : null;

            void ProcessDelete()
            {
                if ((Options & Option.Delete) != 0)
                {
                    data.ReadPu32();  // dunno
                    data.ReadPu32();  // dunno
                }
            }

            int opresult = head & 3;

            switch (opresult)
            {
            case 0:               // folder?
                treeId = data.ReadTreeId();
                data.ReadULong(); // dunno
                data.ReadULong(); // dunno
                ProcessDelete();

                item = new FsFolder(WebDavPath.Combine(folder.FullPath, name), treeId, CloudFolderType.MountPoint, folder, GetFolderSize());
                break;

            case 1:
                var    modifDate = data.ReadDate();
                ulong  size      = data.ReadULong();
                byte[] sha1      = data.ReadNBytes(20);

                //item = new FsFile(WebDavPath.Combine(folder.FullPath == string.Empty ? _fullPath : folder.FullPath, name), modifDate, sha1, size);
                item = new FsFile(WebDavPath.Combine(folder.FullPath, name), modifDate, sha1, size);
                break;

            case 2:
                data.ReadULong();     // dunno
                ProcessDelete();

                item = new FsFolder(WebDavPath.Combine(folder.FullPath, name), null, CloudFolderType.Generic, folder, GetFolderSize());
                break;

            case 3:
                data.ReadULong();     // dunno
                treeId = data.ReadTreeId();
                ProcessDelete();

                item = new FsFolder(WebDavPath.Combine(folder.FullPath, name), treeId, CloudFolderType.Shared, folder, GetFolderSize());
                break;

            default:
                throw new Exception("unknown opresult " + opresult);
            }

            return(item);
        }