Exemple #1
0
        public async Task PutDirectoryAsync(Profile profile, string directory, SharingHandler <ISharingDirectorySender> handler)
        {
            if (profile == null || handler == null || !(profile is NotifyClientProfile receiver))
            {
                throw new ArgumentNullException();
            }
            var directoryInfo = new DirectoryInfo(directory);

            if (!directoryInfo.Exists)
            {
                throw new DirectoryNotFoundException("Directory not found!");
            }
            var packet = new { name = directoryInfo.Name };

            _ = await this.network.ConnectAsync("link.sharing.directory", packet, receiver.GetTcpEndPoint(), async stream =>
            {
                var result = await stream.ReadBlockWithHeaderAsync(this.settings.TcpBufferLimits, this.cancellationToken);
                var data   = new Token(this.generator, result);
                if (data["status"].As <string>() != "wait")
                {
                    throw new NetworkException(NetworkError.InvalidData);
                }
                using (var sender = new DirectorySender(this.context, receiver, stream, directoryInfo.FullName))
                {
                    await this.dispatcher.InvokeAsync(() => handler.Invoke(sender));
                    await sender.LoopAsync();
                }
                return(new Unit());
            }, this.cancellationToken);
        }
Exemple #2
0
        public async Task SendDirectoryAsync(LinkProfile profile, string directoryPath, DirectorySenderHandler handler)
        {
            if (profile == null || handler == null)
            {
                throw new ArgumentNullException();
            }
            var directoryInfo = new DirectoryInfo(directoryPath);

            if (!directoryInfo.Exists)
            {
                throw new DirectoryNotFoundException("Directory not found!");
            }
            var packet = new { name = directoryInfo.Name };

            using (var tcp = await Network.ConnectAsync("link.share.directory", packet, profile.GetTcpEndPoint(), CancellationToken))
            {
                var stream = tcp.GetStream();
                var result = await stream.ReadBlockWithHeaderAsync(Environment.TcpBufferLimits, CancellationToken);

                var data = Generator.AsToken(result);
                if (data["status"].As <string>() != "wait")
                {
                    throw new LinkException(LinkError.InvalidData);
                }
                using (var sender = new DirectorySender(this, profile, stream, directoryInfo.FullName))
                {
                    await UpdateUIAsync(() => handler.Invoke(sender));

                    await sender.LoopAsync();
                }
            }
        }
Exemple #3
0
    public void imethod_12(string string_1)
    {
        DirectorySender class2 = this.safeDictionary_1.Get(string_1) as DirectorySender;

        if (class2 != null)
        {
            class2.method_5();
        }
    }
Exemple #4
0
    public void HnFdepcbbe(string string_1, ulong ulong_0, string string_2, ulong ulong_1)
    {
        TransferingProject project = this.imethod_2(string_1);

        if (project != null)
        {
            SendingFileParas paras = this.class3_0.imethod_0(project.AccepterID);
            int filePackageSize    = paras.FilePackageSize;
            int sendingSpanInMSecs = paras.SendingSpanInMSecs;
            if (project.method_0() != null)
            {
                filePackageSize    = project.method_0().FilePackageSize;
                sendingSpanInMSecs = project.method_0().SendingSpanInMSecs;
            }
            if (filePackageSize > (GlobalUtil.MaxLengthOfMessage - 100))
            {
                filePackageSize = GlobalUtil.MaxLengthOfMessage - 100;
            }
            IFileOutter interface2 = null;
            if (project.IsFolder)
            {
                interface2 = new DirectorySender(this.emptyAgileLogger_0, (IFilePackageHelper)this.object_0, project.OriginPath, project.AccepterID, string_2, ulong_0, ulong_1);
            }
            else if (project.OriginStream == null)
            {
                interface2 = new FileSender(this.emptyAgileLogger_0, (IFilePackageHelper)this.object_0, project.OriginPath, project.AccepterID, ulong_0);
            }
            else
            {
                interface2 = new Class22(this.emptyAgileLogger_0, (IFilePackageHelper)this.object_0, project.OriginPath, project.OriginStream, project.TotalSize, project.AccepterID);
            }
            interface2.imethod_9(filePackageSize);
            interface2.imethod_11(sendingSpanInMSecs);
            interface2.imethod_13(this.int_0);
            interface2.imethod_6(project.ProjectID);
            interface2.FileTransProgress   += new CbFileSendedProgress(this.method_8);
            interface2.FileTransCompleted  += new CbFileTransCompleted(this.method_9);
            interface2.FileTransDisruptted += new CbFileTransDisruptted(this.method_10);
            this.safeDictionary_1.Add(interface2.imethod_5(), interface2);
            if (ulong_0 == 0L)
            {
                this.FileTransStarted(project);
            }
            else
            {
                this.FileTransCompleted(project);
            }
            interface2.HnFdepcbbe(this.bool_0);
        }
    }