Ejemplo n.º 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
            });
        }
Ejemplo n.º 2
0
        private FsItem Deserialize(ResponseBodyStream data, string fullPath)
        {
            fullPath = WebDavPath.Clean(fullPath);

            var      fakeRoot      = new FsFolder(WebDavPath.Parent(fullPath), null, CloudFolderType.Generic, null, null);
            FsFolder currentFolder = fakeRoot;
            FsFolder lastFolder    = null;
            int      lvl           = 0;

            var parseOp = (ParseOp)data.ReadShort();

            while (parseOp != ParseOp.Done)
            {
                switch (parseOp)
                {
                case ParseOp.ReadItem:
                    break;

                case ParseOp.Pin:
                    if (lastFolder != null)
                    {
                        currentFolder = lastFolder;
                        lvl++;
                        parseOp = (ParseOp)data.ReadShort();
                        continue;
                    }
                    else
                    {
                        throw new Exception("lastFolder = null");
                    }

                case ParseOp.PinUpper:
                    if (currentFolder == fakeRoot)
                    {
                        parseOp = (ParseOp)data.ReadShort();
                        continue;
                    }
                    else if (currentFolder.Parent != null)
                    {
                        currentFolder = currentFolder.Parent;
                        lvl--;
                        parseOp = (ParseOp)data.ReadShort();
                        if (currentFolder == null)
                        {
                            throw new Exception("No parent folder A");
                        }
                        continue;
                    }
                    else
                    {
                        throw new Exception("No parent folder B");
                    }

                case ParseOp.Unknown15:
                    long skip = data.ReadPu32();
                    for (long i = 0; i < skip; i++)
                    {
                        data.ReadPu32();
                        data.ReadPu32();
                    }
                    break;

                default:
                    throw new Exception("Unknown parse operation");
                }
                FsItem item = GetItem(data, currentFolder);
                currentFolder.Items.Add(item);

                if (item is FsFolder fsFolder)
                {
                    lastFolder = fsFolder;
                    fsFolder.IsChildsLoaded = lvl < Depth;
                }

                parseOp = (ParseOp)data.ReadShort();
            }

            var res = fakeRoot.Items[0];

            return(res);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        private FsItem Deserialize(ResponseBodyStream data, string fullPath)
        {
            var      fakeFolder    = new FsFolder(string.Empty, null, CloudFolderType.Generic, null, null);
            FsFolder currentFolder = fakeFolder;
            FsFolder lastFolder    = null;

            int itemStart = data.ReadShort();

            while (itemStart != 0)
            {
                switch (itemStart)
                {
                case 1:
                    break;

                case 2:
                    if (lastFolder != null)
                    {
                        currentFolder = lastFolder;
                        itemStart     = data.ReadShort();
                        continue;
                    }
                    else
                    {
                        throw new Exception("lastFolder = null");
                    }

                case 3:
                    if (currentFolder == fakeFolder)
                    {
                        itemStart = data.ReadShort();
                        continue;
                    }
                    else if (currentFolder.Parent != null)
                    {
                        currentFolder = currentFolder.Parent;
                        if (currentFolder == null)
                        {
                            throw new Exception("No parent folder");
                        }

                        continue;
                    }
                    else
                    {
                        throw new Exception("No parent folder");
                    }

                case 15:
                    var skip = data.ReadPu32();
                    for (int i = 0; i < skip; i++)
                    {
                        data.ReadPu32();
                        data.ReadPu32();
                    }
                    break;

                default:
                    throw new Exception("Unknown itemStart");
                }
                FsItem item = GetItem(data, currentFolder);
                currentFolder.Items.Add(item);

                if (item is FsFolder fsFolder)
                {
                    lastFolder = fsFolder;
                }

                itemStart = data.ReadShort();
            }

            var res = fakeFolder.Items[0];

            return(res);
        }