Пример #1
0
        public bool SetupBinaryClient()
        {
            ServerOnline = false;
            _clientBinaryHTTP = null;

            if (!SettingsAreValid()) return false;

            try
            {

                string url = string.Format(@"http://{0}:{1}/JMMServerBinary", AppSettings.JMMServer_Address, AppSettings.JMMServer_Port);

                BinaryMessageEncodingBindingElement encoding = new BinaryMessageEncodingBindingElement();
                encoding.ReaderQuotas.MaxArrayLength = int.MaxValue;
                encoding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                encoding.ReaderQuotas.MaxDepth = int.MaxValue;
                encoding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
                encoding.ReaderQuotas.MaxStringContentLength = int.MaxValue;

                HttpTransportBindingElement transport = new HttpTransportBindingElement();
                transport.MaxReceivedMessageSize = int.MaxValue;
                transport.MaxBufferPoolSize = int.MaxValue;
                transport.MaxBufferSize = int.MaxValue;
                transport.MaxReceivedMessageSize = int.MaxValue;

                Binding binding = new CustomBinding(encoding, transport);

                binding.SendTimeout = new TimeSpan(30, 0, 30);
                binding.ReceiveTimeout = new TimeSpan(30, 0, 30);
                binding.OpenTimeout = new TimeSpan(30, 0, 30);
                binding.CloseTimeout = new TimeSpan(30, 0, 30);

                EndpointAddress endpoint = new EndpointAddress(new Uri(url));

                var factory = new ChannelFactory<JMMServerBinary.IJMMServerChannel>(binding, endpoint);
                foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
                {
                    var dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>();
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                    }
                }

                _clientBinaryHTTP = factory.CreateChannel();

                // try connecting to see if the server is responding
                JMMServerBinary.Contract_ServerStatus status = JMMServerVM.Instance.clientBinaryHTTP.GetServerStatus();
                ServerOnline = true;

                GetServerSettings();

                return true;
            }
            catch (Exception ex)
            {
                logger.Trace("Unable to connect to JMM Server. Internal exception given: " + ex.Message);
                //Utils.ShowErrorMessage(ex);
                return false;
            }
        }
Пример #2
0
        public bool SetupBinaryClient()
        {
            ServerOnline      = false;
            _clientBinaryHTTP = null;
            ImportFolders.Clear();

            if (!SettingsAreValid())
            {
                return(false);
            }

            try
            {
                AnimePluginSettings settings = new AnimePluginSettings();
                string url = string.Format(@"http://{0}:{1}/JMMServerBinary", settings.JMMServer_Address, settings.JMMServer_Port);
                BaseConfig.MyAnimeLog.Write("JMM Server URL: " + url);

                BinaryMessageEncodingBindingElement encoding = new BinaryMessageEncodingBindingElement();
                encoding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
                encoding.ReaderQuotas.MaxBytesPerRead        = int.MaxValue;
                encoding.ReaderQuotas.MaxDepth               = int.MaxValue;
                encoding.ReaderQuotas.MaxNameTableCharCount  = int.MaxValue;
                encoding.ReaderQuotas.MaxStringContentLength = int.MaxValue;

                HttpTransportBindingElement transport = new HttpTransportBindingElement();
                transport.MaxReceivedMessageSize = int.MaxValue;
                transport.MaxBufferPoolSize      = int.MaxValue;
                transport.MaxBufferSize          = int.MaxValue;
                transport.MaxReceivedMessageSize = int.MaxValue;


                Binding binding = new CustomBinding(encoding, transport);

                binding.SendTimeout    = new TimeSpan(30, 0, 30);
                binding.ReceiveTimeout = new TimeSpan(30, 0, 30);
                binding.OpenTimeout    = new TimeSpan(30, 0, 30);
                binding.CloseTimeout   = new TimeSpan(30, 0, 30);

                EndpointAddress endpoint = new EndpointAddress(new Uri(url));

                var factory = new ChannelFactory <JMMServerBinary.IJMMServerChannel>(binding, endpoint);
                foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
                {
                    var dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>();
                    if (dataContractBehavior != null)
                    {
                        dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                    }
                }

                _clientBinaryHTTP = factory.CreateChannel();

                // try connecting to see if the server is responding
                JMMServerBinary.Contract_ServerStatus status = JMMServerVM.Instance.clientBinaryHTTP.GetServerStatus();
                ServerOnline = true;

                GetServerSettings();
                RefreshImportFolders();

                BaseConfig.MyAnimeLog.Write("JMM Server Status: " + status.GeneralQueueState);

                return(true);
            }
            catch (Exception ex)
            {
                //Utils.ShowErrorMessage(ex);
                BaseConfig.MyAnimeLog.Write(ex.ToString());
                return(false);
            }
        }