Exemple #1
0
        private bool Send()
        {
            byte[] data;

            if (SLClient == null ||
                DBSend == null ||
                !SLClient.Connected ||
                DBSend.IsAllRead ||
                !DBSend.Read(out data))
            {
                return(false);
            }


            byte[] result_data = TcpAsyncCommon.CreatePacket(data, PacketMode);// result.ToArray();

            if (result_data.IsNullOrEmpty())
            {
                return(false);
            }

            int sent = 0;
            int size = result_data.Length;

            SendTimeout.Reset();
            do
            {
                int packet = size - sent;
                if (packet > TcpAsyncServer.PacketSizeTCP)
                {
                    packet = TcpAsyncServer.PacketSizeTCP;
                }
                try
                {
                    sent += SLClient.Send(result_data, sent, packet, SocketFlags.None);
                    //Thread.Sleep(1);
                }
                catch (Exception ex)
                {
                    Exceptions.Write(ex);
                    this.StopClient();
                    return(false);
                }

                if (SendTimeout.IsTriggered)
                {
                    return(false);
                }
            }while (sent < size);

            return(true);
        }
        //
        // Without cancellation token
        //
        public async Task SetSocketOptionAsync(SocketOption option, ulong value)
        {
            var cts = new CancellationTokenSource(SendTimeout);

            try {
                await SetSocketOptionAsync(option, value, cts.Token).ConfigureAwait(false);
            }
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                throw new TimeoutException(
                          $"Timeout on send socket option after {SendTimeout.ToString()}.");
            }
        }
        //
        // Without cancellation token
        //
        public async Task CloseAsync()
        {
            var cts = new CancellationTokenSource(SendTimeout);

            try {
                await CloseAsync(cts.Token).ConfigureAwait(false);
            }
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                throw new TimeoutException(
                          $"Timeout on close socket after {SendTimeout.ToString()}.");
            }
        }
        public override int GetHashCode()
        {
            var hashCode = -1751588062;

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(IPAddress);

            hashCode = hashCode * -1521134295 + Port.GetHashCode();
            hashCode = hashCode * -1521134295 + SendTimeout.GetHashCode();
            hashCode = hashCode * -1521134295 + ReciveTimeout.GetHashCode();
            hashCode = hashCode * -1521134295 + SendBufferSize.GetHashCode();
            hashCode = hashCode * -1521134295 + ReciveBufferSize.GetHashCode();
            hashCode = hashCode * -1521134295 + PollingTimeout.GetHashCode();
            return(hashCode);
        }
Exemple #5
0
        public void Save([NotNull] XmlTextWriter output)
        {
            Assert.ArgumentNotNull(output, nameof(output));

            var blowFish          = new BlowFish(BlowFish.CipherKey);
            var encryptedPassword = blowFish.Encrypt_ECB(Password);

            output.WriteStartElement(@"binding");

            output.WriteAttributeString(@"hostName", HostName);
            output.WriteAttributeString(@"useWindowsAuth", UseWindowsAuth ? @"true" : @"false");
            output.WriteAttributeString(@"userName", UserName);
            output.WriteAttributeString(@"password", encryptedPassword);
            output.WriteAttributeString(@"dataService", DataServiceName);
            output.WriteAttributeString(@"webRootPath", WebRootPath);
            output.WriteAttributeString(@"description", Description);
            output.WriteAttributeString(@"isRemoteSitecore", IsRemoteSitecore ? @"true" : @"false");
            output.WriteAttributeString(@"automaticallyUpdate", AutomaticallyUpdate ? @"true" : @"false");
            output.WriteAttributeString(@"isHidden", IsHidden ? @"true" : @"false");

            output.WriteAttributeString(@"hostNameComparisonMode", HostNameComparisonMode.ToString());
            output.WriteAttributeString(@"receiveTimeout", ReceiveTimeout.ToString());
            output.WriteAttributeString(@"sendTimeout", SendTimeout.ToString());
            output.WriteAttributeString(@"openTimeout", OpenTimeout.ToString());
            output.WriteAttributeString(@"closeTimeout", CloseTimeout.ToString());
            output.WriteAttributeString(@"maxReceivedMessageSize", MaxReceivedMessageSize.ToString());
            output.WriteAttributeString(@"maxBufferSize", MaxBufferSize.ToString());
            output.WriteAttributeString(@"maxBufferPoolSize", MaxBufferPoolSize.ToString());
            output.WriteAttributeString(@"maxStringContentLength", MaxStringContentLength.ToString());
            output.WriteAttributeString(@"transferMode", TransferMode.ToString());
            output.WriteAttributeString(@"messageEncoding", MessageEncoding.ToString());
            output.WriteAttributeString(@"textEncoding", TextEncoding.WebName);
            output.WriteAttributeString(@"bypassProxyOnLocal", BypassProxyOnLocal ? @"true" : @"false");
            output.WriteAttributeString(@"useDefaultWebProxy", UseDefaultWebProxy ? @"true" : @"false");

            if (ProxyAddress != null)
            {
                output.WriteAttributeString(@"proxyAddress", ProxyAddress.ToString());
            }
            else
            {
                output.WriteAttributeString(@"proxyAddress", string.Empty);
            }

            output.WriteEndElement();
        }
        //
        // Without cancellation token
        //
        public async Task CloseAsync()
        {
            if (_cleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (!Connected)
            {
                return;
            }

            var cts = new CancellationTokenSource(SendTimeout);

            try {
                await CloseAsync(cts.Token).ConfigureAwait(false);
            }
            catch (OperationCanceledException) when(cts.IsCancellationRequested)
            {
                throw new TimeoutException(
                          $"Timeout on close socket after {SendTimeout.ToString()}.");
            }
        }